@juspay/yama 1.1.0 → 1.2.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,58 @@
1
+ /**
2
+ * Provider Token Limits Utility
3
+ * Centralized management of AI provider token limits and validation
4
+ */
5
+ /**
6
+ * AI Provider types supported by the system
7
+ */
8
+ export type AIProvider = 'vertex' | 'google-ai' | 'gemini' | 'openai' | 'gpt-4' | 'anthropic' | 'claude' | 'azure' | 'bedrock' | 'auto';
9
+ /**
10
+ * Provider token limits configuration
11
+ * These limits are conservative values to avoid API errors
12
+ */
13
+ export declare const PROVIDER_TOKEN_LIMITS: Record<AIProvider, number>;
14
+ /**
15
+ * Conservative limits used by CodeReviewer for safety
16
+ * These are slightly lower than the actual limits to provide buffer
17
+ */
18
+ export declare const CONSERVATIVE_PROVIDER_LIMITS: Record<AIProvider, number>;
19
+ /**
20
+ * Get the token limit for a specific provider
21
+ * @param provider - The AI provider name
22
+ * @param conservative - Whether to use conservative limits (default: false)
23
+ * @returns The token limit for the provider
24
+ */
25
+ export declare function getProviderTokenLimit(provider: string, conservative?: boolean): number;
26
+ /**
27
+ * Validate and adjust token limit for a provider
28
+ * @param provider - The AI provider name
29
+ * @param configuredTokens - The configured token limit
30
+ * @param conservative - Whether to use conservative limits (default: false)
31
+ * @returns The validated and potentially adjusted token limit
32
+ */
33
+ export declare function validateProviderTokenLimit(provider: string, configuredTokens: number | undefined, conservative?: boolean): number;
34
+ /**
35
+ * Get all supported providers
36
+ * @returns Array of supported provider names
37
+ */
38
+ export declare function getSupportedProviders(): AIProvider[];
39
+ /**
40
+ * Check if a provider is supported
41
+ * @param provider - The provider name to check
42
+ * @returns True if the provider is supported
43
+ */
44
+ export declare function isProviderSupported(provider: string): boolean;
45
+ /**
46
+ * Get provider information including limits and support status
47
+ * @param provider - The provider name
48
+ * @param conservative - Whether to use conservative limits
49
+ * @returns Provider information object
50
+ */
51
+ export declare function getProviderInfo(provider: string, conservative?: boolean): {
52
+ provider: string;
53
+ isSupported: boolean;
54
+ tokenLimit: number;
55
+ conservativeLimit: number;
56
+ standardLimit: number;
57
+ };
58
+ //# sourceMappingURL=ProviderLimits.d.ts.map
@@ -0,0 +1,143 @@
1
+ /**
2
+ * Provider Token Limits Utility
3
+ * Centralized management of AI provider token limits and validation
4
+ */
5
+ import { logger } from "./Logger.js";
6
+ /**
7
+ * Provider token limits configuration
8
+ * These limits are conservative values to avoid API errors
9
+ */
10
+ export const PROVIDER_TOKEN_LIMITS = {
11
+ // Google/Vertex AI providers
12
+ 'vertex': 65536, // Vertex AI limit is 65537 exclusive = 65536 max
13
+ 'google-ai': 65536, // Google AI Studio limit
14
+ 'gemini': 65536, // Gemini model limit
15
+ // OpenAI providers
16
+ 'openai': 128000, // OpenAI GPT-4 and newer models
17
+ 'gpt-4': 128000, // GPT-4 specific limit
18
+ // Anthropic providers
19
+ 'anthropic': 200000, // Claude models limit
20
+ 'claude': 200000, // Claude specific limit
21
+ // Microsoft Azure
22
+ 'azure': 128000, // Azure OpenAI limit
23
+ // AWS Bedrock
24
+ 'bedrock': 100000, // AWS Bedrock limit
25
+ // Auto-selection mode (conservative default)
26
+ 'auto': 60000, // Conservative default for auto-selection
27
+ };
28
+ /**
29
+ * Conservative limits used by CodeReviewer for safety
30
+ * These are slightly lower than the actual limits to provide buffer
31
+ */
32
+ export const CONSERVATIVE_PROVIDER_LIMITS = {
33
+ 'vertex': 65536,
34
+ 'google-ai': 65536,
35
+ 'gemini': 65536,
36
+ 'openai': 120000, // Slightly lower for safety
37
+ 'gpt-4': 120000,
38
+ 'anthropic': 190000, // Slightly lower for safety
39
+ 'claude': 190000,
40
+ 'azure': 120000,
41
+ 'bedrock': 95000, // Significantly lower for safety
42
+ 'auto': 60000,
43
+ };
44
+ /**
45
+ * Get the token limit for a specific provider
46
+ * @param provider - The AI provider name
47
+ * @param conservative - Whether to use conservative limits (default: false)
48
+ * @returns The token limit for the provider
49
+ */
50
+ export function getProviderTokenLimit(provider, conservative = false) {
51
+ // Handle null, undefined, or empty string
52
+ if (!provider || typeof provider !== 'string') {
53
+ return conservative ? CONSERVATIVE_PROVIDER_LIMITS.auto : PROVIDER_TOKEN_LIMITS.auto;
54
+ }
55
+ const normalizedProvider = provider.toLowerCase();
56
+ const limits = conservative ? CONSERVATIVE_PROVIDER_LIMITS : PROVIDER_TOKEN_LIMITS;
57
+ // Handle empty string after normalization
58
+ if (normalizedProvider === '') {
59
+ return conservative ? CONSERVATIVE_PROVIDER_LIMITS.auto : PROVIDER_TOKEN_LIMITS.auto;
60
+ }
61
+ // Direct match
62
+ if (normalizedProvider in limits) {
63
+ return limits[normalizedProvider];
64
+ }
65
+ // Partial match - check if provider contains any known provider name
66
+ for (const [key, limit] of Object.entries(limits)) {
67
+ if (normalizedProvider.includes(key) || key.includes(normalizedProvider)) {
68
+ return limit;
69
+ }
70
+ }
71
+ // Default fallback
72
+ return conservative ? CONSERVATIVE_PROVIDER_LIMITS.auto : PROVIDER_TOKEN_LIMITS.auto;
73
+ }
74
+ /**
75
+ * Validate and adjust token limit for a provider
76
+ * @param provider - The AI provider name
77
+ * @param configuredTokens - The configured token limit
78
+ * @param conservative - Whether to use conservative limits (default: false)
79
+ * @returns The validated and potentially adjusted token limit
80
+ */
81
+ export function validateProviderTokenLimit(provider, configuredTokens, conservative = false) {
82
+ const providerLimit = getProviderTokenLimit(provider, conservative);
83
+ if (!configuredTokens || configuredTokens <= 0) {
84
+ logger.debug(`No configured tokens for ${provider}, using provider default: ${providerLimit}`);
85
+ return providerLimit;
86
+ }
87
+ if (configuredTokens > providerLimit) {
88
+ logger.warn(`Configured maxTokens (${configuredTokens}) exceeds ${provider} limit (${providerLimit}). Adjusting to ${providerLimit}.`);
89
+ return providerLimit;
90
+ }
91
+ logger.debug(`Token limit validation passed: ${configuredTokens} <= ${providerLimit} for provider ${provider}`);
92
+ return configuredTokens;
93
+ }
94
+ /**
95
+ * Get all supported providers
96
+ * @returns Array of supported provider names
97
+ */
98
+ export function getSupportedProviders() {
99
+ return Object.keys(PROVIDER_TOKEN_LIMITS);
100
+ }
101
+ /**
102
+ * Check if a provider is supported
103
+ * @param provider - The provider name to check
104
+ * @returns True if the provider is supported
105
+ */
106
+ export function isProviderSupported(provider) {
107
+ // Handle null, undefined, or empty string
108
+ if (!provider || typeof provider !== 'string') {
109
+ return false;
110
+ }
111
+ const normalizedProvider = provider.toLowerCase();
112
+ // Handle empty string after normalization
113
+ if (normalizedProvider === '') {
114
+ return false;
115
+ }
116
+ // Check direct match
117
+ if (normalizedProvider in PROVIDER_TOKEN_LIMITS) {
118
+ return true;
119
+ }
120
+ // Check partial match
121
+ for (const key of Object.keys(PROVIDER_TOKEN_LIMITS)) {
122
+ if (normalizedProvider.includes(key) || key.includes(normalizedProvider)) {
123
+ return true;
124
+ }
125
+ }
126
+ return false;
127
+ }
128
+ /**
129
+ * Get provider information including limits and support status
130
+ * @param provider - The provider name
131
+ * @param conservative - Whether to use conservative limits
132
+ * @returns Provider information object
133
+ */
134
+ export function getProviderInfo(provider, conservative = false) {
135
+ return {
136
+ provider,
137
+ isSupported: isProviderSupported(provider),
138
+ tokenLimit: getProviderTokenLimit(provider, conservative),
139
+ conservativeLimit: getProviderTokenLimit(provider, true),
140
+ standardLimit: getProviderTokenLimit(provider, false),
141
+ };
142
+ }
143
+ //# sourceMappingURL=ProviderLimits.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juspay/yama",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "Enterprise-grade Pull Request automation toolkit with AI-powered code review and description enhancement",
5
5
  "keywords": [
6
6
  "pr",
@@ -52,7 +52,8 @@
52
52
  "build": "tsc && tsc-alias",
53
53
  "dev": "ts-node-dev --respawn --transpile-only src/cli/index.ts",
54
54
  "test": "jest",
55
- "lint": "eslint src/**/*.ts",
55
+ "lint": "eslint .",
56
+ "lint:fix": "eslint . --fix",
56
57
  "type-check": "tsc --noEmit",
57
58
  "format": "prettier --write .",
58
59
  "format:check": "prettier --check .",
@@ -63,7 +64,6 @@
63
64
  "changeset": "changeset",
64
65
  "changeset:version": "changeset version && git add --all",
65
66
  "release": "npm run build && npm run test && changeset publish",
66
- "release:check": "npm run build && publint && size-limit",
67
67
  "release:dry": "npm publish --dry-run",
68
68
  "release:github": "npm publish --registry https://npm.pkg.github.com",
69
69
  "version:check": "npm version --no-git-tag-version",
@@ -89,9 +89,10 @@
89
89
  "@types/jest": "^29.0.0",
90
90
  "@types/lodash": "^4.14.0",
91
91
  "@types/node": "^20.0.0",
92
- "@typescript-eslint/eslint-plugin": "^6.0.0",
93
- "@typescript-eslint/parser": "^6.0.0",
94
- "eslint": "^8.0.0",
92
+ "@eslint/js": "^9.0.0",
93
+ "@typescript-eslint/eslint-plugin": "^8.0.0",
94
+ "@typescript-eslint/parser": "^8.0.0",
95
+ "eslint": "^9.0.0",
95
96
  "jest": "^29.0.0",
96
97
  "rimraf": "^5.0.0",
97
98
  "ts-jest": "^29.0.0",
@@ -4,21 +4,21 @@
4
4
  # AI Provider Configuration
5
5
  providers:
6
6
  ai:
7
- provider: "auto" # Options: auto, google-ai, openai, anthropic, azure, bedrock
8
- model: "best" # Model name or "best" for auto-selection
9
- temperature: 0.3 # Lower = more focused (0.0-1.0)
10
- maxTokens: 2000000 # Maximum tokens for response
11
- timeout: "15m" # Timeout for AI operations
7
+ provider: "auto" # Options: auto, google-ai, openai, anthropic, azure, bedrock
8
+ model: "best" # Model name or "best" for auto-selection
9
+ temperature: 0.3 # Lower = more focused (0.0-1.0)
10
+ maxTokens: 60000 # Maximum tokens for response (provider-aware limits will be applied automatically)
11
+ timeout: "15m" # Timeout for AI operations
12
12
  enableAnalytics: true
13
13
  enableEvaluation: false
14
14
 
15
15
  # Git Platform Configuration
16
16
  git:
17
- platform: "bitbucket" # Options: bitbucket, github, gitlab, azure-devops
17
+ platform: "bitbucket" # Options: bitbucket, github, gitlab, azure-devops
18
18
  credentials:
19
- username: "${BITBUCKET_USERNAME}" # Environment variable
20
- token: "${BITBUCKET_TOKEN}" # Environment variable
21
- baseUrl: "${BITBUCKET_BASE_URL}" # Your Bitbucket server URL
19
+ username: "${BITBUCKET_USERNAME}" # Environment variable
20
+ token: "${BITBUCKET_TOKEN}" # Environment variable
21
+ baseUrl: "${BITBUCKET_BASE_URL}" # Your Bitbucket server URL
22
22
 
23
23
  # Feature Configuration
24
24
  features:
@@ -26,7 +26,14 @@ features:
26
26
  codeReview:
27
27
  enabled: true
28
28
  severityLevels: ["CRITICAL", "MAJOR", "MINOR", "SUGGESTION"]
29
- categories: ["security", "performance", "maintainability", "functionality", "error_handling"]
29
+ categories:
30
+ [
31
+ "security",
32
+ "performance",
33
+ "maintainability",
34
+ "functionality",
35
+ "error_handling",
36
+ ]
30
37
  excludePatterns:
31
38
  - "*.lock"
32
39
  - "*.svg"
@@ -38,7 +45,7 @@ features:
38
45
  - "dist/**"
39
46
  - "build/**"
40
47
  - "vendor/**"
41
- contextLines: 3 # Lines of context around changes
48
+ contextLines: 3 # Lines of context around changes
42
49
  focusAreas:
43
50
  - "Security vulnerabilities"
44
51
  - "Performance bottlenecks"
@@ -48,7 +55,7 @@ features:
48
55
  # Description Enhancement Configuration
49
56
  descriptionEnhancement:
50
57
  enabled: true
51
- preserveContent: true # Always preserve existing content
58
+ preserveContent: true # Always preserve existing content
52
59
  autoFormat: true
53
60
  requiredSections:
54
61
  - key: "changelog"
@@ -65,36 +72,36 @@ features:
65
72
  diffStrategy:
66
73
  enabled: true
67
74
  thresholds:
68
- wholeDiffMaxFiles: 2 # Use whole diff for ≤2 files
69
- fileByFileMinFiles: 3 # Use file-by-file for ≥3 files
75
+ wholeDiffMaxFiles: 2 # Use whole diff for ≤2 files
76
+ fileByFileMinFiles: 3 # Use file-by-file for ≥3 files
70
77
  # Optional: Force a specific strategy regardless of file count
71
78
  # forceStrategy: "file-by-file" # Options: whole, file-by-file, auto
72
79
 
73
80
  # Security Scan Configuration (Future)
74
81
  securityScan:
75
82
  enabled: false
76
- level: "strict" # Options: strict, moderate, basic
83
+ level: "strict" # Options: strict, moderate, basic
77
84
  scanTypes: ["dependencies", "secrets", "vulnerabilities"]
78
85
 
79
86
  # Analytics Configuration (Future)
80
87
  analytics:
81
88
  enabled: false
82
89
  trackMetrics: true
83
- exportFormat: "json" # Options: json, csv, yaml
90
+ exportFormat: "json" # Options: json, csv, yaml
84
91
 
85
92
  # Cache Configuration
86
93
  cache:
87
94
  enabled: true
88
- ttl: "30m" # Time to live for cache entries
95
+ ttl: "30m" # Time to live for cache entries
89
96
  maxSize: "100MB"
90
- storage: "memory" # Options: memory, redis, file
97
+ storage: "memory" # Options: memory, redis, file
91
98
 
92
99
  # Performance Configuration
93
100
  performance:
94
101
  batch:
95
102
  enabled: true
96
- maxConcurrent: 5 # Max concurrent API calls
97
- delayBetween: "1s" # Delay between batches
103
+ maxConcurrent: 5 # Max concurrent API calls
104
+ delayBetween: "1s" # Delay between batches
98
105
  optimization:
99
106
  reuseConnections: true
100
107
  compressRequests: false
@@ -108,7 +115,7 @@ rules:
108
115
  severity: "CRITICAL"
109
116
  message: "Hardcoded secrets detected"
110
117
  suggestion: "Use environment variables or secure configuration"
111
-
118
+
112
119
  - name: "SQL injection prevention"
113
120
  pattern: "query\\([^?]+\\+.*\\)"
114
121
  severity: "CRITICAL"
@@ -134,3 +141,12 @@ monitoring:
134
141
  metrics: ["api_calls", "cache_hits", "processing_time"]
135
142
  exportFormat: "prometheus"
136
143
  interval: "1m"
144
+
145
+ # Memory Bank Configuration
146
+ memoryBank:
147
+ enabled: true
148
+ path: "memory-bank" # Primary path to look for memory bank files
149
+ fallbackPaths: # Optional fallback paths if primary doesn't exist
150
+ - "docs/memory-bank"
151
+ - ".memory-bank"
152
+ - "project-docs/context"