@credal/actions 0.1.18 → 0.1.21

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.
package/README.md CHANGED
@@ -1,4 +1,7 @@
1
- # actions
1
+ ![Credal Logo](assets/credal-logo.svg)
2
+
3
+ ## Credal.ai's Open Source Actions Framework
4
+ Easily add custom actions for your Credal Copilots. Read more about Credal's Agent platform [here](https://www.credal.ai/products/ai-agent-platform).
2
5
 
3
6
  ## Adding or updating actions
4
7
 
@@ -149,6 +149,11 @@ exports.jiraCreateJiraTicketDefinition = {
149
149
  type: "string",
150
150
  description: "The assignee for the new ticket creation",
151
151
  },
152
+ customFields: {
153
+ type: "object",
154
+ description: "Custom fields to be set on the create ticket request",
155
+ additionalProperties: true,
156
+ },
152
157
  },
153
158
  },
154
159
  output: {
@@ -427,6 +432,82 @@ exports.credalCallCopilotDefinition = {
427
432
  type: "string",
428
433
  description: "The response from the Credal Copilot",
429
434
  },
435
+ referencedSources: {
436
+ type: "array",
437
+ description: "The sources referenced in the response",
438
+ items: {
439
+ type: "object",
440
+ description: "The source referenced in the response",
441
+ required: ["id", "externalResourceId", "name"],
442
+ properties: {
443
+ id: {
444
+ type: "string",
445
+ description: "The id of the source",
446
+ },
447
+ externalResourceId: {
448
+ type: "object",
449
+ required: ["externalResourceId", "resourceType"],
450
+ description: "The external resource id of the source",
451
+ properties: {
452
+ externalResourceId: {
453
+ type: "string",
454
+ description: "The external resource id of the source",
455
+ },
456
+ resourceType: {
457
+ type: "string",
458
+ description: "The type of the resource",
459
+ },
460
+ },
461
+ },
462
+ name: {
463
+ type: "string",
464
+ description: "The name of the source",
465
+ },
466
+ url: {
467
+ type: "string",
468
+ description: "The url of the source",
469
+ },
470
+ },
471
+ },
472
+ },
473
+ sourcesInDataContext: {
474
+ type: "array",
475
+ description: "The sources in the data context of the response",
476
+ items: {
477
+ type: "object",
478
+ description: "The source in the data context of the response",
479
+ required: ["id", "externalResourceId", "name"],
480
+ properties: {
481
+ id: {
482
+ type: "string",
483
+ description: "The id of the source",
484
+ },
485
+ externalResourceId: {
486
+ type: "object",
487
+ description: "The external resource id of the source",
488
+ required: ["externalResourceId", "resourceType"],
489
+ properties: {
490
+ externalResourceId: {
491
+ type: "string",
492
+ description: "The external resource id of the source",
493
+ },
494
+ resourceType: {
495
+ type: "string",
496
+ description: "The type of the resource",
497
+ },
498
+ },
499
+ },
500
+ name: {
501
+ type: "string",
502
+ description: "The name of the source",
503
+ },
504
+ url: {
505
+ type: "string",
506
+ description: "The url of the source",
507
+ },
508
+ },
509
+ },
510
+ },
430
511
  },
431
512
  },
432
513
  name: "callCopilot",
@@ -868,7 +949,7 @@ exports.finnhubSymbolLookupDefinition = {
868
949
  properties: {
869
950
  query: {
870
951
  type: "string",
871
- description: "The query to look up",
952
+ description: "The symbol or colloquial name of the company to look up",
872
953
  },
873
954
  },
874
955
  },
