@credal/actions 0.1.0 → 0.1.1

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.
@@ -14,6 +14,7 @@ const listConversations_1 = __importDefault(require("./providers/slack/listConve
14
14
  const sendMessage_1 = __importDefault(require("./providers/slack/sendMessage"));
15
15
  const getRowByFieldValue_1 = __importDefault(require("./providers/snowflake/getRowByFieldValue"));
16
16
  const createZendeskTicket_1 = __importDefault(require("./providers/zendesk/createZendeskTicket"));
17
+ const createJiraTicket_1 = __importDefault(require("./providers/jira/createJiraTicket"));
17
18
  exports.ActionMapper = {
18
19
  math: {
19
20
  add: {
@@ -76,4 +77,11 @@ exports.ActionMapper = {
76
77
  outputSchema: types_1.snowflakeGetRowByFieldValueOutputSchema,
77
78
  },
78
79
  },
80
+ jira: {
81
+ createJiraTicket: {
82
+ fn: createJiraTicket_1.default,
83
+ paramsSchema: types_1.jiraCreateJiraTicketParamsSchema,
84
+ outputSchema: types_1.jiraCreateJiraTicketOutputSchema,
85
+ },
86
+ },
79
87
  };
@@ -145,12 +145,26 @@ exports.jiraCreateJiraTicketDefinition = {
145
145
  type: "string",
146
146
  description: "The reporter for the new ticket creation",
147
147
  },
148
+ assignee: {
149
+ type: "string",
150
+ description: "The assignee for the new ticket creation",
151
+ },
148
152
  username: {
149
153
  type: "string",
150
154
  description: "The username of the person creating the ticket",
151
155
  },
152
156
  },
153
157
  },
158
+ output: {
159
+ type: "object",
160
+ required: ["ticketUrl"],
161
+ properties: {
162
+ ticketUrl: {
163
+ type: "string",
164
+ description: "The url to the created Jira Ticket",
165
+ },
166
+ },
167
+ },
154
168
  name: "createJiraTicket",
155
169
  provider: "jira",
156
170
  };
