@juspay/yama 1.0.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,17 +1,20 @@
1
- "use strict";
2
1
  /**
3
2
  * Enhanced Bitbucket Provider - Optimized from both pr-police.js and pr-describe.js
4
3
  * Provides unified, cached, and optimized Bitbucket operations
5
4
  */
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.BitbucketProvider = void 0;
8
- exports.createBitbucketProvider = createBitbucketProvider;
9
- const types_1 = require("../../types");
10
- const Logger_1 = require("../../utils/Logger");
11
- const Cache_1 = require("../../utils/Cache");
12
- class BitbucketProvider {
5
+ import { ProviderError, } from "../../types/index.js";
6
+ import { logger } from "../../utils/Logger.js";
7
+ import { cache, Cache } from "../../utils/Cache.js";
8
+ export class BitbucketProvider {
9
+ apiClient;
10
+ branchHandlers;
11
+ pullRequestHandlers;
12
+ reviewHandlers;
13
+ fileHandlers;
14
+ initialized = false;
15
+ baseUrl;
16
+ credentials;
13
17
  constructor(credentials) {
14
- this.initialized = false;
15
18
  this.credentials = credentials;
16
19
  this.baseUrl = credentials.baseUrl || "https://your-bitbucket-server.com";
17
20
  }
@@ -23,7 +26,7 @@ class BitbucketProvider {
23
26
  return;
24
27
  }
25
28
  try {
26
- Logger_1.logger.debug("Initializing Bitbucket MCP handlers...");
29
+ logger.debug("Initializing Bitbucket MCP handlers...");
27
30
  const dynamicImport = eval("(specifier) => import(specifier)");
28
31
  const [{ BitbucketApiClient }, { BranchHandlers }, { PullRequestHandlers }, { ReviewHandlers }, { FileHandlers },] = await Promise.all([
29
32
  dynamicImport("@nexus2520/bitbucket-mcp-server/build/utils/api-client.js"),
@@ -38,10 +41,10 @@ class BitbucketProvider {
38
41
  this.reviewHandlers = new ReviewHandlers(this.apiClient, this.credentials.username);
39
42
  this.fileHandlers = new FileHandlers(this.apiClient, this.baseUrl);
40
43
  this.initialized = true;
41
- Logger_1.logger.debug("Bitbucket MCP handlers initialized successfully");
44
+ logger.debug("Bitbucket MCP handlers initialized successfully");
42
45
  }
43
46
  catch (error) {
44
- throw new types_1.ProviderError(`Failed to initialize Bitbucket provider: ${error.message}`);
47
+ throw new ProviderError(`Failed to initialize Bitbucket provider: ${error.message}`);
45
48
  }
46
49
  }
47
50
  /**
@@ -79,11 +82,11 @@ class BitbucketProvider {
79
82
  await this.initialize();
80
83
  const { workspace, repository, branch } = identifier;
81
84
  if (!branch) {
82
- throw new types_1.ProviderError("Branch name is required");
85
+ throw new ProviderError("Branch name is required");
83
86
  }
84
- const cacheKey = Cache_1.Cache.keys.branchInfo(workspace, repository, branch);
85
- return Cache_1.cache.getOrSet(cacheKey, async () => {
86
- Logger_1.logger.debug(`Finding PR for branch: ${workspace}/${repository}@${branch}`);
87
+ const cacheKey = Cache.keys.branchInfo(workspace, repository, branch);
88
+ return cache.getOrSet(cacheKey, async () => {
89
+ logger.debug(`Finding PR for branch: ${workspace}/${repository}@${branch}`);
87
90
  const rawBranchData = await this.branchHandlers.handleGetBranch({
88
91
  workspace,
89
92
  repository,
@@ -96,8 +99,8 @@ class BitbucketProvider {
96
99
  branchData.open_pull_requests.length > 0) {
97
100
  const firstPR = branchData.open_pull_requests[0];
98
101
  // Debug author data structure
99
- Logger_1.logger.debug(`Author data structure: ${JSON.stringify(firstPR.author, null, 2)}`);
100
- Logger_1.logger.debug(`Raw firstPR keys: ${Object.keys(firstPR).join(", ")}`);
102
+ logger.debug(`Author data structure: ${JSON.stringify(firstPR.author, null, 2)}`);
103
+ logger.debug(`Raw firstPR keys: ${Object.keys(firstPR).join(", ")}`);
101
104
  return {
102
105
  id: firstPR.id,
103
106
  title: firstPR.title,
@@ -115,7 +118,7 @@ class BitbucketProvider {
115
118
  fileChanges: firstPR.file_changes || [],
116
119
  };
117
120
  }
118
- throw new types_1.ProviderError(`No open PR found for branch: ${branch}`);
121
+ throw new ProviderError(`No open PR found for branch: ${branch}`);
119
122
  }, 3600);
120
123
  }
121
124
  /**
@@ -125,11 +128,11 @@ class BitbucketProvider {
125
128
  await this.initialize();
126
129
  const { workspace, repository, pullRequestId } = identifier;
127
130
  if (!pullRequestId) {
128
- throw new types_1.ProviderError("Pull request ID is required");
131
+ throw new ProviderError("Pull request ID is required");
129
132
  }
130
- const cacheKey = Cache_1.Cache.keys.prInfo(workspace, repository, pullRequestId);
131
- return Cache_1.cache.getOrSet(cacheKey, async () => {
132
- Logger_1.logger.debug(`Getting PR details: ${workspace}/${repository}#${pullRequestId}`);
133
+ const cacheKey = Cache.keys.prInfo(workspace, repository, pullRequestId);
134
+ return cache.getOrSet(cacheKey, async () => {
135
+ logger.debug(`Getting PR details: ${workspace}/${repository}#${pullRequestId}`);
133
136
  const rawPRDetails = await this.pullRequestHandlers.handleGetPullRequest({
134
137
  workspace,
135
138
  repository,
@@ -137,8 +140,8 @@ class BitbucketProvider {
137
140
  });
138
141
  const prData = this.parseMCPResponse(rawPRDetails);
139
142
  // Debug author data structure
140
- Logger_1.logger.debug(`PR Details author data structure: ${JSON.stringify(prData.author, null, 2)}`);
141
- Logger_1.logger.debug(`PR Details raw keys: ${Object.keys(prData).join(", ")}`);
143
+ logger.debug(`PR Details author data structure: ${JSON.stringify(prData.author, null, 2)}`);
144
+ logger.debug(`PR Details raw keys: ${Object.keys(prData).join(", ")}`);
142
145
  return {
143
146
  id: prData.id,
144
147
  title: prData.title,
@@ -166,16 +169,16 @@ class BitbucketProvider {
166
169
  await this.initialize();
167
170
  const { workspace, repository, pullRequestId } = identifier;
168
171
  if (!pullRequestId) {
169
- throw new types_1.ProviderError("Pull request ID is required");
172
+ throw new ProviderError("Pull request ID is required");
170
173
  }
171
174
  // Create a cache key that includes include patterns if specified
172
175
  const cacheKey = includePatterns && includePatterns.length === 1
173
176
  ? `file-diff:${workspace}:${repository}:${pullRequestId}:${includePatterns[0]}`
174
- : Cache_1.Cache.keys.prDiff(workspace, repository, pullRequestId);
175
- return Cache_1.cache.getOrSet(cacheKey, async () => {
176
- Logger_1.logger.debug(`Getting PR diff: ${workspace}/${repository}#${pullRequestId}`);
177
+ : Cache.keys.prDiff(workspace, repository, pullRequestId);
178
+ return cache.getOrSet(cacheKey, async () => {
179
+ logger.debug(`Getting PR diff: ${workspace}/${repository}#${pullRequestId}`);
177
180
  if (includePatterns) {
178
- Logger_1.logger.debug(`Include patterns: ${includePatterns.join(", ")}`);
181
+ logger.debug(`Include patterns: ${includePatterns.join(", ")}`);
179
182
  }
180
183
  const args = {
181
184
  workspace,
@@ -203,9 +206,9 @@ class BitbucketProvider {
203
206
  */
204
207
  async getFileContent(workspace, repository, filePath, branch) {
205
208
  await this.initialize();
206
- const cacheKey = Cache_1.Cache.keys.fileContent(workspace, repository, filePath, branch);
207
- return Cache_1.cache.getOrSet(cacheKey, async () => {
208
- Logger_1.logger.debug(`Getting file content: ${workspace}/${repository}/${filePath}@${branch}`);
209
+ const cacheKey = Cache.keys.fileContent(workspace, repository, filePath, branch);
210
+ return cache.getOrSet(cacheKey, async () => {
211
+ logger.debug(`Getting file content: ${workspace}/${repository}/${filePath}@${branch}`);
209
212
  const result = await this.fileHandlers.handleGetFileContent({
210
213
  workspace,
211
214
  repository,
@@ -226,9 +229,9 @@ class BitbucketProvider {
226
229
  */
227
230
  async listDirectoryContent(workspace, repository, path, branch) {
228
231
  await this.initialize();
229
- const cacheKey = Cache_1.Cache.keys.directoryContent(workspace, repository, path, branch);
230
- return Cache_1.cache.getOrSet(cacheKey, async () => {
231
- Logger_1.logger.debug(`Listing directory: ${workspace}/${repository}/${path}@${branch}`);
232
+ const cacheKey = Cache.keys.directoryContent(workspace, repository, path, branch);
233
+ return cache.getOrSet(cacheKey, async () => {
234
+ logger.debug(`Listing directory: ${workspace}/${repository}/${path}@${branch}`);
232
235
  const result = await this.fileHandlers.handleListDirectoryContent({
233
236
  workspace,
234
237
  repository,
@@ -246,11 +249,11 @@ class BitbucketProvider {
246
249
  await this.initialize();
247
250
  const { workspace, repository, pullRequestId } = identifier;
248
251
  if (!pullRequestId) {
249
- throw new types_1.ProviderError("Pull request ID is required");
252
+ throw new ProviderError("Pull request ID is required");
250
253
  }
251
254
  try {
252
- Logger_1.logger.debug(`Updating PR description: ${workspace}/${repository}#${pullRequestId}`);
253
- Logger_1.logger.debug(`Description length: ${description.length} characters`);
255
+ logger.debug(`Updating PR description: ${workspace}/${repository}#${pullRequestId}`);
256
+ logger.debug(`Description length: ${description.length} characters`);
254
257
  const result = await this.pullRequestHandlers.handleUpdatePullRequest({
255
258
  workspace,
256
259
  repository,
@@ -258,15 +261,15 @@ class BitbucketProvider {
258
261
  description: description,
259
262
  });
260
263
  // Log the raw MCP response
261
- Logger_1.logger.debug(`Raw MCP update response: ${JSON.stringify(result, null, 2)}`);
264
+ logger.debug(`Raw MCP update response: ${JSON.stringify(result, null, 2)}`);
262
265
  const updateData = this.parseMCPResponse(result);
263
266
  // Log the parsed response
264
- Logger_1.logger.debug(`Parsed update response: ${JSON.stringify(updateData, null, 2)}`);
267
+ logger.debug(`Parsed update response: ${JSON.stringify(updateData, null, 2)}`);
265
268
  // Invalidate related cache entries
266
- Cache_1.cache.del(Cache_1.Cache.keys.prInfo(workspace, repository, pullRequestId));
269
+ cache.del(Cache.keys.prInfo(workspace, repository, pullRequestId));
267
270
  // Check if the response indicates actual success
268
271
  if (typeof updateData === "string" && updateData.includes("Error")) {
269
- Logger_1.logger.error(`Update response contains error: ${updateData}`);
272
+ logger.error(`Update response contains error: ${updateData}`);
270
273
  return {
271
274
  success: false,
272
275
  message: updateData,
@@ -278,8 +281,8 @@ class BitbucketProvider {
278
281
  };
279
282
  }
280
283
  catch (error) {
281
- Logger_1.logger.error(`Failed to update PR description: ${error.message}`);
282
- throw new types_1.ProviderError(`Update failed: ${error.message}`);
284
+ logger.error(`Failed to update PR description: ${error.message}`);
285
+ throw new ProviderError(`Update failed: ${error.message}`);
283
286
  }
284
287
  }
285
288
  /**
@@ -289,10 +292,10 @@ class BitbucketProvider {
289
292
  await this.initialize();
290
293
  const { workspace, repository, pullRequestId } = identifier;
291
294
  if (!pullRequestId) {
292
- throw new types_1.ProviderError("Pull request ID is required");
295
+ throw new ProviderError("Pull request ID is required");
293
296
  }
294
297
  try {
295
- Logger_1.logger.debug(`Adding comment to PR: ${workspace}/${repository}#${pullRequestId}`);
298
+ logger.debug(`Adding comment to PR: ${workspace}/${repository}#${pullRequestId}`);
296
299
  const args = {
297
300
  workspace,
298
301
  repository,
@@ -312,13 +315,13 @@ class BitbucketProvider {
312
315
  if (options.suggestion) {
313
316
  args.suggestion = options.suggestion;
314
317
  }
315
- Logger_1.logger.debug(`🔍 Inline comment details:`);
316
- Logger_1.logger.debug(` File: ${options.filePath}`);
317
- Logger_1.logger.debug(` Code snippet: "${options.codeSnippet}"`);
318
- Logger_1.logger.debug(` Match strategy: ${options.matchStrategy}`);
318
+ logger.debug(`🔍 Inline comment details:`);
319
+ logger.debug(` File: ${options.filePath}`);
320
+ logger.debug(` Code snippet: "${options.codeSnippet}"`);
321
+ logger.debug(` Match strategy: ${options.matchStrategy}`);
319
322
  if (options.searchContext) {
320
- Logger_1.logger.debug(` Search context before: ${JSON.stringify(options.searchContext.before)}`);
321
- Logger_1.logger.debug(` Search context after: ${JSON.stringify(options.searchContext.after)}`);
323
+ logger.debug(` Search context before: ${JSON.stringify(options.searchContext.before)}`);
324
+ logger.debug(` Search context after: ${JSON.stringify(options.searchContext.after)}`);
322
325
  }
323
326
  }
324
327
  else if (options.filePath && options.lineNumber) {
@@ -326,12 +329,12 @@ class BitbucketProvider {
326
329
  args.file_path = options.filePath;
327
330
  args.line_number = options.lineNumber;
328
331
  args.line_type = options.lineType || "CONTEXT";
329
- Logger_1.logger.debug(`🔍 Line-based comment details:`);
330
- Logger_1.logger.debug(` File: ${options.filePath}`);
331
- Logger_1.logger.debug(` Line: ${options.lineNumber}`);
332
- Logger_1.logger.debug(` Type: ${options.lineType || "CONTEXT"}`);
332
+ logger.debug(`🔍 Line-based comment details:`);
333
+ logger.debug(` File: ${options.filePath}`);
334
+ logger.debug(` Line: ${options.lineNumber}`);
335
+ logger.debug(` Type: ${options.lineType || "CONTEXT"}`);
333
336
  }
334
- Logger_1.logger.debug(`🔍 MCP addComment args: ${JSON.stringify(args, null, 2)}`);
337
+ logger.debug(`🔍 MCP addComment args: ${JSON.stringify(args, null, 2)}`);
335
338
  const result = await this.pullRequestHandlers.handleAddComment(args);
336
339
  // Parse response exactly like pr-police.js
337
340
  let commentData;
@@ -347,8 +350,8 @@ class BitbucketProvider {
347
350
  };
348
351
  }
349
352
  catch (error) {
350
- Logger_1.logger.error(`Failed to add comment: ${error.message}`);
351
- throw new types_1.ProviderError(`Comment failed: ${error.message}`);
353
+ logger.error(`Failed to add comment: ${error.message}`);
354
+ throw new ProviderError(`Comment failed: ${error.message}`);
352
355
  }
353
356
  }
354
357
  /**
@@ -423,8 +426,8 @@ class BitbucketProvider {
423
426
  provider: "bitbucket",
424
427
  initialized: this.initialized,
425
428
  baseUrl: this.baseUrl,
426
- cacheStats: Cache_1.cache.stats(),
427
- cacheHitRatio: Cache_1.cache.getHitRatio(),
429
+ cacheStats: cache.stats(),
430
+ cacheHitRatio: cache.getHitRatio(),
428
431
  };
429
432
  }
430
433
  /**
@@ -432,13 +435,12 @@ class BitbucketProvider {
432
435
  */
433
436
  clearCache() {
434
437
  // Clear all cache entries (could be made more specific)
435
- Cache_1.cache.clear();
436
- Logger_1.logger.debug("BitbucketProvider cache cleared");
438
+ cache.clear();
439
+ logger.debug("BitbucketProvider cache cleared");
437
440
  }
438
441
  }
439
- exports.BitbucketProvider = BitbucketProvider;
440
442
  // Export factory function
441
- function createBitbucketProvider(credentials) {
443
+ export function createBitbucketProvider(credentials) {
442
444
  return new BitbucketProvider(credentials);
443
445
  }
444
446
  //# sourceMappingURL=BitbucketProvider.js.map
@@ -2,9 +2,9 @@
2
2
  * Enhanced Code Reviewer - Optimized to work with Unified Context
3
3
  * Preserves all original functionality from pr-police.js but optimized
4
4
  */
5
- import { ReviewResult, ReviewOptions, AIProviderConfig, CodeReviewConfig } from "../types";
6
- import { UnifiedContext } from "../core/ContextGatherer";
7
- import { BitbucketProvider } from "../core/providers/BitbucketProvider";
5
+ import { ReviewResult, ReviewOptions, AIProviderConfig, CodeReviewConfig } from "../types/index.js";
6
+ import { UnifiedContext } from "../core/ContextGatherer.js";
7
+ import { BitbucketProvider } from "../core/providers/BitbucketProvider.js";
8
8
  export declare class CodeReviewer {
9
9
  private neurolink;
10
10
  private bitbucketProvider;