본문으로 건너뛰기
Skillpedia
웹사이트 및 UI (프런트엔드)7.8k · #13070

panel-data-resilient

하는 일

이 스킬은 자체 데이터를 가져오는 순수 TypeScript 대시보드 패널을 만드는 방법을 보여 줍니다. 각 패널은 실패하는 서비스에 대한 호출을 잠시 멈춘 뒤 다시 시도합니다. 라이브 웹 대시보드를 만드는 개발자를 위한 스킬입니다.

사용하는 경우

  • ✓온라인 데이터 피드가 중단되어도 깨지지 않는 대시보드 패널을 원할 때.
  • ✓외부 웹 서비스를 호출하고 재시도 로직이 필요한 새 위젯을 추가할 때.
  • ✓패널이 멈추지 않고 분명한 로딩 또는 오류 상태를 보여 주기를 원할 때.

스킬 링크

https://github.com/HKUDS/AgentPilot/blob/main/openspace/legacy/v1/showcase/skills/panel-data-resilient/SKILL.md

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/HKUDS/AgentPilot/blob/main/openspace/legacy/v1/showcase/skills/panel-data-resilient/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

AI에게 요청하는 예시

“사용하는 데이터 서비스가 중단되어도 계속 작동하는 대시보드 패널을 만들어 주실 수 있나요?”

매주 새 스킬 5개. 읽는 데 1분.

작동 방식

패널은 실패 횟수를 세는 도우미를 통해 데이터를 요청합니다. 여러 번 실패하면 다시 시도하기 전에 기다리며, 그 사이에는 저장된 결과를 보여 줄 수 있습니다.

기술 내용 (원본 SKILL.md)

작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.

Resilient Panel Pattern

This skill merges the best of data-service and panel-component to create panels that are both resilient to API failures and easy to implement. Each panel manages its own data fetching with built-in circuit breaker patterns and renders content using vanilla TypeScript.

Architecture Overview

  1. Service Module: Each panel has a dedicated service module for data fetching, using circuit breakers for resilience.
  2. Panel Class: Extends a base Panel class with built-in loading/error states and content rendering.
  3. Data Flow: Panels automatically fetch data, handle errors, and retry as needed.

Implementation

1. Circuit Breaker Utility

Create src/utils/circuit-breaker.ts (same as in data-service but with enhanced logging):

interface CircuitState {
  failures: number;
  cooldownUntil: number;
}

interface CacheEntry<T> {
  data: T;
  timestamp: number;
}

export interface CircuitBreakerOptions {
  name: string;
  maxFailures?: number;
  cooldownMs?: number;
  cacheTtlMs?: number;
}

export class CircuitBreaker<T> {
  private state: CircuitState = { failures: 0, cooldownUntil: 0 };
  private cache: CacheEntry<T> | null = null;
  private name: string;
  private maxFailures: number;
  private cooldownMs: number;
  private cacheTtlMs: number;

  constructor(options: CircuitBreakerOptions) {
    this.name = options.name;
    this.maxFailures = options.maxFailures ?? 2;
    this.cooldownMs = options.cooldownMs ?? 5 * 60 * 1000;  // 5 minutes
    this.cacheTtlMs = options.cacheTtlMs ?? 10 * 60 * 1000; // 10 minutes
  }

  isOnCooldown(): boolean {
    if (Date.now() < this.state.cooldownUntil) return true;
    if (this.state.cooldownUntil > 0) {
      this.state = { failures: 0, cooldownUntil: 0 };
    }
    return false;
  }

  getCached(): T | null {
    if (this.cache && Date.now() - this.cache.timestamp < this.cacheTtlMs) {
      return this.cache.data;
    }
    return null;
  }

  recordSuccess(data: T): void {
    this.state = { failures: 0, cooldownUntil: 0 };
    this.cache = { data, timestamp: Date.now() };
  }

  recordFailure(error?: string): void {
    this.state.failures++;
    if (this.state.failures >= this.maxFailures) {
      this.state.cooldownUntil = Date.now() + this.cooldownMs;
      console.warn(`[${this.name}] Cooldown for ${this.cooldownMs / 1000}s`);
    }
  }

  async execute<R extends T>(fn: () => Promise<R>, defaultValue: R): Promise<R> {
    if (this.isOnCooldown()) {
      const cached = this.getCached();
      return (cached as R) ?? defaultValue;
    }
    const cached = this.getCached();
    if (cached !== null) return cached as R;
    try {
      const result = await fn();
      this.recordSuccess(result);
      return result;
    } catch (e) {
      console.error(`[${this.name}] Failed:`, e);
      this.recordFailure(String(e));
      return defaultValue;
    }
  }
}

export function createCircuitBreaker<T>(options: CircuitBreakerOptions): CircuitBreaker<T> {
  return new CircuitBreaker<T>(options);
}

2. Base Panel Class

Create src/components/Panel.ts with enhanced error handling and retry logic:

export interface PanelOptions {
  id: string;
  title: string;
  showCount?: boolean;
  className?: string;
}

export class Panel {
  protected element: HTMLElement;
  protected content: HTMLElement;
  protected header: HTMLElement;
  protected countEl: HTMLElement | null = null;
  protected panelId: string;
  private _fetching = false;

  constructor(options: PanelOptions) {
    this.panelId = options.id;
    this.element = document.createElement('div');
    this.element.className = `panel ${options.className || ''}`;
    this.element.dataset.panel = options.id;

    // Header
    this.header = document.createElement('div');
    this.header.className = 'panel-header';

    const headerLeft = document.createElement('div');
    headerLeft.className = 'panel-header-left';

    const title = document.createElement('span');
    title.className = 'panel-title';
    title.textContent = options.title;
    headerLeft.appendChild(title);
    this.header.appendChild(headerLeft);

    // Count badge (optional)
    if (options.showCount) {
      this.countEl = document.createElement('span');
      this.countEl.className = 'panel-count';
      this.countEl.textContent = '0';
      this.header.appendChild(this.countEl);
    }

    // Content area
    this.content = document.createElement('div');
    this.content.cl
자주 묻는 질문

이 방식을 쓰려면 React나 다른 프레임워크가 필요한가요?

아니요. 이 방식은 순수 TypeScript와 브라우저에 내장된 페이지 기능을 사용합니다.

서킷 브레이커를 쉽게 말하면 무엇인가요?

실패하는 서비스에 대한 반복 요청을 짧은 시간 멈춘 뒤, 다시 요청을 허용하는 스위치입니다.

어떤 웹 데이터 소스에도 쓸 수 있나요?

네, 패널이 웹으로 데이터를 요청할 수 있다면 가능합니다. 예시는 일반적이므로 자신의 데이터 소스를 연결해 쓸 수 있습니다.

상세 정보

작성자의 원본 설명

Create resilient, data-driven dashboard panels with integrated API handling and UI components, combining circuit breaker patterns with vanilla TypeScript panel architecture.

repo: HKUDS/AgentPilot

인기도

GitHub 스타
7.8k
순위
#13070
라이선스
MIT
업데이트
2026. 11. 1.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