midnight-mcp 0.1.41 → 0.2.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.
- package/README.md +32 -1
- package/dist/bin.d.ts +1 -0
- package/dist/bin.js +10764 -0
- package/dist/index.d.ts +205 -3
- package/dist/index.js +10722 -15
- package/package.json +16 -6
- package/dist/config/compact-version.d.ts +0 -183
- package/dist/config/compact-version.js +0 -423
- package/dist/db/index.d.ts +0 -3
- package/dist/db/index.js +0 -2
- package/dist/db/vectorStore.d.ts +0 -69
- package/dist/db/vectorStore.js +0 -196
- package/dist/pipeline/embeddings.d.ts +0 -25
- package/dist/pipeline/embeddings.js +0 -103
- package/dist/pipeline/github.d.ts +0 -84
- package/dist/pipeline/github.js +0 -399
- package/dist/pipeline/index.d.ts +0 -11
- package/dist/pipeline/index.js +0 -6
- package/dist/pipeline/indexer.d.ts +0 -41
- package/dist/pipeline/indexer.js +0 -254
- package/dist/pipeline/parser.d.ts +0 -46
- package/dist/pipeline/parser.js +0 -436
- package/dist/pipeline/releases.d.ts +0 -112
- package/dist/pipeline/releases.js +0 -298
- package/dist/pipeline/repository.d.ts +0 -372
- package/dist/pipeline/repository.js +0 -520
- package/dist/prompts/index.d.ts +0 -3
- package/dist/prompts/index.js +0 -2
- package/dist/prompts/templates.d.ts +0 -26
- package/dist/prompts/templates.js +0 -443
- package/dist/resources/code.d.ts +0 -15
- package/dist/resources/code.js +0 -122
- package/dist/resources/content/code-content.d.ts +0 -6
- package/dist/resources/content/code-content.js +0 -802
- package/dist/resources/content/docs-content.d.ts +0 -14
- package/dist/resources/content/docs-content.js +0 -1202
- package/dist/resources/content/index.d.ts +0 -6
- package/dist/resources/content/index.js +0 -6
- package/dist/resources/docs.d.ts +0 -15
- package/dist/resources/docs.js +0 -98
- package/dist/resources/index.d.ts +0 -6
- package/dist/resources/index.js +0 -13
- package/dist/resources/schemas.d.ts +0 -16
- package/dist/resources/schemas.js +0 -407
- package/dist/scripts/index-repos.d.ts +0 -12
- package/dist/scripts/index-repos.js +0 -53
- package/dist/server.d.ts +0 -43
- package/dist/server.js +0 -696
- package/dist/services/index.d.ts +0 -6
- package/dist/services/index.js +0 -6
- package/dist/services/sampling.d.ts +0 -62
- package/dist/services/sampling.js +0 -277
- package/dist/tools/analyze.d.ts +0 -106
- package/dist/tools/analyze.js +0 -431
- package/dist/tools/generation.d.ts +0 -9
- package/dist/tools/generation.js +0 -285
- package/dist/tools/health.d.ts +0 -120
- package/dist/tools/health.js +0 -365
- package/dist/tools/index.d.ts +0 -14
- package/dist/tools/index.js +0 -22
- package/dist/tools/meta.d.ts +0 -61
- package/dist/tools/meta.js +0 -282
- package/dist/tools/repository/constants.d.ts +0 -19
- package/dist/tools/repository/constants.js +0 -324
- package/dist/tools/repository/handlers.d.ts +0 -373
- package/dist/tools/repository/handlers.js +0 -724
- package/dist/tools/repository/index.d.ts +0 -9
- package/dist/tools/repository/index.js +0 -13
- package/dist/tools/repository/schemas.d.ts +0 -153
- package/dist/tools/repository/schemas.js +0 -106
- package/dist/tools/repository/tools.d.ts +0 -7
- package/dist/tools/repository/tools.js +0 -484
- package/dist/tools/repository/validation.d.ts +0 -106
- package/dist/tools/repository/validation.js +0 -820
- package/dist/tools/repository.d.ts +0 -6
- package/dist/tools/repository.js +0 -7
- package/dist/tools/search.d.ts +0 -76
- package/dist/tools/search.js +0 -423
- package/dist/types/index.d.ts +0 -2
- package/dist/types/index.js +0 -2
- package/dist/types/mcp.d.ts +0 -187
- package/dist/types/mcp.js +0 -6
- package/dist/utils/cache.d.ts +0 -77
- package/dist/utils/cache.js +0 -172
- package/dist/utils/config.d.ts +0 -70
- package/dist/utils/config.js +0 -294
- package/dist/utils/errors.d.ts +0 -111
- package/dist/utils/errors.js +0 -165
- package/dist/utils/health.d.ts +0 -29
- package/dist/utils/health.js +0 -132
- package/dist/utils/hosted-api.d.ts +0 -67
- package/dist/utils/hosted-api.js +0 -119
- package/dist/utils/index.d.ts +0 -16
- package/dist/utils/index.js +0 -15
- package/dist/utils/logger.d.ts +0 -48
- package/dist/utils/logger.js +0 -124
- package/dist/utils/rate-limit.d.ts +0 -61
- package/dist/utils/rate-limit.js +0 -148
- package/dist/utils/validation.d.ts +0 -52
- package/dist/utils/validation.js +0 -255
package/dist/utils/health.js
DELETED
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Health check utilities for MCP server monitoring
|
|
3
|
-
*/
|
|
4
|
-
import { githubClient } from "../pipeline/index.js";
|
|
5
|
-
// Track server start time
|
|
6
|
-
const startTime = Date.now();
|
|
7
|
-
// Get package version
|
|
8
|
-
const VERSION = process.env.npm_package_version || "0.0.3";
|
|
9
|
-
/**
|
|
10
|
-
* Check if GitHub API is accessible
|
|
11
|
-
*/
|
|
12
|
-
async function checkGitHubAPI() {
|
|
13
|
-
const start = Date.now();
|
|
14
|
-
try {
|
|
15
|
-
// Try to get rate limit info (lightweight API call)
|
|
16
|
-
const rateLimit = await githubClient.getRateLimit();
|
|
17
|
-
const latency = Date.now() - start;
|
|
18
|
-
if (rateLimit.remaining < 100) {
|
|
19
|
-
return {
|
|
20
|
-
status: "warn",
|
|
21
|
-
message: `Rate limit low: ${rateLimit.remaining}/${rateLimit.limit} remaining`,
|
|
22
|
-
latency,
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
return {
|
|
26
|
-
status: "pass",
|
|
27
|
-
message: `Rate limit: ${rateLimit.remaining}/${rateLimit.limit}`,
|
|
28
|
-
latency,
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
catch (error) {
|
|
32
|
-
return {
|
|
33
|
-
status: "fail",
|
|
34
|
-
message: `GitHub API error: ${error instanceof Error ? error.message : String(error)}`,
|
|
35
|
-
latency: Date.now() - start,
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Check if ChromaDB is accessible (optional dependency)
|
|
41
|
-
*/
|
|
42
|
-
async function checkVectorStore() {
|
|
43
|
-
try {
|
|
44
|
-
// Import dynamically to handle optional dependency
|
|
45
|
-
const { vectorStore } = await import("../db/index.js");
|
|
46
|
-
// Check if vector store is initialized
|
|
47
|
-
if (vectorStore) {
|
|
48
|
-
return {
|
|
49
|
-
status: "pass",
|
|
50
|
-
message: "Vector store available",
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
return {
|
|
54
|
-
status: "warn",
|
|
55
|
-
message: "Vector store not initialized (semantic search unavailable)",
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
catch {
|
|
59
|
-
return {
|
|
60
|
-
status: "warn",
|
|
61
|
-
message: "Vector store not configured (semantic search unavailable)",
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Check memory usage
|
|
67
|
-
*/
|
|
68
|
-
function checkMemory() {
|
|
69
|
-
const usage = process.memoryUsage();
|
|
70
|
-
const heapUsedMB = Math.round(usage.heapUsed / 1024 / 1024);
|
|
71
|
-
const heapTotalMB = Math.round(usage.heapTotal / 1024 / 1024);
|
|
72
|
-
const percentUsed = Math.round((usage.heapUsed / usage.heapTotal) * 100);
|
|
73
|
-
if (percentUsed > 90) {
|
|
74
|
-
return {
|
|
75
|
-
status: "fail",
|
|
76
|
-
message: `High memory usage: ${heapUsedMB}MB/${heapTotalMB}MB (${percentUsed}%)`,
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
if (percentUsed > 75) {
|
|
80
|
-
return {
|
|
81
|
-
status: "warn",
|
|
82
|
-
message: `Elevated memory usage: ${heapUsedMB}MB/${heapTotalMB}MB (${percentUsed}%)`,
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
return {
|
|
86
|
-
status: "pass",
|
|
87
|
-
message: `Memory: ${heapUsedMB}MB/${heapTotalMB}MB (${percentUsed}%)`,
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Perform a full health check
|
|
92
|
-
*/
|
|
93
|
-
export async function getHealthStatus() {
|
|
94
|
-
const checks = [];
|
|
95
|
-
// Run all health checks in parallel
|
|
96
|
-
const [githubCheck, vectorCheck] = await Promise.all([
|
|
97
|
-
checkGitHubAPI(),
|
|
98
|
-
checkVectorStore(),
|
|
99
|
-
]);
|
|
100
|
-
const memoryCheck = checkMemory();
|
|
101
|
-
checks.push({ name: "github_api", ...githubCheck }, { name: "vector_store", ...vectorCheck }, { name: "memory", ...memoryCheck });
|
|
102
|
-
// Determine overall status
|
|
103
|
-
const hasFailure = checks.some((c) => c.status === "fail");
|
|
104
|
-
const hasWarning = checks.some((c) => c.status === "warn");
|
|
105
|
-
let status = "healthy";
|
|
106
|
-
if (hasFailure) {
|
|
107
|
-
status = "unhealthy";
|
|
108
|
-
}
|
|
109
|
-
else if (hasWarning) {
|
|
110
|
-
status = "degraded";
|
|
111
|
-
}
|
|
112
|
-
return {
|
|
113
|
-
status,
|
|
114
|
-
timestamp: new Date().toISOString(),
|
|
115
|
-
version: VERSION,
|
|
116
|
-
uptime: Math.round((Date.now() - startTime) / 1000),
|
|
117
|
-
checks,
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* Get a quick health check (no external calls)
|
|
122
|
-
*/
|
|
123
|
-
export function getQuickHealthStatus() {
|
|
124
|
-
return {
|
|
125
|
-
status: "healthy",
|
|
126
|
-
timestamp: new Date().toISOString(),
|
|
127
|
-
version: VERSION,
|
|
128
|
-
uptime: Math.round((Date.now() - startTime) / 1000),
|
|
129
|
-
checks: [{ name: "server", status: "pass" }],
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
//# sourceMappingURL=health.js.map
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Client for the hosted Midnight MCP API
|
|
3
|
-
* Used when running in hosted mode (default)
|
|
4
|
-
*/
|
|
5
|
-
export interface HostedSearchResult {
|
|
6
|
-
code?: string;
|
|
7
|
-
content?: string;
|
|
8
|
-
relevanceScore: number;
|
|
9
|
-
source: {
|
|
10
|
-
repository: string;
|
|
11
|
-
filePath: string;
|
|
12
|
-
lines?: string;
|
|
13
|
-
section?: string;
|
|
14
|
-
};
|
|
15
|
-
codeType?: string;
|
|
16
|
-
name?: string;
|
|
17
|
-
isExported?: boolean;
|
|
18
|
-
}
|
|
19
|
-
export interface HostedSearchResponse {
|
|
20
|
-
results: HostedSearchResult[];
|
|
21
|
-
totalResults: number;
|
|
22
|
-
query: string;
|
|
23
|
-
category?: string;
|
|
24
|
-
warnings?: string[];
|
|
25
|
-
lastIndexed?: string | null;
|
|
26
|
-
}
|
|
27
|
-
export interface HostedSearchFilter {
|
|
28
|
-
language?: string;
|
|
29
|
-
repository?: string;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Search Compact code via hosted API
|
|
33
|
-
*/
|
|
34
|
-
export declare function searchCompactHosted(query: string, limit?: number): Promise<HostedSearchResponse>;
|
|
35
|
-
/**
|
|
36
|
-
* Search TypeScript code via hosted API
|
|
37
|
-
*/
|
|
38
|
-
export declare function searchTypeScriptHosted(query: string, limit?: number, includeTypes?: boolean): Promise<HostedSearchResponse>;
|
|
39
|
-
/**
|
|
40
|
-
* Search documentation via hosted API
|
|
41
|
-
*/
|
|
42
|
-
export declare function searchDocsHosted(query: string, limit?: number, category?: string): Promise<HostedSearchResponse>;
|
|
43
|
-
/**
|
|
44
|
-
* Generic search via hosted API
|
|
45
|
-
*/
|
|
46
|
-
export declare function searchHosted(query: string, limit?: number, filter?: HostedSearchFilter): Promise<HostedSearchResponse>;
|
|
47
|
-
/**
|
|
48
|
-
* Check if the hosted API is available
|
|
49
|
-
*/
|
|
50
|
-
export declare function checkHostedApiHealth(): Promise<{
|
|
51
|
-
available: boolean;
|
|
52
|
-
documentsIndexed?: number;
|
|
53
|
-
error?: string;
|
|
54
|
-
}>;
|
|
55
|
-
/**
|
|
56
|
-
* Get hosted API stats
|
|
57
|
-
*/
|
|
58
|
-
export declare function getHostedApiStats(): Promise<{
|
|
59
|
-
documentsIndexed: number;
|
|
60
|
-
repositories: number;
|
|
61
|
-
}>;
|
|
62
|
-
/**
|
|
63
|
-
* Track a tool call to the hosted API
|
|
64
|
-
* Fire-and-forget - doesn't block on response
|
|
65
|
-
*/
|
|
66
|
-
export declare function trackToolCall(tool: string, success: boolean, durationMs?: number, version?: string): void;
|
|
67
|
-
//# sourceMappingURL=hosted-api.d.ts.map
|
package/dist/utils/hosted-api.js
DELETED
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Client for the hosted Midnight MCP API
|
|
3
|
-
* Used when running in hosted mode (default)
|
|
4
|
-
*/
|
|
5
|
-
import { config, logger } from "./index.js";
|
|
6
|
-
const API_TIMEOUT = 10000; // 10 seconds
|
|
7
|
-
/**
|
|
8
|
-
* Make a request to the hosted API
|
|
9
|
-
*/
|
|
10
|
-
async function apiRequest(endpoint, options = {}) {
|
|
11
|
-
const url = `${config.hostedApiUrl}${endpoint}`;
|
|
12
|
-
const controller = new AbortController();
|
|
13
|
-
const timeout = setTimeout(() => controller.abort(), API_TIMEOUT);
|
|
14
|
-
try {
|
|
15
|
-
const response = await fetch(url, {
|
|
16
|
-
...options,
|
|
17
|
-
signal: controller.signal,
|
|
18
|
-
headers: {
|
|
19
|
-
"Content-Type": "application/json",
|
|
20
|
-
"User-Agent": "midnight-mcp",
|
|
21
|
-
...options.headers,
|
|
22
|
-
},
|
|
23
|
-
});
|
|
24
|
-
if (!response.ok) {
|
|
25
|
-
const errorData = (await response
|
|
26
|
-
.json()
|
|
27
|
-
.catch(() => ({ error: "Unknown error" })));
|
|
28
|
-
throw new Error(errorData.error || `API error: ${response.status}`);
|
|
29
|
-
}
|
|
30
|
-
return (await response.json());
|
|
31
|
-
}
|
|
32
|
-
catch (error) {
|
|
33
|
-
if (error instanceof Error && error.name === "AbortError") {
|
|
34
|
-
throw new Error("API request timed out. The hosted service may be unavailable.");
|
|
35
|
-
}
|
|
36
|
-
throw error;
|
|
37
|
-
}
|
|
38
|
-
finally {
|
|
39
|
-
clearTimeout(timeout);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Search Compact code via hosted API
|
|
44
|
-
*/
|
|
45
|
-
export async function searchCompactHosted(query, limit = 10) {
|
|
46
|
-
logger.debug("Searching Compact code via hosted API", { query });
|
|
47
|
-
return apiRequest("/v1/search/compact", {
|
|
48
|
-
method: "POST",
|
|
49
|
-
body: JSON.stringify({ query, limit }),
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Search TypeScript code via hosted API
|
|
54
|
-
*/
|
|
55
|
-
export async function searchTypeScriptHosted(query, limit = 10, includeTypes = true) {
|
|
56
|
-
logger.debug("Searching TypeScript code via hosted API", { query });
|
|
57
|
-
return apiRequest("/v1/search/typescript", {
|
|
58
|
-
method: "POST",
|
|
59
|
-
body: JSON.stringify({ query, limit, includeTypes }),
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Search documentation via hosted API
|
|
64
|
-
*/
|
|
65
|
-
export async function searchDocsHosted(query, limit = 10, category = "all") {
|
|
66
|
-
logger.debug("Searching documentation via hosted API", { query });
|
|
67
|
-
return apiRequest("/v1/search/docs", {
|
|
68
|
-
method: "POST",
|
|
69
|
-
body: JSON.stringify({ query, limit, category }),
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Generic search via hosted API
|
|
74
|
-
*/
|
|
75
|
-
export async function searchHosted(query, limit = 10, filter) {
|
|
76
|
-
logger.debug("Searching via hosted API", { query, filter });
|
|
77
|
-
return apiRequest("/v1/search", {
|
|
78
|
-
method: "POST",
|
|
79
|
-
body: JSON.stringify({ query, limit, filter }),
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Check if the hosted API is available
|
|
84
|
-
*/
|
|
85
|
-
export async function checkHostedApiHealth() {
|
|
86
|
-
try {
|
|
87
|
-
const response = await apiRequest("/health");
|
|
88
|
-
return {
|
|
89
|
-
available: response.status === "healthy",
|
|
90
|
-
documentsIndexed: response.vectorStore?.documentsIndexed,
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
catch (error) {
|
|
94
|
-
return {
|
|
95
|
-
available: false,
|
|
96
|
-
error: error instanceof Error ? error.message : String(error),
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Get hosted API stats
|
|
102
|
-
*/
|
|
103
|
-
export async function getHostedApiStats() {
|
|
104
|
-
return apiRequest("/v1/stats");
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Track a tool call to the hosted API
|
|
108
|
-
* Fire-and-forget - doesn't block on response
|
|
109
|
-
*/
|
|
110
|
-
export function trackToolCall(tool, success, durationMs, version) {
|
|
111
|
-
// Fire and forget - don't await, don't block
|
|
112
|
-
apiRequest("/v1/track/tool", {
|
|
113
|
-
method: "POST",
|
|
114
|
-
body: JSON.stringify({ tool, success, durationMs, version }),
|
|
115
|
-
}).catch(() => {
|
|
116
|
-
// Silently ignore tracking errors
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
//# sourceMappingURL=hosted-api.js.map
|
package/dist/utils/index.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export { config, isHostedMode, isLocalMode } from "./config.js";
|
|
2
|
-
export type { Config, RepositoryConfig } from "./config.js";
|
|
3
|
-
export { DEFAULT_REPOSITORIES } from "./config.js";
|
|
4
|
-
export { logger, setMCPLogCallback } from "./logger.js";
|
|
5
|
-
export { MCPError, ErrorCodes, createUserError, formatErrorResponse, withErrorHandling, SelfCorrectionHints, } from "./errors.js";
|
|
6
|
-
export { validateQuery, validateRepository, validatePath, validateRef, validateNumber, validateToolArgs, sanitizeString, } from "./validation.js";
|
|
7
|
-
export type { ValidationResult } from "./validation.js";
|
|
8
|
-
export { getHealthStatus, getQuickHealthStatus } from "./health.js";
|
|
9
|
-
export type { HealthStatus } from "./health.js";
|
|
10
|
-
export { updateRateLimitFromHeaders, updateRateLimit, getRateLimitStatus, shouldProceedWithRequest, getTimeUntilReset, formatRateLimitStatus, decrementRemaining, } from "./rate-limit.js";
|
|
11
|
-
export type { RateLimitInfo, RateLimitStatus } from "./rate-limit.js";
|
|
12
|
-
export { Cache, createCacheKey, searchCache, fileCache, metadataCache, pruneAllCaches, } from "./cache.js";
|
|
13
|
-
export type { CacheOptions, CacheEntry, CacheStats } from "./cache.js";
|
|
14
|
-
export { searchCompactHosted, searchTypeScriptHosted, searchDocsHosted, searchHosted, checkHostedApiHealth, getHostedApiStats, trackToolCall, } from "./hosted-api.js";
|
|
15
|
-
export type { HostedSearchResult, HostedSearchResponse, HostedSearchFilter, } from "./hosted-api.js";
|
|
16
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/utils/index.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export { config, isHostedMode, isLocalMode } from "./config.js";
|
|
2
|
-
export { DEFAULT_REPOSITORIES } from "./config.js";
|
|
3
|
-
export { logger, setMCPLogCallback } from "./logger.js";
|
|
4
|
-
export { MCPError, ErrorCodes, createUserError, formatErrorResponse, withErrorHandling, SelfCorrectionHints, } from "./errors.js";
|
|
5
|
-
// Validation utilities
|
|
6
|
-
export { validateQuery, validateRepository, validatePath, validateRef, validateNumber, validateToolArgs, sanitizeString, } from "./validation.js";
|
|
7
|
-
// Health check utilities
|
|
8
|
-
export { getHealthStatus, getQuickHealthStatus } from "./health.js";
|
|
9
|
-
// Rate limit tracking
|
|
10
|
-
export { updateRateLimitFromHeaders, updateRateLimit, getRateLimitStatus, shouldProceedWithRequest, getTimeUntilReset, formatRateLimitStatus, decrementRemaining, } from "./rate-limit.js";
|
|
11
|
-
// Caching utilities
|
|
12
|
-
export { Cache, createCacheKey, searchCache, fileCache, metadataCache, pruneAllCaches, } from "./cache.js";
|
|
13
|
-
// Hosted API client
|
|
14
|
-
export { searchCompactHosted, searchTypeScriptHosted, searchDocsHosted, searchHosted, checkHostedApiHealth, getHostedApiStats, trackToolCall, } from "./hosted-api.js";
|
|
15
|
-
//# sourceMappingURL=index.js.map
|
package/dist/utils/logger.d.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
type LogLevel = "debug" | "info" | "warn" | "error";
|
|
2
|
-
type LogFormat = "text" | "json";
|
|
3
|
-
type MCPLogCallback = (level: "debug" | "info" | "notice" | "warning" | "error", logger: string, data: unknown) => void;
|
|
4
|
-
/**
|
|
5
|
-
* Set the MCP log callback to send logs to the client
|
|
6
|
-
*/
|
|
7
|
-
export declare function setMCPLogCallback(callback: MCPLogCallback | null): void;
|
|
8
|
-
declare class Logger {
|
|
9
|
-
private level;
|
|
10
|
-
private format;
|
|
11
|
-
private service;
|
|
12
|
-
constructor(level?: LogLevel, format?: LogFormat, service?: string);
|
|
13
|
-
/**
|
|
14
|
-
* Set log format at runtime
|
|
15
|
-
*/
|
|
16
|
-
setFormat(format: LogFormat): void;
|
|
17
|
-
/**
|
|
18
|
-
* Set log level at runtime
|
|
19
|
-
*/
|
|
20
|
-
setLevel(level: LogLevel): void;
|
|
21
|
-
private shouldLog;
|
|
22
|
-
private formatTextMessage;
|
|
23
|
-
private formatJsonMessage;
|
|
24
|
-
private formatMessage;
|
|
25
|
-
debug(message: string, meta?: object): void;
|
|
26
|
-
info(message: string, meta?: object): void;
|
|
27
|
-
warn(message: string, meta?: object): void;
|
|
28
|
-
error(message: string, meta?: object): void;
|
|
29
|
-
/**
|
|
30
|
-
* Create a child logger with additional context
|
|
31
|
-
*/
|
|
32
|
-
child(context: object): ChildLogger;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Child logger that includes additional context in all log messages
|
|
36
|
-
*/
|
|
37
|
-
declare class ChildLogger {
|
|
38
|
-
private parent;
|
|
39
|
-
private context;
|
|
40
|
-
constructor(parent: Logger, context: object);
|
|
41
|
-
debug(message: string, meta?: object): void;
|
|
42
|
-
info(message: string, meta?: object): void;
|
|
43
|
-
warn(message: string, meta?: object): void;
|
|
44
|
-
error(message: string, meta?: object): void;
|
|
45
|
-
}
|
|
46
|
-
export declare const logger: Logger;
|
|
47
|
-
export {};
|
|
48
|
-
//# sourceMappingURL=logger.d.ts.map
|
package/dist/utils/logger.js
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import { config } from "./config.js";
|
|
2
|
-
// Global MCP log callback (set by server)
|
|
3
|
-
let mcpLogCallback = null;
|
|
4
|
-
/**
|
|
5
|
-
* Set the MCP log callback to send logs to the client
|
|
6
|
-
*/
|
|
7
|
-
export function setMCPLogCallback(callback) {
|
|
8
|
-
mcpLogCallback = callback;
|
|
9
|
-
}
|
|
10
|
-
const LOG_LEVELS = {
|
|
11
|
-
debug: 0,
|
|
12
|
-
info: 1,
|
|
13
|
-
warn: 2,
|
|
14
|
-
error: 3,
|
|
15
|
-
};
|
|
16
|
-
class Logger {
|
|
17
|
-
level;
|
|
18
|
-
format;
|
|
19
|
-
service;
|
|
20
|
-
constructor(level = "info", format = "text", service = "midnight-mcp") {
|
|
21
|
-
this.level = level;
|
|
22
|
-
this.format = format;
|
|
23
|
-
this.service = service;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Set log format at runtime
|
|
27
|
-
*/
|
|
28
|
-
setFormat(format) {
|
|
29
|
-
this.format = format;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Set log level at runtime
|
|
33
|
-
*/
|
|
34
|
-
setLevel(level) {
|
|
35
|
-
this.level = level;
|
|
36
|
-
}
|
|
37
|
-
shouldLog(level) {
|
|
38
|
-
return LOG_LEVELS[level] >= LOG_LEVELS[this.level];
|
|
39
|
-
}
|
|
40
|
-
formatTextMessage(level, message, meta) {
|
|
41
|
-
const timestamp = new Date().toISOString();
|
|
42
|
-
const metaStr = meta ? ` ${JSON.stringify(meta)}` : "";
|
|
43
|
-
return `[${timestamp}] [${level.toUpperCase()}] ${message}${metaStr}`;
|
|
44
|
-
}
|
|
45
|
-
formatJsonMessage(level, message, meta) {
|
|
46
|
-
const entry = {
|
|
47
|
-
timestamp: new Date().toISOString(),
|
|
48
|
-
level,
|
|
49
|
-
message,
|
|
50
|
-
service: this.service,
|
|
51
|
-
};
|
|
52
|
-
if (meta) {
|
|
53
|
-
entry.meta = meta;
|
|
54
|
-
}
|
|
55
|
-
return JSON.stringify(entry);
|
|
56
|
-
}
|
|
57
|
-
formatMessage(level, message, meta) {
|
|
58
|
-
if (this.format === "json") {
|
|
59
|
-
return this.formatJsonMessage(level, message, meta);
|
|
60
|
-
}
|
|
61
|
-
return this.formatTextMessage(level, message, meta);
|
|
62
|
-
}
|
|
63
|
-
debug(message, meta) {
|
|
64
|
-
if (this.shouldLog("debug")) {
|
|
65
|
-
console.error(this.formatMessage("debug", message, meta));
|
|
66
|
-
}
|
|
67
|
-
// Also send to MCP client
|
|
68
|
-
mcpLogCallback?.("debug", this.service, { message, ...meta });
|
|
69
|
-
}
|
|
70
|
-
info(message, meta) {
|
|
71
|
-
if (this.shouldLog("info")) {
|
|
72
|
-
console.error(this.formatMessage("info", message, meta));
|
|
73
|
-
}
|
|
74
|
-
// Also send to MCP client
|
|
75
|
-
mcpLogCallback?.("info", this.service, { message, ...meta });
|
|
76
|
-
}
|
|
77
|
-
warn(message, meta) {
|
|
78
|
-
if (this.shouldLog("warn")) {
|
|
79
|
-
console.error(this.formatMessage("warn", message, meta));
|
|
80
|
-
}
|
|
81
|
-
// Also send to MCP client (MCP uses "warning" not "warn")
|
|
82
|
-
mcpLogCallback?.("warning", this.service, { message, ...meta });
|
|
83
|
-
}
|
|
84
|
-
error(message, meta) {
|
|
85
|
-
if (this.shouldLog("error")) {
|
|
86
|
-
console.error(this.formatMessage("error", message, meta));
|
|
87
|
-
}
|
|
88
|
-
// Also send to MCP client
|
|
89
|
-
mcpLogCallback?.("error", this.service, { message, ...meta });
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Create a child logger with additional context
|
|
93
|
-
*/
|
|
94
|
-
child(context) {
|
|
95
|
-
return new ChildLogger(this, context);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Child logger that includes additional context in all log messages
|
|
100
|
-
*/
|
|
101
|
-
class ChildLogger {
|
|
102
|
-
parent;
|
|
103
|
-
context;
|
|
104
|
-
constructor(parent, context) {
|
|
105
|
-
this.parent = parent;
|
|
106
|
-
this.context = context;
|
|
107
|
-
}
|
|
108
|
-
debug(message, meta) {
|
|
109
|
-
this.parent.debug(message, { ...this.context, ...meta });
|
|
110
|
-
}
|
|
111
|
-
info(message, meta) {
|
|
112
|
-
this.parent.info(message, { ...this.context, ...meta });
|
|
113
|
-
}
|
|
114
|
-
warn(message, meta) {
|
|
115
|
-
this.parent.warn(message, { ...this.context, ...meta });
|
|
116
|
-
}
|
|
117
|
-
error(message, meta) {
|
|
118
|
-
this.parent.error(message, { ...this.context, ...meta });
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
// Determine log format from environment
|
|
122
|
-
const logFormat = process.env.LOG_FORMAT === "json" ? "json" : "text";
|
|
123
|
-
export const logger = new Logger(config.logLevel, logFormat);
|
|
124
|
-
//# sourceMappingURL=logger.js.map
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Rate limit tracking and management utilities
|
|
3
|
-
* Tracks GitHub API rate limits and warns before hitting limits
|
|
4
|
-
*/
|
|
5
|
-
export interface RateLimitInfo {
|
|
6
|
-
limit: number;
|
|
7
|
-
remaining: number;
|
|
8
|
-
reset: Date;
|
|
9
|
-
used: number;
|
|
10
|
-
}
|
|
11
|
-
export interface RateLimitStatus {
|
|
12
|
-
isLimited: boolean;
|
|
13
|
-
isWarning: boolean;
|
|
14
|
-
remaining: number;
|
|
15
|
-
limit: number;
|
|
16
|
-
resetAt: Date;
|
|
17
|
-
percentUsed: number;
|
|
18
|
-
message: string;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Update rate limit info from API response headers
|
|
22
|
-
*/
|
|
23
|
-
export declare function updateRateLimitFromHeaders(headers: Record<string, string | undefined>): void;
|
|
24
|
-
/**
|
|
25
|
-
* Update rate limit info directly
|
|
26
|
-
*/
|
|
27
|
-
export declare function updateRateLimit(info: RateLimitInfo): void;
|
|
28
|
-
/**
|
|
29
|
-
* Get current rate limit status
|
|
30
|
-
*/
|
|
31
|
-
export declare function getRateLimitStatus(): RateLimitStatus;
|
|
32
|
-
/**
|
|
33
|
-
* Check if we should proceed with an API call
|
|
34
|
-
* Returns true if safe to proceed, false if we should wait/fail
|
|
35
|
-
*/
|
|
36
|
-
export declare function shouldProceedWithRequest(): {
|
|
37
|
-
proceed: boolean;
|
|
38
|
-
reason?: string;
|
|
39
|
-
waitMs?: number;
|
|
40
|
-
};
|
|
41
|
-
/**
|
|
42
|
-
* Get time until rate limit resets
|
|
43
|
-
*/
|
|
44
|
-
export declare function getTimeUntilReset(): number;
|
|
45
|
-
/**
|
|
46
|
-
* Check if cached rate limit info is stale
|
|
47
|
-
*/
|
|
48
|
-
export declare function isRateLimitStale(): boolean;
|
|
49
|
-
/**
|
|
50
|
-
* Get cached rate limit info
|
|
51
|
-
*/
|
|
52
|
-
export declare function getCachedRateLimit(): RateLimitInfo | null;
|
|
53
|
-
/**
|
|
54
|
-
* Decrement remaining count (for optimistic tracking)
|
|
55
|
-
*/
|
|
56
|
-
export declare function decrementRemaining(): void;
|
|
57
|
-
/**
|
|
58
|
-
* Format rate limit status for display
|
|
59
|
-
*/
|
|
60
|
-
export declare function formatRateLimitStatus(): string;
|
|
61
|
-
//# sourceMappingURL=rate-limit.d.ts.map
|