@aparte/plugin-cards

中文文档
1.0.2发布于 2026/11/08MITTypeScriptES Module零依赖构建来源已验证近 30 天下载 1973

Rich cards for aparté — a tool's result drawn as a card (weather, items, products, places, figures, orders, stocks, scores, plans, media, links), with variants and live controls, from any source.

原始使用文档
文档目录13 节
  1. Pictures
  2. The weather card — @aparte/plugin-cards/weather
  3. The generic card — @aparte/plugin-cards/items
  4. The product card — @aparte/plugin-cards/product
  5. The place card — @aparte/plugin-cards/place
  6. The key-figures card — @aparte/plugin-cards/stats
  7. The order card — @aparte/plugin-cards/order
  8. The stock card — @aparte/plugin-cards/stock
  9. The plan card — @aparte/plugin-cards/plan
  10. The score card — @aparte/plugin-cards/score
  11. The media card — @aparte/plugin-cards/media
  12. The link card — @aparte/plugin-cards/link
  13. The kit — @aparte/plugin-cards

@aparte/plugin-cards

Rich cards for aparté: a tool's result drawn as a card instead of a row — weather, products, places, figures, orders, quotes, plans, scores, media, links — in variants, from your tool's own fields. Each card has its own entry, so an app ships only the cards it imports.

The weather card of @aparte/plugin-cards, in an aparté chat The product card of @aparte/plugin-cards, in an aparté chat The place card of @aparte/plugin-cards, in an aparté chat The stock card of @aparte/plugin-cards, in an aparté chat The order card of @aparte/plugin-cards, in an aparté chat The items card of @aparte/plugin-cards, in an aparté chat The stats card of @aparte/plugin-cards, in an aparté chat The score card of @aparte/plugin-cards, in an aparté chat The plan card of @aparte/plugin-cards, in an aparté chat The media card of @aparte/plugin-cards, in an aparté chat The link card of @aparte/plugin-cards, in an aparté chat

Each picture links to its card's page, where it runs live.

npm install @aparte/plugin-cards @aparte/core
import { setupWeatherCard } from '@aparte/plugin-cards/weather';

setupWeatherCard({
  tool: 'get_weather',
  map: (result) => ({ location: result.city, temperature: result.temp_c, condition: result.sky }),
  variant: 'hero', // or 'compact', 'forecast', or a function of the data
});

The full guide: apartejs.dev/guides/cards.

Pictures

A card's pictures come from a tool's data, so they follow the chat's image policy: a picture from a host your app has not allowed waits behind one "Show images" button on the card. Allow your own sources:

import { aparteGlobalConfig } from '@aparte/core';

aparteGlobalConfig.setImagePolicy(['self', 'https://cdn.example.com']);

Pictures and the image policy gives the whole rule.

The weather card — @aparte/plugin-cards/weather

  • setupWeatherCard(options) plugs the card in and returns the function that unplugs it. options: tool, map, mapInput, variant, actions, onChange, config.
  • weatherCard is the card itself: weatherCard.setup(options), and weatherCard.segment(data) for a card segment with its fallback sentence.
  • readWeather(raw) is the card's reading of its fields; fromOpenMeteo(response, { location }) reads an Open-Meteo forecast response.
  • conditionFromWmo, conditionFromOpenWeather and conditionFromText turn the usual APIs' codes into one of WEATHER_CONDITIONS.
  • Types: WeatherInput, WeatherData, WeatherHour, WeatherDay, WeatherCondition, WeatherVariant, WindUnit.

The generic card — @aparte/plugin-cards/items

Articles, search results, anything with a title and a picture: carousel (default), list, grid.

  • setupItemsCard(options), itemsCard (.setup, .segment), readItems(raw), ITEMS_MAX (10).
  • Types: ItemsInput, ItemInput, ItemImage, Item, ItemsData, ItemsVariant.

The product card — @aparte/plugin-cards/product

Prices, discount, rating, stock, merchant, options: card (default), compact, detail. Its reader takes schema.org, Shopify, Google Shopping and Fake Store shapes, and prices written as text.

  • setupProductCard(options), productCard (.setup, .segment), readProducts(raw), discountOf(product).
  • Types: ProductsInput, ProductInput, Product, ProductData, ProductAvailability, ProductVariant.

The place card — @aparte/plugin-cards/place

