@gitlab/gitlab-ai-provider 3.1.1 → 3.1.3
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/CHANGELOG.md +9 -0
- package/README.md +9 -30
- package/dist/gitlab-gitlab-ai-provider-3.1.3.tgz +0 -0
- package/dist/index.d.mts +75 -85
- package/dist/index.d.ts +75 -85
- package/dist/index.js +174 -1307
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +171 -1301
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/dist/gitlab-gitlab-ai-provider-3.1.1.tgz +0 -0
package/dist/index.mjs
CHANGED
|
@@ -45,14 +45,17 @@ var directAccessTokenSchema = z.object({
|
|
|
45
45
|
headers: z.record(z.string()),
|
|
46
46
|
token: z.string()
|
|
47
47
|
});
|
|
48
|
+
var DEFAULT_AI_GATEWAY_URL = "https://cloud.gitlab.com";
|
|
48
49
|
var GitLabDirectAccessClient = class {
|
|
49
50
|
config;
|
|
50
51
|
fetchFn;
|
|
52
|
+
aiGatewayUrl;
|
|
51
53
|
cachedToken = null;
|
|
52
54
|
tokenExpiresAt = 0;
|
|
53
55
|
constructor(config) {
|
|
54
56
|
this.config = config;
|
|
55
57
|
this.fetchFn = config.fetch ?? fetch;
|
|
58
|
+
this.aiGatewayUrl = config.aiGatewayUrl || process.env["GITLAB_AI_GATEWAY_URL"] || DEFAULT_AI_GATEWAY_URL;
|
|
56
59
|
}
|
|
57
60
|
/**
|
|
58
61
|
* Get a direct access token for the Anthropic proxy.
|
|
@@ -89,12 +92,23 @@ var GitLabDirectAccessClient = class {
|
|
|
89
92
|
return await this.getDirectAccessToken(true);
|
|
90
93
|
} catch (refreshError) {
|
|
91
94
|
throw new GitLabError({
|
|
92
|
-
message: `Failed to get direct access token: ${response.status} ${response.statusText} - ${errorText}
|
|
95
|
+
message: `Failed to get direct access token: ${response.status} ${response.statusText} - ${errorText}`,
|
|
96
|
+
statusCode: response.status,
|
|
97
|
+
responseBody: errorText
|
|
93
98
|
});
|
|
94
99
|
}
|
|
95
100
|
}
|
|
101
|
+
if (response.status === 403) {
|
|
102
|
+
throw new GitLabError({
|
|
103
|
+
message: `Access denied to GitLab AI features (${this.config.instanceUrl}). This may indicate that: (1) GitLab Duo is not enabled on this instance, (2) Your account does not have access to AI features, or (3) The third-party agents feature is not available. Original error: ${response.status} ${response.statusText} - ${errorText}`,
|
|
104
|
+
statusCode: response.status,
|
|
105
|
+
responseBody: errorText
|
|
106
|
+
});
|
|
107
|
+
}
|
|
96
108
|
throw new GitLabError({
|
|
97
|
-
message: `Failed to get direct access token: ${response.status} ${response.statusText} - ${errorText}
|
|
109
|
+
message: `Failed to get direct access token: ${response.status} ${response.statusText} - ${errorText}`,
|
|
110
|
+
statusCode: response.status,
|
|
111
|
+
responseBody: errorText
|
|
98
112
|
});
|
|
99
113
|
}
|
|
100
114
|
const data = await response.json();
|
|
@@ -116,7 +130,8 @@ var GitLabDirectAccessClient = class {
|
|
|
116
130
|
* Get the Anthropic proxy base URL
|
|
117
131
|
*/
|
|
118
132
|
getAnthropicProxyUrl() {
|
|
119
|
-
|
|
133
|
+
const baseUrl = this.aiGatewayUrl.replace(/\/$/, "");
|
|
134
|
+
return `${baseUrl}/ai/v1/proxy/anthropic/`;
|
|
120
135
|
}
|
|
121
136
|
/**
|
|
122
137
|
* Invalidate the cached token
|
|
@@ -143,7 +158,8 @@ var GitLabAgenticLanguageModel = class {
|
|
|
143
158
|
getHeaders: config.getHeaders,
|
|
144
159
|
refreshApiKey: config.refreshApiKey,
|
|
145
160
|
fetch: config.fetch,
|
|
146
|
-
featureFlags: config.featureFlags
|
|
161
|
+
featureFlags: config.featureFlags,
|
|
162
|
+
aiGatewayUrl: config.aiGatewayUrl
|
|
147
163
|
});
|
|
148
164
|
}
|
|
149
165
|
get provider() {
|
|
@@ -155,10 +171,12 @@ var GitLabAgenticLanguageModel = class {
|
|
|
155
171
|
*/
|
|
156
172
|
async getAnthropicClient(forceRefresh = false) {
|
|
157
173
|
const tokenData = await this.directAccessClient.getDirectAccessToken(forceRefresh);
|
|
174
|
+
const { "x-api-key": _removed, ...filteredHeaders } = tokenData.headers;
|
|
158
175
|
this.anthropicClient = new Anthropic({
|
|
176
|
+
apiKey: null,
|
|
159
177
|
authToken: tokenData.token,
|
|
160
178
|
baseURL: this.directAccessClient.getAnthropicProxyUrl(),
|
|
161
|
-
defaultHeaders:
|
|
179
|
+
defaultHeaders: filteredHeaders
|
|
162
180
|
});
|
|
163
181
|
return this.anthropicClient;
|
|
164
182
|
}
|
|
@@ -392,114 +410,155 @@ var GitLabAgenticLanguageModel = class {
|
|
|
392
410
|
const self = this;
|
|
393
411
|
const stream = new ReadableStream({
|
|
394
412
|
start: async (controller) => {
|
|
413
|
+
const contentBlocks = {};
|
|
414
|
+
const usage = {
|
|
415
|
+
inputTokens: 0,
|
|
416
|
+
outputTokens: 0,
|
|
417
|
+
totalTokens: 0
|
|
418
|
+
};
|
|
419
|
+
let finishReason = "unknown";
|
|
395
420
|
try {
|
|
396
|
-
const anthropicStream = client.messages.stream(requestBody
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
let currentToolName = null;
|
|
400
|
-
const usage = {
|
|
401
|
-
inputTokens: 0,
|
|
402
|
-
outputTokens: 0,
|
|
403
|
-
totalTokens: 0
|
|
404
|
-
};
|
|
405
|
-
let finishReason = "unknown";
|
|
421
|
+
const anthropicStream = client.messages.stream(requestBody, {
|
|
422
|
+
signal: options.abortSignal
|
|
423
|
+
});
|
|
406
424
|
controller.enqueue({
|
|
407
425
|
type: "stream-start",
|
|
408
426
|
warnings: []
|
|
409
427
|
});
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
type
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
428
|
+
await new Promise((resolve2, reject) => {
|
|
429
|
+
anthropicStream.on("streamEvent", (event) => {
|
|
430
|
+
try {
|
|
431
|
+
switch (event.type) {
|
|
432
|
+
case "message_start":
|
|
433
|
+
if (event.message.usage) {
|
|
434
|
+
usage.inputTokens = event.message.usage.input_tokens;
|
|
435
|
+
}
|
|
436
|
+
controller.enqueue({
|
|
437
|
+
type: "response-metadata",
|
|
438
|
+
id: event.message.id,
|
|
439
|
+
modelId: event.message.model
|
|
440
|
+
});
|
|
441
|
+
break;
|
|
442
|
+
case "content_block_start":
|
|
443
|
+
if (event.content_block.type === "text") {
|
|
444
|
+
const textId = `text-${event.index}`;
|
|
445
|
+
contentBlocks[event.index] = { type: "text", id: textId };
|
|
446
|
+
controller.enqueue({
|
|
447
|
+
type: "text-start",
|
|
448
|
+
id: textId
|
|
449
|
+
});
|
|
450
|
+
} else if (event.content_block.type === "tool_use") {
|
|
451
|
+
contentBlocks[event.index] = {
|
|
452
|
+
type: "tool-call",
|
|
453
|
+
toolCallId: event.content_block.id,
|
|
454
|
+
toolName: event.content_block.name,
|
|
455
|
+
input: ""
|
|
456
|
+
};
|
|
457
|
+
controller.enqueue({
|
|
458
|
+
type: "tool-input-start",
|
|
459
|
+
id: event.content_block.id,
|
|
460
|
+
toolName: event.content_block.name
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
break;
|
|
464
|
+
case "content_block_delta": {
|
|
465
|
+
const block = contentBlocks[event.index];
|
|
466
|
+
if (event.delta.type === "text_delta" && block?.type === "text") {
|
|
467
|
+
controller.enqueue({
|
|
468
|
+
type: "text-delta",
|
|
469
|
+
id: block.id,
|
|
470
|
+
delta: event.delta.text
|
|
471
|
+
});
|
|
472
|
+
} else if (event.delta.type === "input_json_delta" && block?.type === "tool-call") {
|
|
473
|
+
block.input += event.delta.partial_json;
|
|
474
|
+
controller.enqueue({
|
|
475
|
+
type: "tool-input-delta",
|
|
476
|
+
id: block.toolCallId,
|
|
477
|
+
delta: event.delta.partial_json
|
|
478
|
+
});
|
|
479
|
+
}
|
|
480
|
+
break;
|
|
481
|
+
}
|
|
482
|
+
case "content_block_stop": {
|
|
483
|
+
const block = contentBlocks[event.index];
|
|
484
|
+
if (block?.type === "text") {
|
|
485
|
+
controller.enqueue({
|
|
486
|
+
type: "text-end",
|
|
487
|
+
id: block.id
|
|
488
|
+
});
|
|
489
|
+
} else if (block?.type === "tool-call") {
|
|
490
|
+
controller.enqueue({
|
|
491
|
+
type: "tool-input-end",
|
|
492
|
+
id: block.toolCallId
|
|
493
|
+
});
|
|
494
|
+
controller.enqueue({
|
|
495
|
+
type: "tool-call",
|
|
496
|
+
toolCallId: block.toolCallId,
|
|
497
|
+
toolName: block.toolName,
|
|
498
|
+
input: block.input === "" ? "{}" : block.input
|
|
499
|
+
});
|
|
500
|
+
}
|
|
501
|
+
delete contentBlocks[event.index];
|
|
502
|
+
break;
|
|
503
|
+
}
|
|
504
|
+
case "message_delta":
|
|
505
|
+
if (event.usage) {
|
|
506
|
+
usage.outputTokens = event.usage.output_tokens;
|
|
507
|
+
usage.totalTokens = (usage.inputTokens || 0) + event.usage.output_tokens;
|
|
508
|
+
}
|
|
509
|
+
if (event.delta.stop_reason) {
|
|
510
|
+
finishReason = self.convertFinishReason(event.delta.stop_reason);
|
|
511
|
+
}
|
|
512
|
+
break;
|
|
513
|
+
case "message_stop": {
|
|
484
514
|
controller.enqueue({
|
|
485
|
-
type: "
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
input: JSON.stringify(block.input)
|
|
515
|
+
type: "finish",
|
|
516
|
+
finishReason,
|
|
517
|
+
usage
|
|
489
518
|
});
|
|
519
|
+
break;
|
|
490
520
|
}
|
|
491
521
|
}
|
|
492
|
-
|
|
493
|
-
type: "finish",
|
|
494
|
-
finishReason,
|
|
495
|
-
usage
|
|
496
|
-
});
|
|
497
|
-
break;
|
|
522
|
+
} catch {
|
|
498
523
|
}
|
|
524
|
+
});
|
|
525
|
+
anthropicStream.on("end", () => {
|
|
526
|
+
resolve2();
|
|
527
|
+
});
|
|
528
|
+
anthropicStream.on("error", (error) => {
|
|
529
|
+
reject(error);
|
|
530
|
+
});
|
|
531
|
+
});
|
|
532
|
+
for (const [, block] of Object.entries(contentBlocks)) {
|
|
533
|
+
if (block.type === "tool-call") {
|
|
534
|
+
controller.enqueue({
|
|
535
|
+
type: "tool-input-end",
|
|
536
|
+
id: block.toolCallId
|
|
537
|
+
});
|
|
538
|
+
controller.enqueue({
|
|
539
|
+
type: "tool-call",
|
|
540
|
+
toolCallId: block.toolCallId,
|
|
541
|
+
toolName: block.toolName,
|
|
542
|
+
input: block.input === "" ? "{}" : block.input
|
|
543
|
+
});
|
|
499
544
|
}
|
|
500
545
|
}
|
|
501
546
|
controller.close();
|
|
502
547
|
} catch (error) {
|
|
548
|
+
for (const [, block] of Object.entries(contentBlocks)) {
|
|
549
|
+
if (block.type === "tool-call") {
|
|
550
|
+
controller.enqueue({
|
|
551
|
+
type: "tool-input-end",
|
|
552
|
+
id: block.toolCallId
|
|
553
|
+
});
|
|
554
|
+
controller.enqueue({
|
|
555
|
+
type: "tool-call",
|
|
556
|
+
toolCallId: block.toolCallId,
|
|
557
|
+
toolName: block.toolName,
|
|
558
|
+
input: block.input === "" ? "{}" : block.input
|
|
559
|
+
});
|
|
560
|
+
}
|
|
561
|
+
}
|
|
503
562
|
if (!isRetry && self.isTokenError(error)) {
|
|
504
563
|
self.directAccessClient.invalidateToken();
|
|
505
564
|
controller.enqueue({
|
|
@@ -857,7 +916,8 @@ function createGitLab(options = {}) {
|
|
|
857
916
|
fetch: options.fetch,
|
|
858
917
|
anthropicModel: agenticOptions?.anthropicModel ?? getAnthropicModelForModelId(modelId),
|
|
859
918
|
maxTokens: agenticOptions?.maxTokens,
|
|
860
|
-
featureFlags
|
|
919
|
+
featureFlags,
|
|
920
|
+
aiGatewayUrl: options.aiGatewayUrl
|
|
861
921
|
});
|
|
862
922
|
};
|
|
863
923
|
const createDefaultModel = (modelId) => {
|
|
@@ -883,1196 +943,9 @@ function createGitLab(options = {}) {
|
|
|
883
943
|
}
|
|
884
944
|
var gitlab = createGitLab();
|
|
885
945
|
|
|
886
|
-
// src/gitlab-api-tools.ts
|
|
887
|
-
var GITLAB_API_TOOLS = [
|
|
888
|
-
// Merge Request Tools
|
|
889
|
-
{
|
|
890
|
-
name: "gitlab_get_merge_request",
|
|
891
|
-
description: `Get details of a specific merge request by project and MR IID.
|
|
892
|
-
Returns: title, description, state, author, assignees, reviewers, labels, diff stats, and discussion notes.`,
|
|
893
|
-
input_schema: {
|
|
894
|
-
type: "object",
|
|
895
|
-
properties: {
|
|
896
|
-
project_id: {
|
|
897
|
-
type: "string",
|
|
898
|
-
description: 'The project ID or URL-encoded path (e.g., "gitlab-org/gitlab" or "123")'
|
|
899
|
-
},
|
|
900
|
-
mr_iid: {
|
|
901
|
-
type: "number",
|
|
902
|
-
description: "The internal ID of the merge request within the project"
|
|
903
|
-
},
|
|
904
|
-
include_changes: {
|
|
905
|
-
type: "boolean",
|
|
906
|
-
description: "Whether to include the list of changed files (default: false)"
|
|
907
|
-
}
|
|
908
|
-
},
|
|
909
|
-
required: ["project_id", "mr_iid"]
|
|
910
|
-
}
|
|
911
|
-
},
|
|
912
|
-
{
|
|
913
|
-
name: "gitlab_list_merge_requests",
|
|
914
|
-
description: `List merge requests for a project or search globally.
|
|
915
|
-
Can filter by state (opened, closed, merged, all), scope (assigned_to_me, created_by_me), and labels.`,
|
|
916
|
-
input_schema: {
|
|
917
|
-
type: "object",
|
|
918
|
-
properties: {
|
|
919
|
-
project_id: {
|
|
920
|
-
type: "string",
|
|
921
|
-
description: "The project ID or path. If not provided, searches globally."
|
|
922
|
-
},
|
|
923
|
-
state: {
|
|
924
|
-
type: "string",
|
|
925
|
-
enum: ["opened", "closed", "merged", "all"],
|
|
926
|
-
description: "Filter by MR state (default: opened)"
|
|
927
|
-
},
|
|
928
|
-
scope: {
|
|
929
|
-
type: "string",
|
|
930
|
-
enum: ["assigned_to_me", "created_by_me", "all"],
|
|
931
|
-
description: "Filter by scope"
|
|
932
|
-
},
|
|
933
|
-
search: {
|
|
934
|
-
type: "string",
|
|
935
|
-
description: "Search MRs by title or description"
|
|
936
|
-
},
|
|
937
|
-
labels: {
|
|
938
|
-
type: "string",
|
|
939
|
-
description: "Comma-separated list of labels to filter by"
|
|
940
|
-
},
|
|
941
|
-
limit: {
|
|
942
|
-
type: "number",
|
|
943
|
-
description: "Maximum number of results (default: 20)"
|
|
944
|
-
}
|
|
945
|
-
},
|
|
946
|
-
required: []
|
|
947
|
-
}
|
|
948
|
-
},
|
|
949
|
-
{
|
|
950
|
-
name: "gitlab_get_mr_changes",
|
|
951
|
-
description: `Get the file changes (diff) for a merge request.
|
|
952
|
-
Returns the list of files changed with their diffs.`,
|
|
953
|
-
input_schema: {
|
|
954
|
-
type: "object",
|
|
955
|
-
properties: {
|
|
956
|
-
project_id: {
|
|
957
|
-
type: "string",
|
|
958
|
-
description: "The project ID or URL-encoded path"
|
|
959
|
-
},
|
|
960
|
-
mr_iid: {
|
|
961
|
-
type: "number",
|
|
962
|
-
description: "The internal ID of the merge request"
|
|
963
|
-
}
|
|
964
|
-
},
|
|
965
|
-
required: ["project_id", "mr_iid"]
|
|
966
|
-
}
|
|
967
|
-
},
|
|
968
|
-
{
|
|
969
|
-
name: "gitlab_list_mr_discussions",
|
|
970
|
-
description: `List discussions (comments/threads) on a merge request.
|
|
971
|
-
Returns all discussion threads including resolved status.`,
|
|
972
|
-
input_schema: {
|
|
973
|
-
type: "object",
|
|
974
|
-
properties: {
|
|
975
|
-
project_id: {
|
|
976
|
-
type: "string",
|
|
977
|
-
description: "The project ID or URL-encoded path"
|
|
978
|
-
},
|
|
979
|
-
mr_iid: {
|
|
980
|
-
type: "number",
|
|
981
|
-
description: "The internal ID of the merge request"
|
|
982
|
-
}
|
|
983
|
-
},
|
|
984
|
-
required: ["project_id", "mr_iid"]
|
|
985
|
-
}
|
|
986
|
-
},
|
|
987
|
-
{
|
|
988
|
-
name: "gitlab_create_mr_note",
|
|
989
|
-
description: `Add a comment/note to a merge request.`,
|
|
990
|
-
input_schema: {
|
|
991
|
-
type: "object",
|
|
992
|
-
properties: {
|
|
993
|
-
project_id: {
|
|
994
|
-
type: "string",
|
|
995
|
-
description: "The project ID or URL-encoded path"
|
|
996
|
-
},
|
|
997
|
-
mr_iid: {
|
|
998
|
-
type: "number",
|
|
999
|
-
description: "The internal ID of the merge request"
|
|
1000
|
-
},
|
|
1001
|
-
body: {
|
|
1002
|
-
type: "string",
|
|
1003
|
-
description: "The content of the note/comment (supports Markdown)"
|
|
1004
|
-
}
|
|
1005
|
-
},
|
|
1006
|
-
required: ["project_id", "mr_iid", "body"]
|
|
1007
|
-
}
|
|
1008
|
-
},
|
|
1009
|
-
// Issue Tools
|
|
1010
|
-
{
|
|
1011
|
-
name: "gitlab_get_issue",
|
|
1012
|
-
description: `Get details of a specific issue by project and issue IID.
|
|
1013
|
-
Returns: title, description, state, author, assignees, labels, milestone, weight, and comments.`,
|
|
1014
|
-
input_schema: {
|
|
1015
|
-
type: "object",
|
|
1016
|
-
properties: {
|
|
1017
|
-
project_id: {
|
|
1018
|
-
type: "string",
|
|
1019
|
-
description: "The project ID or URL-encoded path"
|
|
1020
|
-
},
|
|
1021
|
-
issue_iid: {
|
|
1022
|
-
type: "number",
|
|
1023
|
-
description: "The internal ID of the issue within the project"
|
|
1024
|
-
}
|
|
1025
|
-
},
|
|
1026
|
-
required: ["project_id", "issue_iid"]
|
|
1027
|
-
}
|
|
1028
|
-
},
|
|
1029
|
-
{
|
|
1030
|
-
name: "gitlab_list_issues",
|
|
1031
|
-
description: `List issues for a project or search globally.
|
|
1032
|
-
Can filter by state, labels, assignee, milestone.`,
|
|
1033
|
-
input_schema: {
|
|
1034
|
-
type: "object",
|
|
1035
|
-
properties: {
|
|
1036
|
-
project_id: {
|
|
1037
|
-
type: "string",
|
|
1038
|
-
description: "The project ID or path. If not provided, searches globally."
|
|
1039
|
-
},
|
|
1040
|
-
state: {
|
|
1041
|
-
type: "string",
|
|
1042
|
-
enum: ["opened", "closed", "all"],
|
|
1043
|
-
description: "Filter by issue state (default: opened)"
|
|
1044
|
-
},
|
|
1045
|
-
scope: {
|
|
1046
|
-
type: "string",
|
|
1047
|
-
enum: ["assigned_to_me", "created_by_me", "all"],
|
|
1048
|
-
description: "Filter by scope"
|
|
1049
|
-
},
|
|
1050
|
-
search: {
|
|
1051
|
-
type: "string",
|
|
1052
|
-
description: "Search issues by title or description"
|
|
1053
|
-
},
|
|
1054
|
-
labels: {
|
|
1055
|
-
type: "string",
|
|
1056
|
-
description: "Comma-separated list of labels to filter by"
|
|
1057
|
-
},
|
|
1058
|
-
milestone: {
|
|
1059
|
-
type: "string",
|
|
1060
|
-
description: "Filter by milestone title"
|
|
1061
|
-
},
|
|
1062
|
-
limit: {
|
|
1063
|
-
type: "number",
|
|
1064
|
-
description: "Maximum number of results (default: 20)"
|
|
1065
|
-
}
|
|
1066
|
-
},
|
|
1067
|
-
required: []
|
|
1068
|
-
}
|
|
1069
|
-
},
|
|
1070
|
-
{
|
|
1071
|
-
name: "gitlab_create_issue_note",
|
|
1072
|
-
description: `Add a comment/note to an issue.`,
|
|
1073
|
-
input_schema: {
|
|
1074
|
-
type: "object",
|
|
1075
|
-
properties: {
|
|
1076
|
-
project_id: {
|
|
1077
|
-
type: "string",
|
|
1078
|
-
description: "The project ID or URL-encoded path"
|
|
1079
|
-
},
|
|
1080
|
-
issue_iid: {
|
|
1081
|
-
type: "number",
|
|
1082
|
-
description: "The internal ID of the issue"
|
|
1083
|
-
},
|
|
1084
|
-
body: {
|
|
1085
|
-
type: "string",
|
|
1086
|
-
description: "The content of the note/comment (supports Markdown)"
|
|
1087
|
-
}
|
|
1088
|
-
},
|
|
1089
|
-
required: ["project_id", "issue_iid", "body"]
|
|
1090
|
-
}
|
|
1091
|
-
},
|
|
1092
|
-
// Pipeline/CI Tools
|
|
1093
|
-
{
|
|
1094
|
-
name: "gitlab_list_pipelines",
|
|
1095
|
-
description: `List pipelines for a project.
|
|
1096
|
-
Can filter by status, ref (branch/tag), username.`,
|
|
1097
|
-
input_schema: {
|
|
1098
|
-
type: "object",
|
|
1099
|
-
properties: {
|
|
1100
|
-
project_id: {
|
|
1101
|
-
type: "string",
|
|
1102
|
-
description: "The project ID or URL-encoded path"
|
|
1103
|
-
},
|
|
1104
|
-
status: {
|
|
1105
|
-
type: "string",
|
|
1106
|
-
enum: ["running", "pending", "success", "failed", "canceled", "skipped", "manual"],
|
|
1107
|
-
description: "Filter by pipeline status"
|
|
1108
|
-
},
|
|
1109
|
-
ref: {
|
|
1110
|
-
type: "string",
|
|
1111
|
-
description: "Filter by branch or tag name"
|
|
1112
|
-
},
|
|
1113
|
-
limit: {
|
|
1114
|
-
type: "number",
|
|
1115
|
-
description: "Maximum number of results (default: 20)"
|
|
1116
|
-
}
|
|
1117
|
-
},
|
|
1118
|
-
required: ["project_id"]
|
|
1119
|
-
}
|
|
1120
|
-
},
|
|
1121
|
-
{
|
|
1122
|
-
name: "gitlab_get_pipeline",
|
|
1123
|
-
description: `Get details of a specific pipeline including its jobs.`,
|
|
1124
|
-
input_schema: {
|
|
1125
|
-
type: "object",
|
|
1126
|
-
properties: {
|
|
1127
|
-
project_id: {
|
|
1128
|
-
type: "string",
|
|
1129
|
-
description: "The project ID or URL-encoded path"
|
|
1130
|
-
},
|
|
1131
|
-
pipeline_id: {
|
|
1132
|
-
type: "number",
|
|
1133
|
-
description: "The ID of the pipeline"
|
|
1134
|
-
}
|
|
1135
|
-
},
|
|
1136
|
-
required: ["project_id", "pipeline_id"]
|
|
1137
|
-
}
|
|
1138
|
-
},
|
|
1139
|
-
{
|
|
1140
|
-
name: "gitlab_list_pipeline_jobs",
|
|
1141
|
-
description: `List jobs for a pipeline, optionally filter by scope (failed, success, etc).`,
|
|
1142
|
-
input_schema: {
|
|
1143
|
-
type: "object",
|
|
1144
|
-
properties: {
|
|
1145
|
-
project_id: {
|
|
1146
|
-
type: "string",
|
|
1147
|
-
description: "The project ID or URL-encoded path"
|
|
1148
|
-
},
|
|
1149
|
-
pipeline_id: {
|
|
1150
|
-
type: "number",
|
|
1151
|
-
description: "The ID of the pipeline"
|
|
1152
|
-
},
|
|
1153
|
-
scope: {
|
|
1154
|
-
type: "string",
|
|
1155
|
-
enum: [
|
|
1156
|
-
"created",
|
|
1157
|
-
"pending",
|
|
1158
|
-
"running",
|
|
1159
|
-
"failed",
|
|
1160
|
-
"success",
|
|
1161
|
-
"canceled",
|
|
1162
|
-
"skipped",
|
|
1163
|
-
"manual"
|
|
1164
|
-
],
|
|
1165
|
-
description: "Filter jobs by scope/status"
|
|
1166
|
-
}
|
|
1167
|
-
},
|
|
1168
|
-
required: ["project_id", "pipeline_id"]
|
|
1169
|
-
}
|
|
1170
|
-
},
|
|
1171
|
-
{
|
|
1172
|
-
name: "gitlab_get_job_log",
|
|
1173
|
-
description: `Get the log/trace output of a specific CI job.`,
|
|
1174
|
-
input_schema: {
|
|
1175
|
-
type: "object",
|
|
1176
|
-
properties: {
|
|
1177
|
-
project_id: {
|
|
1178
|
-
type: "string",
|
|
1179
|
-
description: "The project ID or URL-encoded path"
|
|
1180
|
-
},
|
|
1181
|
-
job_id: {
|
|
1182
|
-
type: "number",
|
|
1183
|
-
description: "The ID of the job"
|
|
1184
|
-
}
|
|
1185
|
-
},
|
|
1186
|
-
required: ["project_id", "job_id"]
|
|
1187
|
-
}
|
|
1188
|
-
},
|
|
1189
|
-
{
|
|
1190
|
-
name: "gitlab_retry_job",
|
|
1191
|
-
description: `Retry a failed or canceled CI job.`,
|
|
1192
|
-
input_schema: {
|
|
1193
|
-
type: "object",
|
|
1194
|
-
properties: {
|
|
1195
|
-
project_id: {
|
|
1196
|
-
type: "string",
|
|
1197
|
-
description: "The project ID or URL-encoded path"
|
|
1198
|
-
},
|
|
1199
|
-
job_id: {
|
|
1200
|
-
type: "number",
|
|
1201
|
-
description: "The ID of the job to retry"
|
|
1202
|
-
}
|
|
1203
|
-
},
|
|
1204
|
-
required: ["project_id", "job_id"]
|
|
1205
|
-
}
|
|
1206
|
-
},
|
|
1207
|
-
// Repository Tools
|
|
1208
|
-
{
|
|
1209
|
-
name: "gitlab_get_file",
|
|
1210
|
-
description: `Get the contents of a file from a repository.`,
|
|
1211
|
-
input_schema: {
|
|
1212
|
-
type: "object",
|
|
1213
|
-
properties: {
|
|
1214
|
-
project_id: {
|
|
1215
|
-
type: "string",
|
|
1216
|
-
description: "The project ID or URL-encoded path"
|
|
1217
|
-
},
|
|
1218
|
-
file_path: {
|
|
1219
|
-
type: "string",
|
|
1220
|
-
description: "Path to the file in the repository"
|
|
1221
|
-
},
|
|
1222
|
-
ref: {
|
|
1223
|
-
type: "string",
|
|
1224
|
-
description: "Branch, tag, or commit SHA (default: default branch)"
|
|
1225
|
-
}
|
|
1226
|
-
},
|
|
1227
|
-
required: ["project_id", "file_path"]
|
|
1228
|
-
}
|
|
1229
|
-
},
|
|
1230
|
-
{
|
|
1231
|
-
name: "gitlab_list_commits",
|
|
1232
|
-
description: `List commits in a repository. Can filter by branch/ref and path.`,
|
|
1233
|
-
input_schema: {
|
|
1234
|
-
type: "object",
|
|
1235
|
-
properties: {
|
|
1236
|
-
project_id: {
|
|
1237
|
-
type: "string",
|
|
1238
|
-
description: "The project ID or URL-encoded path"
|
|
1239
|
-
},
|
|
1240
|
-
ref: {
|
|
1241
|
-
type: "string",
|
|
1242
|
-
description: "Branch or tag name"
|
|
1243
|
-
},
|
|
1244
|
-
path: {
|
|
1245
|
-
type: "string",
|
|
1246
|
-
description: "File or directory path to filter commits"
|
|
1247
|
-
},
|
|
1248
|
-
since: {
|
|
1249
|
-
type: "string",
|
|
1250
|
-
description: "Only commits after this date (ISO 8601 format)"
|
|
1251
|
-
},
|
|
1252
|
-
until: {
|
|
1253
|
-
type: "string",
|
|
1254
|
-
description: "Only commits before this date (ISO 8601 format)"
|
|
1255
|
-
},
|
|
1256
|
-
limit: {
|
|
1257
|
-
type: "number",
|
|
1258
|
-
description: "Maximum number of results (default: 20)"
|
|
1259
|
-
}
|
|
1260
|
-
},
|
|
1261
|
-
required: ["project_id"]
|
|
1262
|
-
}
|
|
1263
|
-
},
|
|
1264
|
-
{
|
|
1265
|
-
name: "gitlab_get_commit_diff",
|
|
1266
|
-
description: `Get the diff for a specific commit.`,
|
|
1267
|
-
input_schema: {
|
|
1268
|
-
type: "object",
|
|
1269
|
-
properties: {
|
|
1270
|
-
project_id: {
|
|
1271
|
-
type: "string",
|
|
1272
|
-
description: "The project ID or URL-encoded path"
|
|
1273
|
-
},
|
|
1274
|
-
sha: {
|
|
1275
|
-
type: "string",
|
|
1276
|
-
description: "The commit SHA"
|
|
1277
|
-
}
|
|
1278
|
-
},
|
|
1279
|
-
required: ["project_id", "sha"]
|
|
1280
|
-
}
|
|
1281
|
-
},
|
|
1282
|
-
{
|
|
1283
|
-
name: "gitlab_list_branches",
|
|
1284
|
-
description: `List branches in a repository.`,
|
|
1285
|
-
input_schema: {
|
|
1286
|
-
type: "object",
|
|
1287
|
-
properties: {
|
|
1288
|
-
project_id: {
|
|
1289
|
-
type: "string",
|
|
1290
|
-
description: "The project ID or URL-encoded path"
|
|
1291
|
-
},
|
|
1292
|
-
search: {
|
|
1293
|
-
type: "string",
|
|
1294
|
-
description: "Search branches by name"
|
|
1295
|
-
}
|
|
1296
|
-
},
|
|
1297
|
-
required: ["project_id"]
|
|
1298
|
-
}
|
|
1299
|
-
},
|
|
1300
|
-
// Search Tools
|
|
1301
|
-
{
|
|
1302
|
-
name: "gitlab_search",
|
|
1303
|
-
description: `Search across GitLab for various resources.
|
|
1304
|
-
Scopes: projects, issues, merge_requests, milestones, users, blobs (code), commits, notes, wiki_blobs`,
|
|
1305
|
-
input_schema: {
|
|
1306
|
-
type: "object",
|
|
1307
|
-
properties: {
|
|
1308
|
-
scope: {
|
|
1309
|
-
type: "string",
|
|
1310
|
-
enum: [
|
|
1311
|
-
"projects",
|
|
1312
|
-
"issues",
|
|
1313
|
-
"merge_requests",
|
|
1314
|
-
"milestones",
|
|
1315
|
-
"users",
|
|
1316
|
-
"blobs",
|
|
1317
|
-
"commits",
|
|
1318
|
-
"notes",
|
|
1319
|
-
"wiki_blobs"
|
|
1320
|
-
],
|
|
1321
|
-
description: "The scope of the search"
|
|
1322
|
-
},
|
|
1323
|
-
search: {
|
|
1324
|
-
type: "string",
|
|
1325
|
-
description: "The search query"
|
|
1326
|
-
},
|
|
1327
|
-
project_id: {
|
|
1328
|
-
type: "string",
|
|
1329
|
-
description: "Limit search to a specific project (optional)"
|
|
1330
|
-
},
|
|
1331
|
-
limit: {
|
|
1332
|
-
type: "number",
|
|
1333
|
-
description: "Maximum number of results (default: 20)"
|
|
1334
|
-
}
|
|
1335
|
-
},
|
|
1336
|
-
required: ["scope", "search"]
|
|
1337
|
-
}
|
|
1338
|
-
},
|
|
1339
|
-
// Project Tools
|
|
1340
|
-
{
|
|
1341
|
-
name: "gitlab_get_project",
|
|
1342
|
-
description: `Get details of a specific project.`,
|
|
1343
|
-
input_schema: {
|
|
1344
|
-
type: "object",
|
|
1345
|
-
properties: {
|
|
1346
|
-
project_id: {
|
|
1347
|
-
type: "string",
|
|
1348
|
-
description: 'The project ID or URL-encoded path (e.g., "gitlab-org/gitlab")'
|
|
1349
|
-
}
|
|
1350
|
-
},
|
|
1351
|
-
required: ["project_id"]
|
|
1352
|
-
}
|
|
1353
|
-
},
|
|
1354
|
-
{
|
|
1355
|
-
name: "gitlab_list_project_members",
|
|
1356
|
-
description: `List members of a project.`,
|
|
1357
|
-
input_schema: {
|
|
1358
|
-
type: "object",
|
|
1359
|
-
properties: {
|
|
1360
|
-
project_id: {
|
|
1361
|
-
type: "string",
|
|
1362
|
-
description: "The project ID or URL-encoded path"
|
|
1363
|
-
}
|
|
1364
|
-
},
|
|
1365
|
-
required: ["project_id"]
|
|
1366
|
-
}
|
|
1367
|
-
}
|
|
1368
|
-
];
|
|
1369
|
-
var GitLabApiToolExecutor = class {
|
|
1370
|
-
config;
|
|
1371
|
-
constructor(config) {
|
|
1372
|
-
this.config = config;
|
|
1373
|
-
}
|
|
1374
|
-
get headers() {
|
|
1375
|
-
return {
|
|
1376
|
-
Authorization: `Bearer ${this.config.token}`,
|
|
1377
|
-
"Content-Type": "application/json"
|
|
1378
|
-
};
|
|
1379
|
-
}
|
|
1380
|
-
async fetchApi(method, path4, body) {
|
|
1381
|
-
const url = `${this.config.instanceUrl}/api/v4${path4}`;
|
|
1382
|
-
const fetchFn = this.config.fetch || fetch;
|
|
1383
|
-
const response = await fetchFn(url, {
|
|
1384
|
-
method,
|
|
1385
|
-
headers: this.headers,
|
|
1386
|
-
body: body ? JSON.stringify(body) : void 0
|
|
1387
|
-
});
|
|
1388
|
-
if (!response.ok) {
|
|
1389
|
-
const errorText = await response.text();
|
|
1390
|
-
throw new Error(`GitLab API error ${response.status}: ${errorText}`);
|
|
1391
|
-
}
|
|
1392
|
-
const text = await response.text();
|
|
1393
|
-
if (!text) {
|
|
1394
|
-
return {};
|
|
1395
|
-
}
|
|
1396
|
-
return JSON.parse(text);
|
|
1397
|
-
}
|
|
1398
|
-
encodeProjectId(projectId) {
|
|
1399
|
-
if (projectId.includes("/")) {
|
|
1400
|
-
return encodeURIComponent(projectId);
|
|
1401
|
-
}
|
|
1402
|
-
return projectId;
|
|
1403
|
-
}
|
|
1404
|
-
/**
|
|
1405
|
-
* Execute a GitLab API tool by name
|
|
1406
|
-
*/
|
|
1407
|
-
async execute(toolName, input) {
|
|
1408
|
-
try {
|
|
1409
|
-
switch (toolName) {
|
|
1410
|
-
// Merge Request tools
|
|
1411
|
-
case "gitlab_get_merge_request":
|
|
1412
|
-
return this.getMergeRequest(input);
|
|
1413
|
-
case "gitlab_list_merge_requests":
|
|
1414
|
-
return this.listMergeRequests(input);
|
|
1415
|
-
case "gitlab_get_mr_changes":
|
|
1416
|
-
return this.getMrChanges(input);
|
|
1417
|
-
case "gitlab_list_mr_discussions":
|
|
1418
|
-
return this.listMrDiscussions(input);
|
|
1419
|
-
case "gitlab_create_mr_note":
|
|
1420
|
-
return this.createMrNote(input);
|
|
1421
|
-
// Issue tools
|
|
1422
|
-
case "gitlab_get_issue":
|
|
1423
|
-
return this.getIssue(input);
|
|
1424
|
-
case "gitlab_list_issues":
|
|
1425
|
-
return this.listIssues(input);
|
|
1426
|
-
case "gitlab_create_issue_note":
|
|
1427
|
-
return this.createIssueNote(input);
|
|
1428
|
-
// Pipeline tools
|
|
1429
|
-
case "gitlab_list_pipelines":
|
|
1430
|
-
return this.listPipelines(input);
|
|
1431
|
-
case "gitlab_get_pipeline":
|
|
1432
|
-
return this.getPipeline(input);
|
|
1433
|
-
case "gitlab_list_pipeline_jobs":
|
|
1434
|
-
return this.listPipelineJobs(input);
|
|
1435
|
-
case "gitlab_get_job_log":
|
|
1436
|
-
return this.getJobLog(input);
|
|
1437
|
-
case "gitlab_retry_job":
|
|
1438
|
-
return this.retryJob(input);
|
|
1439
|
-
// Repository tools
|
|
1440
|
-
case "gitlab_get_file":
|
|
1441
|
-
return this.getFile(input);
|
|
1442
|
-
case "gitlab_list_commits":
|
|
1443
|
-
return this.listCommits(input);
|
|
1444
|
-
case "gitlab_get_commit_diff":
|
|
1445
|
-
return this.getCommitDiff(input);
|
|
1446
|
-
case "gitlab_list_branches":
|
|
1447
|
-
return this.listBranches(input);
|
|
1448
|
-
// Search tools
|
|
1449
|
-
case "gitlab_search":
|
|
1450
|
-
return this.search(input);
|
|
1451
|
-
// Project tools
|
|
1452
|
-
case "gitlab_get_project":
|
|
1453
|
-
return this.getProject(input);
|
|
1454
|
-
case "gitlab_list_project_members":
|
|
1455
|
-
return this.listProjectMembers(input);
|
|
1456
|
-
default:
|
|
1457
|
-
return { result: "", error: `Unknown GitLab tool: ${toolName}` };
|
|
1458
|
-
}
|
|
1459
|
-
} catch (error) {
|
|
1460
|
-
return {
|
|
1461
|
-
result: "",
|
|
1462
|
-
error: error instanceof Error ? error.message : String(error)
|
|
1463
|
-
};
|
|
1464
|
-
}
|
|
1465
|
-
}
|
|
1466
|
-
// ========== Merge Request Tools ==========
|
|
1467
|
-
async getMergeRequest(input) {
|
|
1468
|
-
const projectId = this.encodeProjectId(input.project_id);
|
|
1469
|
-
const mrIid = input.mr_iid;
|
|
1470
|
-
const includeChanges = input.include_changes;
|
|
1471
|
-
let path4 = `/projects/${projectId}/merge_requests/${mrIid}`;
|
|
1472
|
-
if (includeChanges) {
|
|
1473
|
-
path4 += "?include_diverged_commits_count=true";
|
|
1474
|
-
}
|
|
1475
|
-
const mr = await this.fetchApi("GET", path4);
|
|
1476
|
-
return { result: JSON.stringify(mr, null, 2) };
|
|
1477
|
-
}
|
|
1478
|
-
async listMergeRequests(input) {
|
|
1479
|
-
const params = new URLSearchParams();
|
|
1480
|
-
params.set("per_page", String(input.limit || 20));
|
|
1481
|
-
if (input.state) params.set("state", input.state);
|
|
1482
|
-
if (input.scope) params.set("scope", input.scope);
|
|
1483
|
-
if (input.search) params.set("search", input.search);
|
|
1484
|
-
if (input.labels) params.set("labels", input.labels);
|
|
1485
|
-
let path4;
|
|
1486
|
-
if (input.project_id) {
|
|
1487
|
-
const projectId = this.encodeProjectId(input.project_id);
|
|
1488
|
-
path4 = `/projects/${projectId}/merge_requests?${params}`;
|
|
1489
|
-
} else {
|
|
1490
|
-
path4 = `/merge_requests?${params}`;
|
|
1491
|
-
}
|
|
1492
|
-
const mrs = await this.fetchApi("GET", path4);
|
|
1493
|
-
return { result: JSON.stringify(mrs, null, 2) };
|
|
1494
|
-
}
|
|
1495
|
-
async getMrChanges(input) {
|
|
1496
|
-
const projectId = this.encodeProjectId(input.project_id);
|
|
1497
|
-
const mrIid = input.mr_iid;
|
|
1498
|
-
const changes = await this.fetchApi(
|
|
1499
|
-
"GET",
|
|
1500
|
-
`/projects/${projectId}/merge_requests/${mrIid}/changes`
|
|
1501
|
-
);
|
|
1502
|
-
return { result: JSON.stringify(changes, null, 2) };
|
|
1503
|
-
}
|
|
1504
|
-
async listMrDiscussions(input) {
|
|
1505
|
-
const projectId = this.encodeProjectId(input.project_id);
|
|
1506
|
-
const mrIid = input.mr_iid;
|
|
1507
|
-
const discussions = await this.fetchApi(
|
|
1508
|
-
"GET",
|
|
1509
|
-
`/projects/${projectId}/merge_requests/${mrIid}/discussions`
|
|
1510
|
-
);
|
|
1511
|
-
return { result: JSON.stringify(discussions, null, 2) };
|
|
1512
|
-
}
|
|
1513
|
-
async createMrNote(input) {
|
|
1514
|
-
const projectId = this.encodeProjectId(input.project_id);
|
|
1515
|
-
const mrIid = input.mr_iid;
|
|
1516
|
-
const body = input.body;
|
|
1517
|
-
const note = await this.fetchApi(
|
|
1518
|
-
"POST",
|
|
1519
|
-
`/projects/${projectId}/merge_requests/${mrIid}/notes`,
|
|
1520
|
-
{ body }
|
|
1521
|
-
);
|
|
1522
|
-
return { result: JSON.stringify(note, null, 2) };
|
|
1523
|
-
}
|
|
1524
|
-
// ========== Issue Tools ==========
|
|
1525
|
-
async getIssue(input) {
|
|
1526
|
-
const projectId = this.encodeProjectId(input.project_id);
|
|
1527
|
-
const issueIid = input.issue_iid;
|
|
1528
|
-
const issue = await this.fetchApi(
|
|
1529
|
-
"GET",
|
|
1530
|
-
`/projects/${projectId}/issues/${issueIid}`
|
|
1531
|
-
);
|
|
1532
|
-
return { result: JSON.stringify(issue, null, 2) };
|
|
1533
|
-
}
|
|
1534
|
-
async listIssues(input) {
|
|
1535
|
-
const params = new URLSearchParams();
|
|
1536
|
-
params.set("per_page", String(input.limit || 20));
|
|
1537
|
-
if (input.state) params.set("state", input.state);
|
|
1538
|
-
if (input.scope) params.set("scope", input.scope);
|
|
1539
|
-
if (input.search) params.set("search", input.search);
|
|
1540
|
-
if (input.labels) params.set("labels", input.labels);
|
|
1541
|
-
if (input.milestone) params.set("milestone", input.milestone);
|
|
1542
|
-
let path4;
|
|
1543
|
-
if (input.project_id) {
|
|
1544
|
-
const projectId = this.encodeProjectId(input.project_id);
|
|
1545
|
-
path4 = `/projects/${projectId}/issues?${params}`;
|
|
1546
|
-
} else {
|
|
1547
|
-
path4 = `/issues?${params}`;
|
|
1548
|
-
}
|
|
1549
|
-
const issues = await this.fetchApi("GET", path4);
|
|
1550
|
-
return { result: JSON.stringify(issues, null, 2) };
|
|
1551
|
-
}
|
|
1552
|
-
async createIssueNote(input) {
|
|
1553
|
-
const projectId = this.encodeProjectId(input.project_id);
|
|
1554
|
-
const issueIid = input.issue_iid;
|
|
1555
|
-
const body = input.body;
|
|
1556
|
-
const note = await this.fetchApi(
|
|
1557
|
-
"POST",
|
|
1558
|
-
`/projects/${projectId}/issues/${issueIid}/notes`,
|
|
1559
|
-
{ body }
|
|
1560
|
-
);
|
|
1561
|
-
return { result: JSON.stringify(note, null, 2) };
|
|
1562
|
-
}
|
|
1563
|
-
// ========== Pipeline Tools ==========
|
|
1564
|
-
async listPipelines(input) {
|
|
1565
|
-
const projectId = this.encodeProjectId(input.project_id);
|
|
1566
|
-
const params = new URLSearchParams();
|
|
1567
|
-
params.set("per_page", String(input.limit || 20));
|
|
1568
|
-
if (input.status) params.set("status", input.status);
|
|
1569
|
-
if (input.ref) params.set("ref", input.ref);
|
|
1570
|
-
const pipelines = await this.fetchApi(
|
|
1571
|
-
"GET",
|
|
1572
|
-
`/projects/${projectId}/pipelines?${params}`
|
|
1573
|
-
);
|
|
1574
|
-
return { result: JSON.stringify(pipelines, null, 2) };
|
|
1575
|
-
}
|
|
1576
|
-
async getPipeline(input) {
|
|
1577
|
-
const projectId = this.encodeProjectId(input.project_id);
|
|
1578
|
-
const pipelineId = input.pipeline_id;
|
|
1579
|
-
const pipeline = await this.fetchApi(
|
|
1580
|
-
"GET",
|
|
1581
|
-
`/projects/${projectId}/pipelines/${pipelineId}`
|
|
1582
|
-
);
|
|
1583
|
-
return { result: JSON.stringify(pipeline, null, 2) };
|
|
1584
|
-
}
|
|
1585
|
-
async listPipelineJobs(input) {
|
|
1586
|
-
const projectId = this.encodeProjectId(input.project_id);
|
|
1587
|
-
const pipelineId = input.pipeline_id;
|
|
1588
|
-
const params = new URLSearchParams();
|
|
1589
|
-
if (input.scope) params.set("scope[]", input.scope);
|
|
1590
|
-
const jobs = await this.fetchApi(
|
|
1591
|
-
"GET",
|
|
1592
|
-
`/projects/${projectId}/pipelines/${pipelineId}/jobs?${params}`
|
|
1593
|
-
);
|
|
1594
|
-
return { result: JSON.stringify(jobs, null, 2) };
|
|
1595
|
-
}
|
|
1596
|
-
async getJobLog(input) {
|
|
1597
|
-
const projectId = this.encodeProjectId(input.project_id);
|
|
1598
|
-
const jobId = input.job_id;
|
|
1599
|
-
const url = `${this.config.instanceUrl}/api/v4/projects/${projectId}/jobs/${jobId}/trace`;
|
|
1600
|
-
const fetchFn = this.config.fetch || fetch;
|
|
1601
|
-
const response = await fetchFn(url, {
|
|
1602
|
-
method: "GET",
|
|
1603
|
-
headers: this.headers
|
|
1604
|
-
});
|
|
1605
|
-
if (!response.ok) {
|
|
1606
|
-
const errorText = await response.text();
|
|
1607
|
-
throw new Error(`GitLab API error ${response.status}: ${errorText}`);
|
|
1608
|
-
}
|
|
1609
|
-
const log = await response.text();
|
|
1610
|
-
const maxLength = 5e4;
|
|
1611
|
-
if (log.length > maxLength) {
|
|
1612
|
-
return {
|
|
1613
|
-
result: `[Log truncated, showing last ${maxLength} characters]
|
|
1614
|
-
|
|
1615
|
-
${log.slice(-maxLength)}`
|
|
1616
|
-
};
|
|
1617
|
-
}
|
|
1618
|
-
return { result: log };
|
|
1619
|
-
}
|
|
1620
|
-
async retryJob(input) {
|
|
1621
|
-
const projectId = this.encodeProjectId(input.project_id);
|
|
1622
|
-
const jobId = input.job_id;
|
|
1623
|
-
const job = await this.fetchApi(
|
|
1624
|
-
"POST",
|
|
1625
|
-
`/projects/${projectId}/jobs/${jobId}/retry`
|
|
1626
|
-
);
|
|
1627
|
-
return { result: JSON.stringify(job, null, 2) };
|
|
1628
|
-
}
|
|
1629
|
-
// ========== Repository Tools ==========
|
|
1630
|
-
async getFile(input) {
|
|
1631
|
-
const projectId = this.encodeProjectId(input.project_id);
|
|
1632
|
-
const filePath = encodeURIComponent(input.file_path);
|
|
1633
|
-
const ref = input.ref || "HEAD";
|
|
1634
|
-
const file = await this.fetchApi(
|
|
1635
|
-
"GET",
|
|
1636
|
-
`/projects/${projectId}/repository/files/${filePath}?ref=${encodeURIComponent(ref)}`
|
|
1637
|
-
);
|
|
1638
|
-
if (file.encoding === "base64") {
|
|
1639
|
-
const decoded = Buffer.from(file.content, "base64").toString("utf-8");
|
|
1640
|
-
return { result: decoded };
|
|
1641
|
-
}
|
|
1642
|
-
return { result: file.content };
|
|
1643
|
-
}
|
|
1644
|
-
async listCommits(input) {
|
|
1645
|
-
const projectId = this.encodeProjectId(input.project_id);
|
|
1646
|
-
const params = new URLSearchParams();
|
|
1647
|
-
params.set("per_page", String(input.limit || 20));
|
|
1648
|
-
if (input.ref) params.set("ref_name", input.ref);
|
|
1649
|
-
if (input.path) params.set("path", input.path);
|
|
1650
|
-
if (input.since) params.set("since", input.since);
|
|
1651
|
-
if (input.until) params.set("until", input.until);
|
|
1652
|
-
const commits = await this.fetchApi(
|
|
1653
|
-
"GET",
|
|
1654
|
-
`/projects/${projectId}/repository/commits?${params}`
|
|
1655
|
-
);
|
|
1656
|
-
return { result: JSON.stringify(commits, null, 2) };
|
|
1657
|
-
}
|
|
1658
|
-
async getCommitDiff(input) {
|
|
1659
|
-
const projectId = this.encodeProjectId(input.project_id);
|
|
1660
|
-
const sha = input.sha;
|
|
1661
|
-
const diff = await this.fetchApi(
|
|
1662
|
-
"GET",
|
|
1663
|
-
`/projects/${projectId}/repository/commits/${sha}/diff`
|
|
1664
|
-
);
|
|
1665
|
-
return { result: JSON.stringify(diff, null, 2) };
|
|
1666
|
-
}
|
|
1667
|
-
async listBranches(input) {
|
|
1668
|
-
const projectId = this.encodeProjectId(input.project_id);
|
|
1669
|
-
const params = new URLSearchParams();
|
|
1670
|
-
if (input.search) params.set("search", input.search);
|
|
1671
|
-
const branches = await this.fetchApi(
|
|
1672
|
-
"GET",
|
|
1673
|
-
`/projects/${projectId}/repository/branches?${params}`
|
|
1674
|
-
);
|
|
1675
|
-
return { result: JSON.stringify(branches, null, 2) };
|
|
1676
|
-
}
|
|
1677
|
-
// ========== Search Tools ==========
|
|
1678
|
-
async search(input) {
|
|
1679
|
-
const scope = input.scope;
|
|
1680
|
-
const searchQuery = input.search;
|
|
1681
|
-
const params = new URLSearchParams();
|
|
1682
|
-
params.set("scope", scope);
|
|
1683
|
-
params.set("search", searchQuery);
|
|
1684
|
-
params.set("per_page", String(input.limit || 20));
|
|
1685
|
-
let path4;
|
|
1686
|
-
if (input.project_id) {
|
|
1687
|
-
const projectId = this.encodeProjectId(input.project_id);
|
|
1688
|
-
path4 = `/projects/${projectId}/search?${params}`;
|
|
1689
|
-
} else {
|
|
1690
|
-
path4 = `/search?${params}`;
|
|
1691
|
-
}
|
|
1692
|
-
const results = await this.fetchApi("GET", path4);
|
|
1693
|
-
return { result: JSON.stringify(results, null, 2) };
|
|
1694
|
-
}
|
|
1695
|
-
// ========== Project Tools ==========
|
|
1696
|
-
async getProject(input) {
|
|
1697
|
-
const projectId = this.encodeProjectId(input.project_id);
|
|
1698
|
-
const project = await this.fetchApi("GET", `/projects/${projectId}`);
|
|
1699
|
-
return { result: JSON.stringify(project, null, 2) };
|
|
1700
|
-
}
|
|
1701
|
-
async listProjectMembers(input) {
|
|
1702
|
-
const projectId = this.encodeProjectId(input.project_id);
|
|
1703
|
-
const members = await this.fetchApi(
|
|
1704
|
-
"GET",
|
|
1705
|
-
`/projects/${projectId}/members`
|
|
1706
|
-
);
|
|
1707
|
-
return { result: JSON.stringify(members, null, 2) };
|
|
1708
|
-
}
|
|
1709
|
-
};
|
|
1710
|
-
function isGitLabApiTool(toolName) {
|
|
1711
|
-
return toolName.startsWith("gitlab_");
|
|
1712
|
-
}
|
|
1713
|
-
|
|
1714
|
-
// src/gitlab-anthropic-tools.ts
|
|
1715
|
-
import * as fs2 from "fs/promises";
|
|
1716
|
-
import * as path2 from "path";
|
|
1717
|
-
import { spawn } from "child_process";
|
|
1718
|
-
var ANTHROPIC_TOOLS = [
|
|
1719
|
-
{
|
|
1720
|
-
name: "list_dir",
|
|
1721
|
-
description: `List directory contents. Shows files and subdirectories relative to the working directory.`,
|
|
1722
|
-
input_schema: {
|
|
1723
|
-
type: "object",
|
|
1724
|
-
properties: {
|
|
1725
|
-
directory: {
|
|
1726
|
-
type: "string",
|
|
1727
|
-
description: "Directory path relative to the working directory"
|
|
1728
|
-
}
|
|
1729
|
-
},
|
|
1730
|
-
required: ["directory"]
|
|
1731
|
-
}
|
|
1732
|
-
},
|
|
1733
|
-
{
|
|
1734
|
-
name: "read_file",
|
|
1735
|
-
description: `Read the contents of a file.`,
|
|
1736
|
-
input_schema: {
|
|
1737
|
-
type: "object",
|
|
1738
|
-
properties: {
|
|
1739
|
-
file_path: {
|
|
1740
|
-
type: "string",
|
|
1741
|
-
description: "The file path to read"
|
|
1742
|
-
}
|
|
1743
|
-
},
|
|
1744
|
-
required: ["file_path"]
|
|
1745
|
-
}
|
|
1746
|
-
},
|
|
1747
|
-
{
|
|
1748
|
-
name: "create_file_with_contents",
|
|
1749
|
-
description: `Create and write contents to a file.`,
|
|
1750
|
-
input_schema: {
|
|
1751
|
-
type: "object",
|
|
1752
|
-
properties: {
|
|
1753
|
-
file_path: {
|
|
1754
|
-
type: "string",
|
|
1755
|
-
description: "The file path to write to"
|
|
1756
|
-
},
|
|
1757
|
-
contents: {
|
|
1758
|
-
type: "string",
|
|
1759
|
-
description: "The contents to write"
|
|
1760
|
-
}
|
|
1761
|
-
},
|
|
1762
|
-
required: ["file_path", "contents"]
|
|
1763
|
-
}
|
|
1764
|
-
},
|
|
1765
|
-
{
|
|
1766
|
-
name: "edit_file",
|
|
1767
|
-
description: `Edit an existing file by replacing a string with a new string.`,
|
|
1768
|
-
input_schema: {
|
|
1769
|
-
type: "object",
|
|
1770
|
-
properties: {
|
|
1771
|
-
file_path: {
|
|
1772
|
-
type: "string",
|
|
1773
|
-
description: "The path of the file to edit"
|
|
1774
|
-
},
|
|
1775
|
-
old_str: {
|
|
1776
|
-
type: "string",
|
|
1777
|
-
description: "The string to replace (include context for uniqueness)"
|
|
1778
|
-
},
|
|
1779
|
-
new_str: {
|
|
1780
|
-
type: "string",
|
|
1781
|
-
description: "The new string value"
|
|
1782
|
-
}
|
|
1783
|
-
},
|
|
1784
|
-
required: ["file_path", "old_str", "new_str"]
|
|
1785
|
-
}
|
|
1786
|
-
},
|
|
1787
|
-
{
|
|
1788
|
-
name: "find_files",
|
|
1789
|
-
description: `Find files by name pattern. Uses glob-like matching.`,
|
|
1790
|
-
input_schema: {
|
|
1791
|
-
type: "object",
|
|
1792
|
-
properties: {
|
|
1793
|
-
name_pattern: {
|
|
1794
|
-
type: "string",
|
|
1795
|
-
description: 'The pattern to search for (e.g., "*.py", "test_*.js")'
|
|
1796
|
-
}
|
|
1797
|
-
},
|
|
1798
|
-
required: ["name_pattern"]
|
|
1799
|
-
}
|
|
1800
|
-
},
|
|
1801
|
-
{
|
|
1802
|
-
name: "mkdir",
|
|
1803
|
-
description: `Create a new directory.`,
|
|
1804
|
-
input_schema: {
|
|
1805
|
-
type: "object",
|
|
1806
|
-
properties: {
|
|
1807
|
-
directory_path: {
|
|
1808
|
-
type: "string",
|
|
1809
|
-
description: "The directory path to create"
|
|
1810
|
-
}
|
|
1811
|
-
},
|
|
1812
|
-
required: ["directory_path"]
|
|
1813
|
-
}
|
|
1814
|
-
},
|
|
1815
|
-
{
|
|
1816
|
-
name: "grep",
|
|
1817
|
-
description: `Search for text patterns within files.`,
|
|
1818
|
-
input_schema: {
|
|
1819
|
-
type: "object",
|
|
1820
|
-
properties: {
|
|
1821
|
-
pattern: {
|
|
1822
|
-
type: "string",
|
|
1823
|
-
description: "The text pattern to search for"
|
|
1824
|
-
},
|
|
1825
|
-
search_directory: {
|
|
1826
|
-
type: "string",
|
|
1827
|
-
description: 'The directory to search in (default: ".")'
|
|
1828
|
-
},
|
|
1829
|
-
case_insensitive: {
|
|
1830
|
-
type: "boolean",
|
|
1831
|
-
description: "Whether to ignore case (default: false)"
|
|
1832
|
-
}
|
|
1833
|
-
},
|
|
1834
|
-
required: ["pattern"]
|
|
1835
|
-
}
|
|
1836
|
-
},
|
|
1837
|
-
{
|
|
1838
|
-
name: "run_command",
|
|
1839
|
-
description: `Run a shell command. Note: git commands should use run_git_command instead.`,
|
|
1840
|
-
input_schema: {
|
|
1841
|
-
type: "object",
|
|
1842
|
-
properties: {
|
|
1843
|
-
program: {
|
|
1844
|
-
type: "string",
|
|
1845
|
-
description: 'The program to execute (e.g., "npm", "python")'
|
|
1846
|
-
},
|
|
1847
|
-
args: {
|
|
1848
|
-
type: "string",
|
|
1849
|
-
description: "Arguments as a single string"
|
|
1850
|
-
}
|
|
1851
|
-
},
|
|
1852
|
-
required: ["program"]
|
|
1853
|
-
}
|
|
1854
|
-
},
|
|
1855
|
-
{
|
|
1856
|
-
name: "run_git_command",
|
|
1857
|
-
description: `Run a git command in the repository.`,
|
|
1858
|
-
input_schema: {
|
|
1859
|
-
type: "object",
|
|
1860
|
-
properties: {
|
|
1861
|
-
command: {
|
|
1862
|
-
type: "string",
|
|
1863
|
-
description: 'Git command (e.g., "status", "log", "diff")'
|
|
1864
|
-
},
|
|
1865
|
-
args: {
|
|
1866
|
-
type: "string",
|
|
1867
|
-
description: "Git command arguments"
|
|
1868
|
-
}
|
|
1869
|
-
},
|
|
1870
|
-
required: ["command"]
|
|
1871
|
-
}
|
|
1872
|
-
}
|
|
1873
|
-
];
|
|
1874
|
-
var AnthropicToolExecutor = class {
|
|
1875
|
-
workingDirectory;
|
|
1876
|
-
constructor(workingDirectory) {
|
|
1877
|
-
this.workingDirectory = workingDirectory;
|
|
1878
|
-
}
|
|
1879
|
-
/**
|
|
1880
|
-
* Execute a tool by name with given input
|
|
1881
|
-
*/
|
|
1882
|
-
async execute(toolName, input) {
|
|
1883
|
-
try {
|
|
1884
|
-
switch (toolName) {
|
|
1885
|
-
case "list_dir":
|
|
1886
|
-
return this.listDir(input.directory);
|
|
1887
|
-
case "read_file":
|
|
1888
|
-
return this.readFile(input.file_path);
|
|
1889
|
-
case "create_file_with_contents":
|
|
1890
|
-
return this.writeFile(input.file_path, input.contents);
|
|
1891
|
-
case "edit_file":
|
|
1892
|
-
return this.editFile(
|
|
1893
|
-
input.file_path,
|
|
1894
|
-
input.old_str,
|
|
1895
|
-
input.new_str
|
|
1896
|
-
);
|
|
1897
|
-
case "find_files":
|
|
1898
|
-
return this.findFiles(input.name_pattern);
|
|
1899
|
-
case "mkdir":
|
|
1900
|
-
return this.mkdir(input.directory_path);
|
|
1901
|
-
case "grep":
|
|
1902
|
-
return this.grep(
|
|
1903
|
-
input.pattern,
|
|
1904
|
-
input.search_directory,
|
|
1905
|
-
input.case_insensitive
|
|
1906
|
-
);
|
|
1907
|
-
case "run_command":
|
|
1908
|
-
return this.runCommand(input.program, input.args);
|
|
1909
|
-
case "run_git_command":
|
|
1910
|
-
return this.runGitCommand(input.command, input.args);
|
|
1911
|
-
default:
|
|
1912
|
-
return { result: "", error: `Unknown tool: ${toolName}` };
|
|
1913
|
-
}
|
|
1914
|
-
} catch (error) {
|
|
1915
|
-
return {
|
|
1916
|
-
result: "",
|
|
1917
|
-
error: error instanceof Error ? error.message : String(error)
|
|
1918
|
-
};
|
|
1919
|
-
}
|
|
1920
|
-
}
|
|
1921
|
-
resolvePath(filePath) {
|
|
1922
|
-
if (path2.isAbsolute(filePath)) {
|
|
1923
|
-
return filePath;
|
|
1924
|
-
}
|
|
1925
|
-
return path2.resolve(this.workingDirectory, filePath);
|
|
1926
|
-
}
|
|
1927
|
-
async listDir(directory) {
|
|
1928
|
-
const dirPath = this.resolvePath(directory || ".");
|
|
1929
|
-
const entries = await fs2.readdir(dirPath, { withFileTypes: true });
|
|
1930
|
-
const result = entries.map((entry) => {
|
|
1931
|
-
const type = entry.isDirectory() ? "d" : "-";
|
|
1932
|
-
return `${type} ${entry.name}`;
|
|
1933
|
-
}).join("\n");
|
|
1934
|
-
return { result };
|
|
1935
|
-
}
|
|
1936
|
-
async readFile(filePath) {
|
|
1937
|
-
const fullPath = this.resolvePath(filePath);
|
|
1938
|
-
const content = await fs2.readFile(fullPath, "utf-8");
|
|
1939
|
-
return { result: content };
|
|
1940
|
-
}
|
|
1941
|
-
async writeFile(filePath, contents) {
|
|
1942
|
-
const fullPath = this.resolvePath(filePath);
|
|
1943
|
-
await fs2.mkdir(path2.dirname(fullPath), { recursive: true });
|
|
1944
|
-
await fs2.writeFile(fullPath, contents, "utf-8");
|
|
1945
|
-
return { result: `File written successfully: ${filePath}` };
|
|
1946
|
-
}
|
|
1947
|
-
async editFile(filePath, oldStr, newStr) {
|
|
1948
|
-
const fullPath = this.resolvePath(filePath);
|
|
1949
|
-
const content = await fs2.readFile(fullPath, "utf-8");
|
|
1950
|
-
if (!content.includes(oldStr)) {
|
|
1951
|
-
return { result: "", error: `String not found in file: "${oldStr.substring(0, 50)}..."` };
|
|
1952
|
-
}
|
|
1953
|
-
const newContent = content.replace(oldStr, newStr);
|
|
1954
|
-
await fs2.writeFile(fullPath, newContent, "utf-8");
|
|
1955
|
-
return { result: `File edited successfully: ${filePath}` };
|
|
1956
|
-
}
|
|
1957
|
-
async findFiles(namePattern) {
|
|
1958
|
-
const results = [];
|
|
1959
|
-
const regex = new RegExp("^" + namePattern.replace(/\*/g, ".*").replace(/\?/g, ".") + "$");
|
|
1960
|
-
const search = async (dir, relativePath = "") => {
|
|
1961
|
-
try {
|
|
1962
|
-
const entries = await fs2.readdir(dir, { withFileTypes: true });
|
|
1963
|
-
for (const entry of entries) {
|
|
1964
|
-
const entryRelativePath = relativePath ? `${relativePath}/${entry.name}` : entry.name;
|
|
1965
|
-
if (entry.isDirectory()) {
|
|
1966
|
-
if (!["node_modules", ".git", "dist", "build", "__pycache__"].includes(entry.name)) {
|
|
1967
|
-
await search(path2.join(dir, entry.name), entryRelativePath);
|
|
1968
|
-
}
|
|
1969
|
-
} else if (regex.test(entry.name)) {
|
|
1970
|
-
results.push(entryRelativePath);
|
|
1971
|
-
}
|
|
1972
|
-
}
|
|
1973
|
-
} catch {
|
|
1974
|
-
}
|
|
1975
|
-
};
|
|
1976
|
-
await search(this.workingDirectory);
|
|
1977
|
-
return { result: results.join("\n") || "No files found" };
|
|
1978
|
-
}
|
|
1979
|
-
async mkdir(directoryPath) {
|
|
1980
|
-
const fullPath = this.resolvePath(directoryPath);
|
|
1981
|
-
await fs2.mkdir(fullPath, { recursive: true });
|
|
1982
|
-
return { result: `Directory created: ${directoryPath}` };
|
|
1983
|
-
}
|
|
1984
|
-
async grep(pattern, searchDirectory, caseInsensitive) {
|
|
1985
|
-
const results = [];
|
|
1986
|
-
const flags = caseInsensitive ? "gi" : "g";
|
|
1987
|
-
const regex = new RegExp(pattern, flags);
|
|
1988
|
-
const searchDir = this.resolvePath(searchDirectory || ".");
|
|
1989
|
-
const search = async (dir, relativePath = "") => {
|
|
1990
|
-
try {
|
|
1991
|
-
const entries = await fs2.readdir(dir, { withFileTypes: true });
|
|
1992
|
-
for (const entry of entries) {
|
|
1993
|
-
const entryRelativePath = relativePath ? `${relativePath}/${entry.name}` : entry.name;
|
|
1994
|
-
const fullPath = path2.join(dir, entry.name);
|
|
1995
|
-
if (entry.isDirectory()) {
|
|
1996
|
-
if (!["node_modules", ".git", "dist", "build", "__pycache__"].includes(entry.name)) {
|
|
1997
|
-
await search(fullPath, entryRelativePath);
|
|
1998
|
-
}
|
|
1999
|
-
} else {
|
|
2000
|
-
try {
|
|
2001
|
-
const content = await fs2.readFile(fullPath, "utf-8");
|
|
2002
|
-
const lines = content.split("\n");
|
|
2003
|
-
for (let i = 0; i < lines.length; i++) {
|
|
2004
|
-
if (regex.test(lines[i])) {
|
|
2005
|
-
results.push(`${entryRelativePath}:${i + 1}: ${lines[i].trim()}`);
|
|
2006
|
-
}
|
|
2007
|
-
}
|
|
2008
|
-
} catch {
|
|
2009
|
-
}
|
|
2010
|
-
}
|
|
2011
|
-
}
|
|
2012
|
-
} catch {
|
|
2013
|
-
}
|
|
2014
|
-
};
|
|
2015
|
-
await search(searchDir);
|
|
2016
|
-
return { result: results.slice(0, 100).join("\n") || "No matches found" };
|
|
2017
|
-
}
|
|
2018
|
-
runCommand(program, args) {
|
|
2019
|
-
if (program === "git") {
|
|
2020
|
-
return Promise.resolve({
|
|
2021
|
-
result: "",
|
|
2022
|
-
error: "Use run_git_command for git operations"
|
|
2023
|
-
});
|
|
2024
|
-
}
|
|
2025
|
-
const parsedArgs = args ? args.match(/(?:[^\s"]+|"[^"]*")+/g) || [] : [];
|
|
2026
|
-
const cleanedArgs = parsedArgs.map((arg) => arg.replace(/^"(.*)"$/, "$1"));
|
|
2027
|
-
return this.executeCommand(program, cleanedArgs);
|
|
2028
|
-
}
|
|
2029
|
-
runGitCommand(command, args) {
|
|
2030
|
-
const gitArgs = [command];
|
|
2031
|
-
if (args) {
|
|
2032
|
-
const parsedArgs = args.match(/(?:[^\s"]+|"[^"]*")+/g) || [];
|
|
2033
|
-
gitArgs.push(...parsedArgs.map((arg) => arg.replace(/^"(.*)"$/, "$1")));
|
|
2034
|
-
}
|
|
2035
|
-
return this.executeCommand("git", gitArgs);
|
|
2036
|
-
}
|
|
2037
|
-
executeCommand(program, args) {
|
|
2038
|
-
return new Promise((resolve3) => {
|
|
2039
|
-
const child = spawn(program, args, {
|
|
2040
|
-
cwd: this.workingDirectory,
|
|
2041
|
-
timeout: 3e4
|
|
2042
|
-
});
|
|
2043
|
-
let stdout = "";
|
|
2044
|
-
let stderr = "";
|
|
2045
|
-
child.stdout?.on("data", (data) => {
|
|
2046
|
-
stdout += data.toString();
|
|
2047
|
-
});
|
|
2048
|
-
child.stderr?.on("data", (data) => {
|
|
2049
|
-
stderr += data.toString();
|
|
2050
|
-
});
|
|
2051
|
-
child.on("error", (error) => {
|
|
2052
|
-
resolve3({
|
|
2053
|
-
result: "",
|
|
2054
|
-
error: `Command failed: ${error.message}`
|
|
2055
|
-
});
|
|
2056
|
-
});
|
|
2057
|
-
child.on("close", (exitCode) => {
|
|
2058
|
-
if (exitCode !== 0 && stderr) {
|
|
2059
|
-
resolve3({
|
|
2060
|
-
result: stdout,
|
|
2061
|
-
error: stderr
|
|
2062
|
-
});
|
|
2063
|
-
} else {
|
|
2064
|
-
resolve3({
|
|
2065
|
-
result: stdout || stderr || `Command completed with exit code ${exitCode}`
|
|
2066
|
-
});
|
|
2067
|
-
}
|
|
2068
|
-
});
|
|
2069
|
-
});
|
|
2070
|
-
}
|
|
2071
|
-
};
|
|
2072
|
-
|
|
2073
946
|
// src/gitlab-project-detector.ts
|
|
2074
|
-
import { spawn
|
|
2075
|
-
import * as
|
|
947
|
+
import { spawn } from "child_process";
|
|
948
|
+
import * as path2 from "path";
|
|
2076
949
|
|
|
2077
950
|
// src/gitlab-project-cache.ts
|
|
2078
951
|
var GitLabProjectCache = class {
|
|
@@ -2178,7 +1051,7 @@ var GitLabProjectDetector = class {
|
|
|
2178
1051
|
* @returns The detected project or null if detection fails
|
|
2179
1052
|
*/
|
|
2180
1053
|
async detectProject(workingDirectory, remoteName = "origin") {
|
|
2181
|
-
const cacheKey =
|
|
1054
|
+
const cacheKey = path2.resolve(workingDirectory);
|
|
2182
1055
|
const cached = this.cache.get(cacheKey);
|
|
2183
1056
|
if (cached) {
|
|
2184
1057
|
return cached;
|
|
@@ -2263,8 +1136,8 @@ var GitLabProjectDetector = class {
|
|
|
2263
1136
|
* @returns The remote URL or null if not found
|
|
2264
1137
|
*/
|
|
2265
1138
|
async getGitRemoteUrl(workingDirectory, remoteName = "origin") {
|
|
2266
|
-
return new Promise((
|
|
2267
|
-
const child =
|
|
1139
|
+
return new Promise((resolve2) => {
|
|
1140
|
+
const child = spawn("git", ["config", "--get", `remote.${remoteName}.url`], {
|
|
2268
1141
|
cwd: workingDirectory,
|
|
2269
1142
|
timeout: this.config.gitTimeout
|
|
2270
1143
|
});
|
|
@@ -2278,13 +1151,13 @@ var GitLabProjectDetector = class {
|
|
|
2278
1151
|
});
|
|
2279
1152
|
child.on("close", (exitCode) => {
|
|
2280
1153
|
if (exitCode === 0 && stdout.trim()) {
|
|
2281
|
-
|
|
1154
|
+
resolve2(stdout.trim());
|
|
2282
1155
|
} else {
|
|
2283
|
-
|
|
1156
|
+
resolve2(null);
|
|
2284
1157
|
}
|
|
2285
1158
|
});
|
|
2286
1159
|
child.on("error", () => {
|
|
2287
|
-
|
|
1160
|
+
resolve2(null);
|
|
2288
1161
|
});
|
|
2289
1162
|
});
|
|
2290
1163
|
}
|
|
@@ -2340,13 +1213,11 @@ var GitLabProjectDetector = class {
|
|
|
2340
1213
|
}
|
|
2341
1214
|
};
|
|
2342
1215
|
export {
|
|
2343
|
-
ANTHROPIC_TOOLS,
|
|
2344
|
-
AnthropicToolExecutor,
|
|
2345
1216
|
BUNDLED_CLIENT_ID,
|
|
2346
|
-
|
|
1217
|
+
DEFAULT_AI_GATEWAY_URL,
|
|
2347
1218
|
GITLAB_COM_URL,
|
|
2348
1219
|
GitLabAgenticLanguageModel,
|
|
2349
|
-
|
|
1220
|
+
GitLabDirectAccessClient,
|
|
2350
1221
|
GitLabError,
|
|
2351
1222
|
GitLabOAuthManager,
|
|
2352
1223
|
GitLabProjectCache,
|
|
@@ -2356,7 +1227,6 @@ export {
|
|
|
2356
1227
|
TOKEN_EXPIRY_SKEW_MS,
|
|
2357
1228
|
createGitLab,
|
|
2358
1229
|
getAnthropicModelForModelId,
|
|
2359
|
-
gitlab
|
|
2360
|
-
isGitLabApiTool
|
|
1230
|
+
gitlab
|
|
2361
1231
|
};
|
|
2362
1232
|
//# sourceMappingURL=index.mjs.map
|