@@ -12,6 +12,7 @@ export declare const AuthParamsSchema: z.ZodObject<{
12
12
  emailFrom: z.ZodOptional<z.ZodString>;
13
13
  emailReplyTo: z.ZodOptional<z.ZodString>;
14
14
  emailBcc: z.ZodOptional<z.ZodString>;
15
+ cloudId: z.ZodOptional<z.ZodString>;
15
16
  }, "strip", z.ZodTypeAny, {
16
17
  username?: string | undefined;
17
18
  authToken?: string | undefined;
@@ -21,6 +22,7 @@ export declare const AuthParamsSchema: z.ZodObject<{
21
22
  emailFrom?: string | undefined;
22
23
  emailReplyTo?: string | undefined;
23
24
  emailBcc?: string | undefined;
25
+ cloudId?: string | undefined;
24
26
  }, {
25
27
  username?: string | undefined;
26
28
  authToken?: string | undefined;
@@ -30,6 +32,7 @@ export declare const AuthParamsSchema: z.ZodObject<{
30
32
  emailFrom?: string | undefined;
31
33
  emailReplyTo?: string | undefined;
32
34
  emailBcc?: string | undefined;
35
+ cloudId?: string | undefined;
33
36
  }>;
34
37
  export type AuthParamsType = z.infer<typeof AuthParamsSchema>;
35
38
  export declare const slackSendMessageParamsSchema: z.ZodObject<{
@@ -129,6 +132,7 @@ export declare const jiraCreateJiraTicketParamsSchema: z.ZodObject<{
129
132
  issueType: z.ZodString;
130
133
  reporter: z.ZodOptional<z.ZodString>;
131
134
  assignee: z.ZodOptional<z.ZodString>;
135
+ customFields: z.ZodOptional<z.ZodObject<{}, "strip", z.ZodAny, z.objectOutputType<{}, z.ZodAny, "strip">, z.objectInputType<{}, z.ZodAny, "strip">>>;
132
136
  }, "strip", z.ZodTypeAny, {
133
137
  description: string;
134
138
  projectKey: string;
@@ -136,6 +140,7 @@ export declare const jiraCreateJiraTicketParamsSchema: z.ZodObject<{
136
140
  issueType: string;
137
141
  reporter?: string | undefined;
138
142
  assignee?: string | undefined;
143
+ customFields?: z.objectOutputType<{}, z.ZodAny, "strip"> | undefined;
139
144
  }, {
140
145
  description: string;
141
146
  projectKey: string;
@@ -143,6 +148,7 @@ export declare const jiraCreateJiraTicketParamsSchema: z.ZodObject<{
143
148
  issueType: string;
144
149
  reporter?: string | undefined;
145
150
  assignee?: string | undefined;
151
+ customFields?: z.objectInputType<{}, z.ZodAny, "strip"> | undefined;
146
152
  }>;
147
153
  export type jiraCreateJiraTicketParamsType = z.infer<typeof jiraCreateJiraTicketParamsSchema>;
148
154
  export declare const jiraCreateJiraTicketOutputSchema: z.ZodObject<{
@@ -457,10 +463,108 @@ export declare const credalCallCopilotParamsSchema: z.ZodObject<{
457
463
  export type credalCallCopilotParamsType = z.infer<typeof credalCallCopilotParamsSchema>;
458
464
  export declare const credalCallCopilotOutputSchema: z.ZodObject<{
459
465
  response: z.ZodString;
466
+ referencedSources: z.ZodOptional<z.ZodArray<z.ZodObject<{
467
+ id: z.ZodString;
468
+ externalResourceId: z.ZodObject<{
469
+ externalResourceId: z.ZodString;
470
+ resourceType: z.ZodString;
471
+ }, "strip", z.ZodTypeAny, {
472
+ externalResourceId: string;
473
+ resourceType: string;
474
+ }, {
475
+ externalResourceId: string;
476
+ resourceType: string;
477
+ }>;
478
+ name: z.ZodString;
479
+ url: z.ZodOptional<z.ZodString>;
480
+ }, "strip", z.ZodTypeAny, {
481
+ name: string;
482
+ id: string;
483
+ externalResourceId: {
484
+ externalResourceId: string;
485
+ resourceType: string;
486
+ };
487
+ url?: string | undefined;
488
+ }, {
489
+ name: string;
490
+ id: string;
491
+ externalResourceId: {
492
+ externalResourceId: string;
493
+ resourceType: string;
494
+ };
495
+ url?: string | undefined;
496
+ }>, "many">>;
497
+ sourcesInDataContext: z.ZodOptional<z.ZodArray<z.ZodObject<{
498
+ id: z.ZodString;
499
+ externalResourceId: z.ZodObject<{
500
+ externalResourceId: z.ZodString;
501
+ resourceType: z.ZodString;
502
+ }, "strip", z.ZodTypeAny, {
503
+ externalResourceId: string;
504
+ resourceType: string;
505
+ }, {
506
+ externalResourceId: string;
507
+ resourceType: string;
508
+ }>;
509
+ name: z.ZodString;
510
+ url: z.ZodOptional<z.ZodString>;
511
+ }, "strip", z.ZodTypeAny, {
512
+ name: string;
513
+ id: string;
514
+ externalResourceId: {
515
+ externalResourceId: string;
516
+ resourceType: string;
517
+ };
518
+ url?: string | undefined;
519
+ }, {
520
+ name: string;
521
+ id: string;
522
+ externalResourceId: {
523
+ externalResourceId: string;
524
+ resourceType: string;
525
+ };
526
+ url?: string | undefined;
527
+ }>, "many">>;
460
528
  }, "strip", z.ZodTypeAny, {
461
529
  response: string;
530
+ referencedSources?: {
531
+ name: string;
532
+ id: string;
533
+ externalResourceId: {
534
+ externalResourceId: string;
535
+ resourceType: string;
536
+ };
537
+ url?: string | undefined;
538
+ }[] | undefined;
539
+ sourcesInDataContext?: {
540
+ name: string;
541
+ id: string;
542
+ externalResourceId: {
543
+ externalResourceId: string;
544
+ resourceType: string;
545
+ };
546
+ url?: string | undefined;
547
+ }[] | undefined;
462
548
  }, {
463
549
  response: string;
550
+ referencedSources?: {
551
+ name: string;
552
+ id: string;
553
+ externalResourceId: {
554
+ externalResourceId: string;
555
+ resourceType: string;
556
+ };
557
+ url?: string | undefined;
558
+ }[] | undefined;
559
+ sourcesInDataContext?: {
560
+ name: string;
561
+ id: string;
562
+ externalResourceId: {
563
+ externalResourceId: string;
564
+ resourceType: string;
565
+ };
566
+ url?: string | undefined;
567
+ }[] | undefined;
464
568
  }>;
465
569
  export type credalCallCopilotOutputType = z.infer<typeof credalCallCopilotOutputSchema>;
466
570
  export type credalCallCopilotFunction = ActionFunction<credalCallCopilotParamsType, AuthParamsType, credalCallCopilotOutputType>;
@@ -11,6 +11,7 @@ exports.AuthParamsSchema = zod_1.z.object({
11
11
  emailFrom: zod_1.z.string().optional(),
12
12
  emailReplyTo: zod_1.z.string().optional(),
13
13
  emailBcc: zod_1.z.string().optional(),
14
+ cloudId: zod_1.z.string().optional(),
14
15
  });
15
16
  exports.slackSendMessageParamsSchema = zod_1.z.object({
16
17
  channelName: zod_1.z.string().describe("The name of the Slack channel to send the message to (e.g. general, alerts)"),
@@ -49,6 +50,11 @@ exports.jiraCreateJiraTicketParamsSchema = zod_1.z.object({
49
50
  issueType: zod_1.z.string().describe("The issue type of the new ticket"),
50
51
  reporter: zod_1.z.string().describe("The reporter for the new ticket creation").optional(),
51
52
  assignee: zod_1.z.string().describe("The assignee for the new ticket creation").optional(),
53
+ customFields: zod_1.z
54
+ .object({})
55
+ .catchall(zod_1.z.any())
56
+ .describe("Custom fields to be set on the create ticket request")
57
+ .optional(),
52
58
  });
53
59
  exports.jiraCreateJiraTicketOutputSchema = zod_1.z.object({
54
60
  ticketUrl: zod_1.z.string().describe("The url to the created Jira Ticket"),
@@ -140,6 +146,38 @@ exports.credalCallCopilotParamsSchema = zod_1.z.object({
140
146
  });
141
147
  exports.credalCallCopilotOutputSchema = zod_1.z.object({
142
148
  response: zod_1.z.string().describe("The response from the Credal Copilot"),
149
+ referencedSources: zod_1.z
150
+ .array(zod_1.z
151
+ .object({
152
+ id: zod_1.z.string().describe("The id of the source"),
153
+ externalResourceId: zod_1.z
154
+ .object({
155
+ externalResourceId: zod_1.z.string().describe("The external resource id of the source"),
156
+ resourceType: zod_1.z.string().describe("The type of the resource"),
157
+ })
158
+ .describe("The external resource id of the source"),
159
+ name: zod_1.z.string().describe("The name of the source"),
160
+ url: zod_1.z.string().describe("The url of the source").optional(),
161
+ })
162
+ .describe("The source referenced in the response"))
163
+ .describe("The sources referenced in the response")
164
+ .optional(),
165
+ sourcesInDataContext: zod_1.z
166
+ .array(zod_1.z
167
+ .object({
168
+ id: zod_1.z.string().describe("The id of the source"),
169
+ externalResourceId: zod_1.z
170
+ .object({
171
+ externalResourceId: zod_1.z.string().describe("The external resource id of the source"),
172
+ resourceType: zod_1.z.string().describe("The type of the resource"),
173
+ })
174
+ .describe("The external resource id of the source"),
175
+ name: zod_1.z.string().describe("The name of the source"),
176
+ url: zod_1.z.string().describe("The url of the source").optional(),
177
+ })
178
+ .describe("The source in the data context of the response"))
179
+ .describe("The sources in the data context of the response")
180
+ .optional(),
143
181
  });
144
182
  exports.zendeskCreateZendeskTicketParamsSchema = zod_1.z.object({
145
183
  subject: zod_1.z.string().describe("The subject of the ticket"),
@@ -245,7 +283,9 @@ exports.googleOauthCreateNewGoogleDocOutputSchema = zod_1.z.object({
245
283
  documentId: zod_1.z.string().describe("The ID of the created Google Doc"),
246
284
  documentUrl: zod_1.z.string().describe("The URL to access the created Google Doc").optional(),
247
285
  });
248
- exports.finnhubSymbolLookupParamsSchema = zod_1.z.object({ query: zod_1.z.string().describe("The query to look up") });
286
+ exports.finnhubSymbolLookupParamsSchema = zod_1.z.object({
287
+ query: zod_1.z.string().describe("The symbol or colloquial name of the company to look up"),
288
+ });
249
289
  exports.finnhubSymbolLookupOutputSchema = zod_1.z.object({
250
290
  result: zod_1.z
251
291
  .array(zod_1.z
@@ -48,6 +48,7 @@ z.object({
48
48
  emailFrom: z.string().optional(),
49
49
  emailReplyTo: z.string().optional(),
50
50
  emailBcc: z.string().optional(),
51
+ cloudId: z.string().optional(),
51
52
  })
52
53
  `;
53
54
  function validateObject(object) {
@@ -8,30 +8,25 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
11
  Object.defineProperty(exports, "__esModule", { value: true });
15
- const axios_1 = __importDefault(require("axios"));
16
- function getConfluenceApi(baseUrl, username, apiToken) {
17
- const api = axios_1.default.create({
12
+ const axiosClient_1 = require("../../util/axiosClient");
13
+ function getConfluenceRequestConfig(baseUrl, username, apiToken) {
14
+ return {
18
15
  baseURL: baseUrl,
19
16
  headers: {
20
17
  Accept: "application/json",
21
- // Tokens are associated with a specific user.
22
18
  Authorization: `Basic ${Buffer.from(`${username}:${apiToken}`).toString("base64")}`,
23
19
  },
24
- });
25
- return api;
20
+ };
26
21
  }
27
22
  const confluenceUpdatePage = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, authParams, }) {
28
23
  const { pageId, username, content, title } = params;
29
24
  const { baseUrl, authToken } = authParams;
30
- const api = getConfluenceApi(baseUrl, username, authToken);
25
+ const config = getConfluenceRequestConfig(baseUrl, username, authToken);
31
26
  // Get current version number
32
- const response = yield api.get(`/api/v2/pages/${pageId}`);
27
+ const response = yield axiosClient_1.axiosClient.get(`/api/v2/pages/${pageId}`, config);
33
28
  const currVersion = response.data.version.number;
34
- yield api.put(`/api/v2/pages/${pageId}`, {
29
+ const payload = {
35
30
  id: pageId,
36
31
  status: "current",
37
32
  title,
@@ -42,6 +37,7 @@ const confluenceUpdatePage = (_a) => __awaiter(void 0, [_a], void 0, function* (
42
37
  version: {
43
38
  number: currVersion + 1,
44
39
  },
45
- });
40
+ };
41
+ yield axiosClient_1.axiosClient.put(`/api/v2/pages/${pageId}`, payload, config);
46
42
  });
47
43
  exports.default = confluenceUpdatePage;
@@ -28,6 +28,8 @@ const callCopilot = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params,
28
28
  response: response.sendChatResult.type === "ai_response_result"
29
29
  ? response.sendChatResult.response.message
30
30
  : "Error getting response",
31
+ referencedSources: response.sendChatResult.type === "ai_response_result" ? response.sendChatResult.referencedSources : [],
32
+ sourcesInDataContext: response.sendChatResult.type === "ai_response_result" ? response.sendChatResult.sourcesInDataContext : [],
31
33
  };
32
34
  });
33
35
  exports.default = callCopilot;
@@ -8,12 +8,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
11
  Object.defineProperty(exports, "__esModule", { value: true });
15
12
  const types_1 = require("../../autogen/types");
16
- const axios_1 = __importDefault(require("axios"));
13
+ const axiosClient_1 = require("../../util/axiosClient");
17
14
  function transformData(data) {
18
15
  return Object.entries(data).map(([key, value]) => ({
19
16
  metric: key,
@@ -29,7 +26,7 @@ function transformData(data) {
29
26
  const getBasicFinancials = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, authParams, }) {
30
27
  try {
31
28
  const apiKey = authParams.apiKey;
32
- const result = yield axios_1.default.get(`https://finnhub.io/api/v1/stock/metric?symbol=${params.symbol}`, {
29
+ const result = yield axiosClient_1.axiosClient.get(`https://finnhub.io/api/v1/stock/metric?symbol=${params.symbol}`, {
33
30
  headers: {
34
31
  "X-Finnhub-Token": apiKey,
35
32
  },
@@ -8,16 +8,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
11
  Object.defineProperty(exports, "__esModule", { value: true });
15
12
  const types_1 = require("../../autogen/types");
16
- const axios_1 = __importDefault(require("axios"));
13
+ const axiosClient_1 = require("../../util/axiosClient");
17
14
  const symbolLookup = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, authParams, }) {
18
15
  try {
19
16
  const apiKey = authParams.apiKey;
20
- const result = yield axios_1.default.get(`https://finnhub.io/api/v1/search?q=${params.query}`, {
17
+ const result = yield axiosClient_1.axiosClient.get(`https://finnhub.io/api/v1/search?q=${params.query}`, {
21
18
  headers: {
22
19
  "X-Finnhub-Token": apiKey,
23
20
  },
@@ -8,63 +8,51 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
11
  Object.defineProperty(exports, "__esModule", { value: true });
15
- const axios_1 = __importDefault(require("axios"));
12
+ const axiosClient_1 = require("../../util/axiosClient");
16
13
  /**
17
14
  * Creates a new Google Doc document using OAuth authentication
18
15
  */
19
16
  const createNewGoogleDoc = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, authParams, }) {
20
- var _b, _c, _d;
21
17
  if (!authParams.authToken) {
22
18
  throw new Error("authToken is required for Google Docs API");
23
19
  }
24
- try {
25
- const { title, content } = params;
26
- const baseApiUrl = "https://docs.googleapis.com/v1/documents";
27
- // Create the document with the provided title
28
- const response = yield axios_1.default.post(baseApiUrl, { title }, {
20
+ const { title, content } = params;
21
+ const baseApiUrl = "https://docs.googleapis.com/v1/documents";
22
+ // Create the document with the provided title
23
+ const response = yield axiosClient_1.axiosClient.post(baseApiUrl, { title }, {
24
+ headers: {
25
+ Authorization: `Bearer ${authParams.authToken}`,
26
+ "Content-Type": "application/json",
27
+ },
28
+ });
29
+ // If content is provided, update the document body with the content
30
+ if (content) {
31
+ const documentId = response.data.documentId;
32
+ // Add the description to the document content
33
+ yield axiosClient_1.axiosClient.post(`${baseApiUrl}/${documentId}:batchUpdate`, {
34
+ requests: [
35
+ {
36
+ insertText: {
37
+ location: {
38
+ index: 1, // Insert at the beginning of the document
39
+ },
40
+ text: content,
41
+ },
42
+ },
43
+ ],
44
+ }, {
29
45
  headers: {
30
46
  Authorization: `Bearer ${authParams.authToken}`,
31
47
  "Content-Type": "application/json",
32
48
  },
33
49
  });
34
- // If description is provided, update the document body with the description
35
- if (content) {
36
- const documentId = response.data.documentId;
37
- // Add the description to the document content
38
- yield axios_1.default.post(`${baseApiUrl}/${documentId}:batchUpdate`, {
39
- requests: [
40
- {
41
- insertText: {
42
- location: {
43
- index: 1, // Insert at the beginning of the document
44
- },
45
- text: content,
46
- },
47
- },
48
- ],
49
- }, {
50
- headers: {
51
- Authorization: `Bearer ${authParams.authToken}`,
52
- "Content-Type": "application/json",
53
- },
54
- });
55
- }
56
- return {
57
- documentId: response.data.documentId,
58
- documentUrl: response.data.documentId
59
- ? `https://docs.google.com/document/d/${response.data.documentId}/edit`
60
- : undefined,
61
- };
62
- }
63
- catch (error) {
64
- if (axios_1.default.isAxiosError(error)) {
65
- throw new Error(`Google Docs API error: ${((_d = (_c = (_b = error.response) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.error) === null || _d === void 0 ? void 0 : _d.message) || error.message}`);
66
- }
67
- throw error;
68
50
  }
51
+ return {
52
+ documentId: response.data.documentId,
53
+ documentUrl: response.data.documentId
54
+ ? `https://docs.google.com/document/d/${response.data.documentId}/edit`
55
+ : undefined,
56
+ };
69
57
  });
70
58
  exports.default = createNewGoogleDoc;
@@ -8,12 +8,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
11
  Object.defineProperty(exports, "__esModule", { value: true });
15
- const axios_1 = __importDefault(require("axios"));
16
12
  const types_1 = require("../../autogen/types");
13
+ const axiosClient_1 = require("../../util/axiosClient");
17
14
  const INCLUDED_TYPES = ["restaurant"];
18
15
  const nearbysearchRestaurants = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, authParams, }) {
19
16
  const url = `https://places.googleapis.com/v1/places:searchNearby`;
@@ -27,7 +24,7 @@ const nearbysearchRestaurants = (_a) => __awaiter(void 0, [_a], void 0, function
27
24
  "places.regularOpeningHours",
28
25
  "places.websiteUri",
29
26
  ].join(",");
30
- const response = yield axios_1.default.post(url, {
27
+ const response = yield axiosClient_1.axiosClient.post(url, {
31
28
  maxResultCount: 20,
32
29
  includedTypes: INCLUDED_TYPES,
33
30
  locationRestriction: {
@@ -8,11 +8,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
11
  Object.defineProperty(exports, "__esModule", { value: true });
15
- const axios_1 = __importDefault(require("axios"));
12
+ const axiosClient_1 = require("../../util/axiosClient");
16
13
  const validateAddress = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, authParams, }) {
17
14
  const url = `https://addressvalidation.googleapis.com/v1:validateAddress?key=${authParams.apiKey}`;
18
15
  const requestBody = {
@@ -20,7 +17,7 @@ const validateAddress = (_a) => __awaiter(void 0, [_a], void 0, function* ({ par
20
17
  addressLines: [...params.addressLines, params.locality, params.regionCode, params.postalCode],
21
18
  },
22
19
  };
23
- const response = yield axios_1.default.post(url, requestBody, {
20
+ const response = yield axiosClient_1.axiosClient.post(url, requestBody, {
24
21
  headers: {
25
22
  "Content-Type": "application/json",
26
23
  },
@@ -8,18 +8,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
11
  Object.defineProperty(exports, "__esModule", { value: true });
15
- const axios_1 = __importDefault(require("axios"));
16
- function getUserAccountId(email, baseUrl, authToken, username) {
12
+ const axiosClient_1 = require("../../util/axiosClient");
13
+ function getUserAccountId(email, apiUrl, authToken) {
17
14
  return __awaiter(this, void 0, void 0, function* () {
18
15
  try {
19
- const response = yield axios_1.default.get(`${baseUrl}/rest/api/3/user/search?query=${encodeURIComponent(email)}`, {
16
+ const response = yield axiosClient_1.axiosClient.get(`${apiUrl}/user/search?query=${encodeURIComponent(email)}`, {
20
17
  headers: {
21
- Authorization: `Basic ${Buffer.from(`${username}:${authToken}`).toString("base64")}`,
22
- "Content-Type": "application/json",
18
+ Authorization: `Bearer ${authToken}`,
19
+ Accept: "application/json",
23
20
  },
24
21
  });
25
22
  if (response.data && response.data.length > 0) {
@@ -28,6 +25,7 @@ function getUserAccountId(email, baseUrl, authToken, username) {
28
25
  return null;
29
26
  }
30
27
  catch (error) {
28
+ // Try to complete request without assignee/reporter.
31
29
  const axiosError = error;
32
30
  console.error("Error finding user:", axiosError.message);
33
31
  return null;
@@ -35,59 +33,49 @@ function getUserAccountId(email, baseUrl, authToken, username) {
35
33
  });
36
34
  }
37
35
  const createJiraTicket = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, authParams, }) {
38
- const { authToken, baseUrl, username } = authParams;
39
- const url = `${baseUrl}/rest/api/3/issue`;
36
+ const { authToken, cloudId, baseUrl } = authParams;
37
+ const apiUrl = `https://api.atlassian.com/ex/jira/${cloudId}/rest/api/3/`;
38
+ if (!cloudId) {
39
+ throw new Error("Cloud ID is required to create a Jira ticket");
40
+ }
40
41
  // If assignee is an email, look up the account ID
41
42
  let reporterId = null;
42
- if (params.reporter &&
43
- typeof params.reporter === "string" &&
44
- params.reporter.includes("@") &&
45
- baseUrl &&
46
- authToken &&
47
- username) {
48
- reporterId = yield getUserAccountId(params.reporter, baseUrl, authToken, username);
43
+ if (params.reporter && typeof params.reporter === "string" && params.reporter.includes("@") && authToken) {
44
+ reporterId = yield getUserAccountId(params.reporter, apiUrl, authToken);
49
45
  }
50
46
  // If assignee is an email, look up the account ID
51
47
  let assigneeId = null;
52
- if (params.assignee &&
53
- typeof params.assignee === "string" &&
54
- params.assignee.includes("@") &&
55
- baseUrl &&
56
- authToken &&
57
- username) {
58
- assigneeId = yield getUserAccountId(params.assignee, baseUrl, authToken, username);
48
+ if (params.assignee && typeof params.assignee === "string" && params.assignee.includes("@") && authToken) {
49
+ assigneeId = yield getUserAccountId(params.assignee, apiUrl, authToken);
59
50
  }
60
- const description = typeof params.description === "string"
61
- ? {
62
- type: "doc",
63
- version: 1,
64
- content: [
65
- {
66
- type: "paragraph",
67
- content: [
68
- {
69
- type: "text",
70
- text: params.description,
71
- },
72
- ],
73
- },
74
- ],
75
- }
76
- : params.description;
51
+ const description = {
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
+ };
77
66
  const payload = {
78
- fields: Object.assign(Object.assign({ project: {
67
+ fields: Object.assign(Object.assign(Object.assign({ project: {
79
68
  key: params.projectKey,
80
69
  }, summary: params.summary, description: description, issuetype: {
81
70
  name: params.issueType,
82
- } }, (reporterId ? { reporter: { id: reporterId } } : {})), (assigneeId ? { assignee: { id: assigneeId } } : {})),
71
+ } }, (reporterId ? { reporter: { id: reporterId } } : {})), (assigneeId ? { assignee: { id: assigneeId } } : {})), (params.customFields ? params.customFields : {})),
83
72
  };
84
- const response = yield axios_1.default.post(url, payload, {
73
+ const response = yield axiosClient_1.axiosClient.post(`${apiUrl}/issue`, payload, {
85
74
  headers: {
86
- Authorization: `Basic ${Buffer.from(`${username}:${authToken}`).toString("base64")}`,
87
- "Content-Type": "application/json",
75
+ Authorization: `Bearer ${authToken}`,
76
+ Accept: "application/json",
88
77
  },
89
78
  });
90
- // At the end of your function, wrap the response
91
79
  return {
92
80
  ticketUrl: `${baseUrl}/browse/${response.data.key}`,
93
81
  };
@@ -8,12 +8,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
11
  Object.defineProperty(exports, "__esModule", { value: true });
15
- const axios_1 = __importDefault(require("axios"));
16
12
  const datetime_1 = require("../../../utils/datetime");
13
+ const axiosClient_1 = require("../../util/axiosClient");
17
14
  const getForecastForLocation = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, authParams, }) {
18
15
  const { latitude, longitude, isoDate } = params;
19
16
  const { userAgent } = authParams;
@@ -21,9 +18,9 @@ const getForecastForLocation = (_a) => __awaiter(void 0, [_a], void 0, function*
21
18
  throw new Error("Invalid ISO date format");
22
19
  }
23
20
  const url = `https://api.weather.gov/points/${latitude},${longitude}`;
24
- const pointsResponse = yield axios_1.default.get(url, { headers: { "User-Agent": userAgent } });
21
+ const pointsResponse = yield axiosClient_1.axiosClient.get(url, { headers: { "User-Agent": userAgent } });
25
22
  const forecastUrl = pointsResponse.data.properties.forecast;
26
- const forecastResponse = yield axios_1.default.get(forecastUrl, {
23
+ const forecastResponse = yield axiosClient_1.axiosClient.get(forecastUrl, {
27
24
  headers: { "User-Agent": userAgent },
28
25
  });
29
26
  const forecastData = forecastResponse.data;
@@ -8,16 +8,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
11
  Object.defineProperty(exports, "__esModule", { value: true });
15
- const axios_1 = __importDefault(require("axios"));
12
+ const axiosClient_1 = require("../../util/axiosClient");
16
13
  const getLatitudeLongitudeFromLocation = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, authParams, }) {
17
14
  const { location } = params;
18
15
  const { userAgent } = authParams;
19
16
  const url = `https://nominatim.openstreetmap.org/search?q=${encodeURIComponent(location)}&format=json`;
20
- const response = yield axios_1.default.get(url, { headers: { "User-Agent": userAgent } });
17
+ const response = yield axiosClient_1.axiosClient.get(url, { headers: { "User-Agent": userAgent } });
21
18
  return response.data.map((result) => ({
22
19
  latitude: parseFloat(result.lat),
23
20
  longitude: parseFloat(result.lon),
@@ -13,7 +13,10 @@ const createXSharePostUrl = ({ params, }) => {
13
13
  }
14
14
  // Add hashtags parameter if it exists
15
15
  if (params.hashtag && params.hashtag.length > 0) {
16
- queryParams.append("hashtags", params.hashtag.join(","));
16
+ const cleanedHashtags = params.hashtag.map(tag => tag.replace(/^#+/, "").trim()).filter(tag => tag.length > 0);
17
+ if (cleanedHashtags.length > 0) {
18
+ queryParams.append("hashtags", cleanedHashtags.join(","));
19
+ }
17
20
  }
18
21
  // Add via parameter if it exists
19
22
  if (params.via) {
@@ -8,11 +8,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
11
  Object.defineProperty(exports, "__esModule", { value: true });
15
- const axios_1 = __importDefault(require("axios"));
12
+ const axiosClient_1 = require("../../util/axiosClient");
16
13
  const createZendeskTicket = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, authParams, }) {
17
14
  const { apiKey } = authParams;
18
15
  const { subdomain, subject, body, requesterEmail } = params;
@@ -29,7 +26,7 @@ const createZendeskTicket = (_a) => __awaiter(void 0, [_a], void 0, function* ({
29
26
  throw new Error("API key is required");
30
27
  }
31
28
  try {
32
- const response = yield axios_1.default.post(url, payload, {
29
+ const response = yield axiosClient_1.axiosClient.post(url, payload, {
33
30
  auth: {
34
31
  username: `${requesterEmail}/token`,
35
32
  password: apiKey,
@@ -0,0 +1,7 @@
1
+ import { AxiosInstance } from "axios";
2
+ export declare class ApiError extends Error {
3
+ status?: number;
4
+ data?: any;
5
+ constructor(message: string, status?: number, data?: any);
6
+ }
7
+ export declare const axiosClient: AxiosInstance;
@@ -0,0 +1,46 @@
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.axiosClient = exports.ApiError = void 0;
7
+ /* eslint-disable @typescript-eslint/no-explicit-any */
8
+ const axios_1 = __importDefault(require("axios"));
9
+ class ApiError extends Error {
10
+ constructor(message, status, data) {
11
+ super(message);
12
+ this.name = "ApiError";
13
+ this.status = status;
14
+ this.data = data;
15
+ }
16
+ }
17
+ exports.ApiError = ApiError;
18
+ /** Create a configured axios instance with interceptors */
19
+ function createAxiosClient() {
20
+ const instance = axios_1.default.create();
21
+ instance.interceptors.request.use(config => {
22
+ return config;
23
+ }, error => {
24
+ console.error("Request setup error:", error.message);
25
+ return Promise.reject(error);
26
+ });
27
+ instance.interceptors.response.use((response) => {
28
+ return response;
29
+ }, (error) => {
30
+ var _a, _b;
31
+ if (error.response) {
32
+ console.error(`API error:`, error.response.status, error.response.data);
33
+ return Promise.reject(new ApiError(`Request failed with status ${error.response.status}`, error.response.status, error.response.data));
34
+ }
35
+ else if (error.request) {
36
+ console.error(`No response received:`, (_a = error.config) === null || _a === void 0 ? void 0 : _a.url);
37
+ return Promise.reject(new ApiError(`No response received from server for ${((_b = error.config) === null || _b === void 0 ? void 0 : _b.url) || "unknown endpoint"}`));
38
+ }
39
+ else {
40
+ console.error(`Request setup error:`, error.message);
41
+ return Promise.reject(new ApiError(`Error making request: ${error.message}`));
42
+ }
43
+ });
44
+ return instance;
45
+ }
46
+ exports.axiosClient = createAxiosClient();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@credal/actions",
3
- "version": "0.1.18",
3
+ "version": "0.1.21",
4
4
  "description": "AI Actions by Credal AI",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",