@credal/actions 0.0.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.
- package/README.md +32 -0
- package/dist/actions/actionMapper.d.ts +9 -0
- package/dist/actions/actionMapper.js +79 -0
- package/dist/actions/autogen/definitions.d.ts +5 -0
- package/dist/actions/autogen/definitions.js +132 -0
- package/dist/actions/autogen/templates.d.ts +11 -0
- package/dist/actions/autogen/templates.js +493 -0
- package/dist/actions/autogen/types.d.ts +482 -0
- package/dist/actions/autogen/types.js +153 -0
- package/dist/actions/definitions.js +35 -0
- package/dist/actions/groups.d.ts +6 -0
- package/dist/actions/groups.js +38 -0
- package/dist/actions/invoke.d.ts +8 -0
- package/dist/actions/invoke.js +20 -0
- package/dist/actions/invokeMapper.d.ts +9 -0
- package/dist/actions/invokeMapper.js +33 -0
- package/dist/actions/parse.d.ts +66 -0
- package/dist/actions/parse.js +201 -0
- package/dist/actions/providers/confluence/updatePage.d.ts +3 -0
- package/dist/actions/providers/confluence/updatePage.js +47 -0
- package/dist/actions/providers/credal/callCopilot.d.ts +3 -0
- package/dist/actions/providers/credal/callCopilot.js +31 -0
- package/dist/actions/providers/googlemaps/validateAddress.d.ts +3 -0
- package/dist/actions/providers/googlemaps/validateAddress.js +30 -0
- package/dist/actions/providers/jira/createJiraTicket.d.ts +3 -0
- package/dist/actions/providers/jira/createJiraTicket.js +34 -0
- package/dist/actions/providers/jira/createTicket.d.ts +3 -0
- package/dist/actions/providers/jira/createTicket.js +34 -0
- package/dist/actions/providers/math/add.d.ts +3 -0
- package/dist/actions/providers/math/add.js +17 -0
- package/dist/actions/providers/math/index.d.ts +1 -0
- package/dist/actions/providers/math/index.js +37 -0
- package/dist/actions/providers/mongodb/insertMongoDoc.d.ts +3 -0
- package/dist/actions/providers/mongodb/insertMongoDoc.js +36 -0
- package/dist/actions/providers/slack/helpers.d.ts +6 -0
- package/dist/actions/providers/slack/helpers.js +53 -0
- package/dist/actions/providers/slack/index.d.ts +1 -0
- package/dist/actions/providers/slack/index.js +37 -0
- package/dist/actions/providers/slack/listConversations.d.ts +3 -0
- package/dist/actions/providers/slack/listConversations.js +41 -0
- package/dist/actions/providers/slack/list_conversations.d.ts +3 -0
- package/dist/actions/providers/slack/list_conversations.js +60 -0
- package/dist/actions/providers/slack/sendMessage.d.ts +3 -0
- package/dist/actions/providers/slack/sendMessage.js +36 -0
- package/dist/actions/providers/snowflake/getRowByFieldValue.d.ts +3 -0
- package/dist/actions/providers/snowflake/getRowByFieldValue.js +100 -0
- package/dist/actions/providers/zendesk/createZendeskTicket.d.ts +3 -0
- package/dist/actions/providers/zendesk/createZendeskTicket.js +48 -0
- package/dist/actions/schema.js +6 -0
- package/dist/actions/types.js +2 -0
- package/dist/app.d.ts +9 -0
- package/dist/app.js +97 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +27 -0
- package/dist/main.js +11 -0
- package/dist/utils/string.d.ts +1 -0
- package/dist/utils/string.js +10 -0
- package/package.json +51 -0
@@ -0,0 +1,38 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.ACTION_GROUPS = void 0;
|
4
|
+
const templates_1 = require("../actions/autogen/templates");
|
5
|
+
exports.ACTION_GROUPS = {
|
6
|
+
SLACK_LIST_CONVERSATIONS: {
|
7
|
+
description: "Actions for interacting with Slack",
|
8
|
+
actions: [templates_1.slackListConversationsDefinition, templates_1.slackSendMessageDefinition],
|
9
|
+
},
|
10
|
+
CONFLUENCE_UPDATE_PAGE: {
|
11
|
+
description: "Action for updating Confluence",
|
12
|
+
actions: [templates_1.confluenceUpdatePageDefinition],
|
13
|
+
},
|
14
|
+
MATH_ADD: {
|
15
|
+
description: "Action for adding two numbers",
|
16
|
+
actions: [templates_1.mathAddDefinition],
|
17
|
+
},
|
18
|
+
MAPS_VALIDATE: {
|
19
|
+
description: "Action for validating a Google maps address",
|
20
|
+
actions: [templates_1.googlemapsValidateAddressDefinition],
|
21
|
+
},
|
22
|
+
CREDAL_CALL_COPILOT: {
|
23
|
+
description: "Action for calling a Credal Copilot",
|
24
|
+
actions: [templates_1.credalCallCopilotDefinition],
|
25
|
+
},
|
26
|
+
ZENDESK_CREATE_TICKET: {
|
27
|
+
description: "Action for creating a Zendesk ticket",
|
28
|
+
actions: [templates_1.zendeskCreateZendeskTicketDefinition],
|
29
|
+
},
|
30
|
+
MONGO_INSERT_DOC: {
|
31
|
+
description: "Action for inserting a document into a MongoDB collection",
|
32
|
+
actions: [templates_1.mongoInsertMongoDocDefinition],
|
33
|
+
},
|
34
|
+
SNOWFLAKE_GET_ROW_BY_FIELD_VALUE: {
|
35
|
+
description: "Action for getting a row from a Snowflake table by field value",
|
36
|
+
actions: [templates_1.snowflakeGetRowByFieldValueDefinition],
|
37
|
+
},
|
38
|
+
};
|
@@ -0,0 +1,20 @@
|
|
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
|
+
exports.invokeAction = invokeAction;
|
13
|
+
const actionMapper_1 = require("./actionMapper");
|
14
|
+
function invokeAction(input) {
|
15
|
+
return __awaiter(this, void 0, void 0, function* () {
|
16
|
+
const { provider, name, parameters, authParams } = input;
|
17
|
+
const providerFunction = actionMapper_1.ActionMapper[provider][name].fn;
|
18
|
+
return providerFunction({ params: parameters, authParams });
|
19
|
+
});
|
20
|
+
}
|
@@ -0,0 +1,9 @@
|
|
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 {};
|
@@ -0,0 +1,33 @@
|
|
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
|
+
};
|
@@ -0,0 +1,66 @@
|
|
1
|
+
import { z } from "zod";
|
2
|
+
declare const actionTemplateSchema: z.ZodObject<z.objectUtil.extendShape<{
|
3
|
+
description: z.ZodString;
|
4
|
+
scopes: z.ZodArray<z.ZodString, "many">;
|
5
|
+
parameters: z.ZodOptional<z.ZodObject<{
|
6
|
+
type: z.ZodString;
|
7
|
+
required: z.ZodArray<z.ZodString, "many">;
|
8
|
+
properties: z.ZodRecord<z.ZodString, z.ZodAny>;
|
9
|
+
}, "strip", z.ZodTypeAny, {
|
10
|
+
type: string;
|
11
|
+
required: string[];
|
12
|
+
properties: Record<string, any>;
|
13
|
+
}, {
|
14
|
+
type: string;
|
15
|
+
required: string[];
|
16
|
+
properties: Record<string, any>;
|
17
|
+
}>>;
|
18
|
+
output: z.ZodOptional<z.ZodObject<{
|
19
|
+
type: z.ZodString;
|
20
|
+
required: z.ZodArray<z.ZodString, "many">;
|
21
|
+
properties: z.ZodRecord<z.ZodString, z.ZodAny>;
|
22
|
+
}, "strip", z.ZodTypeAny, {
|
23
|
+
type: string;
|
24
|
+
required: string[];
|
25
|
+
properties: Record<string, any>;
|
26
|
+
}, {
|
27
|
+
type: string;
|
28
|
+
required: string[];
|
29
|
+
properties: Record<string, any>;
|
30
|
+
}>>;
|
31
|
+
}, {
|
32
|
+
name: z.ZodString;
|
33
|
+
provider: z.ZodString;
|
34
|
+
}>, "strip", z.ZodTypeAny, {
|
35
|
+
description: string;
|
36
|
+
scopes: string[];
|
37
|
+
name: string;
|
38
|
+
provider: string;
|
39
|
+
parameters?: {
|
40
|
+
type: string;
|
41
|
+
required: string[];
|
42
|
+
properties: Record<string, any>;
|
43
|
+
} | undefined;
|
44
|
+
output?: {
|
45
|
+
type: string;
|
46
|
+
required: string[];
|
47
|
+
properties: Record<string, any>;
|
48
|
+
} | undefined;
|
49
|
+
}, {
|
50
|
+
description: string;
|
51
|
+
scopes: string[];
|
52
|
+
name: string;
|
53
|
+
provider: string;
|
54
|
+
parameters?: {
|
55
|
+
type: string;
|
56
|
+
required: string[];
|
57
|
+
properties: Record<string, any>;
|
58
|
+
} | undefined;
|
59
|
+
output?: {
|
60
|
+
type: string;
|
61
|
+
required: string[];
|
62
|
+
properties: Record<string, any>;
|
63
|
+
} | undefined;
|
64
|
+
}>;
|
65
|
+
export type ActionTemplate = z.infer<typeof actionTemplateSchema>;
|
66
|
+
export {};
|
@@ -0,0 +1,201 @@
|
|
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 ajv_1 = __importDefault(require("ajv"));
|
16
|
+
const promises_1 = __importDefault(require("fs/promises"));
|
17
|
+
const js_yaml_1 = __importDefault(require("js-yaml"));
|
18
|
+
const json_schema_to_zod_1 = __importDefault(require("json-schema-to-zod"));
|
19
|
+
const ts_morph_1 = require("ts-morph");
|
20
|
+
const zod_1 = require("zod");
|
21
|
+
const string_1 = require("../utils/string");
|
22
|
+
const jsonObjectSchema = zod_1.z.object({
|
23
|
+
type: zod_1.z.string(),
|
24
|
+
required: zod_1.z.array(zod_1.z.string()),
|
25
|
+
properties: zod_1.z.record(zod_1.z.string(), zod_1.z.any()), // Permissive for now, validate using JSON schema later
|
26
|
+
});
|
27
|
+
const actionSchema = zod_1.z.object({
|
28
|
+
description: zod_1.z.string(),
|
29
|
+
scopes: zod_1.z.array(zod_1.z.string()),
|
30
|
+
parameters: jsonObjectSchema.optional(),
|
31
|
+
output: jsonObjectSchema.optional(),
|
32
|
+
});
|
33
|
+
const actionTemplateSchema = actionSchema.extend({
|
34
|
+
name: zod_1.z.string(),
|
35
|
+
provider: zod_1.z.string(),
|
36
|
+
});
|
37
|
+
const providerSchema = zod_1.z.record(zod_1.z.string(), actionSchema);
|
38
|
+
const configSchema = zod_1.z.object({
|
39
|
+
actions: zod_1.z.record(zod_1.z.string(), providerSchema),
|
40
|
+
});
|
41
|
+
const authParamsSchemaStr = `
|
42
|
+
z.object({
|
43
|
+
authToken: z.string().optional(),
|
44
|
+
baseUrl: z.string().optional(),
|
45
|
+
apiKey: z.string().optional(),
|
46
|
+
})
|
47
|
+
`;
|
48
|
+
function validateObject(object) {
|
49
|
+
return __awaiter(this, void 0, void 0, function* () {
|
50
|
+
const ajv = new ajv_1.default({
|
51
|
+
strict: true,
|
52
|
+
strictTypes: true,
|
53
|
+
strictTuples: true,
|
54
|
+
strictRequired: true,
|
55
|
+
});
|
56
|
+
// validate schema and check required fields
|
57
|
+
const validParameters = ajv.validateSchema(object);
|
58
|
+
if (!validParameters) {
|
59
|
+
throw new Error(`Error validating object: ${JSON.stringify(ajv.errors, null, 4)}`);
|
60
|
+
}
|
61
|
+
// check required fields
|
62
|
+
const requiredFields = object.required;
|
63
|
+
for (const field of requiredFields) {
|
64
|
+
if (!object.properties[field]) {
|
65
|
+
throw new Error(`Required field ${field} is missing`);
|
66
|
+
}
|
67
|
+
}
|
68
|
+
});
|
69
|
+
}
|
70
|
+
function addActionTypes(_a) {
|
71
|
+
return __awaiter(this, arguments, void 0, function* ({ file, prefix, action }) {
|
72
|
+
// add parameter types
|
73
|
+
const paramsName = `${prefix}Params`;
|
74
|
+
yield addTypesToFile({
|
75
|
+
file,
|
76
|
+
obj: action.parameters,
|
77
|
+
fallback: "z.object({})",
|
78
|
+
name: paramsName,
|
79
|
+
});
|
80
|
+
// add output types
|
81
|
+
const outputName = `${prefix}Output`;
|
82
|
+
yield addTypesToFile({
|
83
|
+
file,
|
84
|
+
obj: action.output,
|
85
|
+
fallback: "z.void()",
|
86
|
+
name: outputName,
|
87
|
+
});
|
88
|
+
// add function type
|
89
|
+
const functionName = `${prefix}Function`;
|
90
|
+
file.addTypeAlias({
|
91
|
+
name: functionName,
|
92
|
+
type: `ActionFunction<${paramsName}Type, AuthParamsType, ${outputName}Type>`,
|
93
|
+
isExported: true,
|
94
|
+
});
|
95
|
+
});
|
96
|
+
}
|
97
|
+
function addTypesToFile(_a) {
|
98
|
+
return __awaiter(this, arguments, void 0, function* ({ file, obj, fallback, name, }) {
|
99
|
+
const zodSchema = obj ? (0, json_schema_to_zod_1.default)(obj) : fallback;
|
100
|
+
const zodName = `${name}Schema`;
|
101
|
+
file.addVariableStatement({
|
102
|
+
declarationKind: ts_morph_1.VariableDeclarationKind.Const,
|
103
|
+
isExported: true,
|
104
|
+
declarations: [
|
105
|
+
{
|
106
|
+
name: zodName,
|
107
|
+
initializer: zodSchema,
|
108
|
+
},
|
109
|
+
],
|
110
|
+
});
|
111
|
+
file.addTypeAlias({
|
112
|
+
name: `${name}Type`,
|
113
|
+
type: `z.infer<typeof ${zodName}>`,
|
114
|
+
isExported: true,
|
115
|
+
});
|
116
|
+
});
|
117
|
+
}
|
118
|
+
function generateTypes(_a) {
|
119
|
+
return __awaiter(this, arguments, void 0, function* ({ inputPath = "src/actions/schema.yaml", outputPath = "src/actions/autogen/templates.ts", templatesOutputPath = "src/actions/autogen/types.ts", }) {
|
120
|
+
const yamlContent = yield promises_1.default.readFile(inputPath, "utf8");
|
121
|
+
const rawConfig = js_yaml_1.default.load(yamlContent);
|
122
|
+
// Validate the config
|
123
|
+
const parsedConfig = configSchema.parse(rawConfig);
|
124
|
+
// Generate the TypeScript file
|
125
|
+
// Initialize ts-morph project
|
126
|
+
const project = new ts_morph_1.Project();
|
127
|
+
const templatesFile = project.createSourceFile(outputPath, "", { overwrite: true });
|
128
|
+
const typesFile = project.createSourceFile(templatesOutputPath, "", { overwrite: true });
|
129
|
+
// Add imports
|
130
|
+
templatesFile.addImportDeclaration({
|
131
|
+
moduleSpecifier: "../../actions/parse",
|
132
|
+
namedImports: ["ActionTemplate"],
|
133
|
+
});
|
134
|
+
typesFile.addImportDeclaration({
|
135
|
+
moduleSpecifier: "zod",
|
136
|
+
namedImports: ["z"],
|
137
|
+
});
|
138
|
+
// Initialization: set up generic ActionFunction type
|
139
|
+
typesFile.addTypeAlias({
|
140
|
+
name: "ActionFunction",
|
141
|
+
typeParameters: ["P", "A", "O"],
|
142
|
+
type: "(input: {params: P, authParams: A}) => Promise<O>",
|
143
|
+
isExported: true,
|
144
|
+
});
|
145
|
+
// Initialization: set up authparams zod schema and type
|
146
|
+
typesFile.addVariableStatement({
|
147
|
+
declarationKind: ts_morph_1.VariableDeclarationKind.Const,
|
148
|
+
isExported: true,
|
149
|
+
declarations: [
|
150
|
+
{
|
151
|
+
name: "AuthParamsSchema",
|
152
|
+
initializer: authParamsSchemaStr,
|
153
|
+
},
|
154
|
+
],
|
155
|
+
});
|
156
|
+
typesFile.addTypeAlias({
|
157
|
+
name: "AuthParamsType",
|
158
|
+
type: "z.infer<typeof AuthParamsSchema>",
|
159
|
+
isExported: true,
|
160
|
+
});
|
161
|
+
for (const [categoryName, category] of Object.entries(parsedConfig.actions)) {
|
162
|
+
for (const [actionName, action] of Object.entries(category)) {
|
163
|
+
if (action.parameters) {
|
164
|
+
yield validateObject(action.parameters);
|
165
|
+
}
|
166
|
+
if (action.output) {
|
167
|
+
yield validateObject(action.output);
|
168
|
+
}
|
169
|
+
const actionPrefix = `${categoryName}${(0, string_1.snakeToPascal)(actionName)}`;
|
170
|
+
const constName = `${actionPrefix}Definition`;
|
171
|
+
// Convert the action definition to a string representation
|
172
|
+
const templateObj = Object.assign({ provider: categoryName, name: actionName }, action);
|
173
|
+
// Validate the template object
|
174
|
+
const template = actionTemplateSchema.parse(templateObj);
|
175
|
+
// Add the constant declaration
|
176
|
+
const templateStr = JSON.stringify(template, null, 4);
|
177
|
+
templatesFile.addVariableStatement({
|
178
|
+
declarationKind: ts_morph_1.VariableDeclarationKind.Const,
|
179
|
+
isExported: true,
|
180
|
+
declarations: [
|
181
|
+
{
|
182
|
+
name: constName,
|
183
|
+
type: "ActionTemplate",
|
184
|
+
initializer: templateStr,
|
185
|
+
},
|
186
|
+
],
|
187
|
+
});
|
188
|
+
// parameter types
|
189
|
+
yield addActionTypes({
|
190
|
+
file: typesFile,
|
191
|
+
prefix: actionPrefix,
|
192
|
+
action,
|
193
|
+
});
|
194
|
+
}
|
195
|
+
}
|
196
|
+
// Save the generated TypeScript file
|
197
|
+
yield templatesFile.save();
|
198
|
+
yield typesFile.save();
|
199
|
+
});
|
200
|
+
}
|
201
|
+
generateTypes({});
|
@@ -0,0 +1,47 @@
|
|
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
|
+
function getConfluenceApi(baseUrl, username, apiToken) {
|
17
|
+
const api = axios_1.default.create({
|
18
|
+
baseURL: baseUrl,
|
19
|
+
headers: {
|
20
|
+
Accept: "application/json",
|
21
|
+
// Tokens are associated with a specific user.
|
22
|
+
Authorization: `Basic ${Buffer.from(`${username}:${apiToken}`).toString("base64")}`,
|
23
|
+
},
|
24
|
+
});
|
25
|
+
return api;
|
26
|
+
}
|
27
|
+
const confluenceUpdatePage = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, authParams, }) {
|
28
|
+
const { pageId, username, content, title } = params;
|
29
|
+
const { baseUrl, authToken } = authParams;
|
30
|
+
const api = getConfluenceApi(baseUrl, username, authToken);
|
31
|
+
// Get current version number
|
32
|
+
const response = yield api.get(`/api/v2/pages/${pageId}`);
|
33
|
+
const currVersion = response.data.version.number;
|
34
|
+
yield api.put(`/api/v2/pages/${pageId}`, {
|
35
|
+
id: pageId,
|
36
|
+
status: "current",
|
37
|
+
title,
|
38
|
+
body: {
|
39
|
+
representation: "storage",
|
40
|
+
value: content,
|
41
|
+
},
|
42
|
+
version: {
|
43
|
+
number: currVersion + 1,
|
44
|
+
},
|
45
|
+
});
|
46
|
+
});
|
47
|
+
exports.default = confluenceUpdatePage;
|
@@ -0,0 +1,31 @@
|
|
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 sdk_1 = require("@credal/sdk");
|
13
|
+
const callCopilot = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, authParams, }) {
|
14
|
+
const requestBody = {
|
15
|
+
agentId: params.agentId,
|
16
|
+
query: params.query,
|
17
|
+
userEmail: params.userEmail,
|
18
|
+
};
|
19
|
+
const client = new sdk_1.CredalClient({ apiKey: authParams.apiKey });
|
20
|
+
const response = yield client.copilots.sendMessage({
|
21
|
+
agentId: requestBody.agentId,
|
22
|
+
message: requestBody.query,
|
23
|
+
userEmail: requestBody.userEmail,
|
24
|
+
});
|
25
|
+
return {
|
26
|
+
response: response.sendChatResult.type === "ai_response_result"
|
27
|
+
? response.sendChatResult.response.message
|
28
|
+
: "Error getting response",
|
29
|
+
};
|
30
|
+
});
|
31
|
+
exports.default = callCopilot;
|
@@ -0,0 +1,30 @@
|
|
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 validateAddress = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, authParams, }) {
|
17
|
+
const url = `https://addressvalidation.googleapis.com/v1:validateAddress?key=${authParams.apiKey}`;
|
18
|
+
const requestBody = {
|
19
|
+
address: {
|
20
|
+
addressLines: [...params.addressLines, params.locality, params.regionCode, params.postalCode],
|
21
|
+
},
|
22
|
+
};
|
23
|
+
const response = yield axios_1.default.post(url, requestBody, {
|
24
|
+
headers: {
|
25
|
+
"Content-Type": "application/json",
|
26
|
+
},
|
27
|
+
});
|
28
|
+
return response.data;
|
29
|
+
});
|
30
|
+
exports.default = validateAddress;
|
@@ -0,0 +1,34 @@
|
|
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;
|
@@ -0,0 +1,34 @@
|
|
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;
|
@@ -0,0 +1,17 @@
|
|
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 mathAdd = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params }) {
|
13
|
+
return {
|
14
|
+
result: params.a + params.b,
|
15
|
+
};
|
16
|
+
});
|
17
|
+
exports.default = mathAdd;
|
@@ -0,0 +1 @@
|
|
1
|
+
export * as add from "./add";
|
@@ -0,0 +1,37 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
9
|
+
}) : (function(o, m, k, k2) {
|
10
|
+
if (k2 === undefined) k2 = k;
|
11
|
+
o[k2] = m[k];
|
12
|
+
}));
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
15
|
+
}) : function(o, v) {
|
16
|
+
o["default"] = v;
|
17
|
+
});
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
19
|
+
var ownKeys = function(o) {
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
21
|
+
var ar = [];
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
23
|
+
return ar;
|
24
|
+
};
|
25
|
+
return ownKeys(o);
|
26
|
+
};
|
27
|
+
return function (mod) {
|
28
|
+
if (mod && mod.__esModule) return mod;
|
29
|
+
var result = {};
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
31
|
+
__setModuleDefault(result, mod);
|
32
|
+
return result;
|
33
|
+
};
|
34
|
+
})();
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
36
|
+
exports.add = void 0;
|
37
|
+
exports.add = __importStar(require("./add"));
|