@heybox/hb-sdk 0.5.10 → 0.5.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/README.md +99 -55
  2. package/dist/cli-chunks/{create-D1W2pkHZ.cjs → create-Ba353lSg.cjs} +1 -1
  3. package/dist/cli-chunks/{dev-DwbE-c1x.cjs → dev-BhPFNef-.cjs} +1 -1
  4. package/dist/cli-chunks/{doctor-Bx71WFjM.cjs → doctor-CP4kwgAn.cjs} +1 -1
  5. package/dist/cli-chunks/{index-D5bZjpH9.cjs → index-BfpHPA6k.cjs} +2 -2
  6. package/dist/cli-chunks/{index-BBatNb1l.cjs → index-DeamIV1-.cjs} +57 -13
  7. package/dist/cli-chunks/{login-BX0YmVyi.cjs → login-DMNap0-y.cjs} +2 -2
  8. package/dist/cli-chunks/{remote-YDmSxyYi.cjs → remote-gXUjRvGB.cjs} +117 -3
  9. package/dist/cli-chunks/{session-BxZBXDZ-.cjs → session-D5Vf-fNZ.cjs} +1 -1
  10. package/dist/cli.cjs +1 -1
  11. package/dist/devtools/mock-host/main.js +590 -0
  12. package/dist/index.cjs.js +84 -4
  13. package/dist/index.esm.js +84 -5
  14. package/dist/miniapp-publish.cjs.js +8 -0
  15. package/dist/miniapp-publish.esm.js +5 -1
  16. package/dist/protocol.cjs.js +50 -0
  17. package/dist/protocol.esm.js +46 -1
  18. package/package.json +2 -4
  19. package/skill/SKILL.md +4 -3
  20. package/skill/references/api-protocol.md +27 -7
  21. package/skill/references/api-root.md +64 -4
  22. package/skill/references/cli.md +3 -3
  23. package/skill/references/examples.md +2 -1
  24. package/skill/references/llms-index.md +16 -37
  25. package/skill/references/recipes.md +9 -9
  26. package/skill/references/safety-boundaries.md +3 -2
  27. package/skill/scripts/sync-references.mjs +35 -25
  28. package/skill/skill.json +4 -4
  29. package/types/core/client.d.ts +5 -1
  30. package/types/core/sdk.d.ts +3 -0
  31. package/types/core/singleton.d.ts +3 -0
  32. package/types/index.d.ts +3 -1
  33. package/types/miniapp-publish/index.d.ts +4 -0
  34. package/types/modules/cloud/index.d.ts +100 -0
  35. package/types/protocol/capabilities.d.ts +55 -2
  36. package/types/protocol.d.ts +3 -2
@@ -19,7 +19,7 @@
19
19
  ## Package metadata
20
20
 
21
21
  - Package: `@heybox/hb-sdk`
22
- - Version at generation time: `0.5.9`
22
+ - Version at generation time: `0.5.11`
23
23
  - Public root export: `@heybox/hb-sdk`
24
24
  - Protocol export: `@heybox/hb-sdk/protocol`
25
25
  - Vite plugin export: `@heybox/hb-sdk/vite`
@@ -30,13 +30,29 @@
30
30
  export { createMiniProgramSDK, MiniProgramSDK } from './core/sdk';
31
31
  export { HbMiniProgramSDKError, HbMiniProgramNetworkError } from './core/errors';
32
32
  export type { MiniProgramSDKOptions } from './core/client';
33
- export { ready, on, off, auth, user, share, viewport, storage, network, ui, device, navigation } from './core/singleton';
33
+ export { ready, on, off, auth, user, share, viewport, storage, network, ui, device, navigation, cloud } from './core/singleton';
34
34
  export type {
35
35
  MiniProgramEventHandler,
36
36
  MiniProgramEventName,
37
37
  MiniProgramEventPayloadMap,
38
38
  } from './protocol/types';
39
39
  export type { LoginPayload, LoginResult, MiniProgramAuthModule } from './modules/auth';
