मुख्य सामग्री पर जाएँ
Skillpedia
वेबसाइट और UI (frontend)7.8k · #13070

panel-data-resilient

यह क्या करती है

यह स्किल दिखाती है कि सादे TypeScript में ऐसे डैशबोर्ड पैनल कैसे बनाएं जो अपना डेटा खुद लाते हैं। हर पैनल फेल होती सेवा पर कुछ देर कॉल रोकता है, फिर दोबारा कोशिश करता है। यह लाइव वेब डैशबोर्ड बनाने वाले डेवलपर्स के लिए है।

कब इस्तेमाल करें

  • ✓जब आप ऐसा डैशबोर्ड पैनल चाहते हैं जो ऑनलाइन डेटा फ़ीड बंद होने पर न टूटे।
  • ✓जब आप ऐसा नया विजेट जोड़ रहे हैं जो बाहरी वेब सेवा को कॉल करता है और रीट्राई लॉजिक चाहिए।
  • ✓जब आप चाहते हैं कि पैनल अटकने के बजाय लोडिंग या एरर की साफ़ स्थिति दिखाएं।

Skill का लिंक

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

इसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।

कैसे इस्तेमाल करें

सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।

पेस्ट करने के लिए तैयार मैसेज

इस skill से मेरी मदद करो: https://github.com/HKUDS/AgentPilot/blob/main/openspace/legacy/v1/showcase/skills/panel-data-resilient/SKILL.md इस लिंक की SKILL.md फ़ाइल पढ़ो और मेरे काम में उसके निर्देशों का पालन करो।
क्या आप चाहते हैं कि आपका AI ऐसी skills खुद ढूँढे?मुफ़्त Skillpedia MCP इंस्टॉल करें: बस एक लाइन, और हर काम से पहले यह 15,000+ skills में खोजता है।1 मिनट में इंस्टॉल करें →

AI से क्या माँगें: उदाहरण

“क्या आप ऐसा डैशबोर्ड पैनल बना सकते हैं जो अपनी इस्तेमाल की जा रही डेटा सेवा बंद होने पर भी चलता रहे?”

हर हफ़्ते 5 नई skills, 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
अपडेट की गई
1/11/2026

क्या यह skill काम की है?

0

लॉग इन करें वोट करने के लिए।

कमेंट

  • …

इस repository की और skills

मिलती-जुलती skills