add install ollama models , fixes
This commit is contained in:
@@ -10,24 +10,43 @@ export interface LogEntry {
|
||||
level: 'info' | 'warning' | 'error' | 'debug';
|
||||
message: string;
|
||||
details?: Record<string, any>;
|
||||
category: 'system' | 'provider' | 'user' | 'error' | 'api' | 'auth' | 'database' | 'network' | 'performance';
|
||||
category:
|
||||
| 'system'
|
||||
| 'provider'
|
||||
| 'user'
|
||||
| 'error'
|
||||
| 'api'
|
||||
| 'auth'
|
||||
| 'database'
|
||||
| 'network'
|
||||
| 'performance'
|
||||
| 'settings'
|
||||
| 'task'
|
||||
| 'update'
|
||||
| 'feature';
|
||||
subCategory?: string;
|
||||
duration?: number;
|
||||
statusCode?: number;
|
||||
source?: string;
|
||||
stack?: string;
|
||||
metadata?: {
|
||||
component?: string;
|
||||
action?: string;
|
||||
userId?: string;
|
||||
sessionId?: string;
|
||||
previousValue?: any;
|
||||
newValue?: any;
|
||||
};
|
||||
}
|
||||
|
||||
interface LogDetails extends Record<string, any> {
|
||||
type: string;
|
||||
message: string;
|
||||
}
|
||||
|
||||
const MAX_LOGS = 1000; // Maximum number of logs to keep in memory
|
||||
|
||||
class LogStore {
|
||||
logInfo(message: string, details: { type: string; message: string }) {
|
||||
return this.addLog(message, 'info', 'system', details);
|
||||
}
|
||||
|
||||
logSuccess(message: string, details: { type: string; message: string }) {
|
||||
return this.addLog(message, 'info', 'system', { ...details, success: true });
|
||||
}
|
||||
private _logs = map<Record<string, LogEntry>>({});
|
||||
showLogs = atom(true);
|
||||
private _readLogs = new Set<string>();
|
||||
@@ -106,13 +125,13 @@ class LogStore {
|
||||
}
|
||||
}
|
||||
|
||||
addLog(
|
||||
// Base log method for general logging
|
||||
private _addLog(
|
||||
message: string,
|
||||
level: LogEntry['level'] = 'info',
|
||||
category: LogEntry['category'] = 'system',
|
||||
level: LogEntry['level'],
|
||||
category: LogEntry['category'],
|
||||
details?: Record<string, any>,
|
||||
statusCode?: number,
|
||||
duration?: number,
|
||||
metadata?: LogEntry['metadata'],
|
||||
) {
|
||||
const id = this._generateId();
|
||||
const entry: LogEntry = {
|
||||
@@ -122,8 +141,7 @@ class LogStore {
|
||||
message,
|
||||
details,
|
||||
category,
|
||||
statusCode,
|
||||
duration,
|
||||
metadata,
|
||||
};
|
||||
|
||||
this._logs.setKey(id, entry);
|
||||
@@ -133,19 +151,40 @@ class LogStore {
|
||||
return id;
|
||||
}
|
||||
|
||||
// Specialized method for API logging
|
||||
private _addApiLog(
|
||||
message: string,
|
||||
method: string,
|
||||
url: string,
|
||||
details: {
|
||||
method: string;
|
||||
url: string;
|
||||
statusCode: number;
|
||||
duration: number;
|
||||
request: any;
|
||||
response: any;
|
||||
},
|
||||
) {
|
||||
const statusCode = details.statusCode;
|
||||
return this._addLog(message, statusCode >= 400 ? 'error' : 'info', 'api', details, {
|
||||
component: 'api',
|
||||
action: method,
|
||||
});
|
||||
}
|
||||
|
||||
// System events
|
||||
logSystem(message: string, details?: Record<string, any>) {
|
||||
return this.addLog(message, 'info', 'system', details);
|
||||
return this._addLog(message, 'info', 'system', details);
|
||||
}
|
||||
|
||||
// Provider events
|
||||
logProvider(message: string, details?: Record<string, any>) {
|
||||
return this.addLog(message, 'info', 'provider', details);
|
||||
return this._addLog(message, 'info', 'provider', details);
|
||||
}
|
||||
|
||||
// User actions
|
||||
logUserAction(message: string, details?: Record<string, any>) {
|
||||
return this.addLog(message, 'info', 'user', details);
|
||||
return this._addLog(message, 'info', 'user', details);
|
||||
}
|
||||
|
||||
// API Connection Logging
|
||||
@@ -153,7 +192,7 @@ class LogStore {
|
||||
const message = `${method} ${endpoint} - ${statusCode} (${duration}ms)`;
|
||||
const level = statusCode >= 400 ? 'error' : statusCode >= 300 ? 'warning' : 'info';
|
||||
|
||||
return this.addLog(message, level, 'api', {
|
||||
return this._addLog(message, level, 'api', {
|
||||
...details,
|
||||
endpoint,
|
||||
method,
|
||||
@@ -172,7 +211,7 @@ class LogStore {
|
||||
const message = `Auth ${action} - ${success ? 'Success' : 'Failed'}`;
|
||||
const level = success ? 'info' : 'error';
|
||||
|
||||
return this.addLog(message, level, 'auth', {
|
||||
return this._addLog(message, level, 'auth', {
|
||||
...details,
|
||||
action,
|
||||
success,
|
||||
@@ -185,7 +224,7 @@ class LogStore {
|
||||
const message = `Network ${status}`;
|
||||
const level = status === 'offline' ? 'error' : status === 'reconnecting' ? 'warning' : 'info';
|
||||
|
||||
return this.addLog(message, level, 'network', {
|
||||
return this._addLog(message, level, 'network', {
|
||||
...details,
|
||||
status,
|
||||
timestamp: new Date().toISOString(),
|
||||
@@ -197,7 +236,7 @@ class LogStore {
|
||||
const message = `DB ${operation} - ${success ? 'Success' : 'Failed'} (${duration}ms)`;
|
||||
const level = success ? 'info' : 'error';
|
||||
|
||||
return this.addLog(message, level, 'database', {
|
||||
return this._addLog(message, level, 'database', {
|
||||
...details,
|
||||
operation,
|
||||
success,
|
||||
@@ -218,17 +257,17 @@ class LogStore {
|
||||
}
|
||||
: { error, ...details };
|
||||
|
||||
return this.addLog(message, 'error', 'error', errorDetails);
|
||||
return this._addLog(message, 'error', 'error', errorDetails);
|
||||
}
|
||||
|
||||
// Warning events
|
||||
logWarning(message: string, details?: Record<string, any>) {
|
||||
return this.addLog(message, 'warning', 'system', details);
|
||||
return this._addLog(message, 'warning', 'system', details);
|
||||
}
|
||||
|
||||
// Debug events
|
||||
logDebug(message: string, details?: Record<string, any>) {
|
||||
return this.addLog(message, 'debug', 'system', details);
|
||||
return this._addLog(message, 'debug', 'system', details);
|
||||
}
|
||||
|
||||
clearLogs() {
|
||||
@@ -269,7 +308,35 @@ class LogStore {
|
||||
this._saveReadLogs();
|
||||
}
|
||||
|
||||
// Network request logging
|
||||
// API interactions
|
||||
logApiCall(
|
||||
method: string,
|
||||
endpoint: string,
|
||||
statusCode: number,
|
||||
duration: number,
|
||||
requestData?: any,
|
||||
responseData?: any,
|
||||
) {
|
||||
return this._addLog(
|
||||
`API ${method} ${endpoint}`,
|
||||
statusCode >= 400 ? 'error' : 'info',
|
||||
'api',
|
||||
{
|
||||
method,
|
||||
endpoint,
|
||||
statusCode,
|
||||
duration,
|
||||
request: requestData,
|
||||
response: responseData,
|
||||
},
|
||||
{
|
||||
component: 'api',
|
||||
action: method,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
// Network operations
|
||||
logNetworkRequest(
|
||||
method: string,
|
||||
url: string,
|
||||
@@ -278,7 +345,7 @@ class LogStore {
|
||||
requestData?: any,
|
||||
responseData?: any,
|
||||
) {
|
||||
this.addLog(
|
||||
return this._addLog(
|
||||
`${method} ${url}`,
|
||||
statusCode >= 400 ? 'error' : 'info',
|
||||
'network',
|
||||
@@ -290,45 +357,30 @@ class LogStore {
|
||||
request: requestData,
|
||||
response: responseData,
|
||||
},
|
||||
statusCode,
|
||||
duration,
|
||||
{
|
||||
component: 'network',
|
||||
action: method,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
// Authentication events
|
||||
logAuthEvent(event: string, success: boolean, details?: Record<string, any>) {
|
||||
this.addLog(`Auth ${event} ${success ? 'succeeded' : 'failed'}`, success ? 'info' : 'error', 'auth', details);
|
||||
}
|
||||
|
||||
// API interactions
|
||||
logApiCall(
|
||||
endpoint: string,
|
||||
method: string,
|
||||
statusCode: number,
|
||||
duration: number,
|
||||
requestData?: any,
|
||||
responseData?: any,
|
||||
) {
|
||||
this.addLog(
|
||||
`API ${method} ${endpoint}`,
|
||||
statusCode >= 400 ? 'error' : 'info',
|
||||
'api',
|
||||
return this._addLog(
|
||||
`Auth ${event} ${success ? 'succeeded' : 'failed'}`,
|
||||
success ? 'info' : 'error',
|
||||
'auth',
|
||||
details,
|
||||
{
|
||||
endpoint,
|
||||
method,
|
||||
statusCode,
|
||||
duration,
|
||||
request: requestData,
|
||||
response: responseData,
|
||||
component: 'auth',
|
||||
action: event,
|
||||
},
|
||||
statusCode,
|
||||
duration,
|
||||
);
|
||||
}
|
||||
|
||||
// Performance monitoring
|
||||
// Performance tracking
|
||||
logPerformance(operation: string, duration: number, details?: Record<string, any>) {
|
||||
this.addLog(
|
||||
return this._addLog(
|
||||
`Performance: ${operation}`,
|
||||
duration > 1000 ? 'warning' : 'info',
|
||||
'performance',
|
||||
@@ -337,18 +389,29 @@ class LogStore {
|
||||
duration,
|
||||
...details,
|
||||
},
|
||||
undefined,
|
||||
duration,
|
||||
{
|
||||
component: 'performance',
|
||||
action: 'metric',
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
// Error logging with stack trace
|
||||
// Error handling
|
||||
logErrorWithStack(error: Error, category: LogEntry['category'] = 'error', details?: Record<string, any>) {
|
||||
this.addLog(error.message, 'error', category, {
|
||||
...details,
|
||||
name: error.name,
|
||||
stack: error.stack,
|
||||
});
|
||||
return this._addLog(
|
||||
error.message,
|
||||
'error',
|
||||
category,
|
||||
{
|
||||
...details,
|
||||
name: error.name,
|
||||
stack: error.stack,
|
||||
},
|
||||
{
|
||||
component: category,
|
||||
action: 'error',
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
// Refresh logs (useful for real-time updates)
|
||||
@@ -356,6 +419,101 @@ class LogStore {
|
||||
const currentLogs = this._logs.get();
|
||||
this._logs.set({ ...currentLogs });
|
||||
}
|
||||
|
||||
// Enhanced logging methods
|
||||
logInfo(message: string, details: LogDetails) {
|
||||
return this._addLog(message, 'info', 'system', details);
|
||||
}
|
||||
|
||||
logSuccess(message: string, details: LogDetails) {
|
||||
return this._addLog(message, 'info', 'system', { ...details, success: true });
|
||||
}
|
||||
|
||||
logApiRequest(
|
||||
method: string,
|
||||
url: string,
|
||||
details: {
|
||||
method: string;
|
||||
url: string;
|
||||
statusCode: number;
|
||||
duration: number;
|
||||
request: any;
|
||||
response: any;
|
||||
},
|
||||
) {
|
||||
return this._addApiLog(`API ${method} ${url}`, method, url, details);
|
||||
}
|
||||
|
||||
logSettingsChange(component: string, setting: string, oldValue: any, newValue: any) {
|
||||
return this._addLog(
|
||||
`Settings changed in ${component}: ${setting}`,
|
||||
'info',
|
||||
'settings',
|
||||
{
|
||||
setting,
|
||||
previousValue: oldValue,
|
||||
newValue,
|
||||
},
|
||||
{
|
||||
component,
|
||||
action: 'settings_change',
|
||||
previousValue: oldValue,
|
||||
newValue,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
logFeatureToggle(featureId: string, enabled: boolean) {
|
||||
return this._addLog(
|
||||
`Feature ${featureId} ${enabled ? 'enabled' : 'disabled'}`,
|
||||
'info',
|
||||
'feature',
|
||||
{ featureId, enabled },
|
||||
{
|
||||
component: 'features',
|
||||
action: 'feature_toggle',
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
logTaskOperation(taskId: string, operation: string, status: string, details?: any) {
|
||||
return this._addLog(
|
||||
`Task ${taskId}: ${operation} - ${status}`,
|
||||
'info',
|
||||
'task',
|
||||
{ taskId, operation, status, ...details },
|
||||
{
|
||||
component: 'task-manager',
|
||||
action: 'task_operation',
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
logProviderAction(provider: string, action: string, success: boolean, details?: any) {
|
||||
return this._addLog(
|
||||
`Provider ${provider}: ${action} - ${success ? 'Success' : 'Failed'}`,
|
||||
success ? 'info' : 'error',
|
||||
'provider',
|
||||
{ provider, action, success, ...details },
|
||||
{
|
||||
component: 'providers',
|
||||
action: 'provider_action',
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
logPerformanceMetric(component: string, operation: string, duration: number, details?: any) {
|
||||
return this._addLog(
|
||||
`Performance: ${component} - ${operation} took ${duration}ms`,
|
||||
duration > 1000 ? 'warning' : 'info',
|
||||
'performance',
|
||||
{ component, operation, duration, ...details },
|
||||
{
|
||||
component,
|
||||
action: 'performance_metric',
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export const logStore = new LogStore();
|
||||
|
||||
Reference in New Issue
Block a user