[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6KKAY9D076R759PV0WRK730":3,"skill-same:01M6KKAY9D076R759PV0WRK730":74},{"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":42,"linkOnly":43,"markdownContent":44,"markdownBody":45,"frontMatter":46,"refName":47,"commitSha":48,"skillDirectory":49,"forksCount":13,"repositoryHtmlUrl":50,"repositoryHomepageUrl":6,"ownerHtmlUrl":51,"ownerBlogUrl":6,"ownerDescription":52,"updatedAt":53,"install":54,"resources":67},"01M6KKAY9D076R759PV0WRK730","data-service",null,"Create data fetching services with circuit breaker pattern for API resilience. 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\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],"data service","data","service","pattern","data fetching","for","circuit","retry","with","panel","Circuit Breaker","components","circuit breaker pattern","fetch","api","services","cache","create","resilience","2026-11-10 10:12:30",false,"---\nname: data-service\ndescription: Create data fetching services with circuit breaker pattern for API resilience. 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.\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:\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## 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. **API proxy**: Frontend calls `\u002Fapi\u002F...` which proxies to external APIs (hides API keys)\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\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.\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:\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## 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. **API proxy**: Frontend calls `\u002Fapi\u002F...` which proxies to external APIs (hides API keys)\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\n",{"name":5,"description":7},"main","ff671ef61ed6587c49bd54c81cdc751c0b99e363","showcase\u002Fskills\u002Fdata-service","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":55,"prompt":65,"zipAvailable":66},[56,59,62],{"tool":57,"command":58},"npx","npx skills add AG064\u002FOpenSpace --skill data-service",{"tool":60,"command":61},"bunx","bunx skills add AG064\u002FOpenSpace --skill data-service",{"tool":63,"command":64},"pnpm","pnpm dlx skills add AG064\u002FOpenSpace --skill data-service","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FAG064\u002FOpenSpace\u002Fblob\u002Fmain\u002Fshowcase\u002Fskills\u002Fdata-service\u002FSKILL.md",true,[68],{"path":69,"resourceType":70,"resourceTypeDesc":71,"sizeBytes":72,"sourceHtmlUrl":73},".skill_id","OTHER","其他",26,"https:\u002F\u002Fgithub.com\u002FAG064\u002FOpenSpace\u002Fblob\u002Fmain\u002Fshowcase\u002Fskills\u002Fdata-service\u002F.skill_id",[75,98,114,123,146,162],{"skillNo":76,"name":77,"nameZh":6,"description":78,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":79,"categories":80,"keywords":81,"publishedAt":42},"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",[],[82,83,84,85,86,87,28,88,89,90,91,92,93,94,95,96,97],"write special chars ts check","check","write","filters","Existing","type-checking","errors","script","output","type","files","only","template","file","python","typescript",{"skillNo":99,"name":100,"nameZh":6,"description":101,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":102,"categories":103,"keywords":104,"publishedAt":42},"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",[],[105,106,84,94,107,108,95,96,109,110,111,112,113,28,89,31],"readback","write special chars readback","cleanup","read","scripts","verification","via","post","helper",{"skillNo":115,"name":116,"nameZh":6,"description":117,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":118,"categories":119,"keywords":120,"publishedAt":42},"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",[],[84,121,96,28,111,94,122,95,89],"write special chars heredoc","shell",{"skillNo":124,"name":125,"nameZh":6,"description":126,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":127,"categories":128,"keywords":130,"publishedAt":42},"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",[129],{"categoryNo":18,"categoryName":19,"taxonomyType":20,"taxonomyTypeDesc":21},[131,132,133,134,97,135,136,137,138,139,28,140,32,141,142,143,144,37,24,145],"reference","worldmonitor","worldmonitor reference","dashboard","css","architecture","extracting","hierarchy","source","layer","patterns","edge functions","integrations","open","scheduler",{"skillNo":147,"name":148,"nameZh":6,"description":149,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":150,"categories":151,"keywords":152,"publishedAt":42},"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",[],[153,154,155,156,28,157,31,158,159,160,161],"virtual list","list","virtual","chunk","dom","rendering","recycling","implement","performance",{"skillNo":163,"name":164,"nameZh":6,"description":165,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":166,"categories":167,"keywords":168,"publishedAt":42},"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",[],[169,170,171,172,173,174,95,175,176,177],"directory","verify","structure","verify directory structure","access","first","issues","diagnose","file access"]