foundryvtt-mcp 0.11.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.
- package/LICENSE +21 -0
- package/README.md +142 -0
- package/dist/character/manager.d.ts +92 -0
- package/dist/character/manager.d.ts.map +1 -0
- package/dist/character/manager.js +208 -0
- package/dist/character/manager.js.map +1 -0
- package/dist/combat/manager.d.ts +94 -0
- package/dist/combat/manager.d.ts.map +1 -0
- package/dist/combat/manager.js +373 -0
- package/dist/combat/manager.js.map +1 -0
- package/dist/config/index.d.ts +114 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +177 -0
- package/dist/config/index.js.map +1 -0
- package/dist/diagnostics/client.d.ts +193 -0
- package/dist/diagnostics/client.d.ts.map +1 -0
- package/dist/diagnostics/client.js +314 -0
- package/dist/diagnostics/client.js.map +1 -0
- package/dist/diagnostics/types.d.ts +414 -0
- package/dist/diagnostics/types.d.ts.map +1 -0
- package/dist/diagnostics/types.js +94 -0
- package/dist/diagnostics/types.js.map +1 -0
- package/dist/foundry/auth.d.ts +19 -0
- package/dist/foundry/auth.d.ts.map +1 -0
- package/dist/foundry/auth.js +135 -0
- package/dist/foundry/auth.js.map +1 -0
- package/dist/foundry/client.d.ts +95 -0
- package/dist/foundry/client.d.ts.map +1 -0
- package/dist/foundry/client.js +692 -0
- package/dist/foundry/client.js.map +1 -0
- package/dist/foundry/types.d.ts +805 -0
- package/dist/foundry/types.d.ts.map +1 -0
- package/dist/foundry/types.js +13 -0
- package/dist/foundry/types.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +199 -0
- package/dist/index.js.map +1 -0
- package/dist/resources/index.d.ts +3 -0
- package/dist/resources/index.d.ts.map +1 -0
- package/dist/resources/index.js +93 -0
- package/dist/resources/index.js.map +1 -0
- package/dist/tools/base.d.ts +80 -0
- package/dist/tools/base.d.ts.map +1 -0
- package/dist/tools/base.js +73 -0
- package/dist/tools/base.js.map +1 -0
- package/dist/tools/definitions.d.ts +414 -0
- package/dist/tools/definitions.d.ts.map +1 -0
- package/dist/tools/definitions.js +429 -0
- package/dist/tools/definitions.js.map +1 -0
- package/dist/tools/handlers/actors.d.ts +31 -0
- package/dist/tools/handlers/actors.d.ts.map +1 -0
- package/dist/tools/handlers/actors.js +76 -0
- package/dist/tools/handlers/actors.js.map +1 -0
- package/dist/tools/handlers/chat.d.ts +13 -0
- package/dist/tools/handlers/chat.d.ts.map +1 -0
- package/dist/tools/handlers/chat.js +38 -0
- package/dist/tools/handlers/chat.js.map +1 -0
- package/dist/tools/handlers/combat.d.ts +11 -0
- package/dist/tools/handlers/combat.d.ts.map +1 -0
- package/dist/tools/handlers/combat.js +48 -0
- package/dist/tools/handlers/combat.js.map +1 -0
- package/dist/tools/handlers/diagnostics.d.ts +64 -0
- package/dist/tools/handlers/diagnostics.d.ts.map +1 -0
- package/dist/tools/handlers/diagnostics.js +182 -0
- package/dist/tools/handlers/diagnostics.js.map +1 -0
- package/dist/tools/handlers/dice.d.ts +39 -0
- package/dist/tools/handlers/dice.d.ts.map +1 -0
- package/dist/tools/handlers/dice.js +53 -0
- package/dist/tools/handlers/dice.js.map +1 -0
- package/dist/tools/handlers/generation.d.ts +44 -0
- package/dist/tools/handlers/generation.d.ts.map +1 -0
- package/dist/tools/handlers/generation.js +205 -0
- package/dist/tools/handlers/generation.js.map +1 -0
- package/dist/tools/handlers/items.d.ts +21 -0
- package/dist/tools/handlers/items.d.ts.map +1 -0
- package/dist/tools/handlers/items.js +50 -0
- package/dist/tools/handlers/items.js.map +1 -0
- package/dist/tools/handlers/journals.d.ts +22 -0
- package/dist/tools/handlers/journals.d.ts.map +1 -0
- package/dist/tools/handlers/journals.js +62 -0
- package/dist/tools/handlers/journals.js.map +1 -0
- package/dist/tools/handlers/resources.d.ts +13 -0
- package/dist/tools/handlers/resources.d.ts.map +1 -0
- package/dist/tools/handlers/resources.js +188 -0
- package/dist/tools/handlers/resources.js.map +1 -0
- package/dist/tools/handlers/scenes.d.ts +18 -0
- package/dist/tools/handlers/scenes.d.ts.map +1 -0
- package/dist/tools/handlers/scenes.js +34 -0
- package/dist/tools/handlers/scenes.js.map +1 -0
- package/dist/tools/handlers/users.d.ts +11 -0
- package/dist/tools/handlers/users.d.ts.map +1 -0
- package/dist/tools/handlers/users.js +34 -0
- package/dist/tools/handlers/users.js.map +1 -0
- package/dist/tools/handlers/utils.d.ts +11 -0
- package/dist/tools/handlers/utils.d.ts.map +1 -0
- package/dist/tools/handlers/utils.js +24 -0
- package/dist/tools/handlers/utils.js.map +1 -0
- package/dist/tools/handlers/world.d.ts +26 -0
- package/dist/tools/handlers/world.d.ts.map +1 -0
- package/dist/tools/handlers/world.js +92 -0
- package/dist/tools/handlers/world.js.map +1 -0
- package/dist/tools/index.d.ts +19 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +22 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/new-router.d.ts +29 -0
- package/dist/tools/new-router.d.ts.map +1 -0
- package/dist/tools/new-router.js +97 -0
- package/dist/tools/new-router.js.map +1 -0
- package/dist/tools/registry.d.ts +51 -0
- package/dist/tools/registry.d.ts.map +1 -0
- package/dist/tools/registry.js +79 -0
- package/dist/tools/registry.js.map +1 -0
- package/dist/tools/resources.d.ts +16 -0
- package/dist/tools/resources.d.ts.map +1 -0
- package/dist/tools/resources.js +63 -0
- package/dist/tools/resources.js.map +1 -0
- package/dist/tools/router.d.ts +22 -0
- package/dist/tools/router.d.ts.map +1 -0
- package/dist/tools/router.js +128 -0
- package/dist/tools/router.js.map +1 -0
- package/dist/utils/cache-instance.d.ts +25 -0
- package/dist/utils/cache-instance.d.ts.map +1 -0
- package/dist/utils/cache-instance.js +30 -0
- package/dist/utils/cache-instance.js.map +1 -0
- package/dist/utils/cache.d.ts +80 -0
- package/dist/utils/cache.d.ts.map +1 -0
- package/dist/utils/cache.js +205 -0
- package/dist/utils/cache.js.map +1 -0
- package/dist/utils/diagnostics.d.ts +114 -0
- package/dist/utils/diagnostics.d.ts.map +1 -0
- package/dist/utils/diagnostics.js +330 -0
- package/dist/utils/diagnostics.js.map +1 -0
- package/dist/utils/logger.d.ts +137 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +158 -0
- package/dist/utils/logger.js.map +1 -0
- package/package.json +98 -0
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Configuration management for FoundryVTT MCP Server
|
|
3
|
+
*
|
|
4
|
+
* This module handles loading and validating configuration from environment variables
|
|
5
|
+
* using Zod schemas for type safety and runtime validation.
|
|
6
|
+
*
|
|
7
|
+
* @version 0.1.0
|
|
8
|
+
* @author FoundryVTT MCP Team
|
|
9
|
+
*/
|
|
10
|
+
import { z } from 'zod';
|
|
11
|
+
/**
|
|
12
|
+
* Zod schema for validating server configuration
|
|
13
|
+
*
|
|
14
|
+
* Defines the structure and validation rules for all configuration options,
|
|
15
|
+
* including server settings, FoundryVTT connection details, and caching options.
|
|
16
|
+
*/
|
|
17
|
+
const ConfigSchema = z.object({
|
|
18
|
+
serverName: z.string().default('foundryvtt-mcp'),
|
|
19
|
+
serverVersion: z.string().default('0.1.0'),
|
|
20
|
+
logLevel: z.enum(['debug', 'info', 'warn', 'error']).default('info'),
|
|
21
|
+
nodeEnv: z.enum(['development', 'production', 'test']).default('development'),
|
|
22
|
+
foundry: z.object({
|
|
23
|
+
url: z
|
|
24
|
+
.string()
|
|
25
|
+
.url('Invalid FoundryVTT URL - must include protocol (http:// or https://)')
|
|
26
|
+
.refine((url) => {
|
|
27
|
+
try {
|
|
28
|
+
const parsed = new URL(url);
|
|
29
|
+
return parsed.protocol === 'http:' || parsed.protocol === 'https:';
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
}, 'URL must use http:// or https:// protocol')
|
|
35
|
+
.refine((url) => {
|
|
36
|
+
try {
|
|
37
|
+
const parsed = new URL(url);
|
|
38
|
+
// Warning for localhost in production
|
|
39
|
+
if (process.env.NODE_ENV === 'production' &&
|
|
40
|
+
(parsed.hostname === 'localhost' || parsed.hostname === '127.0.0.1')) {
|
|
41
|
+
console.warn('⚠️ Warning: Using localhost URL in production environment');
|
|
42
|
+
}
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
}, 'URL validation failed'),
|
|
49
|
+
apiKey: z.string().optional(),
|
|
50
|
+
username: z.string().optional(),
|
|
51
|
+
password: z.string().optional(),
|
|
52
|
+
userId: z.string().optional(),
|
|
53
|
+
socketPath: z.string().default('/socket.io/'),
|
|
54
|
+
timeout: z.number().default(10000),
|
|
55
|
+
retryAttempts: z.number().default(3),
|
|
56
|
+
retryDelay: z.number().default(1000),
|
|
57
|
+
}),
|
|
58
|
+
cache: z.object({
|
|
59
|
+
enabled: z.boolean().default(true),
|
|
60
|
+
ttlSeconds: z.number().default(300), // 5 minutes
|
|
61
|
+
maxSize: z.number().default(1000),
|
|
62
|
+
}),
|
|
63
|
+
});
|
|
64
|
+
/**
|
|
65
|
+
* Loads and validates configuration from environment variables
|
|
66
|
+
*
|
|
67
|
+
* Reads configuration from process.env, applies defaults where appropriate,
|
|
68
|
+
* and validates the result against the ConfigSchema. In test environments,
|
|
69
|
+
* throws errors instead of exiting the process to allow proper test handling.
|
|
70
|
+
*
|
|
71
|
+
* @returns Validated configuration object
|
|
72
|
+
* @throws Error in test environment, process exits with code 1 in production
|
|
73
|
+
* @example
|
|
74
|
+
* ```typescript
|
|
75
|
+
* const config = loadConfig();
|
|
76
|
+
* console.log(`Server: ${config.serverName} v${config.serverVersion}`);
|
|
77
|
+
* console.log(`FoundryVTT URL: ${config.foundry.url}`);
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
function loadConfig() {
|
|
81
|
+
const rawConfig = {
|
|
82
|
+
serverName: process.env.MCP_SERVER_NAME,
|
|
83
|
+
serverVersion: process.env.MCP_SERVER_VERSION,
|
|
84
|
+
logLevel: process.env.LOG_LEVEL,
|
|
85
|
+
nodeEnv: process.env.NODE_ENV,
|
|
86
|
+
foundry: {
|
|
87
|
+
url: process.env.FOUNDRY_URL,
|
|
88
|
+
apiKey: process.env.FOUNDRY_API_KEY,
|
|
89
|
+
username: process.env.FOUNDRY_USERNAME,
|
|
90
|
+
password: process.env.FOUNDRY_PASSWORD,
|
|
91
|
+
userId: process.env.FOUNDRY_USER_ID,
|
|
92
|
+
socketPath: process.env.FOUNDRY_SOCKET_PATH,
|
|
93
|
+
timeout: process.env.FOUNDRY_TIMEOUT ? parseInt(process.env.FOUNDRY_TIMEOUT, 10) : undefined,
|
|
94
|
+
retryAttempts: process.env.FOUNDRY_RETRY_ATTEMPTS
|
|
95
|
+
? parseInt(process.env.FOUNDRY_RETRY_ATTEMPTS, 10)
|
|
96
|
+
: undefined,
|
|
97
|
+
retryDelay: process.env.FOUNDRY_RETRY_DELAY
|
|
98
|
+
? parseInt(process.env.FOUNDRY_RETRY_DELAY, 10)
|
|
99
|
+
: undefined,
|
|
100
|
+
},
|
|
101
|
+
cache: {
|
|
102
|
+
enabled: process.env.CACHE_ENABLED !== undefined ? process.env.CACHE_ENABLED === 'true' : undefined,
|
|
103
|
+
ttlSeconds: process.env.CACHE_TTL_SECONDS
|
|
104
|
+
? parseInt(process.env.CACHE_TTL_SECONDS, 10)
|
|
105
|
+
: undefined,
|
|
106
|
+
maxSize: process.env.CACHE_MAX_SIZE ? parseInt(process.env.CACHE_MAX_SIZE, 10) : undefined,
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
try {
|
|
110
|
+
return ConfigSchema.parse(rawConfig);
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
if (error instanceof z.ZodError) {
|
|
114
|
+
console.error('❌ Configuration validation failed:');
|
|
115
|
+
error.issues.forEach((err) => {
|
|
116
|
+
console.error(` ${err.path.join('.')}: ${err.message}`);
|
|
117
|
+
// Provide specific guidance for common URL errors
|
|
118
|
+
if (err.path.includes('url')) {
|
|
119
|
+
console.error(' 💡 URL Examples:');
|
|
120
|
+
console.error(' • Local: http://localhost:30000');
|
|
121
|
+
console.error(' • Reverse Proxy: https://foundry.example.com');
|
|
122
|
+
console.error(' • Network IP: http://192.168.1.100:30000');
|
|
123
|
+
console.error(' • Custom Port: https://foundry.example.com:8443');
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
console.error('\n📋 Configuration Help:');
|
|
127
|
+
console.error(' • Check your environment variables and .env file');
|
|
128
|
+
console.error(' • Ensure FOUNDRY_URL includes protocol (http:// or https://)');
|
|
129
|
+
console.error(' • For setup guidance, see: SETUP_GUIDE.md');
|
|
130
|
+
console.error(' • Run the setup wizard: npm run setup');
|
|
131
|
+
}
|
|
132
|
+
// In test environment, throw error instead of exiting process
|
|
133
|
+
if (process.env.NODE_ENV === 'test') {
|
|
134
|
+
throw error;
|
|
135
|
+
}
|
|
136
|
+
process.exit(1);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Cached configuration instance
|
|
141
|
+
*/
|
|
142
|
+
let _config = null;
|
|
143
|
+
/**
|
|
144
|
+
* Gets the global configuration instance
|
|
145
|
+
*
|
|
146
|
+
* This loads and caches the configuration on first access, allowing tests
|
|
147
|
+
* to set environment variables before triggering configuration validation.
|
|
148
|
+
*
|
|
149
|
+
* @returns Validated configuration object
|
|
150
|
+
* @example
|
|
151
|
+
* ```typescript
|
|
152
|
+
* import { config } from './config/index.js';
|
|
153
|
+
*
|
|
154
|
+
* console.log(`Connecting to ${config.foundry.url}`);
|
|
155
|
+
* if (config.foundry.apiKey) {
|
|
156
|
+
* console.log('Using local REST API module with API key');
|
|
157
|
+
* } else {
|
|
158
|
+
* console.log('Using WebSocket connection with username/password');
|
|
159
|
+
* }
|
|
160
|
+
* ```
|
|
161
|
+
*/
|
|
162
|
+
export const config = new Proxy({}, {
|
|
163
|
+
get(_target, prop) {
|
|
164
|
+
if (_config === null) {
|
|
165
|
+
_config = loadConfig();
|
|
166
|
+
}
|
|
167
|
+
return _config[prop];
|
|
168
|
+
},
|
|
169
|
+
});
|
|
170
|
+
/**
|
|
171
|
+
* Resets the cached configuration - used for testing
|
|
172
|
+
* @internal
|
|
173
|
+
*/
|
|
174
|
+
export function resetConfig() {
|
|
175
|
+
_config = null;
|
|
176
|
+
}
|
|
177
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;;GAKG;AACH,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC;IAC5B,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,gBAAgB,CAAC;IAChD,aAAa,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC;IAC1C,QAAQ,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC;IACpE,OAAO,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,aAAa,EAAE,YAAY,EAAE,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC;IAE7E,OAAO,EAAE,CAAC,CAAC,MAAM,CAAC;QAChB,GAAG,EAAE,CAAC;aACH,MAAM,EAAE;aACR,GAAG,CAAC,sEAAsE,CAAC;aAC3E,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE;YACd,IAAI,CAAC;gBACH,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;gBAC5B,OAAO,MAAM,CAAC,QAAQ,KAAK,OAAO,IAAI,M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,KAAK,CAAC,+CAA+C,CAAC,CAAC;oBAC/D,OAAO,CAAC,KAAK,CAAC,sDAAsD,CAAC,CAAC;gBACxE,CAAC;YACH,CAAC,CAAC,CAAC;YACH,OAAO,CAAC,KAAK,CAAC,0BAA0B,CAAC,CAAC;YAC1C,OAAO,CAAC,KAAK,CAAC,oDAAoD,CAAC,CAAC;YACpE,OAAO,CAAC,KAAK,CAAC,gEAAgE,CAAC,CAAC;YAChF,OAAO,CAAC,KAAK,CAAC,6CAA6C,CAAC,CAAC;YAC7D,OAAO,CAAC,KAAK,CAAC,yCAAyC,CAAC,CAAC;QAC3D,CAAC;QAED,8DAA8D;QAC9D,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,MAAM,EAAE,CAAC;YACpC,MAAM,KAAK,CAAC;QACd,CAAC;QAED,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC;AAED;;GAEG;AACH,IAAI,OAAO,GAAkB,IAAI,CAAC;AAElC;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,IAAI,KAAK,CAAC,EAAY,EAAE;IAC5C,GAAG,CAAC,OAAO,EAAE,IAAI;QACf,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;YACrB,OAAO,GAAG,UAAU,EAAE,CAAC;QACzB,CAAC;QACD,OAAO,OAAO,CAAC,IAAoB,CAAC,CAAC;IACvC,CAAC;CACF,CAAC,CAAC;AAEH;;;GAGG;AACH,MAAM,UAAU,WAAW;IACzB,OAAO,GAAG,IAAI,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview DiagnosticsClient for accessing FoundryVTT logs and system health
|
|
3
|
+
*
|
|
4
|
+
* This module provides a client interface for accessing diagnostic information
|
|
5
|
+
* from FoundryVTT through the REST API module's diagnostic endpoints.
|
|
6
|
+
*
|
|
7
|
+
* @version 0.1.0
|
|
8
|
+
* @author FoundryVTT MCP Team
|
|
9
|
+
*/
|
|
10
|
+
import type { z } from 'zod';
|
|
11
|
+
import type { FoundryClient } from '../foundry/client.js';
|
|
12
|
+
import type { LogPatternSearchParams, LogSearchParams } from './types.js';
|
|
13
|
+
import { ErrorDiagnosisSchema, type LogEntrySchema, LogResponseSchema, LogSearchResponseSchema, SystemHealthSchema } from './types.js';
|
|
14
|
+
type LogEntry = z.infer<typeof LogEntrySchema>;
|
|
15
|
+
type LogResponse = z.infer<typeof LogResponseSchema>;
|
|
16
|
+
type LogSearchResponse = z.infer<typeof LogSearchResponseSchema>;
|
|
17
|
+
type SystemHealth = z.infer<typeof SystemHealthSchema>;
|
|
18
|
+
type ErrorDiagnosis = z.infer<typeof ErrorDiagnosisSchema>;
|
|
19
|
+
/**
|
|
20
|
+
* Client for accessing FoundryVTT diagnostic and logging information
|
|
21
|
+
*
|
|
22
|
+
* Provides methods to retrieve logs, search for specific patterns,
|
|
23
|
+
* monitor system health, and analyze errors through the REST API.
|
|
24
|
+
*
|
|
25
|
+
* @class DiagnosticsClient
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* const diagnostics = new DiagnosticsClient(foundryClient);
|
|
29
|
+
*
|
|
30
|
+
* // Get recent errors
|
|
31
|
+
* const errors = await diagnostics.getRecentLogs({ level: 'error', lines: 20 });
|
|
32
|
+
*
|
|
33
|
+
* // Search for specific patterns
|
|
34
|
+
* const matches = await diagnostics.searchLogs({ pattern: 'TypeError', timeframe: '3600' });
|
|
35
|
+
*
|
|
36
|
+
* // Check system health
|
|
37
|
+
* const health = await diagnostics.getSystemHealth();
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export declare class DiagnosticsClient {
|
|
41
|
+
private foundryClient;
|
|
42
|
+
/**
|
|
43
|
+
* Create a new DiagnosticsClient instance
|
|
44
|
+
*
|
|
45
|
+
* @param foundryClient - The FoundryClient instance to use for API calls
|
|
46
|
+
*/
|
|
47
|
+
constructor(foundryClient: FoundryClient);
|
|
48
|
+
/**
|
|
49
|
+
* Get recent log entries with optional filtering
|
|
50
|
+
*
|
|
51
|
+
* @param params - Search parameters for filtering logs
|
|
52
|
+
* @returns Promise resolving to log response with entries and metadata
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* // Get last 50 log entries
|
|
57
|
+
* const logs = await diagnostics.getRecentLogs();
|
|
58
|
+
*
|
|
59
|
+
* // Get only error logs from the last hour
|
|
60
|
+
* const errors = await diagnostics.getRecentLogs({
|
|
61
|
+
* level: 'error',
|
|
62
|
+
* since: new Date(Date.now() - 3600000).toISOString()
|
|
63
|
+
* });
|
|
64
|
+
*
|
|
65
|
+
* // Get logs with stack traces included
|
|
66
|
+
* const detailed = await diagnostics.getRecentLogs({
|
|
67
|
+
* lines: 100,
|
|
68
|
+
* includeStack: true
|
|
69
|
+
* });
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
getRecentLogs(params?: LogSearchParams): Promise<LogResponse>;
|
|
73
|
+
/**
|
|
74
|
+
* Search log entries for specific patterns using regular expressions
|
|
75
|
+
*
|
|
76
|
+
* @param params - Search parameters including pattern and filters
|
|
77
|
+
* @returns Promise resolving to matching log entries
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```typescript
|
|
81
|
+
* // Search for any TypeError occurrences
|
|
82
|
+
* const typeErrors = await diagnostics.searchLogs({
|
|
83
|
+
* pattern: 'TypeError'
|
|
84
|
+
* });
|
|
85
|
+
*
|
|
86
|
+
* // Search for network errors in the last hour
|
|
87
|
+
* const networkErrors = await diagnostics.searchLogs({
|
|
88
|
+
* pattern: 'Failed to fetch|Network Error',
|
|
89
|
+
* timeframe: '3600',
|
|
90
|
+
* level: 'error'
|
|
91
|
+
* });
|
|
92
|
+
*
|
|
93
|
+
* // Case-sensitive search for specific module errors
|
|
94
|
+
* const moduleErrors = await diagnostics.searchLogs({
|
|
95
|
+
* pattern: 'Module.*failed',
|
|
96
|
+
* caseSensitive: true
|
|
97
|
+
* });
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
searchLogs(params: LogPatternSearchParams): Promise<LogSearchResponse>;
|
|
101
|
+
/**
|
|
102
|
+
* Get comprehensive system health and performance metrics
|
|
103
|
+
*
|
|
104
|
+
* @returns Promise resolving to complete system health information
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```typescript
|
|
108
|
+
* const health = await diagnostics.getSystemHealth();
|
|
109
|
+
*
|
|
110
|
+
* console.log(`Server status: ${health.status}`);
|
|
111
|
+
* console.log(`Active users: ${health.users.active}/${health.users.total}`);
|
|
112
|
+
* console.log(`Recent errors: ${health.logs.recentErrors}`);
|
|
113
|
+
* console.log(`Health score: ${health.healthScore}%`);
|
|
114
|
+
*
|
|
115
|
+
* if (health.status === 'critical') {
|
|
116
|
+
* console.warn('Server requires immediate attention!');
|
|
117
|
+
* }
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
getSystemHealth(): Promise<SystemHealth>;
|
|
121
|
+
/**
|
|
122
|
+
* Analyze recent errors and get diagnostic suggestions
|
|
123
|
+
*
|
|
124
|
+
* @param timeframe - Time window in seconds to analyze (default: 3600)
|
|
125
|
+
* @returns Promise resolving to error diagnosis with suggestions
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* ```typescript
|
|
129
|
+
* // Analyze errors from the last hour
|
|
130
|
+
* const diagnosis = await diagnostics.diagnoseErrors();
|
|
131
|
+
*
|
|
132
|
+
* // Analyze errors from the last 30 minutes
|
|
133
|
+
* const recentDiagnosis = await diagnostics.diagnoseErrors(1800);
|
|
134
|
+
*
|
|
135
|
+
* console.log(`Health score: ${diagnosis.healthScore}/100`);
|
|
136
|
+
* console.log(`Total errors: ${diagnosis.summary.totalErrors}`);
|
|
137
|
+
*
|
|
138
|
+
* // Display suggestions
|
|
139
|
+
* diagnosis.suggestions.forEach(suggestion => {
|
|
140
|
+
* console.log(`${suggestion.priority.toUpperCase()}: ${suggestion.suggestion}`);
|
|
141
|
+
* });
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
144
|
+
diagnoseErrors(timeframe?: number): Promise<ErrorDiagnosis>;
|
|
145
|
+
/**
|
|
146
|
+
* Get errors filtered by severity and time window
|
|
147
|
+
*
|
|
148
|
+
* @param timeframe - Time window in seconds (default: 3600)
|
|
149
|
+
* @param level - Log level to filter by (default: 'error')
|
|
150
|
+
* @returns Promise resolving to filtered log entries
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* ```typescript
|
|
154
|
+
* // Get all errors from the last 2 hours
|
|
155
|
+
* const errors = await diagnostics.getErrorsOnly(7200);
|
|
156
|
+
*
|
|
157
|
+
* // Get warnings from the last 30 minutes
|
|
158
|
+
* const warnings = await diagnostics.getErrorsOnly(1800, 'warn');
|
|
159
|
+
* ```
|
|
160
|
+
*/
|
|
161
|
+
getErrorsOnly(timeframe?: number, level?: LogEntry['level']): Promise<LogEntry[]>;
|
|
162
|
+
/**
|
|
163
|
+
* Monitor system health and return status summary
|
|
164
|
+
*
|
|
165
|
+
* @returns Promise resolving to simplified health status
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* ```typescript
|
|
169
|
+
* const status = await diagnostics.getHealthStatus();
|
|
170
|
+
* // Returns: { status: 'healthy' | 'warning' | 'critical', score: number }
|
|
171
|
+
* ```
|
|
172
|
+
*/
|
|
173
|
+
getHealthStatus(): Promise<{
|
|
174
|
+
status: SystemHealth['status'];
|
|
175
|
+
score?: number;
|
|
176
|
+
}>;
|
|
177
|
+
/**
|
|
178
|
+
* Check if diagnostics API is available
|
|
179
|
+
*
|
|
180
|
+
* @returns Promise resolving to boolean indicating availability
|
|
181
|
+
*
|
|
182
|
+
* @example
|
|
183
|
+
* ```typescript
|
|
184
|
+
* const available = await diagnostics.isAvailable();
|
|
185
|
+
* if (!available) {
|
|
186
|
+
* console.log('Diagnostics API not available - check module installation');
|
|
187
|
+
* }
|
|
188
|
+
* ```
|
|
189
|
+
*/
|
|
190
|
+
isAvailable(): Promise<boolean>;
|
|
191
|
+
}
|
|
192
|
+
export {};
|
|
193
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/diagnostics/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAC7B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAE1D,OAAO,KAAK,EAAE,sBAAsB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC1E,OAAO,EACL,oBAAoB,EACpB,KAAK,cAAc,EACnB,iBAAiB,EACjB,uBAAuB,EACvB,kBAAkB,EACnB,MAAM,YAAY,CAAC;AAEpB,KAAK,QAAQ,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,cAAc,CAAC,CAAC;AAC/C,KAAK,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AACrD,KAAK,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AACjE,KAAK,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AACvD,KAAK,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAE3D;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,iBAAiB;IAMhB,OAAO,CAAC,aAAa;IALjC;;;;OAIG;gBACiB,aAAa,EAAE,aAAa;IAEhD;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACG,aAAa,CAAC,MAAM,GAAE,eAAoB,GAAG,OAAO,CAAC,WAAW,CAAC;IA0CvE;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACG,UAAU,CAA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