LiaNhà phát triển

Bắt đầu

Tất cả những gì một trợ lý lập trình AI cần để xây dựng một ứng dụng Lia đúng cách. Tài liệu dưới dạng Markdown, llms.txt, một bản mô tả OpenAPI của máy chủ API, các loại TypeScript, và một tệp quy tắc cho dự án của bạn.

Những tài liệu này được viết để đọc bởi con người và các công cụ AI cùng lúc. Hướng trợ lý của bạn (Claude, ChatGPT, Cursor, Copilot, Claude Code hoặc bất kỳ công cụ nào khác) đến các tệp bên dưới, và thêm tệp quy tắc vào dự án của bạn, để nó viết mã Lia theo cách đúng ngay từ đầu.

#Đối với trợ lý của bạn

Cái gìỞ đâuSử dụng nó để
Một bản đồ tài liệu/llms.txtNhững điều cơ bản và mọi trang, với liên kết đến Markdown của nó. Bắt đầu ở đây.
Tất cả tài liệu trong một tệp/llms-full.txtDán hoặc đính kèm khi công cụ của bạn có thể't duyệt.
Một trang bất kỳ dưới dạng MarkdownThêm .md đến địa chỉ của nó, như /concepts/payments.mdMột chủ đề tại một thời điểm. Mỗi trang's Sao chép trang menu cũng làm điều đó.
Máy chủ API theo OpenAPI 3.1/openapi.jsonTạo khách hàng có kiểu, hoặc để một đại lý gọi API đúng cách.
Một tệp quy tắc cho dự án của bạn/AGENTS.mdDưới đây: các quy tắc quan trọng nhất, trong một tệp mà các trợ lý đọc.
Loại TypeScriptnpm install @lia-labs/sdkMỗi phương pháp'các tham số và câu trả lời của bạn, mọi sự kiện'dữ liệu.

#Sao chép trang

Mỗi trang có một Sao chép trang menu bên cạnh tiêu đề của nó:

  • Sao chép dưới dạng Markdown đặt trang này vào clipboard của bạn, sẵn sàng dán vào một cuộc trò chuyện.
  • Xem dưới dạng Markdown mở Markdown của nó.
  • Mở trong Claude và Mở trong ChatGPT khởi tạo cuộc trò chuyện đọc trang.

#Thêm quy tắc vào dự án của bạn

Lưu thành AGENTS.md trong dự án của bạn (hoặc CLAUDE.md cho Claude Code, hoặc một quy tắc trong .cursor/rules/). Các trợ lý đọc nó trước khi họ viết mã, vì vậy họ tuân theo Lia'quy tắc mà không cần được nói mỗi lần. Nó's cũng được gửi đến người /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.

#Hỏi những câu hỏi tốt

Một số gợi ý hoạt động tốt với các tệp trên:

#Nếu có điều gì đó'mà sai

Công cụ AI vẫn có thể mắc sai lầm. Điều Tham khảo SDK và máy chủ API là nguồn gốc của sự thật, và Kiểm tra ứng dụng của bạn hiển thị cách kiểm tra tất cả mọi thứ trước khi phát trực tiếp.

Được dịch tự động. Tiếng Anh là nguồn tin cậy. Đọc bằng tiếng Anh

Nhập để tìm kiếm trên mọi trang, phương pháp và điểm cuối.