@@ -113,6 +113,7 @@ export declare const jiraCreateJiraTicketParamsSchema: z.ZodObject<{
113
113
  description: z.ZodString;
114
114
  issueType: z.ZodString;
115
115
  reporter: z.ZodOptional<z.ZodString>;
116
+ assignee: z.ZodOptional<z.ZodString>;
116
117
  username: z.ZodString;
117
118
  }, "strip", z.ZodTypeAny, {
118
119
  description: string;
@@ -121,6 +122,7 @@ export declare const jiraCreateJiraTicketParamsSchema: z.ZodObject<{
121
122
  summary: string;
122
123
  issueType: string;
123
124
  reporter?: string | undefined;
125
+ assignee?: string | undefined;
124
126
  }, {
125
127
  description: string;
126
128
  username: string;
@@ -128,9 +130,16 @@ export declare const jiraCreateJiraTicketParamsSchema: z.ZodObject<{
128
130
  summary: string;
129
131
  issueType: string;
130
132
  reporter?: string | undefined;
133
+ assignee?: string | undefined;
131
134
  }>;
132
135
  export type jiraCreateJiraTicketParamsType = z.infer<typeof jiraCreateJiraTicketParamsSchema>;
133
- export declare const jiraCreateJiraTicketOutputSchema: z.ZodVoid;
136
+ export declare const jiraCreateJiraTicketOutputSchema: z.ZodObject<{
137
+ ticketUrl: z.ZodString;
138
+ }, "strip", z.ZodTypeAny, {
139
+ ticketUrl: string;
140
+ }, {
141
+ ticketUrl: string;
142
+ }>;
134
143
  export type jiraCreateJiraTicketOutputType = z.infer<typeof jiraCreateJiraTicketOutputSchema>;
135
144
  export type jiraCreateJiraTicketFunction = ActionFunction<jiraCreateJiraTicketParamsType, AuthParamsType, jiraCreateJiraTicketOutputType>;
136
145
  export declare const googlemapsValidateAddressParamsSchema: z.ZodObject<{
@@ -43,9 +43,12 @@ exports.jiraCreateJiraTicketParamsSchema = zod_1.z.object({
43
43
  description: zod_1.z.string().describe("The description for the new ticket"),
44
44
  issueType: zod_1.z.string().describe("The issue type of the new ticket"),
45
45
  reporter: zod_1.z.string().describe("The reporter for the new ticket creation").optional(),
46
+ assignee: zod_1.z.string().describe("The assignee for the new ticket creation").optional(),
46
47
  username: zod_1.z.string().describe("The username of the person creating the ticket"),
47
48
  });
48
- exports.jiraCreateJiraTicketOutputSchema = zod_1.z.void();
49
+ exports.jiraCreateJiraTicketOutputSchema = zod_1.z.object({
50
+ ticketUrl: zod_1.z.string().describe("The url to the created Jira Ticket"),
51
+ });
49
52
  exports.googlemapsValidateAddressParamsSchema = zod_1.z.object({
50
53
  regionCode: zod_1.z.string().describe("The country of the address being verified."),
51
54
  locality: zod_1.z.string().describe("The locality of the address being verified. This is likely a city."),
@@ -1,3 +1,3 @@
1
1
  import { jiraCreateJiraTicketFunction } from "../../autogen/types";
2
- declare const createTicket: jiraCreateJiraTicketFunction;
3
- export default createTicket;
2
+ declare const createJiraTicket: jiraCreateJiraTicketFunction;
3
+ export default createJiraTicket;
@@ -13,15 +13,63 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const axios_1 = __importDefault(require("axios"));
16
- const createTicket = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, authParams, }) {
16
+ function getUserAccountId(email, baseUrl, authToken, username) {
17
+ return __awaiter(this, void 0, void 0, function* () {
18
+ try {
19
+ const response = yield axios_1.default.get(`${baseUrl}/rest/api/3/user/search?query=${encodeURIComponent(email)}`, {
20
+ headers: {
21
+ Authorization: `Basic ${Buffer.from(`${username}:${authToken}`).toString("base64")}`,
22
+ "Content-Type": "application/json",
23
+ },
24
+ });
25
+ if (response.data && response.data.length > 0) {
26
+ return response.data[0].accountId;
27
+ }
28
+ return null;
29
+ }
30
+ catch (error) {
31
+ const axiosError = error;
32
+ console.error("Error finding user:", axiosError.message);
33
+ return null;
34
+ }
35
+ });
36
+ }
37
+ const createJiraTicket = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, authParams, }) {
17
38
  const { authToken, baseUrl } = authParams;
18
39
  const url = `${baseUrl}/rest/api/3/issue`;
40
+ // If assignee is an email, look up the account ID
41
+ let reporterId = null;
42
+ if (params.reporter && typeof params.reporter === "string" && params.reporter.includes("@") && baseUrl && authToken) {
43
+ reporterId = yield getUserAccountId(params.reporter, baseUrl, authToken, params.username);
44
+ }
45
+ // If assignee is an email, look up the account ID
46
+ let assigneeId = null;
47
+ if (params.assignee && typeof params.assignee === "string" && params.assignee.includes("@") && baseUrl && authToken) {
48
+ assigneeId = yield getUserAccountId(params.assignee, baseUrl, authToken, params.username);
49
+ }
50
+ const description = typeof params.description === "string"
51
+ ? {
52
+ type: "doc",
53
+ version: 1,
54
+ content: [
55
+ {
56
+ type: "paragraph",
57
+ content: [
58
+ {
59
+ type: "text",
60
+ text: params.description,
61
+ },
62
+ ],
63
+ },
64
+ ],
65
+ }
66
+ : params.description;
19
67
  const payload = {
20
- fields: Object.assign({ project: {
68
+ fields: Object.assign(Object.assign({ project: {
21
69
  key: params.projectKey,
22
- }, summary: params.summary, description: params.description, issuetype: {
70
+ }, summary: params.summary, description: description, issuetype: {
23
71
  name: params.issueType,
24
- } }, (params.reporter ? { reporter: { id: params.reporter } } : {})),
72
+ } }, (reporterId ? { reporter: { id: reporterId } } : {})), (assigneeId ? { assignee: { id: assigneeId } } : {})),
25
73
  };
26
74
  const response = yield axios_1.default.post(url, payload, {
27
75
  headers: {
@@ -29,6 +77,9 @@ const createTicket = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params
29
77
  "Content-Type": "application/json",
30
78
  },
31
79
  });
32
- return response.data;
80
+ // At the end of your function, wrap the response
81
+ return {
82
+ ticketUrl: `${baseUrl}/browse/${response.data.key}`,
83
+ };
33
84
  });
34
- exports.default = createTicket;
85
+ exports.default = createJiraTicket;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@credal/actions",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "AI Actions by Credal AI",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,5 +0,0 @@
1
- import { ActionTemplate } from "@/actions/parse";
2
- export declare const slackSendMessageDefinition: ActionTemplate;
3
- export declare const slackListConversationsDefinition: ActionTemplate;
4
- export declare const mathAddDefinition: ActionTemplate;
5
- export declare const confluenceUpdatePageDefinition: ActionTemplate;
@@ -1,132 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.confluenceUpdatePageDefinition = exports.mathAddDefinition = exports.slackListConversationsDefinition = exports.slackSendMessageDefinition = void 0;
4
- exports.slackSendMessageDefinition = {
5
- provider: "slack",
6
- name: "send_message",
7
- description: "Sends a message to a Slack channel",
8
- scopes: ["chat:write"],
9
- parameters: {
10
- channel: {
11
- type: "string",
12
- description: "The Slack channel to send the message to (e.g., \\#general, \\#alerts)",
13
- required: true,
14
- },
15
- message: {
16
- type: "string",
17
- description: "The message content to send to Slack. Can include markdown formatting.",
18
- required: true,
19
- },
20
- },
21
- output: {},
22
- };
23
- exports.slackListConversationsDefinition = {
24
- provider: "slack",
25
- name: "list_conversations",
26
- description: "Lists all conversations in a Slack workspace",
27
- scopes: ["channels:read", "groups:read", "im:read", "mpim:read"],
28
- authToken: {
29
- type: "string",
30
- description: "The Slack access token to use",
31
- required: true,
32
- },
33
- parameters: {},
34
- output: {
35
- channels: {
36
- type: "array",
37
- description: "A list of channels in Slack",
38
- required: true,
39
- items: {
40
- type: "object",
41
- description: "A channel in Slack",
42
- required: true,
43
- properties: {
44
- id: {
45
- type: "string",
46
- description: "The ID of the channel",
47
- required: true,
48
- },
49
- name: {
50
- type: "string",
51
- description: "The name of the channel",
52
- required: true,
53
- },
54
- topic: {
55
- type: "string",
56
- description: "The topic of the channel",
57
- required: true,
58
- },
59
- purpose: {
60
- type: "string",
61
- description: "The purpose of the channel",
62
- required: true,
63
- },
64
- },
65
- },
66
- },
67
- },
68
- };
69
- exports.mathAddDefinition = {
70
- provider: "math",
71
- name: "add",
72
- description: "Adds two numbers together",
73
- scopes: [],
74
- parameters: {
75
- a: {
76
- type: "number",
77
- description: "The first number to add",
78
- required: true,
79
- },
80
- b: {
81
- type: "number",
82
- description: "The second number to add",
83
- required: true,
84
- },
85
- },
86
- output: {
87
- result: {
88
- type: "number",
89
- description: "The sum of the two numbers",
90
- required: true,
91
- },
92
- },
93
- };
94
- exports.confluenceUpdatePageDefinition = {
95
- provider: "confluence",
96
- name: "updatePage",
97
- description: "Updates a confluence page with the new content specified",
98
- scopes: [],
99
- authToken: {
100
- type: "string",
101
- description: "The access token to use for confluence",
102
- required: true,
103
- },
104
- baseUrl: {
105
- type: "string",
106
- description: "The base url required to access the confluence instance",
107
- required: true,
108
- },
109
- parameters: {
110
- pageId: {
111
- type: "string",
112
- description: "The page id that should be updated",
113
- required: true,
114
- },
115
- title: {
116
- type: "string",
117
- description: "The title of the page that should be updated",
118
- required: true,
119
- },
120
- username: {
121
- type: "string",
122
- description: "The username of the person updating the page",
123
- required: true,
124
- },
125
- content: {
126
- type: "string",
127
- description: "The new content for the page",
128
- required: true,
129
- },
130
- },
131
- output: {},
132
- };
@@ -1,35 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mathAddDefinition = exports.slackSendMessageDefinition = void 0;
4
- exports.slackSendMessageDefinition = {
5
- name: "send_message",
6
- description: "Sends a message to a Slack channel",
7
- parameters: {
8
- "channel": {
9
- "type": "string",
10
- "description": "The Slack channel to send the message to (e.g., \\#general, \\#alerts)",
11
- "required": true
12
- },
13
- "message": {
14
- "type": "string",
15
- "description": "The message content to send to Slack. Can include markdown formatting.",
16
- "required": true
17
- }
18
- }
19
- };
20
- exports.mathAddDefinition = {
21
- name: "add",
22
- description: "Adds two numbers together",
23
- parameters: {
24
- "a": {
25
- "type": "number",
26
- "description": "The first number to add",
27
- "required": true
28
- },
29
- "b": {
30
- "type": "number",
31
- "description": "The second number to add",
32
- "required": true
33
- }
34
- }
35
- };
@@ -1,9 +0,0 @@
1
- import { type ActionFunction } from "./autogen/types";
2
- import { z } from "zod";
3
- interface ActionFunctionComponents {
4
- fn: ActionFunction<any, any, any>;
5
- paramsSchema: z.ZodSchema;
6
- outputSchema: z.ZodSchema;
7
- }
8
- export declare const FunctionMapper: Record<string, Record<string, ActionFunctionComponents>>;
9
- export {};
@@ -1,33 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.FunctionMapper = void 0;
7
- const add_1 = __importDefault(require("./providers/math/add"));
8
- const list_conversations_1 = __importDefault(require("./providers/slack/list_conversations"));
9
- const updatePage_1 = __importDefault(require("./providers/confluence/updatePage"));
10
- const types_1 = require("./autogen/types");
11
- exports.FunctionMapper = {
12
- math: {
13
- add: {
14
- fn: add_1.default,
15
- paramsSchema: types_1.mathAddParamsSchema,
16
- outputSchema: types_1.mathAddOutputSchema,
17
- },
18
- },
19
- slack: {
20
- listConversations: {
21
- fn: list_conversations_1.default,
22
- paramsSchema: types_1.slackListConversationsParamsSchema,
23
- outputSchema: types_1.slackListConversationsOutputSchema,
24
- },
25
- },
26
- confluence: {
27
- updatePage: {
28
- fn: updatePage_1.default,
29
- paramsSchema: types_1.confluenceUpdatePageParamsSchema,
30
- outputSchema: types_1.confluenceUpdatePageOutputSchema,
31
- },
32
- },
33
- };
@@ -1,3 +0,0 @@
1
- import { jiraCreateTicketFunction } from "../../autogen/types";
2
- declare const createTicket: jiraCreateTicketFunction;
3
- export default createTicket;
@@ -1,34 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- const axios_1 = __importDefault(require("axios"));
16
- const createTicket = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, authParams, }) {
17
- const { authToken, baseUrl } = authParams;
18
- const url = `${baseUrl}/rest/api/3/issue`;
19
- const payload = {
20
- fields: Object.assign({ project: {
21
- key: params.projectKey,
22
- }, summary: params.summary, description: params.description, issuetype: {
23
- name: params.issueType,
24
- } }, (params.reporter ? { reporter: { id: params.reporter } } : {})),
25
- };
26
- const response = yield axios_1.default.post(url, payload, {
27
- headers: {
28
- Authorization: `Basic ${Buffer.from(`${params.username}:${authToken}`).toString("base64")}`,
29
- "Content-Type": "application/json",
30
- },
31
- });
32
- return response.data;
33
- });
34
- exports.default = createTicket;
@@ -1,3 +0,0 @@
1
- import { slackListConversationsFunction } from "../../../actions/autogen/types";
2
- declare const slackListConversations: slackListConversationsFunction;
3
- export default slackListConversations;
@@ -1,60 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- const web_api_1 = require("@slack/web-api");
13
- const slackListConversations = (_a) => __awaiter(void 0, [_a], void 0, function* ({ authParams, }) {
14
- var _b;
15
- const client = new web_api_1.WebClient(authParams.authToken);
16
- const allChannels = [];
17
- let cursor;
18
- const limit = 100;
19
- try {
20
- do {
21
- const response = yield client.conversations.list({
22
- exclude_archived: true,
23
- limit: limit,
24
- cursor: cursor,
25
- });
26
- if (!response.ok) {
27
- throw new Error(`Slack API error: ${response.error}`);
28
- }
29
- // Add channels from this page to our results
30
- if (response.channels && Array.isArray(response.channels)) {
31
- allChannels.push(...response.channels);
32
- }
33
- // Get cursor for next page
34
- cursor = (_b = response.response_metadata) === null || _b === void 0 ? void 0 : _b.next_cursor;
35
- // If user specified a limit and we've hit it, stop paginating
36
- if (limit && allChannels.length >= limit) {
37
- allChannels.splice(limit); // Trim to exact limit
38
- break;
39
- }
40
- } while (cursor && cursor.length > 0);
41
- return {
42
- channels: allChannels.map(channel => ({
43
- id: channel.id,
44
- name: channel.name,
45
- topic: channel.topic.value,
46
- purpose: channel.purpose.value,
47
- })),
48
- };
49
- }
50
- catch (error) {
51
- if (error instanceof Error) {
52
- // Enhance error with more context
53
- throw new Error(`Failed to list Slack conversations: ${error.message}`);
54
- }
55
- else {
56
- throw error;
57
- }
58
- }
59
- });
60
- exports.default = slackListConversations;
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createParametersObject = createParametersObject;
4
- function createParametersObject(parameters) {
5
- return Object.fromEntries(Object.entries(parameters).map(([key, param]) => [key, param.type]));
6
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
package/dist/main.js DELETED
@@ -1,11 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const list_conversations_1 = __importDefault(require("./actions/providers/slack/list_conversations"));
7
- const result = (0, list_conversations_1.default)({
8
- accessToken: "xoxp-4172665288294-8092684180551-8154529379075-89f1f70cc06e5648e8f912ba96f56626"
9
- }).then((result) => {
10
- console.log(result);
11
- });