@heybox/hb-sdk 0.1.3 → 0.2.0-alpha.1

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 (67) hide show
  1. package/README.md +149 -345
  2. package/bin/hb-sdk.cjs +3 -0
  3. package/dist/cli.cjs +10117 -0
  4. package/dist/devtools/mock-host/index.html +252 -0
  5. package/dist/devtools/mock-host/main.js +975 -0
  6. package/dist/index.cjs.js +474 -85
  7. package/dist/index.esm.js +465 -71
  8. package/dist/protocol.cjs.js +163 -0
  9. package/dist/protocol.esm.js +148 -0
  10. package/dist/templates/vue3-vite-ts/.gitignore.ejs +5 -0
  11. package/dist/templates/vue3-vite-ts/README.md.ejs +42 -0
  12. package/dist/templates/vue3-vite-ts/index.html.ejs +12 -0
  13. package/dist/templates/vue3-vite-ts/package.json.ejs +28 -0
  14. package/dist/templates/vue3-vite-ts/src/App.vue +63 -0
  15. package/dist/templates/vue3-vite-ts/src/__tests__/App.spec.ts +67 -0
  16. package/dist/templates/vue3-vite-ts/src/main.ts +5 -0
  17. package/dist/templates/vue3-vite-ts/src/styles.css +60 -0
  18. package/dist/templates/vue3-vite-ts/src/vite-env.d.ts +1 -0
  19. package/dist/templates/vue3-vite-ts/tsconfig.app.json +17 -0
  20. package/dist/templates/vue3-vite-ts/tsconfig.json +11 -0
  21. package/dist/templates/vue3-vite-ts/tsconfig.node.json +11 -0
  22. package/dist/templates/vue3-vite-ts/vite.config.ts +6 -0
  23. package/dist/templates/vue3-vite-ts/vitest.config.ts +10 -0
  24. package/package.json +30 -5
  25. package/skill/SKILL.md +95 -0
  26. package/skill/references/api-protocol.md +135 -0
  27. package/skill/references/api-root.md +346 -0
  28. package/skill/references/cli.md +360 -0
  29. package/skill/references/examples.md +107 -0
  30. package/skill/references/llms-index.md +44 -0
  31. package/skill/references/recipes.md +374 -0
  32. package/skill/references/safety-boundaries.md +28 -0
  33. package/skill/references/smoke-evaluation.md +24 -0
  34. package/skill/scripts/check-references.mjs +14 -0
  35. package/skill/scripts/package-skill.mjs +60 -0
  36. package/skill/scripts/package-skill.sh +6 -0
  37. package/skill/scripts/skill-metadata.mjs +74 -0
  38. package/skill/scripts/sync-references.mjs +541 -0
  39. package/skill/scripts/validate-skill.mjs +233 -0
  40. package/skill/skill.json +11 -0
  41. package/types/core/client.d.ts +23 -3
  42. package/types/core/errors.d.ts +45 -2
  43. package/types/core/sdk.d.ts +78 -10
  44. package/types/core/singleton.d.ts +33 -7
  45. package/types/core/utils.d.ts +2 -0
  46. package/types/index.d.ts +14 -6
  47. package/types/modules/auth/index.d.ts +35 -0
  48. package/types/modules/network/index.d.ts +120 -0
  49. package/types/modules/share/index.d.ts +9 -5
  50. package/types/modules/share/screenshot.d.ts +9 -3
  51. package/types/modules/share/show-share-menu.d.ts +9 -3
  52. package/types/modules/share/types.d.ts +24 -4
  53. package/types/modules/storage/index.d.ts +56 -0
  54. package/types/modules/user/get-info.d.ts +6 -2
  55. package/types/modules/user/index.d.ts +8 -10
  56. package/types/modules/user/types.d.ts +1 -0
  57. package/types/modules/viewport/index.d.ts +71 -0
  58. package/types/protocol/capabilities.d.ts +180 -0
  59. package/types/protocol/guards.d.ts +6 -1
  60. package/types/protocol/types.d.ts +19 -4
  61. package/types/protocol.d.ts +13 -0
  62. package/types/modules/system/get-storage.d.ts +0 -15
  63. package/types/modules/system/get-window-info.d.ts +0 -16
  64. package/types/modules/system/index.d.ts +0 -23
  65. package/types/modules/system/set-storage.d.ts +0 -12
  66. package/types/modules/system/types.d.ts +0 -34
  67. package/types/modules/user/login.d.ts +0 -18