Rating, price level, open now (computed from the hours, across midnight), distance, and Directions / Call / Website buttons: card (default), compact, detail (with the week's hours). Its reader takes both generations of Google Places and Yelp.

  • setupPlaceCard(options) (adds currencySymbol, now and builtIns), placeCard (.setup, .segment), readPlaces(raw), readHours(raw), readTime(raw), placeStatus(hours, date), isOpenAt(hours, date), directionsUrl(place), phoneUrl(phone).
  • Types: PlaceInput, Place, PlaceData, PlaceHoursInput, PlaceHoursRange, PlacePrice, PlaceStatus, PlaceKind, PlaceVariant, PlaceCardOptions.

The key-figures card — @aparte/plugin-cards/stats

KPIs with their change and a sparkline: tiles (default), list, hero. A plain record ({ Revenue: 12000 }) is read as label → value pairs.

  • setupStatsCard(options), statsCard (.setup, .segment), readStats(raw), statValue(config, stat), statChange(config, stat), humanizeKey(key).
  • Types: StatsInput, StatInput, Stat, StatsData, StatFormat, StatIcon, StatsVariant.

The order card — @aparte/plugin-cards/order

An order or a booking as its receipt: receipt (default), compact, confirmation. Its reader takes Shopify, WooCommerce and Stripe Checkout (minorUnits: true for amounts in cents).

  • setupOrderCard(options), orderCard (.setup, .segment), readOrder(raw), readWhen(value), nightsOf(from, to).
  • Types: OrderInput, OrderLineInput, OrderDateInput, OrderData, OrderLine, OrderFact, OrderWhen, OrderKind, OrderStatus, OrderVariant.

The stock card — @aparte/plugin-cards/stock

A quote with its chart: chart (default), compact, ticker, candles. Range buttons over the chart when the quote lists ranges and the card has an onChange. Its reader takes Yahoo Finance, Alpha Vantage, Finnhub, CoinGecko and Binance.

  • setupStockCard(options), stockCard (.setup, .segment), readQuotes(raw), directionOf(quote), baselineOf(quote), digitsOf(quote).
  • Types: QuotesInput, QuoteInput, Quote, StockData, ChartPoint, Candle, MarketState, StockRange, StockVariant.

The plan card — @aparte/plugin-cards/plan

An agent's plan or task list, updated in place as it works: checklist (default), timeline, compact. Its reader takes Markdown checklists and the todo lists agents already write.

  • setupPlanCard(options), planCard (.setup, .segment), readPlan(raw), readStatus(value), planProgress(data), durationText(config, seconds), PLAN_STEPS_SHOWN (50).
  • Types: PlanInput, PlanStepInput, PlanStep, PlanData, PlanProgress, PlanStatus, PlanVariant.

The score card — @aparte/plugin-cards/score

A match or a scoreboard, any sport: card (default), compact, detail. Its reader takes API-Football, football-data.org, ESPN and TheSportsDB.

  • setupScoreCard(options) (adds now), scoreCard (.setup, .segment), readMatches(raw), teamColor(value), monogram(team), inkOn(hex).
  • Types: ScoreInput, MatchInput, TeamInput, MatchPeriodInput, MatchEventInput, ScoreData, Match, Team, MatchPeriod, MatchEvent, MatchStatus, MatchSide, MatchEventType, Sport, ScoreVariant, ScoreCardOptions.

The media card — @aparte/plugin-cards/media

Pictures, videos and sounds, with a lightbox: single (default), gallery, strip. Native <video> and <audio>; a YouTube or Vimeo page is a poster that links to it.

  • setupMediaCard(options), mediaCard (.setup, .segment), readMedia(raw), readDuration(value), formatDuration(config, seconds).
  • Types: MediumInput, Medium, MediaData, MediaKind, MediaVariant, MediaCardOptions.

A web page, previewed: card (default), compact, quote. Its reader takes Open Graph, Twitter keys and the usual search APIs; the card fetches nothing.

  • setupLinkCard(options), linkCard (.setup, .segment), readLinks(raw).
  • Types: LinkInput, Link, LinkData, LinkType, LinkVariant, LinkCardOptions.

The kit — @aparte/plugin-cards

What every card is made with, for a card of your own that behaves like ours (three sources, states, variants, language switch, buttons):

  • setupCardFences(options) (CardFenceOptions, CARD_FENCE_PREFIX): draws a ```card-weather block of JSON in an answer as its card, for backends that send only text; load fetches each card the first time a block names it.
  • defineCard(definition) and CARD_SEGMENT_TYPE; types CardDefinition, CardSetupOptions, CardContext, CardAction, CardActionEventDetail, CardActionsContext, CardOrigin, CardChangeEventDetail, AparteCardSegment.
  • Controls, drawn only when the card has an onChange: segmented (SegmentedOptions), toggle (ToggleOptions), slider (SliderOptions). A press fires aparte-card-change, and what onChange returns is drawn in place.
  • Drawing: el, glyph, carousel (CarouselOptions), rating (RatingOptions), sparkline and sparklinePath (SparklineOptions).
  • Reading: safeUrl, webUrl, num, str, toDate, currencyCode.
  • Writing: formatNumber, formatPercent, formatPrice, formatUnit, formatDay, formatHour, formatWhen; word, languageOf, intlTag, with CardWord and CardLanguage.

A card's words come in the ten languages of @aparte/locales, picked by the locale's tag; a key of your locale wins (aparteGlobalConfig.extendLocale({ cardsWeatherWind: 'Gusts' })).

ESM-only. Part of the aparté monorepo. MIT.

版本与发布记录

@aparte/plugin-cards 共发布 14 个版本,首次发布于 2026/11/01;过去 12 个月发布了 14 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.0.2latest2026/11/08今天
1.0.12026/11/08今天
1.0.02026/11/071 天前
0.32.12026/11/026 天前
0.32.02026/11/026 天前
0.31.02026/11/026 天前

关于 @aparte/plugin-cards 的常见问题

@aparte/plugin-cards 是什么?

Rich cards for aparté — a tool's result drawn as a card (weather, items, products, places, figures, orders, stocks, scores, plans, media, links), with variants and live controls, from any source.

如何安装 @aparte/plugin-cards?

在项目目录运行 npm install @aparte/plugin-cards,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@aparte/core(>=1.0.2 <2.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@aparte/plugin-cards 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@aparte/plugin-cards 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@aparte/plugin-cards 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=18。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@aparte/plugin-cards 可以商用吗?

@aparte/plugin-cards 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@aparte/plugin-cards 的下载量有多少?

根据 npm 官方下载统计,@aparte/plugin-cards 在 2026/10/06 – 2026/11/04 这 30 天内被下载 1,973 次,日均约 66 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@aparte/plugin-cards 还在维护吗?

最新版本 1.0.2 发布于 2026/11/08(今天);至今共发布 14 个版本,其中过去 12 个月发布了 14 个;首次发布于 2026/11/01。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。