Interface for models that can track and expose trouble states.

TroubleAware provides a standardized way for KOS models to expose their trouble states, making it easy to monitor, display, and react to issues throughout the system. Any model implementing this interface can be monitored for troubles and integrated with trouble management UI.

Key Concepts

  • Trouble aggregation - Models can aggregate troubles from multiple sources
  • Status summary - Provides a single status string for quick checks
  • Type grouping - Troubles organized by type for filtering and display
  • Read-only access - Troubles are exposed as readonly for safety

Example

// Check if a model has troubles
function checkModelHealth(model: TroubleAware) {
if (model.troubles.length > 0) {
console.warn(`Model has ${model.troubles.length} troubles`);
console.warn(`Status: ${model.troubleStatus}`);

// Check specific trouble types
const errors = model.troublesByType['ERROR'] || [];
const warnings = model.troublesByType['WARNING'] || [];

if (errors.length > 0) {
handleCriticalErrors(errors);
}
}
}

Example

// React component using TroubleAware
const TroubleIndicator: React.FC<{ model: TroubleAware }> = ({ model }) => {
const troubles = model.troubles;
const highPriority = troubles.filter(t => t.rank >= 7);

if (troubles.length === 0) {
return <StatusIcon color="green" />;
}

return (
<div className="trouble-indicator">
<StatusIcon color={highPriority.length > 0 ? 'red' : 'yellow'} />
<span>{model.troubleStatus}</span>
<Badge count={troubles.length} />
</div>
);
};

Example

// Implementing TroubleAware
class MyModel implements TroubleAware {
private _troubles: TroubleModel[] = [];

get troubles(): readonly TroubleModel[] {
return this._troubles;
}

get troubleStatus(): string {
if (this._troubles.length === 0) return 'OK';
const highest = this._troubles.reduce((max, t) =>
t.rank > max.rank ? t : max
);
return highest.reason || 'Unknown issue';
}

get troublesByType(): Record<string, TroubleModel[]> {
return this._troubles.reduce((groups, trouble) => {
const type = trouble.type;
groups[type] = groups[type] || [];
groups[type].push(trouble);
return groups;
}, {} as Record<string, TroubleModel[]>);
}
}

See

  • TroubleModel - The trouble model interface
  • isTroubleAware - Type guard for checking TroubleAware
  • useTroubleDecoration - Hook for trouble-based styling
interface TroubleAware {
    troubles: TroubleModel<any>[];
    troubleStatus: string;
    troublesByType: Record<string, TroubleModel<any>[]>;
}

Hierarchy

  • TroubleAware

    Properties

    troubles: TroubleModel<any>[]

    Array of troubles directly related to this model. Troubles are typically sorted by rank (highest priority first).

    troubleStatus: string

    Summary status string representing the highest priority trouble. Returns a human-readable status or 'OK' if no troubles exist.

    troublesByType: Record<string, TroubleModel<any>[]>

    Troubles organized by their type property. Useful for filtering and categorized display of issues.

    Example

    const errorTroubles = model.troublesByType['ERROR'] || [];
    const warningTroubles = model.troublesByType['WARNING'] || [];