40
+ export type {
41
+ DeleteCurrentUserLeaderboardEntryPayload,
42
+ DeleteCurrentUserLeaderboardEntryResult,
43
+ GetCurrentUserLeaderboardEntryPayload,
44
+ GetCurrentUserLeaderboardEntryResult,
45
+ GetLeaderboardInfoPayload,
46
+ GetLeaderboardInfoResult,
47
+ GetLeaderboardListPayload,
48
+ GetLeaderboardListResult,
49
+ LeaderboardEntry,
50
+ LeaderboardOrder,
51
+ MiniProgramCloudLeaderboardModule,
52
+ MiniProgramCloudModule,
53
+ SubmitLeaderboardEntryPayload,
54
+ SubmitLeaderboardEntryResult,
55
+ } from './modules/cloud';
40
56
  export type {
41
57
  BasePlatformAccountInfo,
42
58
  CurrentUserAvatarConfig,
@@ -157,7 +173,7 @@ export type {
157
173
  ReloadResult,
158
174
  } from './modules/navigation';
159
175
 
160
- import { auth, device, navigation, network, off, on, ready, share, storage, ui, viewport, user } from './core/singleton';
176
+ import { auth, cloud, device, navigation, network, off, on, ready, share, storage, ui, viewport, user } from './core/singleton';
161
177
 
162
178
  const hbSDK = {
163
179
  ready,
@@ -172,6 +188,7 @@ const hbSDK = {
172
188
  ui,
173
189
  device,
174
190
  navigation,
191
+ cloud,
175
192
  };
176
193
 
177
194
  export default hbSDK;
@@ -543,6 +560,49 @@ const { data } = await storage.getStorage<{ theme: string }>({
543
560
 
544
561
  storage key 只允许 1-128 位字母、数字、下划线和连字符。父容器会按小程序维度隔离 key,外部小程序不能读写黑盒客户端全局 storage。
545
562
 
563
+ ### 云端排行榜
564
+
565
+ `cloud.leaderboard` 是平台托管的远端排行榜能力,不是本地 storage,也不是通用网络请求。小程序页面不能传 `userId`;宿主和服务端会按当前登录用户注入身份。
566
+
567
+ ```ts
568
+ import { cloud } from '@heybox/hb-sdk';
569
+
570
+ const entry = await cloud.leaderboard.submit({
571
+ key: 'cube_run_total',
572
+ score: 150,
573
+ extra: {
574
+ run: 2,
575
+ },
576
+ });
577
+
578
+ const list = await cloud.leaderboard.getList({
579
+ key: 'cube_run_total',
580
+ limit: 20,
581
+ });
582
+
583
+ const current = await cloud.leaderboard.getCurrentUserEntry({
584
+ key: 'cube_run_total',
585
+ });
586
+
587
+ await cloud.leaderboard.deleteCurrentUserEntry({
588
+ key: 'cube_run_total',
589
+ });
590
+
591
+ const info = await cloud.leaderboard.getInfo({
592
+ key: 'cube_run_total',
593
+ });
594
+ ```
595
+
596
+ 排行榜需要先通过管理端创建;管理端创建成功时服务端会同步准备记录集合,之后运行时可立即读写。`key` 不传时服务端会查找当前小程序已创建的 `default` 榜单,不存在时会拒绝请求,不会自动创建空榜。单个小程序最多创建 3 个排行榜,超出时服务端返回 `LEADERBOARD_LIMIT_EXCEEDED`。
597
+
598
+ `order` 在创建榜单时固定,`desc` 表示分数越大越靠前,`asc` 表示分数越小越靠前。同分时按更早更新时间优先,再按 `userId` 稳定排序。`rankLimit` 为 `0` 表示列表不限制展示名次;大于 `0` 时限制 `getList()` 展示范围。当前用户记录仍会保留,但 `submit()` 和 `getCurrentUserEntry()` 只精确计算前 5000 名,且会优先受 `rankLimit` 限制;超过 `min(rankLimit, 5000)`(`rankLimit=0` 时按 5000)时返回 `ranked: false`、`rank: 0`。
599
+
600
+ `submit()` 只在本次 `score` 更优时更新当前用户记录,并返回最终 `LeaderboardEntry`;如果分数不更优,`extra` 也不会更新。同一用户同一榜单的并发提交由服务端串行保护,锁冲突时返回 `LEADERBOARD_SUBMIT_LOCKED`,业务可稍后重试。首次提交未传 `extra` 会保存为空对象;已有记录提交更优分数但未传 `extra` 时会保留旧 `extra`,需要清空时请显式传 `{}`。`score` 必须是有限安全数字,绝对值不能超过 `Number.MAX_SAFE_INTEGER`;`extra` 必须是 JSON 对象,序列化后的 UTF-8 长度不能超过 2048 字节。
601
+
602
+ `getList()` 默认 20 条、最多 100 条;`cursor` 是服务端返回的不透明分页游标,只能把上一页返回的值原样传给下一次 `getList()`,不要解析、拼接或自行构造。非法 cursor 会按参数错误拒绝。服务端会短暂缓存榜单头部结果,当前缓存前 500 条或 `rankLimit` 范围内记录,`submit()`、`deleteCurrentUserEntry()` 和管理端删榜会触发缓存失效;业务不要依赖毫秒级实时刷新。`getInfo()` 返回 `key/order/rankLimit`,其中 `rankLimit` 不包含当前用户记录的 5000 名精确排名计算上限。
603
+
604
+ 排行榜后端错误会保留为 `HbMiniProgramSDKError.code`,常见值包括 `LEADERBOARD_DEFAULT_NOT_FOUND`、`LEADERBOARD_LIMIT_EXCEEDED`、`LEADERBOARD_SUBMIT_LOCKED`、`LEADERBOARD_TABLE_NOT_READY`、`InvalidArgument`、`NotFound`、`ResourceExhausted`、`Unauthenticated`。业务可以按 `code` 区分未建榜、并发提交、数据表配置异常、参数错误、容量限制和未登录等场景。
605
+
546
606
  ### 网络请求
547
607
 
548
608
  `network.request()` 提供窄化的 axios-like 接口。SDK 只接受公开请求字段,真实请求由父容器运行时映射到宿主网络能力。
@@ -580,7 +640,7 @@ await network.request({
580
640
 
581
641
  ## 生命周期事件
582
642
 
583
- 使用 `on()` 监听父容器派发的小程序事件。`on()` 会返回取消监听函数,组件卸载或页面销毁时应及时调用。
643
+ SDK 实例创建后会自动开始与父容器握手。使用 `on()` 监听父容器派发的小程序事件时,默认单例会被懒创建并自动开始握手;`on()` 会返回取消监听函数,组件卸载或页面销毁时应及时调用。
584
644
 
585
645
  ```ts
586
646
  import { on } from '@heybox/hb-sdk';
@@ -10,7 +10,7 @@
10
10
  - packages/hb-sdk/src/cli/commands/dev.ts
11
11
  - packages/hb-sdk/src/cli/commands/login.ts
12
12
  - packages/hb-sdk/src/cli/templates/vue3-vite-ts/README.md.ejs
13
- - apps/h5/docs/hb_sdk/src/guide/cli.md
13
+ - apps/docs/hb-sdk/guide/cli.md
14
14
  - packages/hb-sdk/README.md
15
15
 
16
16
  ## Contents
@@ -348,12 +348,12 @@ Agent rules:
348
348
  pnpm --filter @heybox/hb-sdk run test:unit
349
349
  pnpm --filter @heybox/hb-sdk run build:package
350
350
  pnpm --filter @heybox/hb-sdk run check:boundary
351
- pnpm --filter @heybox/hb-sdk run check:docs-sync
351
+ pnpm exec hbexec hb-sdk check
352
352
  ```
353
353
 
354
354
  `check:boundary` 用于保护 SDK、CLI、mock host 与 runtime 之间的依赖边界。调整 CLI、mock 或协议导出时应一起运行。
355
355
 
356
- `check:docs-sync` 用于校验 `README`、文档站 llms 镜像、skill references 与公开 `agent-skills` payload 没有漏同步。维护清单见 `packages/hb-sdk/DOC_SYNC_CHECKLIST.md`。
356
+ `hbexec hb-sdk check` 只读校验 docs、skill references,并在临时目录生成与校验 `agent-skills` payload;不要求 canonical artifact 已存在,也不包含 changelog。维护清单见 `packages/hb-sdk/DOC_SYNC_CHECKLIST.md`。
357
357
 
358
358
  ## Generated template README
359
359
 
@@ -5,7 +5,8 @@
5
5
  ## Sources
6
6
 
7
7
  - packages/hb-sdk/README.md
8
- - apps/h5/docs/hb_sdk/src/.vuepress/public/llms/
8
+ - apps/docs/hb-sdk/guide/**
9
+ - apps/docs/hb-sdk/recipes/**
9
10
  ## Positive examples
10
11
 
11
12
  ### Minimal user info
@@ -4,42 +4,21 @@
4
4
 
5
5
  ## Sources
6
6
 
7
- - apps/h5/docs/hb_sdk/src/.vuepress/public/llms.txt
8
- - apps/h5/docs/hb_sdk/src/.vuepress/public/llms/
9
- ## Local generated docs entrypoint
7
+ - apps/docs/hb-sdk/guide/**
8
+ - apps/docs/hb-sdk/recipes/**
9
+ - apps/docs/hb-sdk/reference/**
10
+ - packages/hb-sdk/src/**
11
+ ## Offline references
10
12
 
11
- The docs site maintains `llms.txt` and markdown mirrors under `apps/h5/docs/hb_sdk/src/.vuepress/public/llms/`. Read `llms.txt` first for navigation, then the specific guide/reference/recipe markdown needed for the task.
13
+ The bundled references are generated directly from hand-maintained docs, generated API owner sources, and SDK/CLI sources. They do not depend on the docs site's `.vitepress/public/llms` mirrors.
12
14
 
13
- ```md
14
- # @heybox/hb-sdk
15
- > LLM-friendly index for the `@heybox/hb-sdk` documentation site. API Reference is auto-generated from public exports and source comments; Guide and Recipes are hand-maintained.
16
- This site documents the iframe-side SDK for external mini programs. For AI retrieval, fetch this index first, then follow the linked markdown mirrors under `./llms/`.
17
- ## Docs
18
- - [Documentation home](./llms/README.md): 第一次接入时,按下面顺序读:
19
- - [Guide index](./llms/guide/README.md): Guide 面向第一次接入 `@heybox/hb-sdk` 的开发者,目标是先跑通,再理解边界。
20
- - [Reference index](./llms/reference/README.md): Reference 由 `packages/hb-sdk` 的公开导出与源码注释自动生成,不重复 Guide 的接入流程。
21
- - [Recipes index](./llms/recipes/README.md): Recipes 放可以直接复制到业务里的场景写法。它比 Guide 更具体,比 Reference 更偏组合使用。
22
- - [LLM usage guide](./llms/guide/llms.md): 文档站会自动维护一份标准的 `llms.txt` 索引,以及一组给 AI 直接读取的 Markdown 镜像页,方便模型按文档树逐步抓取内容。
23
- ## API Reference
24
- - [Root API](./llms/reference/root/README.md): 该页面收录从 `src/index.ts` 公开导出的 API。
25
- - [Protocol API](./llms/reference/protocol/README.md): 该页面收录从 `src/protocol.ts` 公开导出的 API。
26
- - [Root functions](./llms/reference/root/functions/README.md)
27
- - [Root interfaces](./llms/reference/root/interfaces/README.md): `on/off` 会基于该映射推导 handler 参数类型。 |
28
- - [Protocol interfaces](./llms/reference/protocol/interfaces/README.md): 所有请求失败都会被规范化成该结构,SDK 侧再包装为 `HbMiniProgramSDKError`。 |
29
- - [Root types](./llms/reference/root/types/README.md): `navigation.close` 不需要入参。
30
- - [Protocol types](./llms/reference/protocol/types/README.md): `navigation.close` 不需要入参。
31
- ## Guides
32
- - [Agent Skill 安装](./llms/guide/agent-skill.md): `hb-sdk` Agent Skill 用来让 AI / Agent 按本仓库约定使用 `@heybox/hb-sdk` 和配套 `hb-sdk` CLI,包括 iframe 小程序接入、`ready`、用户信息、登录、事件、CLI 创建模板、`hb-sdk dev` 本地调试、CLI 登录态、协议边界和常见错误处理。
33
- - [用户与登录](./llms/guide/auth.md): 用户与授权模块当前分工:
34
- - [CLI 与本地 mock 调试](./llms/guide/cli.md): `@heybox/hb-sdk` 同时提供 iframe 内使用的 SDK 和配套 `hb-sdk` CLI。CLI 负责项目模板、本地 Vite 服务、浏览器 mock runtime host 和 CLI 自己的 Heybox 登录缓存;它不是 iframe SDK 登录态的替代品。
35
- - [错误处理](./llms/guide/error-handling.md): SDK 对外抛出的标准错误类型是 `HbMiniProgramSDKError`。
36
- - [安装与运行环境](./llms/guide/installation.md): 如果工坊小程序只是普通展示页面,不调用黑盒开放能力,也不监听 SDK 生命周期事件,可以不安装、不引用、不初始化 `@heybox/hb-sdk`。父容器仍可能在 URL 上注入 `hb_mini_bridge_nonce`,业务页可以直接忽略。
37
- - [事件与生命周期](./llms/guide/lifecycle.md): SDK 通过 `on` 监听父容器派发的小程序生命周期和业务事件。
38
- - [小程序工坊上架规则 v2(试行)](./llms/guide/mini-program-publishing-rules.md): 本规则用于说明小程序工坊的小程序发布、上架和持续在线要求。通过审核不等于获得推荐或公开展示;工坊广场、推荐位、搜索等流量分发规则另行制定。
39
- - [快速开始](./llms/guide/quick-start.md): 如果页面不需要黑盒开放能力,可以不接入 SDK。这是一条需要用户能力时的最短接入路径:等待 SDK 完成握手,然后读取当前用户登录态。
40
- ## Recipes
41
- - [独立 SDK 实例](./llms/recipes/custom-instance.md): 大多数业务页使用默认单例即可。只有在需要隔离上下文时,再创建独立实例。
42
- - [登录门禁](./llms/recipes/login-gate.md): 当业务动作必须登录后才能继续时,可以把登录态判断收敛成 `ensureLogin`。
43
- ## Optional
44
- - Full markdown mirrors for the docs site are available under `./llms/guide/`, `./llms/reference/`, and `./llms/recipes/`.
45
- ```
15
+ - Root SDK and Vite API: `references/api-root.md`
16
+ - Host/runtime protocol API: `references/api-protocol.md`
17
+ - CLI and local development: `references/cli.md`
18
+ - Common flows: `references/recipes.md`
19
+ - Security and capability limits: `references/safety-boundaries.md`
20
+ - Examples and evaluation: `references/examples.md`, `references/smoke-evaluation.md`
21
+
22
+ ## Online supplement
23
+
24
+ Online `llms.txt` and markdown mirrors are optional supplements, not prerequisites for offline Skill use. Their canonical public URL is not frozen: on 2026-07-10 `https://docs.xiaoheihe.cn/hb_sdk/llms.txt` returned 404 and the legacy URL fetch timed out. Do not claim either endpoint is available without a fresh successful response.
@@ -4,12 +4,12 @@
4
4
 
5
5
  ## Sources
6
6
 
7
- - apps/h5/docs/hb_sdk/src/.vuepress/public/llms/guide/quick-start.md
8
- - apps/h5/docs/hb_sdk/src/.vuepress/public/llms/guide/auth.md
9
- - apps/h5/docs/hb_sdk/src/.vuepress/public/llms/guide/lifecycle.md
10
- - apps/h5/docs/hb_sdk/src/.vuepress/public/llms/guide/error-handling.md
11
- - apps/h5/docs/hb_sdk/src/.vuepress/public/llms/recipes/login-gate.md
12
- - apps/h5/docs/hb_sdk/src/.vuepress/public/llms/recipes/custom-instance.md
7
+ - apps/docs/hb-sdk/guide/quick-start.md
8
+ - apps/docs/hb-sdk/guide/auth.md
9
+ - apps/docs/hb-sdk/guide/lifecycle.md
10
+ - apps/docs/hb-sdk/guide/error-handling.md
11
+ - apps/docs/hb-sdk/recipes/login-gate.md
12
+ - apps/docs/hb-sdk/recipes/custom-instance.md
13
13
 
14
14
  ## Contents
15
15
 
@@ -76,7 +76,7 @@ stopAuthChange()
76
76
 
77
77
  默认单例适合一个页面只有一个 SDK 上下文的情况。大多数小程序页面都应该使用默认单例,因为它可以避免重复握手和重复维护事件监听。
78
78
 
79
- 需要控制 `timeout`、注入测试 window 或隔离多个上下文时,再使用 [独立实例](../recipes/custom-instance.md)。
79
+ 需要控制 `timeout`、注入测试 window 或隔离多个上下文时,再使用 [独立实例](../recipes/custom-instance)。
80
80
 
81
81
  ## User and login
82
82
 
@@ -193,8 +193,8 @@ stop()
193
193
 
194
194
  完整载荷与事件名见:
195
195
 
196
- - [MiniProgramEventPayloadMap](../reference/protocol/interfaces/MiniProgramEventPayloadMap.md)
197
- - [MiniProgramEventName](../reference/protocol/types/README.md#miniprogrameventname)
196
+ - [MiniProgramEventPayloadMap](../reference/protocol/interfaces/MiniProgramEventPayloadMap)
197
+ - [MiniProgramEventName](../reference/protocol/types/#miniprogrameventname)
198
198
 
199
199
  ## 生命周期建议
200
200
 
@@ -5,12 +5,13 @@
5
5
  ## Sources
6
6
 
7
7
  - packages/hb-sdk/README.md
8
- - apps/h5/docs/hb_sdk/src/.vuepress/public/llms/guide/auth.md
8
+ - apps/docs/hb-sdk/guide/auth.md
9
9
  ## Required boundaries
10
10
 
11
11
  ## 能力边界
12
12
 
13
- - 调用模块能力前会自动等待 `ready()`,但业务仍建议在页面启动阶段显式 `await ready()`,便于集中处理握手失败。
13
+ - SDK 实例创建后会自动开始握手;默认单例仍按需懒创建,`ready()`、`on()` 或任意模块能力调用都会创建默认单例并开始握手。
14
+ - `ready()` 只等待已有握手结果,不主动触发新的握手;调用模块能力前会自动等待 `ready()`,但业务仍建议在页面启动阶段显式 `await ready()`,便于集中处理握手失败。
14
15
  - `user.getInfo()`、`user.getCurrentUserDetail()`、`user.getCurrentUserProfile()`、`user.getPlatformAccountOverview()`、`user.getPlatformAccountInfo(platform)` 和 `user.getSteamGameList(options)` 不会触发登录;登录必须由业务在用户操作后调用 `auth.login()`。
15
16
  - 当前用户详情和平台账号 API 只允许读取当前登录用户,不支持传入 `userid` 查询其他人,也不透传 `/account/home_v2/` 原始响应。
16
17
  - 分享、截图、UI、设备、导航、storage 和网络请求只开放稳定窄接口,不透传黑盒客户端内部协议参数。
@@ -177,16 +177,14 @@ const viteEntry = read('packages/hb-sdk/src/vite/index.ts');
177
177
  const cliEntry = read('packages/hb-sdk/src/cli/index.ts');
178
178
  const cliTemplateReadme = read('packages/hb-sdk/src/cli/templates/vue3-vite-ts/README.md.ejs');
179
179
  const readme = read('packages/hb-sdk/README.md');
180
- const cliGuide = frontmatterless(read('apps/h5/docs/hb_sdk/src/guide/cli.md'));
181
- const llmsTxt = read('apps/h5/docs/hb_sdk/src/.vuepress/public/llms.txt');
182
- const quickStart = frontmatterless(read('apps/h5/docs/hb_sdk/src/.vuepress/public/llms/guide/quick-start.md'));
183
- const authGuide = frontmatterless(read('apps/h5/docs/hb_sdk/src/.vuepress/public/llms/guide/auth.md'));
184
- const lifecycleGuide = frontmatterless(read('apps/h5/docs/hb_sdk/src/.vuepress/public/llms/guide/lifecycle.md'));
185
- const errorGuide = frontmatterless(read('apps/h5/docs/hb_sdk/src/.vuepress/public/llms/guide/error-handling.md'));
186
- const loginGate = frontmatterless(read('apps/h5/docs/hb_sdk/src/.vuepress/public/llms/recipes/login-gate.md'));
187
- const customInstance = frontmatterless(read('apps/h5/docs/hb_sdk/src/.vuepress/public/llms/recipes/custom-instance.md'));
188
- const referenceHome = frontmatterless(read('apps/h5/docs/hb_sdk/src/.vuepress/public/llms/reference/README.md'));
189
-
180
+ const cliGuide = frontmatterless(read('apps/docs/hb-sdk/guide/cli.md'));
181
+ const quickStart = frontmatterless(read('apps/docs/hb-sdk/guide/quick-start.md'));
182
+ const authGuide = frontmatterless(read('apps/docs/hb-sdk/guide/auth.md'));
183
+ const lifecycleGuide = frontmatterless(read('apps/docs/hb-sdk/guide/lifecycle.md'));
184
+ const errorGuide = frontmatterless(read('apps/docs/hb-sdk/guide/error-handling.md'));
185
+ const loginGate = frontmatterless(read('apps/docs/hb-sdk/recipes/login-gate.md'));
186
+ const customInstance = frontmatterless(read('apps/docs/hb-sdk/recipes/custom-instance.md'));
187
+ const referenceHome = frontmatterless(read('apps/docs/hb-sdk/reference/index.md'));
190
188
  const quickStartSection = extractSection(readme, '## 快速开始');
191
189
  const runtimeEnvironment = extractSection(readme, '## 运行环境');
192
190
  const publicCapabilities = extractSection(readme, '## 常用能力');
@@ -300,7 +298,7 @@ ${lifecycleEvents}
300
298
  files.set('api-protocol.md', `${header('Protocol API reference', [
301
299
  'packages/hb-sdk/src/protocol.ts',
302
300
  'packages/hb-sdk/README.md',
303
- 'apps/h5/docs/hb_sdk/src/.vuepress/public/llms/reference/README.md',
301
+ 'apps/docs/hb-sdk/reference/index.md',
304
302
  ])}${contents([
305
303
  ['Host/runtime-only warning', 'hostruntime-only-warning'],
306
304
  ['Public protocol entrypoint', 'public-protocol-entrypoint'],
@@ -330,7 +328,7 @@ files.set('cli.md', `${header('CLI reference', [
330
328
  'packages/hb-sdk/src/cli/commands/dev.ts',
331
329
  'packages/hb-sdk/src/cli/commands/login.ts',
332
330
  'packages/hb-sdk/src/cli/templates/vue3-vite-ts/README.md.ejs',
333
- 'apps/h5/docs/hb_sdk/src/guide/cli.md',
331
+ 'apps/docs/hb-sdk/guide/cli.md',
334
332
  'packages/hb-sdk/README.md',
335
333
  ])}${contents([
336
334
  ['When to use the CLI', 'when-to-use-the-cli'],
@@ -463,12 +461,12 @@ ${fenced('md', cliTemplateReadme)}
463
461
  `);
464
462
 
465
463
  files.set('recipes.md', `${header('Recipes', [
466
- 'apps/h5/docs/hb_sdk/src/.vuepress/public/llms/guide/quick-start.md',
467
- 'apps/h5/docs/hb_sdk/src/.vuepress/public/llms/guide/auth.md',
468
- 'apps/h5/docs/hb_sdk/src/.vuepress/public/llms/guide/lifecycle.md',
469
- 'apps/h5/docs/hb_sdk/src/.vuepress/public/llms/guide/error-handling.md',
470
- 'apps/h5/docs/hb_sdk/src/.vuepress/public/llms/recipes/login-gate.md',
471
- 'apps/h5/docs/hb_sdk/src/.vuepress/public/llms/recipes/custom-instance.md',
464
+ 'apps/docs/hb-sdk/guide/quick-start.md',
465
+ 'apps/docs/hb-sdk/guide/auth.md',
466
+ 'apps/docs/hb-sdk/guide/lifecycle.md',
467
+ 'apps/docs/hb-sdk/guide/error-handling.md',
468
+ 'apps/docs/hb-sdk/recipes/login-gate.md',
469
+ 'apps/docs/hb-sdk/recipes/custom-instance.md',
472
470
  ])}${contents([
473
471
  ['Quick start', 'quick-start'],
474
472
  ['User and login', 'user-and-login'],
@@ -503,7 +501,7 @@ ${customInstance}
503
501
 
504
502
  files.set('safety-boundaries.md', `${header('Safety boundaries', [
505
503
  'packages/hb-sdk/README.md',
506
- 'apps/h5/docs/hb_sdk/src/.vuepress/public/llms/guide/auth.md',
504
+ 'apps/docs/hb-sdk/guide/auth.md',
507
505
  ])}## Required boundaries
508
506
 
509
507
  ${capabilityBoundaries}
@@ -521,18 +519,30 @@ ${capabilityBoundaries}
521
519
  `);
522
520
 
523
521
  files.set('llms-index.md', `${header('LLM documentation index', [
524
- 'apps/h5/docs/hb_sdk/src/.vuepress/public/llms.txt',
525
- 'apps/h5/docs/hb_sdk/src/.vuepress/public/llms/',
526
- ])}## Local generated docs entrypoint
522
+ 'apps/docs/hb-sdk/guide/**',
523
+ 'apps/docs/hb-sdk/recipes/**',
524
+ 'apps/docs/hb-sdk/reference/**',
525
+ 'packages/hb-sdk/src/**',
526
+ ])}## Offline references
527
+
528
+ The bundled references are generated directly from hand-maintained docs, generated API owner sources, and SDK/CLI sources. They do not depend on the docs site's \`.vitepress/public/llms\` mirrors.
529
+
530
+ - Root SDK and Vite API: \`references/api-root.md\`
531
+ - Host/runtime protocol API: \`references/api-protocol.md\`
532
+ - CLI and local development: \`references/cli.md\`
533
+ - Common flows: \`references/recipes.md\`
534
+ - Security and capability limits: \`references/safety-boundaries.md\`
535
+ - Examples and evaluation: \`references/examples.md\`, \`references/smoke-evaluation.md\`
527
536
 
528
- The docs site maintains \`llms.txt\` and markdown mirrors under \`apps/h5/docs/hb_sdk/src/.vuepress/public/llms/\`. Read \`llms.txt\` first for navigation, then the specific guide/reference/recipe markdown needed for the task.
537
+ ## Online supplement
529
538
 
530
- ${fenced('md', llmsTxt)}
539
+ Online \`llms.txt\` and markdown mirrors are optional supplements, not prerequisites for offline Skill use. Their canonical public URL is not frozen: on 2026-07-10 \`https://docs.xiaoheihe.cn/hb_sdk/llms.txt\` returned 404 and the legacy URL fetch timed out. Do not claim either endpoint is available without a fresh successful response.
531
540
  `);
532
541
 
533
542
  files.set('examples.md', `${header('Smoke examples and anti-examples', [
534
543
  'packages/hb-sdk/README.md',
535
- 'apps/h5/docs/hb_sdk/src/.vuepress/public/llms/',
544
+ 'apps/docs/hb-sdk/guide/**',
545
+ 'apps/docs/hb-sdk/recipes/**',
536
546
  ])}## Positive examples
537
547
 
538
548
  ### Minimal user info
package/skill/skill.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "hb-sdk",
3
- "skillVersion": "0.5.9+skill.02be68ce07ce",
3
+ "skillVersion": "0.5.11+skill.c0b2205c74df",
4
4
  "sdk": {
5
5
  "package": "@heybox/hb-sdk",
6
- "version": "0.5.9",
7
- "compatibility": "0.5.9"
6
+ "version": "0.5.11",
7
+ "compatibility": "0.5.11"
8
8
  },
9
9
  "source": "https://open.xiaoheihe.cn/agent-skills/hb-sdk",
10
- "integrity": "sha256-02be68ce07ce1cf0ecba354d764a47977e4fc3c189b5e4aed3cee1f844fddfd4"
10
+ "integrity": "sha256-c0b2205c74df6a619a08d4f9a974d89a796d1783cc30a1d698d875bd179fd8c3"
11
11
  }
@@ -18,7 +18,7 @@ export interface MiniProgramSDKOptions {
18
18
  /** 精准 postMessage 目标 origin;未传时尝试推断,失败则回退为 `*`。 */
19
19
  targetOrigin?: string;
20
20
  }
21
- type MiniProgramRequesterArgs<Method extends MiniProgramBridgeMethod> = MiniProgramCapabilityPayload<Method> extends void ? [payload?: MiniProgramCapabilityPayload<Method>] : [payload: MiniProgramCapabilityPayload<Method>];
21
+ type MiniProgramRequesterArgs<Method extends MiniProgramBridgeMethod> = MiniProgramCapabilityPayload<Method> extends void ? [payload?: MiniProgramCapabilityPayload<Method>] : undefined extends MiniProgramCapabilityPayload<Method> ? [payload?: MiniProgramCapabilityPayload<Method>] : [payload: MiniProgramCapabilityPayload<Method>];
22
22
  /** 模块 API 发起请求所需的最小能力。 */
23
23
  export interface MiniProgramRequester {
24
24
  /** 向父容器调用指定开放能力。 */
@@ -42,6 +42,8 @@ export declare class MiniProgramBridgeClient implements MiniProgramRequester {
42
42
  private readyTimer?;
43
43
  private handshakeRetryTimer?;
44
44
  private destroyed;
45
+ private runtimeUnavailable;
46
+ private runtimeUnavailableError?;
45
47
  constructor(options?: MiniProgramSDKOptions);
46
48
  /** 等待父容器握手完成。 */
47
49
  ready(): Promise<void>;
@@ -62,6 +64,8 @@ export declare class MiniProgramBridgeClient implements MiniProgramRequester {
62
64
  private resolveReadyOnce;
63
65
  private failReady;
64
66
  private clearReadyTimers;
67
+ private markRuntimeUnavailable;
68
+ private getRuntimeUnavailableError;
65
69
  private rejectAllPending;
66
70
  }
67
71
  export {};
@@ -1,5 +1,6 @@
1
1
  import { type MiniProgramSDKOptions } from './client';
2
2
  import { type MiniProgramAuthModule } from '../modules/auth';
3
+ import { type MiniProgramCloudModule } from '../modules/cloud';
3
4
  import { type MiniProgramShareModule } from '../modules/share';
4
5
  import { type MiniProgramStorageModule } from '../modules/storage';
5
6
  import { type MiniProgramNetworkModule } from '../modules/network';
@@ -50,6 +51,8 @@ export declare class MiniProgramSDK {
50
51
  readonly device: MiniProgramDeviceModule;
51
52
  /** 导航与容器控制相关开放能力。 */
52
53
  readonly navigation: MiniProgramNavigationModule;
54
+ /** 云端数据相关开放能力。 */
55
+ readonly cloud: MiniProgramCloudModule;
53
56
  constructor(options?: MiniProgramSDKOptions);
54
57
  /**
55
58
  * 等待 SDK 与父容器完成握手。
@@ -1,4 +1,5 @@
1
1
  import type { MiniProgramAuthModule } from '../modules/auth';
2
+ import type { MiniProgramCloudModule } from '../modules/cloud';
2
3
  import type { MiniProgramShareModule } from '../modules/share';
3
4
  import type { MiniProgramStorageModule } from '../modules/storage';
4
5
  import type { MiniProgramNetworkModule } from '../modules/network';
@@ -49,5 +50,7 @@ export declare const ui: MiniProgramUiModule;
49
50
  export declare const device: MiniProgramDeviceModule;
50
51
  /** 默认 SDK 实例的 navigation 模块。 */
51
52
  export declare const navigation: MiniProgramNavigationModule;
53
+ /** 默认 SDK 实例的 cloud 模块。 */
54
+ export declare const cloud: MiniProgramCloudModule;
52
55
  /** 重置默认 SDK 实例,仅用于测试。 */
53
56
  export declare function resetDefaultSDKForTest(): void;
package/types/index.d.ts CHANGED
@@ -1,9 +1,10 @@
1
1
  export { createMiniProgramSDK, MiniProgramSDK } from './core/sdk';
2
2
  export { HbMiniProgramSDKError, HbMiniProgramNetworkError } from './core/errors';
3
3
  export type { MiniProgramSDKOptions } from './core/client';
4
- export { ready, on, off, auth, user, share, viewport, storage, network, ui, device, navigation } from './core/singleton';
4
+ export { ready, on, off, auth, user, share, viewport, storage, network, ui, device, navigation, cloud } from './core/singleton';
5
5
  export type { MiniProgramEventHandler, MiniProgramEventName, MiniProgramEventPayloadMap, } from './protocol/types';
6
6
  export type { LoginPayload, LoginResult, MiniProgramAuthModule } from './modules/auth';
7
+ export type { DeleteCurrentUserLeaderboardEntryPayload, DeleteCurrentUserLeaderboardEntryResult, GetCurrentUserLeaderboardEntryPayload, GetCurrentUserLeaderboardEntryResult, GetLeaderboardInfoPayload, GetLeaderboardInfoResult, GetLeaderboardListPayload, GetLeaderboardListResult, LeaderboardEntry, LeaderboardOrder, MiniProgramCloudLeaderboardModule, MiniProgramCloudModule, SubmitLeaderboardEntryPayload, SubmitLeaderboardEntryResult, } from './modules/cloud';
7
8
  export type { BasePlatformAccountInfo, CurrentUserAvatarConfig, CurrentUserAvatarDecoration, CurrentUserBbsInfo, CurrentUserDetail, CurrentUserLevelInfo, CurrentUserMedal, CurrentUserProfile, EpicPlatformAccountInfo, GetCurrentUserDetailPayload, GetCurrentUserDetailResult, GetCurrentUserProfilePayload, GetCurrentUserProfileResult, GetPlatformAccountInfoPayload, GetPlatformAccountInfoResult, GetPlatformAccountOverviewPayload, GetPlatformAccountOverviewResult, GetSteamGameListOptions, GetSteamGameListPayload, GetSteamGameListResult, GetUserInfoPayload, GetUserInfoResult, MiniProgramUserInfo, MiniProgramUserInfoResult, MiniProgramUserModule, MobilePlatformAccountInfo, PcHardwareAccountInfo, PlatformAccountInfoMap, PlatformAccountOverview, PlatformAccountResult, PlatformAccountType, PlatformStatItem, PsnPlatformAccountInfo, SteamGameListData, SteamGameListItem, SteamGameListSort, SteamGamePrice, SteamPlatformAccountInfo, SwitchPlatformAccountInfo, UserScopedResult, XboxPlatformAccountInfo, } from './modules/user';
8
9
  export type { MiniProgramScreenshotOptions, MiniProgramScreenshotRect, MiniProgramShareChannel, MiniProgramShareModule, MiniProgramShowShareMenuOptions, ScreenshotPayload, ScreenshotResult, ShowShareMenuPayload, ShowShareMenuResult, } from './modules/share';
9
10
  export type { GetWindowInfoPayload, GetWindowInfoResult, MiniProgramNavigationBarForegroundStyle, MiniProgramSafeArea, MiniProgramSetNavigationBarStyleOptions, MiniProgramViewportModule, MiniProgramWindowInfoResult, SetNavigationBarStylePayload, SetNavigationBarStyleResult, } from './modules/viewport';
@@ -26,5 +27,6 @@ declare const hbSDK: {
26
27
  ui: import(".").MiniProgramUiModule;
27
28
  device: import(".").MiniProgramDeviceModule;
28
29
  navigation: import(".").MiniProgramNavigationModule;
30
+ cloud: import(".").MiniProgramCloudModule;
29
31
  };
30
32
  export default hbSDK;
@@ -10,6 +10,10 @@ export declare const CREATE_USER_MINIPROGRAM_API_PATH = "/mall/developer/user_mi
10
10
  export declare const DETAIL_USER_MINIPROGRAM_API_PATH = "/mall/developer/user_miniprogram/detail";
11
11
  export declare const USER_MINIPROGRAM_PREVIEW_ALLOWLIST_API_PATH = "/mall/developer/user_miniprogram/preview_allowlist";
12
12
  export declare const UPDATE_USER_MINIPROGRAM_PREVIEW_ALLOWLIST_API_PATH = "/mall/developer/user_miniprogram/preview_allowlist/update";
13
+ export declare const CREATE_USER_MINIPROGRAM_LEADERBOARD_API_PATH = "/mall/developer/user_miniprogram/leaderboard/create";
14
+ export declare const DETAIL_USER_MINIPROGRAM_LEADERBOARD_API_PATH = "/mall/developer/user_miniprogram/leaderboard/detail";
15
+ export declare const LIST_USER_MINIPROGRAM_LEADERBOARD_API_PATH = "/mall/developer/user_miniprogram/leaderboard/list";
16
+ export declare const DELETE_USER_MINIPROGRAM_LEADERBOARD_API_PATH = "/mall/developer/user_miniprogram/leaderboard/delete";
13
17
  export declare const PRECHECK_USER_MINIPROGRAM_VERSION_API_PATH = "/mall/developer/user_miniprogram/version/precheck";
14
18
  export declare const SUBMIT_USER_MINIPROGRAM_AUDIT_API_PATH = "/mall/developer/user_miniprogram/version/submit_audit";
15
19
  export declare const USER_MINIPROGRAM_VERSION_PREVIEW_INFO_API_PATH = "/mall/developer/user_miniprogram/version/preview_info";
@@ -0,0 +1,100 @@
1
+ import type { MiniProgramRequester } from '../../core/client';
2
+ export { CLOUD_LEADERBOARD_DELETE_CURRENT_USER_ENTRY_METHOD, CLOUD_LEADERBOARD_GET_CURRENT_USER_ENTRY_METHOD, CLOUD_LEADERBOARD_GET_INFO_METHOD, CLOUD_LEADERBOARD_GET_LIST_METHOD, CLOUD_LEADERBOARD_SUBMIT_METHOD, } from '../../protocol/capabilities';
3
+ /** 排行榜排序方向。 */
4
+ export type LeaderboardOrder = 'asc' | 'desc';
5
+ /** 排行榜记录。 */
6
+ export interface LeaderboardEntry {
7
+ /** 排名;未进入展示范围或超出当前用户排名计算上限时为 0。 */
8
+ rank: number;
9
+ /** 是否进入展示范围并位于当前用户排名计算上限内。 */
10
+ ranked: boolean;
11
+ /** 当前记录所属用户 ID,由平台注入,前端不能传入。 */
12
+ userId: string;
13
+ /** 分数,排行榜唯一排序字段。 */
14
+ score: number;
15
+ /** 展示附加信息,不参与排序和查询。 */
16
+ extra: Record<string, unknown>;
17
+ /** 记录创建时间,秒级时间戳。 */
18
+ createdAt: number;
19
+ /** 记录更新时间,秒级时间戳。 */
20
+ updatedAt: number;
21
+ }
22
+ /** 提交当前用户排行榜分数。 */
23
+ export interface SubmitLeaderboardEntryPayload {
24
+ /** 排行榜 key;不传时由服务端使用当前小程序已创建的 default 榜单。 */
25
+ key?: string;
26
+ /** 本次提交分数,必须是有限安全数字,范围不超过 JavaScript safe number。 */
27
+ score: number;
28
+ /** 展示附加信息,不参与排序和查询;已有记录更新为更优分数时不传则保留旧值,序列化后不超过 2048 字节。 */
29
+ extra?: Record<string, unknown>;
30
+ }
31
+ /** 提交排行榜分数后返回的当前用户最终记录。 */
32
+ export type SubmitLeaderboardEntryResult = LeaderboardEntry;
33
+ /** 读取排行榜列表。 */
34
+ export interface GetLeaderboardListPayload {
35
+ /** 排行榜 key;不传时由服务端使用当前小程序已创建的 default 榜单。 */
36
+ key?: string;
37
+ /** 每页数量,默认 20,最大 100。 */
38
+ limit?: number;
39
+ /** 服务端返回的不透明分页游标;只能原样传回下一页,不能自行构造或解析。 */
40
+ cursor?: string;
41
+ }
42
+ /** 读取排行榜列表的分页结果。 */
43
+ export interface GetLeaderboardListResult {
44
+ /** 当前页排行榜记录。 */
45
+ entries: LeaderboardEntry[];
46
+ /** 下一页不透明分页游标;仅当 hasMore 为 true 时可能返回。 */
47
+ cursor?: string;
48
+ /** 是否还有下一页。 */
49
+ hasMore: boolean;
50
+ }
51
+ /** 读取当前用户在排行榜中的记录。 */
52
+ export interface GetCurrentUserLeaderboardEntryPayload {
53
+ /** 排行榜 key;不传时由服务端使用当前小程序已创建的 default 榜单。 */
54
+ key?: string;
55
+ }
56
+ /** 当前用户排行榜记录;不存在时返回 undefined。 */
57
+ export type GetCurrentUserLeaderboardEntryResult = LeaderboardEntry | undefined;
58
+ /** 删除当前用户在排行榜中的记录。 */
59
+ export interface DeleteCurrentUserLeaderboardEntryPayload {
60
+ /** 排行榜 key;不传时由服务端使用当前小程序已创建的 default 榜单。 */
61
+ key?: string;
62
+ }
63
+ /** 删除当前用户排行榜记录的结果。 */
64
+ export interface DeleteCurrentUserLeaderboardEntryResult {
65
+ /** 是否实际删除了已有记录。 */
66
+ deleted: boolean;
67
+ }
68
+ /** 读取排行榜基础信息。 */
69
+ export interface GetLeaderboardInfoPayload {
70
+ /** 排行榜 key;不传时由服务端使用当前小程序已创建的 default 榜单。 */
71
+ key?: string;
72
+ }
73
+ /** 排行榜基础配置。 */
74
+ export interface GetLeaderboardInfoResult {
75
+ /** 排行榜 key。 */
76
+ key: string;
77
+ /** 排行榜排序方向。 */
78
+ order: LeaderboardOrder;
79
+ /** 列表展示名次上限;0 表示不限制。当前用户记录仍最多精确计算前 5000 名。 */
80
+ rankLimit: number;
81
+ }
82
+ /** 外部小程序可调用的云端排行榜模块。 */
83
+ export interface MiniProgramCloudLeaderboardModule {
84
+ /** 提交当前用户分数。 */
85
+ submit(options: SubmitLeaderboardEntryPayload): Promise<SubmitLeaderboardEntryResult>;
86
+ /** 读取排行榜列表。 */
87
+ getList(options?: GetLeaderboardListPayload): Promise<GetLeaderboardListResult>;
88
+ /** 读取当前用户记录。 */
89
+ getCurrentUserEntry(options?: GetCurrentUserLeaderboardEntryPayload): Promise<GetCurrentUserLeaderboardEntryResult>;
90
+ /** 删除当前用户记录。 */
91
+ deleteCurrentUserEntry(options?: DeleteCurrentUserLeaderboardEntryPayload): Promise<DeleteCurrentUserLeaderboardEntryResult>;
92
+ /** 读取排行榜基础信息。 */
93
+ getInfo(options?: GetLeaderboardInfoPayload): Promise<GetLeaderboardInfoResult>;
94
+ }
95
+ /** 外部小程序可调用的云端能力模块。 */
96
+ export interface MiniProgramCloudModule {
97
+ leaderboard: MiniProgramCloudLeaderboardModule;
98
+ }
99
+ export type { MiniProgramCloudMethod } from '../../protocol/capabilities';
100
+ export declare function createCloudModule(requester: MiniProgramRequester): MiniProgramCloudModule;