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

data-service-proxy-direct

하는 일

이 스킬은 서버 프록시를 거치거나 API에 직접 연결하는 대시보드 데이터 서비스를 AI 에이전트가 작성하도록 안내합니다. API 키를 프록시 뒤에 숨겨야 하는 경우와 직접 호출해도 되는 경우가 함께 있는 개발자를 위한 스킬입니다.

사용하는 경우

  • ✓데이터 서비스가 프록시를 거치는 방식과 직접 API 호출 방식 모두에서 작동해야 할 때.
  • ✓API 키는 서버에 남아야 하지만 일부 호출은 직접 해도 될 때.
  • ✓모든 서비스에 가져오기, 캐시, 재시도 동작이 있기를 원할 때.

스킬 링크

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

AI에게 요청하는 예시

“제 주가 패널의 데이터 서비스를 작성해 주세요. 설정에 따라 우리 프록시를 쓰거나 API를 직접 호출할 수 있어야 합니다.”

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

작동 방식

에이전트는 프록시를 거친 요청 경로와 직접 요청 경로 중 하나를 고르는 서비스를 만듭니다. 호출을 서킷 브레이커로 감싸고, 결과를 캐시하며, 요청이 실패하면 재시도합니다.

기술 내용 (원본 SKILL.md)

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

Data Service Pattern

Each panel's data comes from a dedicated service module in src/services/. Services handle API calls, caching, error handling with circuit breaker pattern, and can work with both proxied and direct API calls.

Circuit Breaker

The circuit breaker prevents cascading failures when an API is down. After N consecutive failures, it enters "cooldown" mode and serves cached data instead of hitting the API.

Create src/utils/circuit-breaker.ts:

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);
}

Service Module Pattern

Each service is a TypeScript module that exports async data-fetching functions. Services can work with both proxied and direct API calls.

Proxied API Example

// src/services/stock-market.ts
import { createCircuitBreaker } from '../utils/circuit-breaker';

export interface StockQuote {
  symbol: string;
  name: string;
  price: number | null;
  change: number | null;
  sparkline?: number[];
}

const breaker = createCircuitBreaker<StockQuote[]>({
  name: 'StockMarket',
  cacheTtlMs: 60_000, // 1 minute cache
});

export async function fetchStockQuotes(symbols: string[]): Promise<StockQuote[]> {
  return breaker.execute(async () => {
    const params = new URLSearchParams({ symbols: symbols.join(',') });
    const resp = await fetch(`/api/stocks?${params}`);
    if (!resp.ok) throw new Error(`HTTP ${resp.status}`);
    return resp.json();
  }, []);
}

Direct API Example

// src/services/weather.ts
import { createCircuitBreaker } from '../utils/circuit-breaker';

export interface WeatherData {
  city: string;
  temperature: number;
  condition: string;
  forecast: Array<{
    day: string;
    high: number;
    low: number;
    condition: string;
  }>;
}

const breaker = createCircuitBreaker<WeatherData>({
  name: 'WeatherAPI',
  cacheTtlMs: 30_000, // 30 seconds cache
});

export async function fetchWeather(city: string): Promise<WeatherData> {
  return breaker.execute(async () => {
    const resp = await fetch(`https://wttr.in/${city}?format=j1`);
    if (!resp.ok) throw new Error(`HTTP ${resp.status}`);
    return resp.json();
  }, {
    city,
    temperature: 0,
    condition: 'Unknown',
    forecast: []
  });
}

Key Patterns

  1. **One circuit breaker
자주 묻는 질문

프록시는 언제 쓰나요?

API 키를 서버에 숨겨야 할 때 프록시를 쓰라고 스킬은 제안합니다.

서비스는 실패한 호출을 재시도하나요?

네, 스킬은 서비스가 캐싱과 함께 재시도도 처리한다고 설명합니다.

같은 패널이 두 방식을 모두 쓸 수 있나요?

네, 서비스는 프록시를 거치는 경로나 직접 경로 중 하나를 쓰도록 설정할 수 있습니다.

상세 정보

작성자의 원본 설명

Create resilient data fetching services with circuit breaker pattern, supporting both proxied and direct API calls. Services handle fetch, cache, retry, and expose typed data to panel components.

repo: HKUDS/AgentPilot

인기도

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

이 스킬이 유용한가요?

0

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

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