Lia开发者

开始使用

AI代码助手构建Lia应用所需的一切。文档为Markdown格式,llms.txt,OpenAPI服务器的API规范,TypeScript类型,以及你项目的规则文件。

这些文档旨在由人和AI工具 alike 阅读。将你的助手(Claude,ChatGPT,Cursor,Copilot,Claude Code 或任何其他)指向下面的文件,并将规则文件添加到你的项目中,这样它就能第一次正确地写出Lia代码。

#对于你的助手

什么哪里用于
文档的目录/llms.txt基本内容和每一页,带有其 Markdown 的链接。从这里开始。
所有文档在一个文件中/llms-full.txt当您的工具可以时,粘贴或附加它't 浏览。
任何页面作为 Markdown添加 .md 到它的地址,比如 /concepts/payments.md一次一个主题。每一页's 复制页面 菜单也这样做。
服务器API 作为OpenAPI 3.1/openapi.json生成类型化的客户端,或者让代理正确调用API。
您项目的规则文件/AGENTS.md以下:助手读取的文件中最重要的规则。
TypeScript 类型npm install @lia-labs/sdk每种方法'的参数和答案,每个事件'的数据。

#复制页面

每个页面都有一个 复制页面 在标题旁边的菜单中:

  • 复制为Markdown 将页面放到剪贴板上,准备粘贴到聊天中。
  • 以 Markdown 格式查看 打开其Markdown。
  • 在 Claude 中打开 和 在 ChatGPT 中打开 开始一个读取页面的聊天。

#将规则添加到您的项目

保存为 AGENTS.md 在您的项目中(或 CLAUDE.md 对于 Claude Code,或在 .cursor/rules/)。助手在他们编写代码之前会阅读它,因此他们会遵循 Lia'的规则,而无需每次被告知。它's 也在 /AGENTS.md.

AGENTS.md
# Building a Lia app

This is a web app that runs inside the Lia app (lialabs.org), like a Telegram mini app. Docs: https://docs.lialabs.org (every page as Markdown: add .md; everything: https://docs.lialabs.org/llms-full.txt).

## The SDK
- In a page without a build step: <script src="https://api.lialabs.org/sdk/lia-apps-v1.js"></script> gives window.Lia. Never copy or bundle that file.
- With a bundler: npm install @lia-labs/sdk (or @lia-labs/sdk-react, -preact, -vue, -svelte, -solid, -angular, @lia-labs/elements). Use one or the other on a page, never both.
- Call init() first, then ready() once the first screen is drawn. Outside Lia every call fails with code "not_in_lia"; for local development call mockLia() when isLia() is false.
- Every failure is an Error with a code. "cancelled" from pay() is a normal no, not an error to report.

## Trust
- Never trust the page. Your server verifies a session token (from init() or session(), 15 minutes) with POST https://api.lialabs.org/api/apps/v1/session/verify and takes the player id from Lia's answer, never from the page.
- Secret keys (lia_test_..., lia_live_...) and the webhook secret (whsec_...) live on the server only. The app id is the only public identifier.
- Prices come from Lia's records: the page passes a product id to pay(), never an amount.

## Payments
- pay(productId) opens Lia's pay sheet and answers { chargeId, productId }. The server then checks GET /charges/:id (its player, product and status), gives the item once per charge id, and calls POST /charges/:id/deliver. If it can't deliver, POST /charges/:id/refund.
- On opening, call charges() and deliver any paid, undelivered charges; listen with onCharge() too. Webhooks (charge.paid) are a nudge: check with the API, and verify the Lia-Signature header (HMAC SHA-256 of "<t>.<raw body>" with the whsec_ secret).

## Rewards, ads, notifications
- Pay players in $LIA only from the server: POST /rewards with a key that names the reason (a key pays once, ever). At most 10,000 LIA a reward; handle pool_empty and daily_limit.
- A rewarded video answers { watched, adId }: give the reward only after the server checks POST /ads/verify (watched, and the same player), once per adId.
- Between rounds and games, call Lia.showInterstitialAd() (Lia paces it: about one every 90 seconds and every 2nd round; "too_soon" means carry on). Rewarded videos only behind a button the player chooses (a hint, a second chance), never by themselves between rounds. Test keys always get Google's test ads.
- Banners and native ads (SDK 1.7): Lia.showBanner({ position: "bottom" | "top" }) and Lia.showNativeAd({ placement: "card" | "sheet" }). Lia draws them natively beside the page (the page gets shorter), never inside it: don't build an ad slot in your own HTML for them, just let the layout follow the viewport height. Show the card at pauses (a results screen) and hideNativeAd() when play resumes; both answer { shown: false, reason } when there's nothing to show, so carry on. For an ad inside the page's own content, use the developer's own AdSense or Google Ad Manager tags: Lia lets only Google's ad frames load and opens ad taps in Safari; that revenue is the developer's own, not counted by Lia. For games: pin Lia.showBanner({ position: "top" }) before Lia.ready() and keep it for the visit; put in-page ad rows only on calm screens (home, lobby), never over or under the board; don't use the native card or sheet over gameplay.
- Notifications are opt-in (requestNotifications()), sent by the server with POST /notifications, at most 3 a day per person from one app, an hour apart, 180 characters, no links. Use a startParam to open the right screen.

## Feel like Lia
- Use Lia's theme (CSS variables --lia-bg-color, --lia-text-color, --lia-hint-color...), the safe areas (--lia-safe-area-inset-bottom), Lia.language (13 languages) and Lia.rtl for dir.
- Use Lia's mainButton for the main action, backButton for your own screens, Lia's dialogs and toasts, and play sound only while soundOn.
- Only your own pages load in the frame: open other sites with openLink(url).

## Conventions
- In text people read: "$LIA" for the token, "LIA" next to numbers (5 LIA).
- Retry server POSTs with the same Idempotency-Key header.

#提出好问题

一些与上面文件配合良好的提示:

#如果发生某事'错了

AI 工具仍可能出错。 SDK 参考 和 服务器 API 是真相的来源,而且 测试你的应用 展示如何在上线前检查所有内容。

自动翻译。英语是真实来源。 阅读英文

输入以搜索每一页、方法和端点。