@credal/actions 0.2.53 → 0.2.55
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/dist/actions/autogen/templates.js +5 -1
- package/dist/actions/autogen/types.d.ts +7 -0
- package/dist/actions/autogen/types.js +1 -0
- package/dist/actions/providers/gitlab/searchGroup.d.ts +1 -1
- package/dist/actions/providers/gitlab/searchGroup.js +81 -7
- package/dist/actions/providers/google-oauth/getDriveFileContentById.js +44 -29
- package/dist/actions/util/axiosClient.d.ts +1 -0
- package/dist/actions/util/axiosClient.js +3 -0
- package/package.json +1 -1
|
@@ -9913,7 +9913,7 @@ export const gitlabSearchGroupDefinition = {
|
|
|
9913
9913
|
properties: {
|
|
9914
9914
|
metadata: {
|
|
9915
9915
|
type: "object",
|
|
9916
|
-
required: ["path", "basename", "data", "project_id", "ref", "startline", "filename"],
|
|
9916
|
+
required: ["path", "basename", "data", "project_id", "ref", "startline", "filename", "web_url"],
|
|
9917
9917
|
properties: {
|
|
9918
9918
|
path: {
|
|
9919
9919
|
type: "string",
|
|
@@ -9943,6 +9943,10 @@ export const gitlabSearchGroupDefinition = {
|
|
|
9943
9943
|
type: "string",
|
|
9944
9944
|
description: "The filename of the blob",
|
|
9945
9945
|
},
|
|
9946
|
+
web_url: {
|
|
9947
|
+
type: "string",
|
|
9948
|
+
description: "The URL of the blob",
|
|
9949
|
+
},
|
|
9946
9950
|
},
|
|
9947
9951
|
},
|
|
9948
9952
|
matchedMergeRequests: {
|
|
@@ -6716,11 +6716,13 @@ export declare const gitlabSearchGroupOutputSchema: z.ZodObject<{
|
|
|
6716
6716
|
ref: z.ZodString;
|
|
6717
6717
|
startline: z.ZodNumber;
|
|
6718
6718
|
filename: z.ZodString;
|
|
6719
|
+
web_url: z.ZodString;
|
|
6719
6720
|
}, "strip", z.ZodTypeAny, {
|
|
6720
6721
|
path: string;
|
|
6721
6722
|
data: string;
|
|
6722
6723
|
filename: string;
|
|
6723
6724
|
project_id: number;
|
|
6725
|
+
web_url: string;
|
|
6724
6726
|
basename: string;
|
|
6725
6727
|
ref: string;
|
|
6726
6728
|
startline: number;
|
|
@@ -6729,6 +6731,7 @@ export declare const gitlabSearchGroupOutputSchema: z.ZodObject<{
|
|
|
6729
6731
|
data: string;
|
|
6730
6732
|
filename: string;
|
|
6731
6733
|
project_id: number;
|
|
6734
|
+
web_url: string;
|
|
6732
6735
|
basename: string;
|
|
6733
6736
|
ref: string;
|
|
6734
6737
|
startline: number;
|
|
@@ -6755,6 +6758,7 @@ export declare const gitlabSearchGroupOutputSchema: z.ZodObject<{
|
|
|
6755
6758
|
data: string;
|
|
6756
6759
|
filename: string;
|
|
6757
6760
|
project_id: number;
|
|
6761
|
+
web_url: string;
|
|
6758
6762
|
basename: string;
|
|
6759
6763
|
ref: string;
|
|
6760
6764
|
startline: number;
|
|
@@ -6771,6 +6775,7 @@ export declare const gitlabSearchGroupOutputSchema: z.ZodObject<{
|
|
|
6771
6775
|
data: string;
|
|
6772
6776
|
filename: string;
|
|
6773
6777
|
project_id: number;
|
|
6778
|
+
web_url: string;
|
|
6774
6779
|
basename: string;
|
|
6775
6780
|
ref: string;
|
|
6776
6781
|
startline: number;
|
|
@@ -6812,6 +6817,7 @@ export declare const gitlabSearchGroupOutputSchema: z.ZodObject<{
|
|
|
6812
6817
|
data: string;
|
|
6813
6818
|
filename: string;
|
|
6814
6819
|
project_id: number;
|
|
6820
|
+
web_url: string;
|
|
6815
6821
|
basename: string;
|
|
6816
6822
|
ref: string;
|
|
6817
6823
|
startline: number;
|
|
@@ -6853,6 +6859,7 @@ export declare const gitlabSearchGroupOutputSchema: z.ZodObject<{
|
|
|
6853
6859
|
data: string;
|
|
6854
6860
|
filename: string;
|
|
6855
6861
|
project_id: number;
|
|
6862
|
+
web_url: string;
|
|
6856
6863
|
basename: string;
|
|
6857
6864
|
ref: string;
|
|
6858
6865
|
startline: number;
|
|
@@ -3475,6 +3475,7 @@ export const gitlabSearchGroupOutputSchema = z.object({
|
|
|
3475
3475
|
ref: z.string().describe("The ref of the blob"),
|
|
3476
3476
|
startline: z.number().describe("The start line of the blob"),
|
|
3477
3477
|
filename: z.string().describe("The filename of the blob"),
|
|
3478
|
+
web_url: z.string().describe("The URL of the blob"),
|
|
3478
3479
|
}),
|
|
3479
3480
|
matchedMergeRequests: z
|
|
3480
3481
|
.array(z.object({
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { gitlabSearchGroupFunction } from "../../autogen/types.js";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Searches for merge requests and blobs in a GitLab group
|
|
4
4
|
*/
|
|
5
5
|
declare const searchGroup: gitlabSearchGroupFunction;
|
|
6
6
|
export default searchGroup;
|
|
@@ -9,16 +9,75 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { MISSING_AUTH_TOKEN } from "../../util/missingAuthConstants.js";
|
|
11
11
|
const GITLAB_API_URL = "https://gitlab.com";
|
|
12
|
+
// Cache for project paths to avoid repeated API calls
|
|
13
|
+
const projectPathCache = new Map();
|
|
12
14
|
function gitlabFetch(endpoint, authToken) {
|
|
13
15
|
return __awaiter(this, void 0, void 0, function* () {
|
|
14
16
|
const res = yield fetch(endpoint, {
|
|
15
|
-
headers: {
|
|
17
|
+
headers: {
|
|
18
|
+
Authorization: `Bearer ${authToken}`,
|
|
19
|
+
},
|
|
16
20
|
});
|
|
17
21
|
if (!res.ok)
|
|
18
22
|
throw new Error(`GitLab API error: ${res.status} ${res.statusText}`);
|
|
19
23
|
return res.json();
|
|
20
24
|
});
|
|
21
25
|
}
|
|
26
|
+
function getProjectPath(projectId, authToken, baseUrl) {
|
|
27
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
// Check cache first
|
|
29
|
+
if (projectPathCache.has(projectId)) {
|
|
30
|
+
return projectPathCache.get(projectId);
|
|
31
|
+
}
|
|
32
|
+
try {
|
|
33
|
+
const project = yield gitlabFetch(`${baseUrl}/projects/${projectId}`, authToken);
|
|
34
|
+
const path = project.path_with_namespace;
|
|
35
|
+
projectPathCache.set(projectId, path);
|
|
36
|
+
return path;
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
console.warn(`Failed to fetch project path for project ${projectId}:`, error);
|
|
40
|
+
// Fallback to project ID if we can't get the path
|
|
41
|
+
return `project-${projectId}`;
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
function constructBlobUrl(input) {
|
|
46
|
+
const { baseUrl, projectPath, ref, path, startline } = input;
|
|
47
|
+
let url = `${baseUrl}/${projectPath}/-/blob/${ref}/${path}`;
|
|
48
|
+
// Add line number anchor if provided
|
|
49
|
+
if (startline && startline > 0) {
|
|
50
|
+
url += `#L${startline}`;
|
|
51
|
+
}
|
|
52
|
+
return url;
|
|
53
|
+
}
|
|
54
|
+
function enhanceBlobWithUrl(blob, authToken, baseUrl, gitlabWebBaseUrl) {
|
|
55
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
56
|
+
try {
|
|
57
|
+
const projectPath = yield getProjectPath(blob.project_id, authToken, baseUrl);
|
|
58
|
+
const web_url = constructBlobUrl({
|
|
59
|
+
baseUrl: gitlabWebBaseUrl,
|
|
60
|
+
projectPath,
|
|
61
|
+
ref: blob.ref,
|
|
62
|
+
path: blob.path,
|
|
63
|
+
startline: blob.startline,
|
|
64
|
+
});
|
|
65
|
+
return Object.assign(Object.assign({}, blob), { web_url });
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
console.warn(`Failed to construct URL for blob in project ${blob.project_id}:`, error);
|
|
69
|
+
// Fallback URL construction
|
|
70
|
+
const fallbackUrl = constructBlobUrl({
|
|
71
|
+
baseUrl: gitlabWebBaseUrl,
|
|
72
|
+
projectPath: `project-${blob.project_id}`,
|
|
73
|
+
ref: blob.ref,
|
|
74
|
+
path: blob.path,
|
|
75
|
+
startline: blob.startline,
|
|
76
|
+
});
|
|
77
|
+
return Object.assign(Object.assign({}, blob), { web_url: fallbackUrl });
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
22
81
|
function globalSearch(input) {
|
|
23
82
|
return __awaiter(this, void 0, void 0, function* () {
|
|
24
83
|
const { scope, query, groupId, authToken, baseUrl } = input;
|
|
@@ -34,29 +93,44 @@ function getMRDiffs(input) {
|
|
|
34
93
|
});
|
|
35
94
|
}
|
|
36
95
|
/**
|
|
37
|
-
*
|
|
96
|
+
* Searches for merge requests and blobs in a GitLab group
|
|
38
97
|
*/
|
|
39
98
|
const searchGroup = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, authParams, }) {
|
|
40
99
|
const { authToken, baseUrl } = authParams;
|
|
41
|
-
const gitlabBaseUrl =
|
|
100
|
+
const gitlabBaseUrl = baseUrl !== null && baseUrl !== void 0 ? baseUrl : GITLAB_API_URL;
|
|
101
|
+
const gitlabBaseApiUrl = `${gitlabBaseUrl}/api/v4`;
|
|
42
102
|
if (!authToken) {
|
|
43
103
|
throw new Error(MISSING_AUTH_TOKEN);
|
|
44
104
|
}
|
|
45
105
|
const { query, groupId } = params;
|
|
46
106
|
const [mrResults, blobResults] = yield Promise.all([
|
|
47
|
-
globalSearch({
|
|
48
|
-
|
|
107
|
+
globalSearch({
|
|
108
|
+
scope: "merge_requests",
|
|
109
|
+
query,
|
|
110
|
+
groupId,
|
|
111
|
+
authToken,
|
|
112
|
+
baseUrl: gitlabBaseApiUrl,
|
|
113
|
+
}),
|
|
114
|
+
globalSearch({
|
|
115
|
+
scope: "blobs",
|
|
116
|
+
query,
|
|
117
|
+
groupId,
|
|
118
|
+
authToken,
|
|
119
|
+
baseUrl: gitlabBaseApiUrl,
|
|
120
|
+
}),
|
|
49
121
|
]);
|
|
50
122
|
const mergeRequests = yield Promise.all(mrResults.map((metadata) => __awaiter(void 0, void 0, void 0, function* () {
|
|
51
123
|
const diffs = yield getMRDiffs({
|
|
52
124
|
projectId: metadata.project_id,
|
|
53
125
|
mrIid: metadata.iid,
|
|
54
126
|
authToken,
|
|
55
|
-
baseUrl:
|
|
127
|
+
baseUrl: gitlabBaseApiUrl,
|
|
56
128
|
});
|
|
57
129
|
return { metadata, diffs };
|
|
58
130
|
})));
|
|
59
|
-
|
|
131
|
+
// Enhance blobs with web URLs
|
|
132
|
+
const blobsWithUrls = yield Promise.all(blobResults.map(blob => enhanceBlobWithUrl(blob, authToken, gitlabBaseApiUrl, gitlabBaseUrl)));
|
|
133
|
+
const blobs = blobsWithUrls.map(blob => {
|
|
60
134
|
const matches = mergeRequests
|
|
61
135
|
.filter(mr => mr.metadata.project_id === blob.project_id && mr.diffs.some(diff => diff.new_path === blob.path))
|
|
62
136
|
.map(mr => {
|
|
@@ -7,7 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import { createAxiosClientWithTimeout } from "../../util/axiosClient.js";
|
|
10
|
+
import { createAxiosClientWithTimeout, isAxiosTimeoutError } from "../../util/axiosClient.js";
|
|
11
11
|
import mammoth from "mammoth";
|
|
12
12
|
import { MISSING_AUTH_TOKEN } from "../../util/missingAuthConstants.js";
|
|
13
13
|
import { extractTextFromPdf } from "../../../utils/pdf.js";
|
|
@@ -50,16 +50,21 @@ const getDriveFileContentById = (_a) => __awaiter(void 0, [_a], void 0, function
|
|
|
50
50
|
content = parseGoogleDocFromRawContentToPlainText(docsRes.data);
|
|
51
51
|
}
|
|
52
52
|
catch (docsError) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
53
|
+
if (isAxiosTimeoutError(docsError)) {
|
|
54
|
+
console.log("Request timed out using Google Docs API - dont retry");
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
console.log("Error using Google Docs API", docsError);
|
|
58
|
+
// Fallback to Drive API export if Docs API fails
|
|
59
|
+
const exportUrl = `${BASE_URL}${encodeURIComponent(fileId)}/export?mimeType=text/plain${sharedDriveParams}`;
|
|
60
|
+
const exportRes = yield axiosClient.get(exportUrl, {
|
|
61
|
+
headers: {
|
|
62
|
+
Authorization: `Bearer ${authParams.authToken}`,
|
|
63
|
+
},
|
|
64
|
+
responseType: "text",
|
|
65
|
+
});
|
|
66
|
+
content = exportRes.data;
|
|
67
|
+
}
|
|
63
68
|
}
|
|
64
69
|
}
|
|
65
70
|
// Google Sheets - use Google Sheets API instead of Drive export
|
|
@@ -74,17 +79,22 @@ const getDriveFileContentById = (_a) => __awaiter(void 0, [_a], void 0, function
|
|
|
74
79
|
content = parseGoogleSheetsFromRawContentToPlainText(sheetsRes.data);
|
|
75
80
|
}
|
|
76
81
|
catch (sheetsError) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
.
|
|
82
|
+
if (isAxiosTimeoutError(sheetsError)) {
|
|
83
|
+
console.log("Request timed out using Google Sheets API - dont retry");
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
console.log("Error fetching file", sheetsError);
|
|
87
|
+
const exportUrl = `${BASE_URL}${encodeURIComponent(fileId)}/export?mimeType=text/csv${sharedDriveParams}`;
|
|
88
|
+
const exportRes = yield axiosClient.get(exportUrl, {
|
|
89
|
+
headers: { Authorization: `Bearer ${authParams.authToken}` },
|
|
90
|
+
responseType: "text",
|
|
91
|
+
});
|
|
92
|
+
content = exportRes.data
|
|
93
|
+
.split("\n")
|
|
94
|
+
.map((line) => line.replace(/,+$/, ""))
|
|
95
|
+
.map((line) => line.replace(/,{2,}/g, ","))
|
|
96
|
+
.join("\n");
|
|
97
|
+
}
|
|
88
98
|
}
|
|
89
99
|
}
|
|
90
100
|
// Google Slides - use Google Slides API instead of Drive export
|
|
@@ -99,13 +109,18 @@ const getDriveFileContentById = (_a) => __awaiter(void 0, [_a], void 0, function
|
|
|
99
109
|
content = parseGoogleSlidesFromRawContentToPlainText(slidesRes.data);
|
|
100
110
|
}
|
|
101
111
|
catch (slidesError) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
112
|
+
if (isAxiosTimeoutError(slidesError)) {
|
|
113
|
+
console.log("Request timed out using Google Slides API - dont retry");
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
console.log("Error using Google Slides API", slidesError);
|
|
117
|
+
const exportUrl = `${BASE_URL}${encodeURIComponent(fileId)}/export?mimeType=text/plain${sharedDriveParams}`;
|
|
118
|
+
const exportRes = yield axiosClient.get(exportUrl, {
|
|
119
|
+
headers: { Authorization: `Bearer ${authParams.authToken}` },
|
|
120
|
+
responseType: "text",
|
|
121
|
+
});
|
|
122
|
+
content = exportRes.data;
|
|
123
|
+
}
|
|
109
124
|
}
|
|
110
125
|
}
|
|
111
126
|
// PDF files - download and extract text using pdfjs-dist
|
|
@@ -4,5 +4,6 @@ export declare class ApiError extends Error {
|
|
|
4
4
|
data?: any;
|
|
5
5
|
constructor(message: string, status?: number, data?: any);
|
|
6
6
|
}
|
|
7
|
+
export declare function isAxiosTimeoutError(error: unknown): boolean;
|
|
7
8
|
export declare const axiosClient: AxiosInstance;
|
|
8
9
|
export declare function createAxiosClientWithTimeout(timeout: number): AxiosInstance;
|
|
@@ -7,6 +7,9 @@ export class ApiError extends Error {
|
|
|
7
7
|
this.data = data;
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
|
+
export function isAxiosTimeoutError(error) {
|
|
11
|
+
return error instanceof ApiError && !error.status && !error.data;
|
|
12
|
+
}
|
|
10
13
|
/** Create a configured axios instance with interceptors */
|
|
11
14
|
function createAxiosClient(timeout) {
|
|
12
15
|
const instance = axios.create({
|