@juspay/yama 1.0.0

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.
@@ -0,0 +1,419 @@
1
+ /**
2
+ * Core TypeScript types for Yama
3
+ * Consolidates all interfaces and types used across the application
4
+ */
5
+ export interface AIProviderConfig {
6
+ provider?: "auto" | "google-ai" | "openai" | "anthropic" | "azure" | "bedrock";
7
+ model?: string;
8
+ enableFallback?: boolean;
9
+ enableAnalytics?: boolean;
10
+ enableEvaluation?: boolean;
11
+ timeout?: string | number;
12
+ temperature?: number;
13
+ maxTokens?: number;
14
+ retryAttempts?: number;
15
+ }
16
+ export interface AIResponse {
17
+ content: string;
18
+ provider: string;
19
+ model?: string;
20
+ usage?: {
21
+ inputTokens: number;
22
+ outputTokens: number;
23
+ totalTokens: number;
24
+ };
25
+ responseTime?: number;
26
+ analytics?: AnalyticsData;
27
+ evaluation?: EvaluationData;
28
+ }
29
+ export interface AnalyticsData {
30
+ requestId: string;
31
+ timestamp: string;
32
+ provider: string;
33
+ model: string;
34
+ promptTokens: number;
35
+ completionTokens: number;
36
+ totalTokens: number;
37
+ responseTime: number;
38
+ cost?: number;
39
+ }
40
+ export interface EvaluationData {
41
+ overallScore: number;
42
+ qualityMetrics: {
43
+ relevance: number;
44
+ accuracy: number;
45
+ completeness: number;
46
+ clarity: number;
47
+ };
48
+ confidence: number;
49
+ }
50
+ export type GitPlatform = "bitbucket" | "github" | "gitlab" | "azure-devops";
51
+ export interface GitCredentials {
52
+ username: string;
53
+ token: string;
54
+ baseUrl?: string;
55
+ }
56
+ export interface GitProviderConfig {
57
+ platform: GitPlatform;
58
+ credentials: GitCredentials;
59
+ defaultWorkspace?: string;
60
+ }
61
+ export interface PRIdentifier {
62
+ workspace: string;
63
+ repository: string;
64
+ branch?: string;
65
+ pullRequestId?: number | string;
66
+ }
67
+ export interface PRInfo {
68
+ id: number | string;
69
+ title: string;
70
+ description: string;
71
+ author: string;
72
+ state: "OPEN" | "MERGED" | "DECLINED" | "CLOSED";
73
+ sourceRef: string;
74
+ targetRef: string;
75
+ createdDate: string;
76
+ updatedDate: string;
77
+ reviewers?: PRReviewer[];
78
+ comments?: PRComment[];
79
+ fileChanges?: string[];
80
+ }
81
+ export interface PRReviewer {
82
+ user: {
83
+ name: string;
84
+ emailAddress: string;
85
+ displayName: string;
86
+ };
87
+ approved: boolean;
88
+ status: "APPROVED" | "UNAPPROVED" | "NEEDS_WORK";
89
+ }
90
+ export interface PRComment {
91
+ id: number;
92
+ text: string;
93
+ author: {
94
+ name: string;
95
+ displayName: string;
96
+ };
97
+ createdDate: string;
98
+ updatedDate: string;
99
+ anchor?: {
100
+ filePath: string;
101
+ lineFrom: number;
102
+ lineTo: number;
103
+ lineType: "ADDED" | "REMOVED" | "CONTEXT";
104
+ };
105
+ }
106
+ export interface PRDiff {
107
+ diff: string;
108
+ fileChanges: FileChange[];
109
+ totalAdditions: number;
110
+ totalDeletions: number;
111
+ }
112
+ export interface FileChange {
113
+ path: string;
114
+ changeType: "ADDED" | "MODIFIED" | "DELETED" | "RENAMED";
115
+ additions: number;
116
+ deletions: number;
117
+ hunks: DiffHunk[];
118
+ }
119
+ export interface DiffHunk {
120
+ oldStart: number;
121
+ oldLines: number;
122
+ newStart: number;
123
+ newLines: number;
124
+ lines: DiffLine[];
125
+ }
126
+ export interface DiffLine {
127
+ type: "added" | "removed" | "context";
128
+ content: string;
129
+ oldLineNumber?: number;
130
+ newLineNumber?: number;
131
+ }
132
+ export type ViolationSeverity = "CRITICAL" | "MAJOR" | "MINOR" | "SUGGESTION";
133
+ export type ViolationType = "inline" | "general";
134
+ export type ViolationCategory = "security" | "performance" | "maintainability" | "functionality" | "error_handling" | "testing" | "general";
135
+ export interface Violation {
136
+ type: ViolationType;
137
+ file?: string;
138
+ code_snippet?: string;
139
+ search_context?: {
140
+ before: string[];
141
+ after: string[];
142
+ };
143
+ line_type?: "ADDED" | "REMOVED" | "CONTEXT";
144
+ severity: ViolationSeverity;
145
+ category: ViolationCategory;
146
+ issue: string;
147
+ message: string;
148
+ impact: string;
149
+ suggestion?: string;
150
+ }
151
+ export interface ReviewResult {
152
+ violations: Violation[];
153
+ summary: string;
154
+ improvementsSinceLast?: string;
155
+ positiveObservations: string[];
156
+ statistics: ReviewStatistics;
157
+ }
158
+ export interface ReviewStatistics {
159
+ filesReviewed: number;
160
+ totalIssues: number;
161
+ criticalCount: number;
162
+ majorCount: number;
163
+ minorCount: number;
164
+ suggestionCount: number;
165
+ }
166
+ export interface ReviewOptions {
167
+ workspace: string;
168
+ repository: string;
169
+ branch?: string;
170
+ pullRequestId?: number | string;
171
+ dryRun?: boolean;
172
+ verbose?: boolean;
173
+ excludePatterns?: string[];
174
+ customRules?: string;
175
+ contextLines?: number;
176
+ }
177
+ export interface RequiredSection {
178
+ key: string;
179
+ name: string;
180
+ required: boolean;
181
+ present?: boolean;
182
+ content?: string;
183
+ }
184
+ export interface PreservableContent {
185
+ media: string[];
186
+ files: string[];
187
+ links: string[];
188
+ originalText: string;
189
+ }
190
+ export interface SectionAnalysis {
191
+ requiredSections: RequiredSection[];
192
+ missingCount: number;
193
+ preservedContent: PreservableContent;
194
+ gaps: string[];
195
+ }
196
+ export interface EnhancementOptions {
197
+ workspace: string;
198
+ repository: string;
199
+ branch?: string;
200
+ pullRequestId?: number | string;
201
+ dryRun?: boolean;
202
+ verbose?: boolean;
203
+ preserveContent?: boolean;
204
+ ensureRequiredSections?: boolean;
205
+ customSections?: RequiredSection[];
206
+ }
207
+ export interface EnhancementResult {
208
+ originalDescription: string;
209
+ enhancedDescription: string;
210
+ sectionsAdded: string[];
211
+ sectionsEnhanced: string[];
212
+ preservedItems: {
213
+ media: number;
214
+ files: number;
215
+ links: number;
216
+ };
217
+ statistics: {
218
+ originalLength: number;
219
+ enhancedLength: number;
220
+ completedSections: number;
221
+ totalSections: number;
222
+ };
223
+ }
224
+ export interface GuardianConfig {
225
+ providers: {
226
+ ai: AIProviderConfig;
227
+ git: GitProviderConfig;
228
+ };
229
+ features: {
230
+ codeReview: CodeReviewConfig;
231
+ descriptionEnhancement: DescriptionEnhancementConfig;
232
+ diffStrategy?: DiffStrategyConfig;
233
+ securityScan?: SecurityScanConfig;
234
+ analytics?: AnalyticsConfig;
235
+ };
236
+ cache?: CacheConfig;
237
+ performance?: PerformanceConfig;
238
+ rules?: CustomRulesConfig;
239
+ reporting?: ReportingConfig;
240
+ monitoring?: MonitoringConfig;
241
+ }
242
+ export interface CodeReviewConfig {
243
+ enabled: boolean;
244
+ severityLevels: ViolationSeverity[];
245
+ categories: ViolationCategory[];
246
+ excludePatterns: string[];
247
+ contextLines: number;
248
+ customRules?: string;
249
+ systemPrompt?: string;
250
+ analysisTemplate?: string;
251
+ focusAreas?: string[];
252
+ }
253
+ export interface DescriptionEnhancementConfig {
254
+ enabled: boolean;
255
+ preserveContent: boolean;
256
+ requiredSections: RequiredSection[];
257
+ autoFormat: boolean;
258
+ systemPrompt?: string;
259
+ outputTemplate?: string;
260
+ enhancementInstructions?: string;
261
+ }
262
+ export interface DiffStrategyConfig {
263
+ enabled: boolean;
264
+ thresholds: {
265
+ wholeDiffMaxFiles: number;
266
+ fileByFileMinFiles: number;
267
+ };
268
+ forceStrategy?: "whole" | "file-by-file" | "auto";
269
+ }
270
+ export interface SecurityScanConfig {
271
+ enabled: boolean;
272
+ level: "strict" | "moderate" | "basic";
273
+ scanTypes: string[];
274
+ }
275
+ export interface AnalyticsConfig {
276
+ enabled: boolean;
277
+ trackMetrics: boolean;
278
+ exportFormat: "json" | "csv" | "yaml";
279
+ }
280
+ export interface CacheConfig {
281
+ enabled: boolean;
282
+ ttl: string;
283
+ maxSize: string;
284
+ storage: "memory" | "redis" | "file";
285
+ }
286
+ export interface PerformanceConfig {
287
+ batch: {
288
+ enabled: boolean;
289
+ maxConcurrent: number;
290
+ delayBetween: string;
291
+ };
292
+ optimization: {
293
+ reuseConnections: boolean;
294
+ compressRequests: boolean;
295
+ enableHttp2: boolean;
296
+ };
297
+ }
298
+ export interface CustomRulesConfig {
299
+ [category: string]: CustomRule[];
300
+ }
301
+ export interface CustomRule {
302
+ name: string;
303
+ pattern: string;
304
+ severity: ViolationSeverity;
305
+ message?: string;
306
+ suggestion?: string;
307
+ }
308
+ export interface ReportingConfig {
309
+ formats: string[];
310
+ includeAnalytics: boolean;
311
+ includeMetrics: boolean;
312
+ customTemplates?: string;
313
+ }
314
+ export interface MonitoringConfig {
315
+ enabled: boolean;
316
+ metrics: string[];
317
+ exportFormat?: "json" | "prometheus" | "csv";
318
+ endpoint?: string;
319
+ interval?: string;
320
+ }
321
+ export type OperationType = "review" | "enhance-description" | "security-scan" | "analytics" | "all";
322
+ export interface OperationOptions {
323
+ workspace: string;
324
+ repository: string;
325
+ branch?: string;
326
+ pullRequestId?: number | string;
327
+ operations: OperationType[];
328
+ dryRun?: boolean;
329
+ verbose?: boolean;
330
+ config?: Partial<GuardianConfig>;
331
+ }
332
+ export interface OperationResult {
333
+ operation: OperationType;
334
+ status: "success" | "error" | "skipped";
335
+ data?: any;
336
+ error?: string;
337
+ duration: number;
338
+ timestamp: string;
339
+ }
340
+ export interface ProcessResult {
341
+ pullRequest: PRInfo;
342
+ operations: OperationResult[];
343
+ summary: {
344
+ totalOperations: number;
345
+ successCount: number;
346
+ errorCount: number;
347
+ skippedCount: number;
348
+ totalDuration: number;
349
+ };
350
+ }
351
+ export interface StreamUpdate {
352
+ operation: OperationType;
353
+ status: "started" | "progress" | "completed" | "error";
354
+ progress?: number;
355
+ message?: string;
356
+ data?: any;
357
+ timestamp: string;
358
+ }
359
+ export interface StreamOptions {
360
+ onUpdate?: (update: StreamUpdate) => void;
361
+ onError?: (error: Error) => void;
362
+ onComplete?: (result: ProcessResult) => void;
363
+ }
364
+ export type LogLevel = "debug" | "info" | "warn" | "error";
365
+ export interface LoggerOptions {
366
+ level: LogLevel;
367
+ verbose: boolean;
368
+ format: "simple" | "json" | "detailed";
369
+ colors: boolean;
370
+ }
371
+ export interface Logger {
372
+ debug(message: string, ...args: any[]): void;
373
+ info(message: string, ...args: any[]): void;
374
+ warn(message: string, ...args: any[]): void;
375
+ error(message: string, ...args: any[]): void;
376
+ badge(): void;
377
+ phase(message: string): void;
378
+ success(message: string): void;
379
+ }
380
+ export interface CacheEntry<T = any> {
381
+ key: string;
382
+ value: T;
383
+ ttl: number;
384
+ createdAt: number;
385
+ }
386
+ export interface CacheOptions {
387
+ ttl?: number;
388
+ maxSize?: number;
389
+ checkPeriod?: number;
390
+ }
391
+ export interface Cache {
392
+ get<T>(key: string): T | undefined;
393
+ set<T>(key: string, value: T, ttl?: number): boolean;
394
+ del(key: string): number;
395
+ has(key: string): boolean;
396
+ clear(): void;
397
+ keys(): string[];
398
+ stats(): {
399
+ hits: number;
400
+ misses: number;
401
+ keys: number;
402
+ size: number;
403
+ };
404
+ }
405
+ export declare class GuardianError extends Error {
406
+ code: string;
407
+ context?: any | undefined;
408
+ constructor(code: string, message: string, context?: any | undefined);
409
+ }
410
+ export declare class ConfigurationError extends GuardianError {
411
+ constructor(message: string, context?: any);
412
+ }
413
+ export declare class ProviderError extends GuardianError {
414
+ constructor(message: string, context?: any);
415
+ }
416
+ export declare class ValidationError extends GuardianError {
417
+ constructor(message: string, context?: any);
418
+ }
419
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ /**
3
+ * Core TypeScript types for Yama
4
+ * Consolidates all interfaces and types used across the application
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.ValidationError = exports.ProviderError = exports.ConfigurationError = exports.GuardianError = void 0;
8
+ // ============================================================================
9
+ // Error Types
10
+ // ============================================================================
11
+ class GuardianError extends Error {
12
+ constructor(code, message, context) {
13
+ super(message);
14
+ this.code = code;
15
+ this.context = context;
16
+ this.name = "GuardianError";
17
+ }
18
+ }
19
+ exports.GuardianError = GuardianError;
20
+ class ConfigurationError extends GuardianError {
21
+ constructor(message, context) {
22
+ super("CONFIGURATION_ERROR", message, context);
23
+ this.name = "ConfigurationError";
24
+ }
25
+ }
26
+ exports.ConfigurationError = ConfigurationError;
27
+ class ProviderError extends GuardianError {
28
+ constructor(message, context) {
29
+ super("PROVIDER_ERROR", message, context);
30
+ this.name = "ProviderError";
31
+ }
32
+ }
33
+ exports.ProviderError = ProviderError;
34
+ class ValidationError extends GuardianError {
35
+ constructor(message, context) {
36
+ super("VALIDATION_ERROR", message, context);
37
+ this.name = "ValidationError";
38
+ }
39
+ }
40
+ exports.ValidationError = ValidationError;
41
+ // ============================================================================
42
+ // Export all types - Main file, no re-exports needed
43
+ // ============================================================================
44
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,92 @@
1
+ /**
2
+ * Enhanced Cache utility for Yama
3
+ * Provides intelligent caching for PR data, file contents, and AI responses
4
+ */
5
+ import { Cache as ICache, CacheOptions } from "../types";
6
+ export declare class Cache implements ICache {
7
+ private cache;
8
+ private statsData;
9
+ constructor(options?: CacheOptions);
10
+ /**
11
+ * Get value from cache
12
+ */
13
+ get<T>(key: string): T | undefined;
14
+ /**
15
+ * Set value in cache with optional TTL
16
+ */
17
+ set<T>(key: string, value: T, ttl?: number): boolean;
18
+ /**
19
+ * Delete key from cache
20
+ */
21
+ del(key: string): number;
22
+ /**
23
+ * Check if key exists in cache
24
+ */
25
+ has(key: string): boolean;
26
+ /**
27
+ * Clear all cache entries
28
+ */
29
+ clear(): void;
30
+ /**
31
+ * Get all cache keys
32
+ */
33
+ keys(): string[];
34
+ /**
35
+ * Get cache statistics
36
+ */
37
+ stats(): {
38
+ hits: number;
39
+ misses: number;
40
+ keys: number;
41
+ size: number;
42
+ };
43
+ /**
44
+ * Get detailed cache statistics from node-cache
45
+ */
46
+ getDetailedStats(): any;
47
+ /**
48
+ * Get or set pattern - common caching pattern
49
+ */
50
+ getOrSet<T>(key: string, fetchFn: () => Promise<T>, ttl?: number): Promise<T>;
51
+ /**
52
+ * Cache with tags for group invalidation
53
+ */
54
+ private tags;
55
+ setWithTags<T>(key: string, value: T, tags: string[], ttl?: number): boolean;
56
+ /**
57
+ * Invalidate all keys with a specific tag
58
+ */
59
+ invalidateTag(tag: string): number;
60
+ /**
61
+ * Cache key generators for common patterns
62
+ */
63
+ static keys: {
64
+ prInfo: (workspace: string, repository: string, prId: string | number) => string;
65
+ prDiff: (workspace: string, repository: string, prId: string | number) => string;
66
+ fileContent: (workspace: string, repository: string, filePath: string, branch: string) => string;
67
+ directoryContent: (workspace: string, repository: string, path: string, branch: string) => string;
68
+ branchInfo: (workspace: string, repository: string, branch: string) => string;
69
+ aiResponse: (prompt: string, provider: string, model: string) => string;
70
+ projectContext: (workspace: string, repository: string, branch: string) => string;
71
+ reviewResult: (workspace: string, repository: string, prId: string | number, configHash: string) => string;
72
+ };
73
+ /**
74
+ * Smart cache warming for common patterns
75
+ */
76
+ warmPRCache(workspace: string, repository: string, prId: string | number): Promise<void>;
77
+ /**
78
+ * Cleanup expired entries and optimize memory
79
+ */
80
+ cleanup(): void;
81
+ /**
82
+ * Get cache hit ratio
83
+ */
84
+ getHitRatio(): number;
85
+ /**
86
+ * Export cache state for debugging
87
+ */
88
+ debug(): any;
89
+ }
90
+ export declare const cache: Cache;
91
+ export declare function createCache(options?: CacheOptions): Cache;
92
+ //# sourceMappingURL=Cache.d.ts.map