[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6KKASTTRWBFFKTXY0T3QV55":3,"skill-same:01M6KKASTTRWBFFKTXY0T3QV55":75},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":15,"categories":16,"keywords":22,"publishedAt":43,"linkOnly":44,"markdownContent":45,"markdownBody":46,"frontMatter":47,"refName":48,"commitSha":49,"skillDirectory":50,"forksCount":13,"repositoryHtmlUrl":51,"repositoryHomepageUrl":6,"ownerHtmlUrl":52,"ownerBlogUrl":6,"ownerDescription":53,"updatedAt":54,"install":55,"resources":68},"01M6KKASTTRWBFFKTXY0T3QV55","data-service-proxy-direct",null,"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.","AG064\u002FOpenSpace","AG064","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F184930299?v=4","01M6KHVFG7TB73NHX3RDYSTMH2","01M6KHVFMM7XA2PZA9Z83PHS3V",0,"MIT","https:\u002F\u002Fgithub.com\u002FAG064\u002FOpenSpace\u002Fblob\u002Fmain\u002Fshowcase\u002Fskills\u002Fdata-service-proxy-direct\u002FSKILL.md",[17],{"categoryNo":18,"categoryName":19,"taxonomyType":20,"taxonomyTypeDesc":21},"01JBSEEDCAT000000000000033","数据分析师","PROFESSION","适用职业",[23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42],"data service","proxy","data service proxy direct","data","direct","service","pattern","data fetching","calls","retry","with","panel","Circuit Breaker","components","circuit breaker pattern","fetch","api","services","cache","create","2026-11-10 10:12:30",false,"---\nname: data-service-proxy-direct\ndescription: 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.\n---\n\n# Data Service Pattern\n\nEach panel's data comes from a dedicated **service module** in `src\u002Fservices\u002F`. Services handle API calls, caching, error handling with circuit breaker pattern, and can work with both proxied and direct API calls.\n\n## Circuit Breaker\n\nThe 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.\n\nCreate `src\u002Futils\u002Fcircuit-breaker.ts`:\n\n```typescript\ninterface CircuitState {\n  failures: number;\n  cooldownUntil: number;\n}\n\ninterface CacheEntry\u003CT> {\n  data: T;\n  timestamp: number;\n}\n\nexport interface CircuitBreakerOptions {\n  name: string;\n  maxFailures?: number;\n  cooldownMs?: number;\n  cacheTtlMs?: number;\n}\n\nexport class CircuitBreaker\u003CT> {\n  private state: CircuitState = { failures: 0, cooldownUntil: 0 };\n  private cache: CacheEntry\u003CT> | null = null;\n  private name: string;\n  private maxFailures: number;\n  private cooldownMs: number;\n  private cacheTtlMs: number;\n\n  constructor(options: CircuitBreakerOptions) {\n    this.name = options.name;\n    this.maxFailures = options.maxFailures ?? 2;\n    this.cooldownMs = options.cooldownMs ?? 5 * 60 * 1000;  \u002F\u002F 5 minutes\n    this.cacheTtlMs = options.cacheTtlMs ?? 10 * 60 * 1000; \u002F\u002F 10 minutes\n  }\n\n  isOnCooldown(): boolean {\n    if (Date.now() \u003C this.state.cooldownUntil) return true;\n    if (this.state.cooldownUntil > 0) {\n      this.state = { failures: 0, cooldownUntil: 0 };\n    }\n    return false;\n  }\n\n  getCached(): T | null {\n    if (this.cache && Date.now() - this.cache.timestamp \u003C this.cacheTtlMs) {\n      return this.cache.data;\n    }\n    return null;\n  }\n\n  recordSuccess(data: T): void {\n    this.state = { failures: 0, cooldownUntil: 0 };\n    this.cache = { data, timestamp: Date.now() };\n  }\n\n  recordFailure(error?: string): void {\n    this.state.failures++;\n    if (this.state.failures >= this.maxFailures) {\n      this.state.cooldownUntil = Date.now() + this.cooldownMs;\n      console.warn(`[${this.name}] Cooldown for ${this.cooldownMs \u002F 1000}s`);\n    }\n  }\n\n  async execute\u003CR extends T>(fn: () => Promise\u003CR>, defaultValue: R): Promise\u003CR> {\n    if (this.isOnCooldown()) {\n      const cached = this.getCached();\n      return (cached as R) ?? defaultValue;\n    }\n    const cached = this.getCached();\n    if (cached !== null) return cached as R;\n    try {\n      const result = await fn();\n      this.recordSuccess(result);\n      return result;\n    } catch (e) {\n      console.error(`[${this.name}] Failed:`, e);\n      this.recordFailure(String(e));\n      return defaultValue;\n    }\n  }\n}\n\nexport function createCircuitBreaker\u003CT>(options: CircuitBreakerOptions): CircuitBreaker\u003CT> {\n  return new CircuitBreaker\u003CT>(options);\n}\n```\n\n## Service Module Pattern\n\nEach service is a TypeScript module that exports async data-fetching functions. Services can work with both proxied and direct API calls.\n\n### Proxied API Example\n\n```typescript\n\u002F\u002F src\u002Fservices\u002Fstock-market.ts\nimport { createCircuitBreaker } from '..\u002Futils\u002Fcircuit-breaker';\n\nexport interface StockQuote {\n  symbol: string;\n  name: string;\n  price: number | null;\n  change: number | null;\n  sparkline?: number[];\n}\n\nconst breaker = createCircuitBreaker\u003CStockQuote[]>({\n  name: 'StockMarket',\n  cacheTtlMs: 60_000, \u002F\u002F 1 minute cache\n});\n\nexport async function fetchStockQuotes(symbols: string[]): Promise\u003CStockQuote[]> {\n  return breaker.execute(async () => {\n    const params = new URLSearchParams({ symbols: symbols.join(',') });\n    const resp = await fetch(`\u002Fapi\u002Fstocks?${params}`);\n    if (!resp.ok) throw new Error(`HTTP ${resp.status}`);\n    return resp.json();\n  }, []);\n}\n```\n\n### Direct API Example\n\n```typescript\n\u002F\u002F src\u002Fservices\u002Fweather.ts\nimport { createCircuitBreaker } from '..\u002Futils\u002Fcircuit-breaker';\n\nexport interface WeatherData {\n  city: string;\n  temperature: number;\n  condition: string;\n  forecast: Array\u003C{\n    day: string;\n    high: number;\n    low: number;\n    condition: string;\n  }>;\n}\n\nconst breaker = createCircuitBreaker\u003CWeatherData>({\n  name: 'WeatherAPI',\n  cacheTtlMs: 30_000, \u002F\u002F 30 seconds cache\n});\n\nexport async function fetchWeather(city: string): Promise\u003CWeatherData> {\n  return breaker.execute(async () => {\n    const resp = await fetch(`https:\u002F\u002Fwttr.in\u002F${city}?format=j1`);\n    if (!resp.ok) throw new Error(`HTTP ${resp.status}`);\n    return resp.json();\n  }, {\n    city,\n    temperature: 0,\n    condition: 'Unknown',\n    forecast: []\n  });\n}\n```\n\n## Key Patterns\n\n1. **One circuit breaker per API endpoint** — create at module level\n2. **Export typed interfaces** for data shapes\n3. **Wrap fetch calls** in `breaker.execute(fn, defaultValue)`\n4. **Default values** are empty arrays `[]` or empty objects `{}`\n5. **Services are stateless modules** — no class instances, just exported functions\n6. **Support both proxied and direct API calls** — choose based on API requirements\n7. **API proxy**: Frontend calls `\u002Fapi\u002F...` which proxies to external APIs (hides API keys)\n8. **Direct API**: Frontend calls external APIs directly when no sensitive data is involved\n\n## API Proxy Pattern\n\nFor APIs requiring keys, create server-side proxy endpoints:\n\n```typescript\n\u002F\u002F api\u002Fstocks.ts (Vercel serverless function)\nexport default async function handler(req, res) {\n  const { symbols } = req.query;\n  const apiKey = process.env.FINNHUB_API_KEY;\n  const data = await fetch(`https:\u002F\u002Ffinnhub.io\u002Fapi\u002Fv1\u002Fquote?symbol=${symbols}&token=${apiKey}`);\n  res.json(await data.json());\n}\n```\n\nThis keeps API keys server-side and provides a single endpoint for the frontend.\n","# Data Service Pattern\n\nEach panel's data comes from a dedicated **service module** in `src\u002Fservices\u002F`. Services handle API calls, caching, error handling with circuit breaker pattern, and can work with both proxied and direct API calls.\n\n## Circuit Breaker\n\nThe 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.\n\nCreate `src\u002Futils\u002Fcircuit-breaker.ts`:\n\n```typescript\ninterface CircuitState {\n  failures: number;\n  cooldownUntil: number;\n}\n\ninterface CacheEntry\u003CT> {\n  data: T;\n  timestamp: number;\n}\n\nexport interface CircuitBreakerOptions {\n  name: string;\n  maxFailures?: number;\n  cooldownMs?: number;\n  cacheTtlMs?: number;\n}\n\nexport class CircuitBreaker\u003CT> {\n  private state: CircuitState = { failures: 0, cooldownUntil: 0 };\n  private cache: CacheEntry\u003CT> | null = null;\n  private name: string;\n  private maxFailures: number;\n  private cooldownMs: number;\n  private cacheTtlMs: number;\n\n  constructor(options: CircuitBreakerOptions) {\n    this.name = options.name;\n    this.maxFailures = options.maxFailures ?? 2;\n    this.cooldownMs = options.cooldownMs ?? 5 * 60 * 1000;  \u002F\u002F 5 minutes\n    this.cacheTtlMs = options.cacheTtlMs ?? 10 * 60 * 1000; \u002F\u002F 10 minutes\n  }\n\n  isOnCooldown(): boolean {\n    if (Date.now() \u003C this.state.cooldownUntil) return true;\n    if (this.state.cooldownUntil > 0) {\n      this.state = { failures: 0, cooldownUntil: 0 };\n    }\n    return false;\n  }\n\n  getCached(): T | null {\n    if (this.cache && Date.now() - this.cache.timestamp \u003C this.cacheTtlMs) {\n      return this.cache.data;\n    }\n    return null;\n  }\n\n  recordSuccess(data: T): void {\n    this.state = { failures: 0, cooldownUntil: 0 };\n    this.cache = { data, timestamp: Date.now() };\n  }\n\n  recordFailure(error?: string): void {\n    this.state.failures++;\n    if (this.state.failures >= this.maxFailures) {\n      this.state.cooldownUntil = Date.now() + this.cooldownMs;\n      console.warn(`[${this.name}] Cooldown for ${this.cooldownMs \u002F 1000}s`);\n    }\n  }\n\n  async execute\u003CR extends T>(fn: () => Promise\u003CR>, defaultValue: R): Promise\u003CR> {\n    if (this.isOnCooldown()) {\n      const cached = this.getCached();\n      return (cached as R) ?? defaultValue;\n    }\n    const cached = this.getCached();\n    if (cached !== null) return cached as R;\n    try {\n      const result = await fn();\n      this.recordSuccess(result);\n      return result;\n    } catch (e) {\n      console.error(`[${this.name}] Failed:`, e);\n      this.recordFailure(String(e));\n      return defaultValue;\n    }\n  }\n}\n\nexport function createCircuitBreaker\u003CT>(options: CircuitBreakerOptions): CircuitBreaker\u003CT> {\n  return new CircuitBreaker\u003CT>(options);\n}\n```\n\n## Service Module Pattern\n\nEach service is a TypeScript module that exports async data-fetching functions. Services can work with both proxied and direct API calls.\n\n### Proxied API Example\n\n```typescript\n\u002F\u002F src\u002Fservices\u002Fstock-market.ts\nimport { createCircuitBreaker } from '..\u002Futils\u002Fcircuit-breaker';\n\nexport interface StockQuote {\n  symbol: string;\n  name: string;\n  price: number | null;\n  change: number | null;\n  sparkline?: number[];\n}\n\nconst breaker = createCircuitBreaker\u003CStockQuote[]>({\n  name: 'StockMarket',\n  cacheTtlMs: 60_000, \u002F\u002F 1 minute cache\n});\n\nexport async function fetchStockQuotes(symbols: string[]): Promise\u003CStockQuote[]> {\n  return breaker.execute(async () => {\n    const params = new URLSearchParams({ symbols: symbols.join(',') });\n    const resp = await fetch(`\u002Fapi\u002Fstocks?${params}`);\n    if (!resp.ok) throw new Error(`HTTP ${resp.status}`);\n    return resp.json();\n  }, []);\n}\n```\n\n### Direct API Example\n\n```typescript\n\u002F\u002F src\u002Fservices\u002Fweather.ts\nimport { createCircuitBreaker } from '..\u002Futils\u002Fcircuit-breaker';\n\nexport interface WeatherData {\n  city: string;\n  temperature: number;\n  condition: string;\n  forecast: Array\u003C{\n    day: string;\n    high: number;\n    low: number;\n    condition: string;\n  }>;\n}\n\nconst breaker = createCircuitBreaker\u003CWeatherData>({\n  name: 'WeatherAPI',\n  cacheTtlMs: 30_000, \u002F\u002F 30 seconds cache\n});\n\nexport async function fetchWeather(city: string): Promise\u003CWeatherData> {\n  return breaker.execute(async () => {\n    const resp = await fetch(`https:\u002F\u002Fwttr.in\u002F${city}?format=j1`);\n    if (!resp.ok) throw new Error(`HTTP ${resp.status}`);\n    return resp.json();\n  }, {\n    city,\n    temperature: 0,\n    condition: 'Unknown',\n    forecast: []\n  });\n}\n```\n\n## Key Patterns\n\n1. **One circuit breaker per API endpoint** — create at module level\n2. **Export typed interfaces** for data shapes\n3. **Wrap fetch calls** in `breaker.execute(fn, defaultValue)`\n4. **Default values** are empty arrays `[]` or empty objects `{}`\n5. **Services are stateless modules** — no class instances, just exported functions\n6. **Support both proxied and direct API calls** — choose based on API requirements\n7. **API proxy**: Frontend calls `\u002Fapi\u002F...` which proxies to external APIs (hides API keys)\n8. **Direct API**: Frontend calls external APIs directly when no sensitive data is involved\n\n## API Proxy Pattern\n\nFor APIs requiring keys, create server-side proxy endpoints:\n\n```typescript\n\u002F\u002F api\u002Fstocks.ts (Vercel serverless function)\nexport default async function handler(req, res) {\n  const { symbols } = req.query;\n  const apiKey = process.env.FINNHUB_API_KEY;\n  const data = await fetch(`https:\u002F\u002Ffinnhub.io\u002Fapi\u002Fv1\u002Fquote?symbol=${symbols}&token=${apiKey}`);\n  res.json(await data.json());\n}\n```\n\nThis keeps API keys server-side and provides a single endpoint for the frontend.\n",{"name":5,"description":7},"main","ff671ef61ed6587c49bd54c81cdc751c0b99e363","showcase\u002Fskills\u002Fdata-service-proxy-direct","https:\u002F\u002Fgithub.com\u002FAG064\u002FOpenSpace","https:\u002F\u002Fgithub.com\u002FAG064","AG064, E.Mi.\r\n\r\nA person who thinks all the time, yet all they have to think about is nothing. I want to improve the world and work on open source projects","2026-10-08 06:53:48",{"source":8,"skillName":5,"commands":56,"prompt":66,"zipAvailable":67},[57,60,63],{"tool":58,"command":59},"npx","npx skills add AG064\u002FOpenSpace --skill data-service-proxy-direct",{"tool":61,"command":62},"bunx","bunx skills add AG064\u002FOpenSpace --skill data-service-proxy-direct",{"tool":64,"command":65},"pnpm","pnpm dlx skills add AG064\u002FOpenSpace --skill data-service-proxy-direct","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FAG064\u002FOpenSpace\u002Fblob\u002Fmain\u002Fshowcase\u002Fskills\u002Fdata-service-proxy-direct\u002FSKILL.md",true,[69],{"path":70,"resourceType":71,"resourceTypeDesc":72,"sizeBytes":73,"sourceHtmlUrl":74},".skill_id","OTHER","其他",35,"https:\u002F\u002Fgithub.com\u002FAG064\u002FOpenSpace\u002Fblob\u002Fmain\u002Fshowcase\u002Fskills\u002Fdata-service-proxy-direct\u002F.skill_id",[76,100,116,125,148,164],{"skillNo":77,"name":78,"nameZh":6,"description":79,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":80,"categories":81,"keywords":82,"publishedAt":43},"01M6KKMPWA0B5SCCH766F8M5EA","write-special-chars-ts-check","Workaround for write_file failures caused by special characters (apostrophes, backticks, template literals) using a Python heredoc script, plus a reliable TypeScript type-checking step that filters output to only the newly-written files to avoid being misled by pre-existing errors.","https:\u002F\u002Fgithub.com\u002FAG064\u002FOpenSpace\u002Fblob\u002Fmain\u002Fshowcase\u002Fskills\u002Fwrite-special-chars-ts-check\u002FSKILL.md",[],[83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99],"write special chars ts check","check","write","filters","Existing","type-checking","for","errors","script","output","type","files","only","template","file","python","typescript",{"skillNo":101,"name":102,"nameZh":6,"description":103,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":104,"categories":105,"keywords":106,"publishedAt":43},"01M6KKMJXVBNVEY3TRK055F4A7","write-special-chars-readback","Workaround for write_file failures caused by special characters (apostrophes, backticks, template literals) using a Python heredoc script, with mandatory post-write verification via read_file and cleanup of \u002Ftmp helper scripts.","https:\u002F\u002Fgithub.com\u002FAG064\u002FOpenSpace\u002Fblob\u002Fmain\u002Fshowcase\u002Fskills\u002Fwrite-special-chars-readback\u002FSKILL.md",[],[107,108,85,96,109,110,97,98,111,112,113,114,115,89,91,33],"readback","write special chars readback","cleanup","read","scripts","verification","via","post","helper",{"skillNo":117,"name":118,"nameZh":6,"description":119,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":120,"categories":121,"keywords":122,"publishedAt":43},"01M6KKMEGX9M9NC105J0W3Q5B9","write-special-chars-heredoc","Workaround for write_file failures caused by special characters (apostrophes, backticks, template literals) by using a Python heredoc script executed via shell.","https:\u002F\u002Fgithub.com\u002FAG064\u002FOpenSpace\u002Fblob\u002Fmain\u002Fshowcase\u002Fskills\u002Fwrite-special-chars-heredoc\u002FSKILL.md",[],[85,123,98,89,113,96,124,97,91],"write special chars heredoc","shell",{"skillNo":126,"name":127,"nameZh":6,"description":128,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":129,"categories":130,"keywords":132,"publishedAt":43},"01M6KKM8EJ2AATVHZBNB916WT0","worldmonitor-reference","Curated architecture index of the WorldMonitor open-source dashboard. Reference for extracting patterns — vanilla TypeScript, Panel class hierarchy, service layer, CSS grid, API edge functions, refresh scheduler, and 60+ data source integrations.","https:\u002F\u002Fgithub.com\u002FAG064\u002FOpenSpace\u002Fblob\u002Fmain\u002Fshowcase\u002Fskills\u002Fworldmonitor-reference\u002FSKILL.md",[131],{"categoryNo":18,"categoryName":19,"taxonomyType":20,"taxonomyTypeDesc":21},[133,134,135,136,99,137,138,139,140,141,89,142,34,143,144,145,146,39,26,147],"reference","worldmonitor","worldmonitor reference","dashboard","css","architecture","extracting","hierarchy","source","layer","patterns","edge functions","integrations","open","scheduler",{"skillNo":149,"name":150,"nameZh":6,"description":151,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":152,"categories":153,"keywords":154,"publishedAt":43},"01M6KKM39PHYK627F19GE2B9XN","virtual-list","Implement efficient virtual scrolling for rendering large lists with DOM recycling, chunk-based rendering, and performance optimizations","https:\u002F\u002Fgithub.com\u002FAG064\u002FOpenSpace\u002Fblob\u002Fmain\u002Fshowcase\u002Fskills\u002Fvirtual-list\u002FSKILL.md",[],[155,156,157,158,89,159,33,160,161,162,163],"virtual list","list","virtual","chunk","dom","rendering","recycling","implement","performance",{"skillNo":165,"name":166,"nameZh":6,"description":167,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":168,"categories":169,"keywords":170,"publishedAt":43},"01M6KKKY7T2P61Y0JH54CDEJKQ","verify-directory-structure","Diagnose and resolve file access issues by first verifying the directory structure.","https:\u002F\u002Fgithub.com\u002FAG064\u002FOpenSpace\u002Fblob\u002Fmain\u002Fshowcase\u002Fskills\u002Fverify-directory-structure\u002FSKILL.md",[],[171,172,173,174,175,176,97,177,178,179],"directory","verify","structure","verify directory structure","access","first","issues","diagnose","file access"]