@heybox/hb-sdk 0.2.0-alpha.0 → 0.2.0-alpha.2
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.
- package/README.md +193 -452
- package/bin/hb-sdk.cjs +1 -1
- package/dist/cli.cjs +71660 -3903
- package/dist/devtools/mock-host/index.html +13 -387
- package/dist/devtools/mock-host/main.js +975 -0
- package/dist/index.cjs.js +50 -63
- package/dist/index.esm.js +51 -50
- package/dist/miniapp-publish.cjs.js +77 -0
- package/dist/miniapp-publish.esm.js +66 -0
- package/dist/protocol.cjs.js +72 -13
- package/dist/protocol.esm.js +72 -14
- package/dist/templates/vue3-vite-ts/README.md.ejs +1 -5
- package/dist/templates/vue3-vite-ts/package.json.ejs +0 -1
- package/dist/templates/vue3-vite-ts/vite.config.ts +2 -1
- package/dist/vite.cjs.js +62 -0
- package/dist/vite.esm.js +60 -0
- package/package.json +30 -1
- package/skill/SKILL.md +106 -0
- package/skill/references/api-protocol.md +135 -0
- package/skill/references/api-root.md +474 -0
- package/skill/references/cli.md +376 -0
- package/skill/references/examples.md +119 -0
- package/skill/references/llms-index.md +44 -0
- package/skill/references/recipes.md +374 -0
- package/skill/references/safety-boundaries.md +30 -0
- package/skill/references/smoke-evaluation.md +24 -0
- package/skill/scripts/check-references.mjs +14 -0
- package/skill/scripts/package-skill.mjs +60 -0
- package/skill/scripts/package-skill.sh +6 -0
- package/skill/scripts/skill-metadata.mjs +74 -0
- package/skill/scripts/sync-references.mjs +565 -0
- package/skill/scripts/validate-skill.mjs +235 -0
- package/skill/skill.json +11 -0
- package/types/index.d.ts +8 -6
- package/types/miniapp-publish/index.d.ts +23 -0
- package/types/modules/auth/index.d.ts +2 -9
- package/types/modules/network/index.d.ts +6 -11
- package/types/modules/share/index.d.ts +3 -9
- package/types/modules/share/screenshot.d.ts +1 -7
- package/types/modules/share/show-share-menu.d.ts +1 -7
- package/types/modules/storage/index.d.ts +2 -16
- package/types/modules/user/get-info.d.ts +1 -7
- package/types/modules/user/index.d.ts +2 -8
- package/types/modules/viewport/index.d.ts +2 -9
- package/types/protocol/capabilities.d.ts +180 -0
- package/types/protocol.d.ts +8 -13
- package/types/vite/index.d.ts +17 -0
package/dist/protocol.esm.js
CHANGED
|
@@ -31,7 +31,6 @@ function isMiniProgramBridgeMessage(value) {
|
|
|
31
31
|
* 供 SDK 与父容器 runtime 共享同一 bridge method 标识。
|
|
32
32
|
*/
|
|
33
33
|
const AUTH_LOGIN_METHOD = 'auth.login';
|
|
34
|
-
|
|
35
34
|
/**
|
|
36
35
|
* 用户信息能力方法名。
|
|
37
36
|
*
|
|
@@ -39,7 +38,13 @@ const AUTH_LOGIN_METHOD = 'auth.login';
|
|
|
39
38
|
* 供 SDK 与父容器 runtime 共享同一 bridge method 标识。
|
|
40
39
|
*/
|
|
41
40
|
const USER_GET_INFO_METHOD = 'user.getInfo';
|
|
42
|
-
|
|
41
|
+
/**
|
|
42
|
+
* 展示分享面板能力方法名。
|
|
43
|
+
*
|
|
44
|
+
* @remarks
|
|
45
|
+
* 供 SDK 与父容器 runtime 共享同一 bridge method 标识。
|
|
46
|
+
*/
|
|
47
|
+
const SHARE_SHOW_SHARE_MENU_METHOD = 'share.showShareMenu';
|
|
43
48
|
/**
|
|
44
49
|
* 截图分享能力方法名。
|
|
45
50
|
*
|
|
@@ -47,15 +52,13 @@ const USER_GET_INFO_METHOD = 'user.getInfo';
|
|
|
47
52
|
* 供 SDK 与父容器 runtime 共享同一 bridge method 标识。
|
|
48
53
|
*/
|
|
49
54
|
const SHARE_SCREENSHOT_METHOD = 'share.screenshot';
|
|
50
|
-
|
|
51
55
|
/**
|
|
52
|
-
*
|
|
56
|
+
* 视口窗口信息能力方法名。
|
|
53
57
|
*
|
|
54
58
|
* @remarks
|
|
55
59
|
* 供 SDK 与父容器 runtime 共享同一 bridge method 标识。
|
|
56
60
|
*/
|
|
57
|
-
const
|
|
58
|
-
|
|
61
|
+
const VIEWPORT_GET_WINDOW_INFO_METHOD = 'viewport.getWindowInfo';
|
|
59
62
|
/**
|
|
60
63
|
* 读取小程序隔离 storage 能力方法名。
|
|
61
64
|
*
|
|
@@ -70,21 +73,76 @@ const STORAGE_GET_STORAGE_METHOD = 'storage.getStorage';
|
|
|
70
73
|
* 供 SDK 与父容器 runtime 共享同一 bridge method 标识。
|
|
71
74
|
*/
|
|
72
75
|
const STORAGE_SET_STORAGE_METHOD = 'storage.setStorage';
|
|
73
|
-
|
|
74
76
|
/**
|
|
75
|
-
*
|
|
77
|
+
* 发起网络请求能力方法名。
|
|
76
78
|
*
|
|
77
79
|
* @remarks
|
|
78
80
|
* 供 SDK 与父容器 runtime 共享同一 bridge method 标识。
|
|
79
81
|
*/
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
+
const NETWORK_REQUEST_METHOD = 'network.request';
|
|
82
83
|
/**
|
|
83
|
-
*
|
|
84
|
+
* 小程序开放能力目录。
|
|
84
85
|
*
|
|
85
86
|
* @remarks
|
|
86
|
-
*
|
|
87
|
+
* 新增 bridge method 时应先更新这里,再分别补齐 SDK 模块、runtime handler 与测试。
|
|
87
88
|
*/
|
|
88
|
-
const
|
|
89
|
+
const MINI_PROGRAM_PROTOCOL_CAPABILITIES = [
|
|
90
|
+
{
|
|
91
|
+
method: AUTH_LOGIN_METHOD,
|
|
92
|
+
module: 'auth',
|
|
93
|
+
capability: AUTH_LOGIN_METHOD,
|
|
94
|
+
permission: 'auth.login',
|
|
95
|
+
risk: 'medium',
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
method: USER_GET_INFO_METHOD,
|
|
99
|
+
module: 'user',
|
|
100
|
+
capability: USER_GET_INFO_METHOD,
|
|
101
|
+
permission: 'user.getInfo',
|
|
102
|
+
risk: 'medium',
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
method: SHARE_SHOW_SHARE_MENU_METHOD,
|
|
106
|
+
module: 'share',
|
|
107
|
+
capability: SHARE_SHOW_SHARE_MENU_METHOD,
|
|
108
|
+
permission: 'share.basic',
|
|
109
|
+
risk: 'low',
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
method: SHARE_SCREENSHOT_METHOD,
|
|
113
|
+
module: 'share',
|
|
114
|
+
capability: SHARE_SCREENSHOT_METHOD,
|
|
115
|
+
permission: 'share.screenshot',
|
|
116
|
+
risk: 'medium',
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
method: VIEWPORT_GET_WINDOW_INFO_METHOD,
|
|
120
|
+
module: 'viewport',
|
|
121
|
+
capability: VIEWPORT_GET_WINDOW_INFO_METHOD,
|
|
122
|
+
permission: 'viewport.windowInfo',
|
|
123
|
+
risk: 'low',
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
method: STORAGE_GET_STORAGE_METHOD,
|
|
127
|
+
module: 'storage',
|
|
128
|
+
capability: STORAGE_GET_STORAGE_METHOD,
|
|
129
|
+
permission: 'storage.read',
|
|
130
|
+
risk: 'low',
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
method: STORAGE_SET_STORAGE_METHOD,
|
|
134
|
+
module: 'storage',
|
|
135
|
+
capability: STORAGE_SET_STORAGE_METHOD,
|
|
136
|
+
permission: 'storage.write',
|
|
137
|
+
risk: 'medium',
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
method: NETWORK_REQUEST_METHOD,
|
|
141
|
+
module: 'network',
|
|
142
|
+
capability: NETWORK_REQUEST_METHOD,
|
|
143
|
+
permission: 'network.request',
|
|
144
|
+
risk: 'high',
|
|
145
|
+
},
|
|
146
|
+
];
|
|
89
147
|
|
|
90
|
-
export { AUTH_LOGIN_METHOD, MINI_PROGRAM_BRIDGE_NONCE_PARAM, MINI_PROGRAM_MESSAGE_NAMESPACE, MINI_PROGRAM_MESSAGE_VERSION, NETWORK_REQUEST_METHOD, SDK_HANDSHAKE_METHOD, SHARE_SCREENSHOT_METHOD, SHARE_SHOW_SHARE_MENU_METHOD, STORAGE_GET_STORAGE_METHOD, STORAGE_SET_STORAGE_METHOD, USER_GET_INFO_METHOD, VIEWPORT_GET_WINDOW_INFO_METHOD, isMiniProgramBridgeMessage };
|
|
148
|
+
export { AUTH_LOGIN_METHOD, MINI_PROGRAM_BRIDGE_NONCE_PARAM, MINI_PROGRAM_MESSAGE_NAMESPACE, MINI_PROGRAM_MESSAGE_VERSION, MINI_PROGRAM_PROTOCOL_CAPABILITIES, NETWORK_REQUEST_METHOD, SDK_HANDSHAKE_METHOD, SHARE_SCREENSHOT_METHOD, SHARE_SHOW_SHARE_MENU_METHOD, STORAGE_GET_STORAGE_METHOD, STORAGE_SET_STORAGE_METHOD, USER_GET_INFO_METHOD, VIEWPORT_GET_WINDOW_INFO_METHOD, isMiniProgramBridgeMessage };
|
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
8
|
npm install
|
|
9
|
-
npm run dev:mock
|
|
10
9
|
npm run dev
|
|
11
10
|
npm run typecheck
|
|
12
11
|
npm run test:unit
|
|
@@ -15,12 +14,9 @@ npm run build
|
|
|
15
14
|
|
|
16
15
|
## 开发模式
|
|
17
16
|
|
|
18
|
-
- `npm run dev
|
|
19
|
-
- `npm run dev`:只启动小程序页面服务,适合被真实黑盒小程序容器加载。
|
|
17
|
+
- `npm run dev`:启动本地 Vite 服务和 `hb-sdk` 内置 mock runtime host,适合本地调试 SDK 能力;调试页内可点击按钮在 Mac 版 APP 中启动同一页面。
|
|
20
18
|
- `npm run build`:先执行 TypeScript 检查,再构建生产产物。
|
|
21
19
|
|
|
22
|
-
普通浏览器直接打开 `npm run dev` 的页面时,SDK 会因为缺少小程序 iframe 容器或 bridge nonce 而显示错误状态。开发时请优先使用 `npm run dev:mock`。
|
|
23
|
-
|
|
24
20
|
## 更多能力
|
|
25
21
|
|
|
26
22
|
模板页面只保留最小接入示例。其他常用能力可以直接从 `@heybox/hb-sdk` 调用:
|
package/dist/vite.cjs.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var node_fs = require('node:fs');
|
|
4
|
+
var path = require('node:path');
|
|
5
|
+
|
|
6
|
+
const TEMPLATE_VERSION = '0.0.0';
|
|
7
|
+
const SEMVER_LIKE_RE = /^\d+\.\d+\.\d+(?:[-+].*)?$/;
|
|
8
|
+
const TEMPLATE_VERSION_ERROR = '@heybox/hb-sdk 提示:请把 package.json.version 从模板默认的 0.0.0 改成实际版本号再发布';
|
|
9
|
+
function miniappManifest() {
|
|
10
|
+
let root = process.cwd();
|
|
11
|
+
let outDir = 'dist';
|
|
12
|
+
return {
|
|
13
|
+
name: 'heybox-miniapp-manifest',
|
|
14
|
+
apply: 'build',
|
|
15
|
+
configResolved(resolved) {
|
|
16
|
+
root = resolved.root;
|
|
17
|
+
outDir = resolved.build.outDir;
|
|
18
|
+
},
|
|
19
|
+
writeBundle() {
|
|
20
|
+
const version = readMiniappVersion(root);
|
|
21
|
+
if (!SEMVER_LIKE_RE.test(version)) {
|
|
22
|
+
this.warn(`package.json.version "${version}" 不是标准 semver,仍会写入 manifest.json`);
|
|
23
|
+
}
|
|
24
|
+
const manifestPath = path.resolve(root, outDir, 'manifest.json');
|
|
25
|
+
node_fs.mkdirSync(path.dirname(manifestPath), { recursive: true });
|
|
26
|
+
node_fs.writeFileSync(manifestPath, `${JSON.stringify({ version }, null, 2)}\n`);
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function readMiniappVersion(root) {
|
|
31
|
+
const packageJsonPath = path.join(root, 'package.json');
|
|
32
|
+
let content;
|
|
33
|
+
try {
|
|
34
|
+
content = node_fs.readFileSync(packageJsonPath, 'utf8');
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
throw new Error(`@heybox/hb-sdk 读取 package.json 失败:${formatReason(error)}`);
|
|
38
|
+
}
|
|
39
|
+
let packageJson;
|
|
40
|
+
try {
|
|
41
|
+
packageJson = JSON.parse(content);
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
throw new Error(`@heybox/hb-sdk 解析 package.json 失败:${formatReason(error)}`);
|
|
45
|
+
}
|
|
46
|
+
if (typeof packageJson.version !== 'string' || packageJson.version.trim() === '') {
|
|
47
|
+
throw new Error('@heybox/hb-sdk 提示:package.json.version 必须是非空字符串');
|
|
48
|
+
}
|
|
49
|
+
const version = packageJson.version.trim();
|
|
50
|
+
if (version === TEMPLATE_VERSION) {
|
|
51
|
+
throw new Error(TEMPLATE_VERSION_ERROR);
|
|
52
|
+
}
|
|
53
|
+
return version;
|
|
54
|
+
}
|
|
55
|
+
function formatReason(error) {
|
|
56
|
+
if (error instanceof Error && error.message) {
|
|
57
|
+
return error.message;
|
|
58
|
+
}
|
|
59
|
+
return String(error);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
exports.miniappManifest = miniappManifest;
|
package/dist/vite.esm.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { mkdirSync, writeFileSync, readFileSync } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
|
|
4
|
+
const TEMPLATE_VERSION = '0.0.0';
|
|
5
|
+
const SEMVER_LIKE_RE = /^\d+\.\d+\.\d+(?:[-+].*)?$/;
|
|
6
|
+
const TEMPLATE_VERSION_ERROR = '@heybox/hb-sdk 提示:请把 package.json.version 从模板默认的 0.0.0 改成实际版本号再发布';
|
|
7
|
+
function miniappManifest() {
|
|
8
|
+
let root = process.cwd();
|
|
9
|
+
let outDir = 'dist';
|
|
10
|
+
return {
|
|
11
|
+
name: 'heybox-miniapp-manifest',
|
|
12
|
+
apply: 'build',
|
|
13
|
+
configResolved(resolved) {
|
|
14
|
+
root = resolved.root;
|
|
15
|
+
outDir = resolved.build.outDir;
|
|
16
|
+
},
|
|
17
|
+
writeBundle() {
|
|
18
|
+
const version = readMiniappVersion(root);
|
|
19
|
+
if (!SEMVER_LIKE_RE.test(version)) {
|
|
20
|
+
this.warn(`package.json.version "${version}" 不是标准 semver,仍会写入 manifest.json`);
|
|
21
|
+
}
|
|
22
|
+
const manifestPath = path.resolve(root, outDir, 'manifest.json');
|
|
23
|
+
mkdirSync(path.dirname(manifestPath), { recursive: true });
|
|
24
|
+
writeFileSync(manifestPath, `${JSON.stringify({ version }, null, 2)}\n`);
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function readMiniappVersion(root) {
|
|
29
|
+
const packageJsonPath = path.join(root, 'package.json');
|
|
30
|
+
let content;
|
|
31
|
+
try {
|
|
32
|
+
content = readFileSync(packageJsonPath, 'utf8');
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
throw new Error(`@heybox/hb-sdk 读取 package.json 失败:${formatReason(error)}`);
|
|
36
|
+
}
|
|
37
|
+
let packageJson;
|
|
38
|
+
try {
|
|
39
|
+
packageJson = JSON.parse(content);
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
throw new Error(`@heybox/hb-sdk 解析 package.json 失败:${formatReason(error)}`);
|
|
43
|
+
}
|
|
44
|
+
if (typeof packageJson.version !== 'string' || packageJson.version.trim() === '') {
|
|
45
|
+
throw new Error('@heybox/hb-sdk 提示:package.json.version 必须是非空字符串');
|
|
46
|
+
}
|
|
47
|
+
const version = packageJson.version.trim();
|
|
48
|
+
if (version === TEMPLATE_VERSION) {
|
|
49
|
+
throw new Error(TEMPLATE_VERSION_ERROR);
|
|
50
|
+
}
|
|
51
|
+
return version;
|
|
52
|
+
}
|
|
53
|
+
function formatReason(error) {
|
|
54
|
+
if (error instanceof Error && error.message) {
|
|
55
|
+
return error.message;
|
|
56
|
+
}
|
|
57
|
+
return String(error);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export { miniappManifest };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@heybox/hb-sdk",
|
|
3
|
-
"version": "0.2.0-alpha.
|
|
3
|
+
"version": "0.2.0-alpha.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -16,6 +16,19 @@
|
|
|
16
16
|
"node": "./dist/protocol.cjs.js",
|
|
17
17
|
"browser": "./dist/protocol.esm.js",
|
|
18
18
|
"default": "./dist/protocol.esm.js"
|
|
19
|
+
},
|
|
20
|
+
"./miniapp-publish": {
|
|
21
|
+
"types": "./types/miniapp-publish/index.d.ts",
|
|
22
|
+
"heybox": "./src/miniapp-publish/index.ts",
|
|
23
|
+
"node": "./dist/miniapp-publish.cjs.js",
|
|
24
|
+
"browser": "./dist/miniapp-publish.esm.js",
|
|
25
|
+
"default": "./dist/miniapp-publish.esm.js"
|
|
26
|
+
},
|
|
27
|
+
"./vite": {
|
|
28
|
+
"types": "./types/vite/index.d.ts",
|
|
29
|
+
"import": "./dist/vite.esm.js",
|
|
30
|
+
"require": "./dist/vite.cjs.js",
|
|
31
|
+
"default": "./dist/vite.esm.js"
|
|
19
32
|
}
|
|
20
33
|
},
|
|
21
34
|
"bin": {
|
|
@@ -24,11 +37,23 @@
|
|
|
24
37
|
"files": [
|
|
25
38
|
"bin",
|
|
26
39
|
"dist",
|
|
40
|
+
"skill",
|
|
27
41
|
"types"
|
|
28
42
|
],
|
|
29
43
|
"keywords": [],
|
|
30
44
|
"author": "",
|
|
31
45
|
"license": "ISC",
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"cos-nodejs-sdk-v5": "2.15.4"
|
|
48
|
+
},
|
|
49
|
+
"peerDependencies": {
|
|
50
|
+
"vite": ">=5"
|
|
51
|
+
},
|
|
52
|
+
"peerDependenciesMeta": {
|
|
53
|
+
"vite": {
|
|
54
|
+
"optional": true
|
|
55
|
+
}
|
|
56
|
+
},
|
|
32
57
|
"devDependencies": {
|
|
33
58
|
"@rollup/plugin-commonjs": "^28.0.6",
|
|
34
59
|
"@rollup/plugin-json": "^6.1.0",
|
|
@@ -47,10 +72,12 @@
|
|
|
47
72
|
"get-port": "^7.1.0",
|
|
48
73
|
"happy-dom": "^19.0.2",
|
|
49
74
|
"open": "^10.2.0",
|
|
75
|
+
"picocolors": "^1.1.1",
|
|
50
76
|
"rimraf": "^5.0.5",
|
|
51
77
|
"rollup": "^4.52.4",
|
|
52
78
|
"typescript": "^5.9.3",
|
|
53
79
|
"vue": "2.7.16",
|
|
80
|
+
"vite": "^8.0.12",
|
|
54
81
|
"vitest": "^3.2.4"
|
|
55
82
|
},
|
|
56
83
|
"publishConfig": {
|
|
@@ -84,9 +111,11 @@
|
|
|
84
111
|
"build:templates": "node scripts/copy-cli-templates.cjs",
|
|
85
112
|
"build:types": "tsc -p tsconfig.dts.json",
|
|
86
113
|
"check:boundary": "node scripts/check-boundary.cjs",
|
|
114
|
+
"check:docs-sync": "node scripts/check-docs-sync.cjs",
|
|
87
115
|
"clean": "rimraf ./dist && rimraf ./types",
|
|
88
116
|
"test:unit": "NODE_OPTIONS='--conditions=heybox' vitest run",
|
|
89
117
|
"test:unit:coverage": "NODE_OPTIONS='--conditions=heybox' vitest run --coverage",
|
|
118
|
+
"test:vite": "vitest run --config vitest.vite.config.ts",
|
|
90
119
|
"test:watch": "NODE_OPTIONS='--conditions=heybox' vitest"
|
|
91
120
|
}
|
|
92
121
|
}
|
package/skill/SKILL.md
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: hb-sdk
|
|
3
|
+
description: Uses @heybox/hb-sdk and its hb-sdk CLI for Heybox external mini-program iframe pages, local mock development, template creation, skill version checks, and host/runtime protocol integration. Use for ready/auth/user/share/viewport/storage/network APIs, lifecycle events, hb-sdk create/dev/login/doctor, mock runtime debugging, custom SDK instances, or @heybox/hb-sdk/protocol contracts. Don't use for raw postMessage bridge construction in app code, direct cookie/token access, internal Heybox client protocols, separate mock runtimes, or non-Heybox SDKs.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# hb-sdk Agent Procedure
|
|
7
|
+
|
|
8
|
+
Apply these instructions when writing, reviewing, or debugging code that consumes `@heybox/hb-sdk` or uses the companion `hb-sdk` CLI.
|
|
9
|
+
|
|
10
|
+
## Step 1: Classify the task
|
|
11
|
+
|
|
12
|
+
1. If the task is iframe mini-program business code, use the root package import path `@heybox/hb-sdk`.
|
|
13
|
+
2. If the task is parent-container runtime, bridge-server, protocol contract, or `@heybox/hb-sdk-runtime` work, use `@heybox/hb-sdk/protocol` only for shared constants and types.
|
|
14
|
+
3. If the task is project scaffolding, local Vite startup, browser mock runtime, CLI login cache, Agent Skill version diagnosis, or CLI troubleshooting, use the `hb-sdk` CLI workflow.
|
|
15
|
+
4. If the task asks for direct login-state extraction, cookies, tokens, raw Heybox client protocols, or internal hb-sdk package paths, refuse that approach and use the public SDK or CLI boundary instead.
|
|
16
|
+
5. If the task is not about Heybox external mini-program SDK usage, CLI usage, mock runtime, or protocol contracts, do not apply this skill.
|
|
17
|
+
|
|
18
|
+
## Step 2: Load only the needed reference
|
|
19
|
+
|
|
20
|
+
1. For root SDK imports, singleton usage, modules, and errors, read `references/api-root.md`.
|
|
21
|
+
2. For host/runtime protocol contracts only, read `references/api-protocol.md`. Do not use this reference to build iframe business-code bridge messages.
|
|
22
|
+
3. For common business flows, read `references/recipes.md`.
|
|
23
|
+
4. For CLI commands, local mock runtime, generated templates, CLI login cache, Agent Skill doctor, and update reminders, read `references/cli.md`.
|
|
24
|
+
5. For allowed/forbidden capabilities and security boundaries, read `references/safety-boundaries.md`.
|
|
25
|
+
6. For Vite build manifest behavior, read `references/api-root.md` and `references/safety-boundaries.md`.
|
|
26
|
+
7. For generated documentation provenance and deeper API lookup paths, read `references/llms-index.md`.
|
|
27
|
+
8. For smoke-test expectations, positive examples, and anti-examples, read `references/examples.md`.
|
|
28
|
+
9. For evaluating whether another agent followed this skill, read `references/smoke-evaluation.md`.
|
|
29
|
+
|
|
30
|
+
## Step 3: Follow import rules
|
|
31
|
+
|
|
32
|
+
1. Import app-facing SDK APIs from `@heybox/hb-sdk`.
|
|
33
|
+
2. Import protocol contracts from `@heybox/hb-sdk/protocol` only in host/runtime/protocol-maintenance code.
|
|
34
|
+
3. Never import from internal hb-sdk implementation paths; only use the documented package entrypoints.
|
|
35
|
+
4. Prefer named imports for focused code and the default `hbSDK` singleton for compact page-level examples.
|
|
36
|
+
|
|
37
|
+
## Step 4: Implement iframe mini-program code
|
|
38
|
+
|
|
39
|
+
1. Call `await ready()` or `await hbSDK.ready()` near page startup when the page uses SDK capabilities.
|
|
40
|
+
2. Use `user.getInfo()` to read current login state without triggering login.
|
|
41
|
+
3. Use `auth.login()` only when the user action requires login.
|
|
42
|
+
4. Handle `HbMiniProgramSDKError` for bridge/runtime/protocol failures.
|
|
43
|
+
5. Handle `HbMiniProgramNetworkError` separately when HTTP completed but `validateStatus` rejected the status.
|
|
44
|
+
6. Cancel lifecycle/event subscriptions returned by `on()` when the page or component unmounts.
|
|
45
|
+
7. Call `destroy()` on independent instances created by `createMiniProgramSDK()` when they are no longer needed.
|
|
46
|
+
|
|
47
|
+
## Step 5: Use CLI workflows
|
|
48
|
+
|
|
49
|
+
1. Use `hb-sdk create <project-name>` to scaffold a standalone external mini-program template.
|
|
50
|
+
2. Use `hb-sdk dev` for local browser debugging through the built-in mock runtime host.
|
|
51
|
+
3. Use `hb-sdk deploy` to build and publish the current project. It reads `package.json.heybox.miniProgramId`, runs the project's `build` script via the package manager auto-detected by lockfile, then uploads `dist/` to CDN (skipping `manifest.json`, `.DS_Store`, `.map`) and calls the publish API.
|
|
52
|
+
4. Use `hb-sdk deploy --skip-build` only when the `dist/` directory is already prepared by an upstream CI stage. Missing `dist/manifest.json` or `dist/index.html` aborts the run.
|
|
53
|
+
5. Use the Mock runtime host's "在 Mac 版 APP 中启动" button when the page needs to be loaded by the real Heybox mini-program container.
|
|
54
|
+
6. Use `--port`, `--mock-port`, `--host`, and `--no-open` when the default Vite/mock ports, host, or browser opening behavior need to be controlled.
|
|
55
|
+
7. Use `hb-sdk login`, `hb-sdk login status`, and `hb-sdk login clear` only for the CLI's own Heybox auth cache.
|
|
56
|
+
8. Use `hb-sdk doctor` to diagnose whether the local `hb-sdk` skill matches the installed SDK and remote latest skill metadata.
|
|
57
|
+
9. 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`.
|
|
58
|
+
10. If doctor reports `SDK_MISMATCH`, upgrade `@heybox/hb-sdk@latest` before reinstalling the skill.
|
|
59
|
+
11. Do not treat CLI login cache as iframe SDK login state; it does not change `auth.login()`, `user.getInfo()`, `network.request()`, or mock-user behavior.
|
|
60
|
+
12. Keep the CLI and mock runtime under `@heybox/hb-sdk`; do not create or revive a separate mock runtime package.
|
|
61
|
+
13. Do not pass `mini_program_id` as a CLI flag or environment variable; it must come from `package.json.heybox.miniProgramId`.
|
|
62
|
+
14. Do not import deploy / upload internals from outside the CLI; the only externally consumable subpath for publishing is `@heybox/hb-sdk/miniapp-publish`.
|
|
63
|
+
|
|
64
|
+
## Step 6: Preserve capability boundaries
|
|
65
|
+
|
|
66
|
+
For iframe mini-program business code:
|
|
67
|
+
|
|
68
|
+
1. Do not read or request tokens, cookies, phone numbers, or private credentials from the SDK.
|
|
69
|
+
2. Do not expose raw share protocol fields, JS callbacks, activity reporting, custom buttons, post publishing, or upload-only flows.
|
|
70
|
+
3. Do not use unsupported storage operations such as delete, clear, info listing, or global client storage access.
|
|
71
|
+
4. Do not pass raw host protocol fields through `network.request`; use only the public axios-like request config.
|
|
72
|
+
5. Do not construct bridge envelopes, nonce logic, or raw `postMessage` calls.
|
|
73
|
+
6. Build artifacts may include `dist/manifest.json`; business code should not fetch a deployed manifest directly because it is not a CDN asset.
|
|
74
|
+
|
|
75
|
+
For CLI and local development:
|
|
76
|
+
|
|
77
|
+
1. Do not print, persist in templates, or pass through pkey, cookies, tokens, or private credentials.
|
|
78
|
+
2. Do not use `hb-sdk login` as a workaround for iframe SDK authentication.
|
|
79
|
+
3. Do not bypass `hb-sdk dev` by adding a second browser mock host.
|
|
80
|
+
|
|
81
|
+
For host/runtime/protocol-maintenance code:
|
|
82
|
+
|
|
83
|
+
1. Use `@heybox/hb-sdk/protocol` for shared constants and type contracts.
|
|
84
|
+
2. Keep raw protocol details inside the host/runtime boundary; do not leak them into app-facing SDK examples or iframe business code.
|
|
85
|
+
3. Keep bridge handshake and nonce behavior idempotent and compatible with existing SDK clients.
|
|
86
|
+
|
|
87
|
+
## Step 7: Validate changes
|
|
88
|
+
|
|
89
|
+
1. Run the nearest package tests and builds with repo-native commands when editing this repository.
|
|
90
|
+
2. When modifying docs, skill instructions, CLI guidance, or public agent-skill sync points, start with:
|
|
91
|
+
- `pnpm --filter @heybox/hb-sdk run check:docs-sync`
|
|
92
|
+
- `cat packages/hb-sdk/DOC_SYNC_CHECKLIST.md`
|
|
93
|
+
3. When modifying this repo's source skill at `packages/hb-sdk/skill` and preparing distributable artifacts, also run:
|
|
94
|
+
- `node packages/hb-sdk/skill/scripts/package-skill.mjs`
|
|
95
|
+
4. When modifying CLI, mock runtime, package exports, or package dependency direction, also run:
|
|
96
|
+
- `pnpm --filter @heybox/hb-sdk run check:boundary`
|
|
97
|
+
- `pnpm --filter @heybox/hb-sdk run test:unit`
|
|
98
|
+
5. Inspect the generated zip before distribution:
|
|
99
|
+
- `unzip -l packages/hb-sdk/hb-sdk.zip | sed -n '1,120p'`
|
|
100
|
+
6. When adding or modifying the deploy command or its upload pipeline, also run:
|
|
101
|
+
- `pnpm --filter @heybox/hb-sdk run check:boundary`
|
|
102
|
+
- `pnpm --filter @heybox/hb-sdk run test:unit`
|
|
103
|
+
- Verify `dist/cli.cjs` does not have any `require('cos-nodejs-sdk-v5')` left after `build:cli`; the boundary check enforces this automatically.
|
|
104
|
+
6. Verify public payload sync before publishing:
|
|
105
|
+
- `pnpm --filter @heybox-spa/open run sync:agent-skills`
|
|
106
|
+
- `pnpm --filter @heybox-spa/open run check:agent-skills`
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
# Protocol API 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/src/protocol.ts
|
|
8
|
+
- packages/hb-sdk/README.md
|
|
9
|
+
- apps/h5/docs/hb_sdk/src/.vuepress/public/llms/reference/README.md
|
|
10
|
+
|
|
11
|
+
## Contents
|
|
12
|
+
|
|
13
|
+
- [Host/runtime-only warning](#hostruntime-only-warning)
|
|
14
|
+
- [Public protocol entrypoint](#public-protocol-entrypoint)
|
|
15
|
+
- [Protocol context](#protocol-context)
|
|
16
|
+
- [Generated reference index](#generated-reference-index)
|
|
17
|
+
## Host/runtime-only warning
|
|
18
|
+
|
|
19
|
+
Use `@heybox/hb-sdk/protocol` only for parent-container runtime, bridge-server, protocol-contract, or `@heybox/hb-sdk-runtime` integration tasks. Iframe mini-program business code must use root SDK APIs and must not construct bridge envelopes, nonce handling, or raw `postMessage` flows.
|
|
20
|
+
|
|
21
|
+
## Public protocol entrypoint
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
export {
|
|
25
|
+
MINI_PROGRAM_BRIDGE_NONCE_PARAM,
|
|
26
|
+
MINI_PROGRAM_MESSAGE_NAMESPACE,
|
|
27
|
+
MINI_PROGRAM_MESSAGE_VERSION,
|
|
28
|
+
SDK_HANDSHAKE_METHOD,
|
|
29
|
+
} from './protocol/constants';
|
|
30
|
+
export { isMiniProgramBridgeMessage } from './protocol/guards';
|
|
31
|
+
export type {
|
|
32
|
+
MiniProgramBridgeError,
|
|
33
|
+
MiniProgramBridgeMessage,
|
|
34
|
+
MiniProgramBridgeMessageType,
|
|
35
|
+
MiniProgramEventHandler,
|
|
36
|
+
MiniProgramEventName,
|
|
37
|
+
MiniProgramEventPayloadMap,
|
|
38
|
+
} from './protocol/types';
|
|
39
|
+
export {
|
|
40
|
+
AUTH_LOGIN_METHOD,
|
|
41
|
+
MINI_PROGRAM_PROTOCOL_CAPABILITIES,
|
|
42
|
+
NETWORK_REQUEST_METHOD,
|
|
43
|
+
SHARE_SCREENSHOT_METHOD,
|
|
44
|
+
SHARE_SHOW_SHARE_MENU_METHOD,
|
|
45
|
+
STORAGE_GET_STORAGE_METHOD,
|
|
46
|
+
STORAGE_SET_STORAGE_METHOD,
|
|
47
|
+
USER_GET_INFO_METHOD,
|
|
48
|
+
VIEWPORT_GET_WINDOW_INFO_METHOD,
|
|
49
|
+
} from './protocol/capabilities';
|
|
50
|
+
export type {
|
|
51
|
+
MiniProgramAuthMethod,
|
|
52
|
+
MiniProgramBridgeMethod,
|
|
53
|
+
MiniProgramCapabilityDefinition,
|
|
54
|
+
MiniProgramCapabilityModule,
|
|
55
|
+
MiniProgramCapabilityPayload,
|
|
56
|
+
MiniProgramCapabilityPayloadMap,
|
|
57
|
+
MiniProgramCapabilityResult,
|
|
58
|
+
MiniProgramCapabilityResultMap,
|
|
59
|
+
MiniProgramCapabilityRisk,
|
|
60
|
+
MiniProgramNetworkMethod,
|
|
61
|
+
MiniProgramShareMethod,
|
|
62
|
+
MiniProgramStorageMethod,
|
|
63
|
+
MiniProgramUserMethod,
|
|
64
|
+
MiniProgramViewportMethod,
|
|
65
|
+
} from './protocol/capabilities';
|
|
66
|
+
export type { LoginPayload, LoginResult } from './modules/auth';
|
|
67
|
+
export type {
|
|
68
|
+
GetUserInfoPayload,
|
|
69
|
+
GetUserInfoResult,
|
|
70
|
+
MiniProgramUserInfo,
|
|
71
|
+
MiniProgramUserInfoResult,
|
|
72
|
+
} from './modules/user';
|
|
73
|
+
export type { ScreenshotPayload, ScreenshotResult } from './modules/share/screenshot';
|
|
74
|
+
export type { ShowShareMenuPayload, ShowShareMenuResult } from './modules/share/show-share-menu';
|
|
75
|
+
export type {
|
|
76
|
+
MiniProgramScreenshotOptions,
|
|
77
|
+
MiniProgramScreenshotRect,
|
|
78
|
+
MiniProgramShareChannel,
|
|
79
|
+
MiniProgramShowShareMenuOptions,
|
|
80
|
+
} from './modules/share';
|
|
81
|
+
export type {
|
|
82
|
+
GetStoragePayload,
|
|
83
|
+
GetStorageResult,
|
|
84
|
+
SetStoragePayload,
|
|
85
|
+
} from './modules/storage';
|
|
86
|
+
export type {
|
|
87
|
+
GetWindowInfoPayload,
|
|
88
|
+
GetWindowInfoResult,
|
|
89
|
+
MiniProgramSafeArea,
|
|
90
|
+
MiniProgramWindowInfoResult,
|
|
91
|
+
} from './modules/viewport';
|
|
92
|
+
export type {
|
|
93
|
+
MiniProgramNetworkHeaders,
|
|
94
|
+
MiniProgramNetworkParams,
|
|
95
|
+
MiniProgramNetworkRequestConfig,
|
|
96
|
+
MiniProgramNetworkRequestMethod,
|
|
97
|
+
MiniProgramNetworkResponse,
|
|
98
|
+
MiniProgramNetworkValidateStatus,
|
|
99
|
+
NetworkRequestPayload,
|
|
100
|
+
NetworkResponsePayload,
|
|
101
|
+
} from './modules/network';
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Protocol context
|
|
105
|
+
|
|
106
|
+
## SDK 与 Runtime
|
|
107
|
+
|
|
108
|
+
`@heybox/hb-sdk` 跑在 iframe 内部,由外部小程序业务页面使用。`@heybox/hb-sdk-runtime` 跑在 iframe 外部,由黑盒宿主壳层使用,负责启动 iframe、注入 nonce、维护 bridge server、注册能力 handler、转发宿主生命周期与登录态变化。
|
|
109
|
+
|
|
110
|
+
两者共享同一套 bridge 协议。协议字段、事件名或能力 payload 发生变化时,应按同一批次联动升级 SDK 与 runtime;不要只升级其中一侧后假定另一侧自动兼容。
|
|
111
|
+
|
|
112
|
+
## Generated reference index
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
# Reference
|
|
116
|
+
|
|
117
|
+
Reference 由 `packages/hb-sdk` 的公开导出与源码注释自动生成,不重复 Guide 的接入流程。
|
|
118
|
+
|
|
119
|
+
| 导出面 | 说明 |
|
|
120
|
+
| --- | --- |
|
|
121
|
+
| [Root API](./root/README.md) | 来自 `src/index.ts` 的默认导出、命名导出与公开能力。 |
|
|
122
|
+
| [Protocol API](./protocol/README.md) | 来自 `src/protocol.ts` 的协议常量、消息类型与 method 契约。 |
|
|
123
|
+
|
|
124
|
+
## 查询建议
|
|
125
|
+
|
|
126
|
+
- 想查业务接入路径:先看 [Guide](../guide/README.md)。
|
|
127
|
+
- 想查导出符号:从 Root API 或 Protocol API 进入对应分类页。
|
|
128
|
+
- 想看场景化用法:优先看 Guide / Recipes 页面中的“进一步阅读”。
|
|
129
|
+
|
|
130
|
+
## 统计
|
|
131
|
+
|
|
132
|
+
| 导出面 | Classes | Functions | Interfaces | Types | Constants |
|
|
133
|
+
| --- | ---: | ---: | ---: | ---: | ---: |
|
|
134
|
+
| Root API | 3 | 5 | 28 | 29 | 12 |
|
|
135
|
+
| Protocol API | 0 | 1 | 20 | 29 | 13 |
|