@@ -0,0 +1,360 @@
1
+ # CLI reference
2
+
3
+ > Generated by `node packages/hb-sdk/skill/scripts/sync-references.mjs` from the public hb-sdk source/docs. Do not edit by hand; update sources or this generator instead.
4
+
5
+ ## Sources
6
+
7
+ - packages/hb-sdk/package.json
8
+ - packages/hb-sdk/src/cli/index.ts
9
+ - packages/hb-sdk/src/cli/commands/create.ts
10
+ - packages/hb-sdk/src/cli/commands/dev.ts
11
+ - packages/hb-sdk/src/cli/commands/login.ts
12
+ - packages/hb-sdk/src/cli/templates/vue3-vite-ts/README.md.ejs
13
+ - apps/h5/docs/hb_sdk/src/guide/cli.md
14
+ - packages/hb-sdk/README.md
15
+
16
+ ## Contents
17
+
18
+ - [When to use the CLI](#when-to-use-the-cli)
19
+ - [Command surface](#command-surface)
20
+ - [Create a mini-program template](#create-a-mini-program-template)
21
+ - [Local dev and mock runtime](#local-dev-and-mock-runtime)
22
+ - [CLI login cache](#cli-login-cache)
23
+ - [Agent Skill doctor](#agent-skill-doctor)
24
+ - [Update reminders](#update-reminders)
25
+ - [Repository validation commands](#repository-validation-commands)
26
+ - [Generated template README](#generated-template-readme)
27
+ ## When to use the CLI
28
+
29
+ Use the bundled `hb-sdk` CLI when the task is about creating an external mini-program project, starting local Vite development, debugging SDK calls in a browser mock runtime host, or managing the CLI's own Heybox auth cache.
30
+
31
+ Do not use the CLI to replace iframe SDK calls. `hb-sdk login` is for CLI commands only and does not change `auth.login()`, `user.getInfo()`, `network.request()`, or mock-host user state.
32
+
33
+ The CLI, templates, and mock host are owned by `@heybox/hb-sdk`. Do not create a second mock runtime package or move CLI guidance outside this package unless the package boundary changes.
34
+
35
+ ## Command surface
36
+
37
+ ```ts
38
+ import { Command, CommanderError, InvalidArgumentError } from 'commander';
39
+ import { runCreateCommand as defaultRunCreateCommand } from './commands/create';
40
+ import { runDevCommand as defaultRunDevCommand } from './commands/dev';
41
+ import { runDoctorCommand as defaultRunDoctorCommand } from './commands/doctor';
42
+ import {
43
+ clearLoginStatus as defaultClearLoginStatus,
44
+ loginToHeybox as defaultLoginToHeybox,
45
+ printLoginStatus as defaultPrintLoginStatus,
46
+ } from './commands/login';
47
+ import { printUpdateReminder as defaultPrintUpdateReminder } from './update-check';
48
+ import { printError as defaultPrintError } from './utils/errors';
49
+ import { getCliVersion } from './version';
50
+
51
+ export interface CliCommandHandlers {
52
+ clearLoginStatus: typeof defaultClearLoginStatus;
53
+ loginToHeybox: typeof defaultLoginToHeybox;
54
+ printLoginStatus: typeof defaultPrintLoginStatus;
55
+ printUpdateReminder: typeof defaultPrintUpdateReminder;
56
+ runCreateCommand: typeof defaultRunCreateCommand;
57
+ runDevCommand: typeof defaultRunDevCommand;
58
+ runDoctorCommand: typeof defaultRunDoctorCommand;
59
+ }
60
+
61
+ export interface CliRuntimeOptions extends Partial<CliCommandHandlers> {
62
+ argv?: string[];
63
+ printError?: typeof defaultPrintError;
64
+ process?: Pick<NodeJS.Process, 'exit'>;
65
+ }
66
+
67
+ export async function runCli(options: CliRuntimeOptions = {}) {
68
+ const processLike = options.process ?? process;
69
+
70
+ try {
71
+ await createCliProgram(options).parseAsync(options.argv ?? process.argv);
72
+ } catch (error) {
73
+ if (error instanceof CommanderError && error.exitCode === 0) {
74
+ processLike.exit(0);
75
+ return;
76
+ }
77
+
78
+ if (!(error instanceof CommanderError)) {
79
+ (options.printError ?? defaultPrintError)(error);
80
+ }
81
+
82
+ processLike.exit(error instanceof CommanderError ? error.exitCode : 1);
83
+ }
84
+ }
85
+
86
+ export function createCliProgram(overrides: Partial<CliCommandHandlers> = {}) {
87
+ const handlers: CliCommandHandlers = {
88
+ clearLoginStatus: defaultClearLoginStatus,
89
+ loginToHeybox: defaultLoginToHeybox,
90
+ printLoginStatus: defaultPrintLoginStatus,
91
+ printUpdateReminder: defaultPrintUpdateReminder,
92
+ runCreateCommand: defaultRunCreateCommand,
93
+ runDevCommand: defaultRunDevCommand,
94
+ runDoctorCommand: defaultRunDoctorCommand,
95
+ ...overrides,
96
+ };
97
+ const program = new Command();
98
+
99
+ program
100
+ .name('hb-sdk')
101
+ .description('hb-sdk developer tools')
102
+ .version(getCliVersion())
103
+ .showHelpAfterError()
104
+ .exitOverride();
105
+
106
+ program
107
+ .command('create')
108
+ .description('创建外部小程序项目开发模板')
109
+ .argument('<project-name>', '项目目录名,例如 my-miniapp')
110
+ .action(
111
+ withUpdateReminder(async (projectName) => {
112
+ await handlers.runCreateCommand(projectName);
113
+ }, handlers.printUpdateReminder),
114
+ );
115
+
116
+ program
117
+ .command('dev')
118
+ .description('启动当前小程序项目的 Vite dev server 和浏览器 mock runtime host')
119
+ .option('--port <port>', 'App dev server 端口', parsePositivePort)
120
+ .option('--mock-port <port>', 'Mock host 端口', parsePositivePort)
121
+ .option('--host <host>', '传给 Vite 和 mock host 的 host')
122
+ .option('--no-open', '不自动打开浏览器调试页')
123
+ .action(
124
+ withUpdateReminder(async (options) => {
125
+ await handlers.runDevCommand(options);
126
+ }, handlers.printUpdateReminder),
127
+ );
128
+
129
+ program
130
+ .command('doctor')
131
+ .description('诊断 hb-sdk 本地环境和 Agent Skill 版本')
132
+ .action(async () => {
133
+ await handlers.runDoctorCommand();
134
+ });
135
+
136
+ const login = program
137
+ .command('login')
138
+ .description('登录 Heybox 并缓存 CLI 登录态')
139
+ .action(
140
+ withUpdateReminder(async () => {
141
+ await handlers.loginToHeybox();
142
+ }, handlers.printUpdateReminder),
143
+ );
144
+
145
+ login
146
+ .command('status')
147
+ .description('查看脱敏后的 Heybox 登录态')
148
+ .action(
149
+ withUpdateReminder(async () => {
150
+ await handlers.printLoginStatus();
151
+ }, handlers.printUpdateReminder),
152
+ );
153
+
154
+ login
155
+ .command('clear')
156
+ .description('清理 hb-sdk 命名空间中的 Heybox 登录态')
157
+ .action(
158
+ withUpdateReminder(async () => {
159
+ await handlers.clearLoginStatus();
160
+ }, handlers.printUpdateReminder),
161
+ );
162
+
163
+ return program;
164
+ }
165
+
166
+ function withUpdateReminder<Args extends unknown[]>(
167
+ action: (...args: Args) => Promise<void>,
168
+ printUpdateReminder: typeof defaultPrintUpdateReminder,
169
+ ) {
170
+ return async (...args: Args) => {
171
+ await action(...args);
172
+ await printUpdateReminder();
173
+ };
174
+ }
175
+
176
+ function parsePositivePort(value: string) {
177
+ const parsed = Number(value);
178
+ if (!Number.isInteger(parsed) || parsed <= 0) {
179
+ throw new InvalidArgumentError('必须是正整数端口号');
180
+ }
181
+
182
+ return parsed;
183
+ }
184
+ ```
185
+
186
+ ## Create a mini-program template
187
+
188
+ ## 创建外部小程序模板
189
+
190
+ ```bash
191
+ hb-sdk create my-miniapp
192
+ cd my-miniapp
193
+ npm install
194
+ npm run dev
195
+ ```
196
+
197
+ `hb-sdk create <project-name>` 会生成 Vue 3、Vite、TypeScript 和 npm 模板。`project-name` 同时作为目录名和 `package.json` 的 `name`,必须是合法的非 scoped npm 包名。目标目录不存在时会创建;目标目录已存在但非空时会拒绝覆盖。
198
+
199
+ CLI 只生成文件,不会自动安装依赖、初始化 git 或打开编辑器。生成模板后优先运行 `npm run dev`,它会启动 Vite 服务和内置 mock runtime host。
200
+
201
+ Agent rules:
202
+
203
+ - Prefer `hb-sdk create <project-name>` for a new standalone external mini-program template.
204
+ - After creation, the expected next steps are `npm install` and `npm run dev`.
205
+ - Do not claim the CLI installs dependencies, initializes git, opens an editor, or overwrites non-empty directories.
206
+ - Treat `project-name` as an unscoped npm package name and project directory.
207
+
208
+ ## Local dev and mock runtime
209
+
210
+ ## 本地开发模式
211
+
212
+ 已有小程序项目中可以直接运行:
213
+
214
+ ```bash
215
+ hb-sdk dev
216
+ ```
217
+
218
+ `hb-sdk dev` 会从当前目录向上查找最近的 `package.json` 作为项目根目录,加载该项目安装的 `vite`,并优先使用项目内的 Vite 配置文件。命令会同时启动内置 mock runtime host 并默认打开调试页;如果需要真实黑盒小程序容器加载同一页面,点击调试页里的「在 Mac 版 APP 中启动」按钮。项目没有安装 Vite 时,命令会提示安装依赖或把 Vite 放到 `devDependencies`。
219
+
220
+ 常用参数:
221
+
222
+ | 参数 | 说明 |
223
+ | --- | --- |
224
+ | `--port <port>` | 指定小程序 Vite dev server 端口,默认从 `5173` 开始。 |
225
+ | `--mock-port <port>` | 指定 mock host 端口,默认从 `5174` 开始。 |
226
+ | `--host <host>` | 同时传给 Vite 和 mock host 的 host。 |
227
+ | `--no-open` | 不自动打开浏览器调试页。 |
228
+
229
+ ## Mock runtime 边界
230
+
231
+ `hb-sdk dev` 会把实际小程序页面地址编码到 mock host 的 `mini_url` query 中,由 mock host iframe 加载页面并补齐小程序 bridge 环境。mock host 内置登录/登出、`show`、`hide`、在 Mac 版 APP 中启动等调试按钮,并通过同一份 devtools-only runtime adapter 处理 SDK 能力调用。
232
+
233
+ 不要为了本地调试再创建独立 mock runtime 包。CLI、模板和 mock host 都归属 `@heybox/hb-sdk`。
234
+
235
+ 本地 mock runtime 下的 `network.request()` 会通过 `hb-sdk` 本地 mock network proxy 转发真实 HTTP(S) 请求,用于避免浏览器 CORS 影响本地调试。proxy 不会把黑盒客户端私有协议字段暴露给 iframe 业务代码。
236
+
237
+ Use `hb-sdk dev` for local browser SDK debugging. Use the Mock runtime host's "在 Mac 版 APP 中启动" button when the page needs to be loaded by the real Heybox mini-program container.
238
+
239
+ ## CLI login cache
240
+
241
+ ## CLI 登录态
242
+
243
+ ```bash
244
+ hb-sdk login
245
+ hb-sdk login status
246
+ hb-sdk login clear
247
+ ```
248
+
249
+ - `hb-sdk login` 会打开 `login.xiaoheihe.cn`,通过本地临时回调服务接收登录结果。
250
+ - `hb-sdk login status` 只展示脱敏状态、`heyboxId`、登录时间和 cache 路径,不输出 `pkey`、cookie 或完整请求头。
251
+ - `hb-sdk login clear` 只清理 `hb-sdk` 自己命名空间中的 Heybox 登录态。
252
+
253
+ 这份 CLI 登录态不会注入 iframe SDK,也不会改变 `hb-sdk dev` 的 mock 用户、`auth.login()`、`user.getInfo()` 或 `network.request()` 行为。
254
+
255
+ Agent rules:
256
+
257
+ - Keep CLI auth cache separate from iframe SDK login state.
258
+ - It is correct to say status output is redacted.
259
+ - Do not expose or template pkey, cookie, token, or private credential values.
260
+ - Use `hb-sdk login clear` only to clear the `hb-sdk` CLI namespace.
261
+
262
+ ## Agent Skill doctor
263
+
264
+ ## Agent Skill doctor
265
+
266
+ ```bash
267
+ hb-sdk doctor
268
+ ```
269
+
270
+ `hb-sdk doctor` 用来诊断本机 `hb-sdk` Agent Skill 是否匹配当前 SDK。它会对比当前 `@heybox/hb-sdk` 版本、远端 latest skill 元数据,以及本机 `$CODEX_HOME/skills/hb-sdk/skill.json`;没有 `CODEX_HOME` 时读取 `~/.codex/skills/hb-sdk/skill.json`。
271
+
272
+ `doctor` 只诊断,不修改本地文件。需要安装或刷新 skill 时,按输出提示手动执行 `npx skills add`。
273
+
274
+ | 状态 | 含义 |
275
+ | --- | --- |
276
+ | `OK` | SDK、远端 latest skill、本机 skill 全部匹配。 |
277
+ | `SKILL_MISSING` | 本机没有安装 `hb-sdk` skill。 |
278
+ | `SKILL_OUTDATED` | 本机 `skillVersion` 与远端 latest 不一致。 |
279
+ | `SDK_MISMATCH` | 当前 SDK 版本与远端 latest skill 声明的 SDK 版本不一致。 |
280
+ | `REMOTE_UNAVAILABLE` | 无法读取公开 manifest,诊断失败且不会修改本地文件。 |
281
+
282
+ 手动安装或刷新 skill:
283
+
284
+ ```bash
285
+ npx skills add https://open.xiaoheihe.cn/agent-skills/hb-sdk
286
+ ```
287
+
288
+ 如果状态是 `SDK_MISMATCH`,先升级 `@heybox/hb-sdk@latest`,再重新运行 `hb-sdk doctor` 并按提示安装 latest skill。当前只维护 latest skill,不维护历史 SDK 的 skill 快照。
289
+
290
+ Agent rules:
291
+
292
+ - Use `hb-sdk doctor` for read-only diagnosis of local SDK, remote latest skill metadata, and local skill metadata.
293
+ - Do not use `hb-sdk doctor` to auto-install skills; when installation or refresh is needed, tell the user to run `npx skills add https://open.xiaoheihe.cn/agent-skills/hb-sdk`.
294
+ - If doctor reports `SDK_MISMATCH`, tell the user to upgrade `@heybox/hb-sdk@latest` before reinstalling the skill.
295
+ - The supported local skill path is `$CODEX_HOME/skills/hb-sdk/skill.json`, falling back to `~/.codex/skills/hb-sdk/skill.json`.
296
+
297
+ ## Update reminders
298
+
299
+ ## 版本提醒
300
+
301
+ `hb-sdk` CLI 会在命令成功执行后检查 npm registry 上 `@heybox/hb-sdk` 的 `latest` 版本。检查结果会缓存 24 小时;检查失败会静默跳过;`CI=true` 时会跳过检查,避免污染 CI 日志。本地可通过 `HB_SDK_NO_UPDATE_CHECK=1` 禁用检查。
302
+
303
+ ## Repository validation commands
304
+
305
+ ## 本仓库开发
306
+
307
+ ```bash
308
+ pnpm --filter @heybox/hb-sdk run test:unit
309
+ pnpm --filter @heybox/hb-sdk run build:package
310
+ pnpm --filter @heybox/hb-sdk run check:boundary
311
+ ```
312
+
313
+ `check:boundary` 用于保护 SDK、CLI、mock host 与 runtime 之间的依赖边界。调整 CLI、mock 或协议导出时应一起运行。
314
+
315
+ ## Generated template README
316
+
317
+ ````md
318
+ # <%= projectName %>
319
+
320
+ 这是通过 `hb-sdk create` 生成的黑盒外部小程序开发模板。项目使用 Vue 3、Vite、TypeScript 和 `@heybox/hb-sdk`。
321
+
322
+ ## 使用命令
323
+
324
+ ```bash
325
+ npm install
326
+ npm run dev
327
+ npm run typecheck
328
+ npm run test:unit
329
+ npm run build
330
+ ```
331
+
332
+ ## 开发模式
333
+
334
+ - `npm run dev`:启动本地 Vite 服务和 `hb-sdk` 内置 mock runtime host,适合本地调试 SDK 能力;调试页内可点击按钮在 Mac 版 APP 中启动同一页面。
335
+ - `npm run build`:先执行 TypeScript 检查,再构建生产产物。
336
+
337
+ ## 更多能力
338
+
339
+ 模板页面只保留最小接入示例。其他常用能力可以直接从 `@heybox/hb-sdk` 调用:
340
+
341
+ ```ts
342
+ import hbSDK from '@heybox/hb-sdk';
343
+
344
+ await hbSDK.share.showShareMenu({
345
+ title: '<%= projectName %>',
346
+ desc: '分享描述',
347
+ url: window.location.href,
348
+ });
349
+
350
+ await hbSDK.storage.setStorage({
351
+ key: 'settings',
352
+ data: { theme: 'dark' },
353
+ });
354
+
355
+ const response = await hbSDK.network.request({
356
+ method: 'GET',
357
+ url: 'https://jsonplaceholder.typicode.com/todos/1',
358
+ });
359
+ ```
360
+ ````
@@ -0,0 +1,107 @@
1
+ # Smoke examples and anti-examples
2
+
3
+ > Generated by `node packages/hb-sdk/skill/scripts/sync-references.mjs` from the public hb-sdk source/docs. Do not edit by hand; update sources or this generator instead.
4
+
5
+ ## Sources
6
+
7
+ - packages/hb-sdk/README.md
8
+ - apps/h5/docs/hb_sdk/src/.vuepress/public/llms/
9
+ ## Positive examples
10
+
11
+ ### Minimal user info
12
+
13
+ ```ts
14
+ import { ready, user } from '@heybox/hb-sdk';
15
+
16
+ await ready();
17
+
18
+ const result = await user.getInfo();
19
+ if (result.isLogin && result.userInfo) {
20
+ console.log(result.userInfo.nickname);
21
+ }
22
+ ```
23
+
24
+ ### Login gate
25
+
26
+ ```ts
27
+ import { auth, ready, user, HbMiniProgramSDKError } from '@heybox/hb-sdk';
28
+
29
+ export async function ensureLogin() {
30
+ await ready();
31
+
32
+ const current = await user.getInfo();
33
+ if (current.isLogin && current.userInfo) return current.userInfo;
34
+
35
+ try {
36
+ const loginResult = await auth.login();
37
+ return loginResult.userInfo;
38
+ } catch (error) {
39
+ if (error instanceof HbMiniProgramSDKError) {
40
+ console.warn(error.code, error.message);
41
+ }
42
+ return null;
43
+ }
44
+ }
45
+ ```
46
+
47
+ ### Network request
48
+
49
+ ```ts
50
+ import { ready, network, HbMiniProgramNetworkError } from '@heybox/hb-sdk';
51
+
52
+ try {
53
+ await ready();
54
+
55
+ const response = await network.request<{ ok: boolean }>({
56
+ url: 'https://api.example.com/demo',
57
+ method: 'GET',
58
+ validateStatus: status => status >= 200 && status < 400,
59
+ });
60
+ console.log(response.data.ok);
61
+ } catch (error) {
62
+ if (error instanceof HbMiniProgramNetworkError) {
63
+ console.warn(error.status, error.response?.data);
64
+ }
65
+ }
66
+ ```
67
+
68
+ ### Host/runtime protocol import
69
+
70
+ ```ts
71
+ import { NETWORK_REQUEST_METHOD, type NetworkRequestPayload } from '@heybox/hb-sdk/protocol';
72
+
73
+ // Host/runtime integration only. Do not use this in iframe business code.
74
+ export function canHandleNetwork(method: string): method is typeof NETWORK_REQUEST_METHOD {
75
+ return method === NETWORK_REQUEST_METHOD;
76
+ }
77
+ ```
78
+
79
+ ### CLI local mock development
80
+
81
+ ```bash
82
+ hb-sdk create my-miniapp
83
+ cd my-miniapp
84
+ npm install
85
+ npm run dev
86
+
87
+ # In an existing project:
88
+ hb-sdk dev
89
+ ```
90
+
91
+ ### CLI login cache
92
+
93
+ ```bash
94
+ hb-sdk login
95
+ hb-sdk login status
96
+ hb-sdk login clear
97
+ ```
98
+
99
+ ## Negative examples
100
+
101
+ - Do not import from internal hb-sdk implementation paths.
102
+ - Do not read cookies, tokens, phone numbers, or private credentials.
103
+ - Do not create raw `postMessage` bridge envelopes in business pages.
104
+ - Do not call unsupported storage delete/clear/info operations.
105
+ - Do not pass raw internal share/network protocol fields from mini-program code.
106
+ - Do not treat `hb-sdk login` as iframe SDK authentication state.
107
+ - Do not create a second mock runtime package when `hb-sdk dev` is the supported local mock workflow.
@@ -0,0 +1,44 @@
1
+ # LLM documentation index
2
+
3
+ > Generated by `node packages/hb-sdk/skill/scripts/sync-references.mjs` from the public hb-sdk source/docs. Do not edit by hand; update sources or this generator instead.
4
+
5
+ ## Sources
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
10
+
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.
12
+
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): 所有请求失败都会被规范化成该结构,SDK 侧再包装为 `HbMiniProgramSDKError`。 |
28
+ - [Protocol interfaces](./llms/reference/protocol/interfaces/README.md): 所有请求失败都会被规范化成该结构,SDK 侧再包装为 `HbMiniProgramSDKError`。 |
29
+ - [Root types](./llms/reference/root/types/README.md): `user.getInfo` 不需要入参。
30
+ - [Protocol types](./llms/reference/protocol/types/README.md): `user.getInfo` 不需要入参。
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
+ - [快速开始](./llms/guide/quick-start.md): 如果页面不需要黑盒开放能力,可以不接入 SDK。这是一条需要用户能力时的最短接入路径:等待 SDK 完成握手,然后读取当前用户登录态。
39
+ ## Recipes
40
+ - [独立 SDK 实例](./llms/recipes/custom-instance.md): 大多数业务页使用默认单例即可。只有在需要隔离上下文时,再创建独立实例。
41
+ - [登录门禁](./llms/recipes/login-gate.md): 当业务动作必须登录后才能继续时,可以把登录态判断收敛成 `ensureLogin`。
42
+ ## Optional
43
+ - Full markdown mirrors for the docs site are available under `./llms/guide/`, `./llms/reference/`, and `./llms/recipes/`.
44
+ ```