@heybox/hb-sdk 0.5.11 → 0.5.14
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 +5 -4
- package/dist/cli-chunks/{create-BaqN3jeW.cjs → create-BG31rI88.cjs} +1 -1
- package/dist/cli-chunks/{dev-DUZgcgYE.cjs → dev-yEoQHWA7.cjs} +1 -1
- package/dist/cli-chunks/{doctor-DUjQij7b.cjs → doctor-XxxsLM-t.cjs} +1 -1
- package/dist/cli-chunks/{index-BROIiSNN.cjs → index-CkIWhOnc.cjs} +13 -13
- package/dist/cli-chunks/{index-6W5M4MLF.cjs → index-D4o196NT.cjs} +2 -2
- package/dist/cli-chunks/{login-BejyA1mX.cjs → login-w5nfOJDF.cjs} +2 -2
- package/dist/cli-chunks/{remote-ChGmIJC1.cjs → remote-CB40-si7.cjs} +3 -3
- package/dist/cli-chunks/{session-jHF9KWBo.cjs → session-D0rnT6RG.cjs} +1 -1
- package/dist/cli.cjs +1 -1
- package/dist/index.cjs.js +47 -4
- package/dist/index.esm.js +47 -4
- package/package.json +2 -4
- package/skill/SKILL.md +4 -3
- package/skill/references/api-protocol.md +7 -7
- package/skill/references/api-root.md +2 -2
- package/skill/references/cli.md +3 -3
- package/skill/references/examples.md +2 -1
- package/skill/references/llms-index.md +16 -37
- package/skill/references/recipes.md +9 -9
- package/skill/references/safety-boundaries.md +3 -2
- package/skill/scripts/sync-references.mjs +56 -32
- package/skill/scripts/validate-skill.mjs +18 -0
- package/skill/skill.json +4 -4
- package/types/core/client.d.ts +4 -0
package/README.md
CHANGED
|
@@ -330,7 +330,7 @@ await network.request({
|
|
|
330
330
|
|
|
331
331
|
## 生命周期事件
|
|
332
332
|
|
|
333
|
-
|
|
333
|
+
SDK 实例创建后会自动开始与父容器握手。使用 `on()` 监听父容器派发的小程序事件时,默认单例会被懒创建并自动开始握手;`on()` 会返回取消监听函数,组件卸载或页面销毁时应及时调用。
|
|
334
334
|
|
|
335
335
|
```ts
|
|
336
336
|
import { on } from '@heybox/hb-sdk';
|
|
@@ -516,7 +516,8 @@ CLI 登录态只供 CLI 命令访问黑盒接口时复用,不会注入 iframe
|
|
|
516
516
|
|
|
517
517
|
## 能力边界
|
|
518
518
|
|
|
519
|
-
-
|
|
519
|
+
- SDK 实例创建后会自动开始握手;默认单例仍按需懒创建,`ready()`、`on()` 或任意模块能力调用都会创建默认单例并开始握手。
|
|
520
|
+
- `ready()` 只等待已有握手结果,不主动触发新的握手;调用模块能力前会自动等待 `ready()`,但业务仍建议在页面启动阶段显式 `await ready()`,便于集中处理握手失败。
|
|
520
521
|
- `user.getInfo()`、`user.getCurrentUserDetail()`、`user.getCurrentUserProfile()`、`user.getPlatformAccountOverview()`、`user.getPlatformAccountInfo(platform)` 和 `user.getSteamGameList(options)` 不会触发登录;登录必须由业务在用户操作后调用 `auth.login()`。
|
|
521
522
|
- 当前用户详情和平台账号 API 只允许读取当前登录用户,不支持传入 `userid` 查询其他人,也不透传 `/account/home_v2/` 原始响应。
|
|
522
523
|
- 分享、截图、UI、设备、导航、storage 和网络请求只开放稳定窄接口,不透传黑盒客户端内部协议参数。
|
|
@@ -580,9 +581,9 @@ export default defineConfig({
|
|
|
580
581
|
pnpm --filter @heybox/hb-sdk run test:unit
|
|
581
582
|
pnpm --filter @heybox/hb-sdk run build:package
|
|
582
583
|
pnpm --filter @heybox/hb-sdk run check:boundary
|
|
583
|
-
pnpm
|
|
584
|
+
pnpm exec hbexec hb-sdk check
|
|
584
585
|
```
|
|
585
586
|
|
|
586
587
|
`check:boundary` 用于保护 SDK、CLI、mock host 与 runtime 之间的依赖边界。调整 CLI、mock 或协议导出时应一起运行。
|
|
587
588
|
|
|
588
|
-
`
|
|
589
|
+
`hbexec hb-sdk check` 只读校验 docs、skill references,并在临时目录生成与校验 `agent-skills` payload;不要求 canonical artifact 已存在,也不包含 changelog。维护清单见 `packages/hb-sdk/DOC_SYNC_CHECKLIST.md`。
|
|
@@ -5,7 +5,7 @@ var fs = require('node:fs/promises');
|
|
|
5
5
|
var path = require('node:path');
|
|
6
6
|
var require$$0 = require('fs');
|
|
7
7
|
var require$$1 = require('path');
|
|
8
|
-
var index = require('./index-
|
|
8
|
+
var index = require('./index-CkIWhOnc.cjs');
|
|
9
9
|
require('node:module');
|
|
10
10
|
require('os');
|
|
11
11
|
require('readline');
|
|
@@ -9,7 +9,7 @@ var node_url = require('node:url');
|
|
|
9
9
|
var net = require('node:net');
|
|
10
10
|
var node_http = require('node:http');
|
|
11
11
|
var browser = require('./browser-RAy8e8cV.cjs');
|
|
12
|
-
var index = require('./index-
|
|
12
|
+
var index = require('./index-CkIWhOnc.cjs');
|
|
13
13
|
require('node:process');
|
|
14
14
|
require('node:buffer');
|
|
15
15
|
require('node:util');
|
|
@@ -4,7 +4,7 @@ var fs$1 = require('node:fs');
|
|
|
4
4
|
var fs = require('node:fs/promises');
|
|
5
5
|
var os = require('node:os');
|
|
6
6
|
var path = require('node:path');
|
|
7
|
-
var index = require('./index-
|
|
7
|
+
var index = require('./index-CkIWhOnc.cjs');
|
|
8
8
|
require('node:module');
|
|
9
9
|
require('path');
|
|
10
10
|
require('os');
|
|
@@ -234,19 +234,19 @@ function requireArgument () {
|
|
|
234
234
|
|
|
235
235
|
var command = {};
|
|
236
236
|
|
|
237
|
-
const require$5 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli-chunks/index-
|
|
237
|
+
const require$5 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli-chunks/index-CkIWhOnc.cjs', document.baseURI).href)));
|
|
238
238
|
function __require$4() { return require$5("node:events"); }
|
|
239
239
|
|
|
240
|
-
const require$4 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli-chunks/index-
|
|
240
|
+
const require$4 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli-chunks/index-CkIWhOnc.cjs', document.baseURI).href)));
|
|
241
241
|
function __require$3() { return require$4("node:child_process"); }
|
|
242
242
|
|
|
243
|
-
const require$3 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli-chunks/index-
|
|
243
|
+
const require$3 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli-chunks/index-CkIWhOnc.cjs', document.baseURI).href)));
|
|
244
244
|
function __require$2() { return require$3("node:path"); }
|
|
245
245
|
|
|
246
|
-
const require$2 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli-chunks/index-
|
|
246
|
+
const require$2 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli-chunks/index-CkIWhOnc.cjs', document.baseURI).href)));
|
|
247
247
|
function __require$1() { return require$2("node:fs"); }
|
|
248
248
|
|
|
249
|
-
const require$1 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli-chunks/index-
|
|
249
|
+
const require$1 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli-chunks/index-CkIWhOnc.cjs', document.baseURI).href)));
|
|
250
250
|
function __require() { return require$1("node:process"); }
|
|
251
251
|
|
|
252
252
|
var help = {};
|
|
@@ -13094,7 +13094,7 @@ function readErrorMessage(error, options = {}) {
|
|
|
13094
13094
|
}
|
|
13095
13095
|
|
|
13096
13096
|
const CLI_VERSION_PLACEHOLDER = ['__HB', 'SDK', 'CLI', 'VERSION__'].join('_');
|
|
13097
|
-
const BUILT_CLI_VERSION = '0.5.
|
|
13097
|
+
const BUILT_CLI_VERSION = '0.5.14';
|
|
13098
13098
|
const PACKAGE_JSON_CANDIDATES = [
|
|
13099
13099
|
path.resolve(__dirname, '..', '..', 'package.json'),
|
|
13100
13100
|
path.resolve(__dirname, '..', 'package.json'),
|
|
@@ -13411,31 +13411,31 @@ function createCommandLoggerResolver(options) {
|
|
|
13411
13411
|
};
|
|
13412
13412
|
}
|
|
13413
13413
|
const defaultClearLoginStatus = async (...args) => {
|
|
13414
|
-
const { clearLoginStatus } = await Promise.resolve().then(function () { return require('./login-
|
|
13414
|
+
const { clearLoginStatus } = await Promise.resolve().then(function () { return require('./login-w5nfOJDF.cjs'); });
|
|
13415
13415
|
return clearLoginStatus(...args);
|
|
13416
13416
|
};
|
|
13417
13417
|
const defaultLoginToHeybox = async (...args) => {
|
|
13418
|
-
const { loginToHeybox } = await Promise.resolve().then(function () { return require('./login-
|
|
13418
|
+
const { loginToHeybox } = await Promise.resolve().then(function () { return require('./login-w5nfOJDF.cjs'); });
|
|
13419
13419
|
return loginToHeybox(...args);
|
|
13420
13420
|
};
|
|
13421
13421
|
const defaultPrintLoginStatus = async (...args) => {
|
|
13422
|
-
const { printLoginStatus } = await Promise.resolve().then(function () { return require('./login-
|
|
13422
|
+
const { printLoginStatus } = await Promise.resolve().then(function () { return require('./login-w5nfOJDF.cjs'); });
|
|
13423
13423
|
return printLoginStatus(...args);
|
|
13424
13424
|
};
|
|
13425
13425
|
const defaultRunCreateCommand = async (...args) => {
|
|
13426
|
-
const { runCreateCommand } = await Promise.resolve().then(function () { return require('./create-
|
|
13426
|
+
const { runCreateCommand } = await Promise.resolve().then(function () { return require('./create-BG31rI88.cjs'); });
|
|
13427
13427
|
return runCreateCommand(...args);
|
|
13428
13428
|
};
|
|
13429
13429
|
const defaultRunDevCommand = async (...args) => {
|
|
13430
|
-
const { runDevCommand } = await Promise.resolve().then(function () { return require('./dev-
|
|
13430
|
+
const { runDevCommand } = await Promise.resolve().then(function () { return require('./dev-yEoQHWA7.cjs'); });
|
|
13431
13431
|
return runDevCommand(...args);
|
|
13432
13432
|
};
|
|
13433
13433
|
const defaultRunDoctorCommand = async (...args) => {
|
|
13434
|
-
const { runDoctorCommand } = await Promise.resolve().then(function () { return require('./doctor-
|
|
13434
|
+
const { runDoctorCommand } = await Promise.resolve().then(function () { return require('./doctor-XxxsLM-t.cjs'); });
|
|
13435
13435
|
return runDoctorCommand(...args);
|
|
13436
13436
|
};
|
|
13437
13437
|
const defaultRunRemoteCommand = async (...args) => {
|
|
13438
|
-
const { runRemoteCommand } = await Promise.resolve().then(function () { return require('./remote-
|
|
13438
|
+
const { runRemoteCommand } = await Promise.resolve().then(function () { return require('./remote-CB40-si7.cjs'); }).then(function (n) { return n.remote; });
|
|
13439
13439
|
return runRemoteCommand(...args);
|
|
13440
13440
|
};
|
|
13441
13441
|
function resolveStandaloneLogger(options, verbose) {
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var index$2 = require('./index-
|
|
3
|
+
var index$2 = require('./index-CkIWhOnc.cjs');
|
|
4
4
|
var require$$0$2 = require('fs');
|
|
5
5
|
var require$$2$1 = require('crypto');
|
|
6
6
|
var require$$1$2 = require('path');
|
|
7
7
|
var require$$0$3 = require('assert');
|
|
8
8
|
var require$$4$2 = require('events');
|
|
9
9
|
var require$$1$1 = require('util');
|
|
10
|
-
var remote = require('./remote-
|
|
10
|
+
var remote = require('./remote-CB40-si7.cjs');
|
|
11
11
|
var require$$0$5 = require('net');
|
|
12
12
|
var require$$0$4 = require('url');
|
|
13
13
|
var require$$2$2 = require('http');
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
var promises = require('node:readline/promises');
|
|
4
4
|
var node_crypto = require('node:crypto');
|
|
5
5
|
var node_http = require('node:http');
|
|
6
|
-
var session = require('./session-
|
|
6
|
+
var session = require('./session-D0rnT6RG.cjs');
|
|
7
7
|
var browser = require('./browser-RAy8e8cV.cjs');
|
|
8
|
-
var index = require('./index-
|
|
8
|
+
var index = require('./index-CkIWhOnc.cjs');
|
|
9
9
|
require('node:path');
|
|
10
10
|
require('fs');
|
|
11
11
|
require('constants');
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var promises = require('node:readline/promises');
|
|
4
|
-
var session = require('./session-
|
|
4
|
+
var session = require('./session-D0rnT6RG.cjs');
|
|
5
5
|
var childProcess = require('node:child_process');
|
|
6
6
|
var fs = require('node:fs');
|
|
7
7
|
var fs$1 = require('node:fs/promises');
|
|
8
8
|
var path = require('node:path');
|
|
9
|
-
var index = require('./index-
|
|
9
|
+
var index = require('./index-CkIWhOnc.cjs');
|
|
10
10
|
|
|
11
11
|
var re = {exports: {}};
|
|
12
12
|
|
|
@@ -3115,7 +3115,7 @@ async function createDefaultCosClient(uploadToken) {
|
|
|
3115
3115
|
};
|
|
3116
3116
|
}
|
|
3117
3117
|
async function loadCosConstructor() {
|
|
3118
|
-
const cosModule = await Promise.resolve().then(function () { return require('./index-
|
|
3118
|
+
const cosModule = await Promise.resolve().then(function () { return require('./index-D4o196NT.cjs'); }).then(function (n) { return n.index; });
|
|
3119
3119
|
return cosModule.default;
|
|
3120
3120
|
}
|
|
3121
3121
|
function formatSize(bytes) {
|
package/dist/cli.cjs
CHANGED
package/dist/index.cjs.js
CHANGED
|
@@ -211,6 +211,8 @@ class MiniProgramBridgeClient {
|
|
|
211
211
|
readyTimer;
|
|
212
212
|
handshakeRetryTimer;
|
|
213
213
|
destroyed = false;
|
|
214
|
+
runtimeUnavailable = false;
|
|
215
|
+
runtimeUnavailableError;
|
|
214
216
|
constructor(options = {}) {
|
|
215
217
|
this.timeout = options.timeout || DEFAULT_TIMEOUT;
|
|
216
218
|
this.selfWindow = options.selfWindow || getGlobalWindow();
|
|
@@ -224,15 +226,14 @@ class MiniProgramBridgeClient {
|
|
|
224
226
|
this.rejectReady = reject;
|
|
225
227
|
});
|
|
226
228
|
this.readyPromise.catch(() => undefined);
|
|
229
|
+
this.ensureStarted();
|
|
227
230
|
}
|
|
228
231
|
/** 等待父容器握手完成。 */
|
|
229
232
|
ready() {
|
|
230
|
-
this.ensureStarted();
|
|
231
233
|
return this.readyPromise;
|
|
232
234
|
}
|
|
233
235
|
/** 注册小程序事件监听。 */
|
|
234
236
|
on(eventName, handler) {
|
|
235
|
-
this.ensureStarted();
|
|
236
237
|
return this.eventBus.on(eventName, handler);
|
|
237
238
|
}
|
|
238
239
|
/** 移除小程序事件监听。 */
|
|
@@ -241,7 +242,19 @@ class MiniProgramBridgeClient {
|
|
|
241
242
|
}
|
|
242
243
|
/** 调用父容器开放能力。 */
|
|
243
244
|
async request(method, ...args) {
|
|
245
|
+
if (this.destroyed) {
|
|
246
|
+
throw createSDKError('SDK_DESTROYED', '小程序 SDK 已销毁');
|
|
247
|
+
}
|
|
248
|
+
if (this.runtimeUnavailable) {
|
|
249
|
+
throw this.getRuntimeUnavailableError();
|
|
250
|
+
}
|
|
244
251
|
await this.ready();
|
|
252
|
+
if (this.destroyed) {
|
|
253
|
+
throw createSDKError('SDK_DESTROYED', '小程序 SDK 已销毁');
|
|
254
|
+
}
|
|
255
|
+
if (this.runtimeUnavailable) {
|
|
256
|
+
throw this.getRuntimeUnavailableError();
|
|
257
|
+
}
|
|
245
258
|
const payload = args[0];
|
|
246
259
|
const id = createMessageId();
|
|
247
260
|
const message = {
|
|
@@ -286,6 +299,10 @@ class MiniProgramBridgeClient {
|
|
|
286
299
|
this.failReady(createSDKError('SDK_DESTROYED', '小程序 SDK 已销毁'));
|
|
287
300
|
return;
|
|
288
301
|
}
|
|
302
|
+
if (this.runtimeUnavailable) {
|
|
303
|
+
this.failReady(this.getRuntimeUnavailableError());
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
289
306
|
if (this.started) {
|
|
290
307
|
return;
|
|
291
308
|
}
|
|
@@ -305,7 +322,14 @@ class MiniProgramBridgeClient {
|
|
|
305
322
|
try {
|
|
306
323
|
this.postHandshake();
|
|
307
324
|
this.handshakeRetryTimer = setInterval(() => {
|
|
308
|
-
|
|
325
|
+
try {
|
|
326
|
+
this.postHandshake();
|
|
327
|
+
}
|
|
328
|
+
catch (error) {
|
|
329
|
+
this.failReady(error instanceof HbMiniProgramSDKError
|
|
330
|
+
? error
|
|
331
|
+
: createSDKError('HANDSHAKE_FAILED', '小程序沙盒握手发送失败', error));
|
|
332
|
+
}
|
|
309
333
|
}, HANDSHAKE_RETRY_INTERVAL);
|
|
310
334
|
}
|
|
311
335
|
catch (error) {
|
|
@@ -348,7 +372,10 @@ class MiniProgramBridgeClient {
|
|
|
348
372
|
}
|
|
349
373
|
handleEvent(message) {
|
|
350
374
|
const eventName = message.method;
|
|
351
|
-
if (eventName === '
|
|
375
|
+
if (eventName === 'unload') {
|
|
376
|
+
this.markRuntimeUnavailable();
|
|
377
|
+
}
|
|
378
|
+
else if (eventName === 'ready' && !this.runtimeUnavailable) {
|
|
352
379
|
this.resolveReadyOnce();
|
|
353
380
|
}
|
|
354
381
|
this.eventBus.emit(eventName, message.payload);
|
|
@@ -401,6 +428,22 @@ class MiniProgramBridgeClient {
|
|
|
401
428
|
this.handshakeRetryTimer = undefined;
|
|
402
429
|
}
|
|
403
430
|
}
|
|
431
|
+
markRuntimeUnavailable() {
|
|
432
|
+
if (this.runtimeUnavailable) {
|
|
433
|
+
return;
|
|
434
|
+
}
|
|
435
|
+
const error = this.getRuntimeUnavailableError();
|
|
436
|
+
this.runtimeUnavailable = true;
|
|
437
|
+
this.clearReadyTimers();
|
|
438
|
+
this.failReady(error);
|
|
439
|
+
this.rejectAllPending(error);
|
|
440
|
+
}
|
|
441
|
+
getRuntimeUnavailableError() {
|
|
442
|
+
if (!this.runtimeUnavailableError) {
|
|
443
|
+
this.runtimeUnavailableError = createSDKError('RUNTIME_UNAVAILABLE', '小程序运行时已卸载');
|
|
444
|
+
}
|
|
445
|
+
return this.runtimeUnavailableError;
|
|
446
|
+
}
|
|
404
447
|
rejectAllPending(error) {
|
|
405
448
|
this.pendingRequests.forEach(pending => {
|
|
406
449
|
clearTimeout(pending.timer);
|
package/dist/index.esm.js
CHANGED
|
@@ -207,6 +207,8 @@ class MiniProgramBridgeClient {
|
|
|
207
207
|
readyTimer;
|
|
208
208
|
handshakeRetryTimer;
|
|
209
209
|
destroyed = false;
|
|
210
|
+
runtimeUnavailable = false;
|
|
211
|
+
runtimeUnavailableError;
|
|
210
212
|
constructor(options = {}) {
|
|
211
213
|
this.timeout = options.timeout || DEFAULT_TIMEOUT;
|
|
212
214
|
this.selfWindow = options.selfWindow || getGlobalWindow();
|
|
@@ -220,15 +222,14 @@ class MiniProgramBridgeClient {
|
|
|
220
222
|
this.rejectReady = reject;
|
|
221
223
|
});
|
|
222
224
|
this.readyPromise.catch(() => undefined);
|
|
225
|
+
this.ensureStarted();
|
|
223
226
|
}
|
|
224
227
|
/** 等待父容器握手完成。 */
|
|
225
228
|
ready() {
|
|
226
|
-
this.ensureStarted();
|
|
227
229
|
return this.readyPromise;
|
|
228
230
|
}
|
|
229
231
|
/** 注册小程序事件监听。 */
|
|
230
232
|
on(eventName, handler) {
|
|
231
|
-
this.ensureStarted();
|
|
232
233
|
return this.eventBus.on(eventName, handler);
|
|
233
234
|
}
|
|
234
235
|
/** 移除小程序事件监听。 */
|
|
@@ -237,7 +238,19 @@ class MiniProgramBridgeClient {
|
|
|
237
238
|
}
|
|
238
239
|
/** 调用父容器开放能力。 */
|
|
239
240
|
async request(method, ...args) {
|
|
241
|
+
if (this.destroyed) {
|
|
242
|
+
throw createSDKError('SDK_DESTROYED', '小程序 SDK 已销毁');
|
|
243
|
+
}
|
|
244
|
+
if (this.runtimeUnavailable) {
|
|
245
|
+
throw this.getRuntimeUnavailableError();
|
|
246
|
+
}
|
|
240
247
|
await this.ready();
|
|
248
|
+
if (this.destroyed) {
|
|
249
|
+
throw createSDKError('SDK_DESTROYED', '小程序 SDK 已销毁');
|
|
250
|
+
}
|
|
251
|
+
if (this.runtimeUnavailable) {
|
|
252
|
+
throw this.getRuntimeUnavailableError();
|
|
253
|
+
}
|
|
241
254
|
const payload = args[0];
|
|
242
255
|
const id = createMessageId();
|
|
243
256
|
const message = {
|
|
@@ -282,6 +295,10 @@ class MiniProgramBridgeClient {
|
|
|
282
295
|
this.failReady(createSDKError('SDK_DESTROYED', '小程序 SDK 已销毁'));
|
|
283
296
|
return;
|
|
284
297
|
}
|
|
298
|
+
if (this.runtimeUnavailable) {
|
|
299
|
+
this.failReady(this.getRuntimeUnavailableError());
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
285
302
|
if (this.started) {
|
|
286
303
|
return;
|
|
287
304
|
}
|
|
@@ -301,7 +318,14 @@ class MiniProgramBridgeClient {
|
|
|
301
318
|
try {
|
|
302
319
|
this.postHandshake();
|
|
303
320
|
this.handshakeRetryTimer = setInterval(() => {
|
|
304
|
-
|
|
321
|
+
try {
|
|
322
|
+
this.postHandshake();
|
|
323
|
+
}
|
|
324
|
+
catch (error) {
|
|
325
|
+
this.failReady(error instanceof HbMiniProgramSDKError
|
|
326
|
+
? error
|
|
327
|
+
: createSDKError('HANDSHAKE_FAILED', '小程序沙盒握手发送失败', error));
|
|
328
|
+
}
|
|
305
329
|
}, HANDSHAKE_RETRY_INTERVAL);
|
|
306
330
|
}
|
|
307
331
|
catch (error) {
|
|
@@ -344,7 +368,10 @@ class MiniProgramBridgeClient {
|
|
|
344
368
|
}
|
|
345
369
|
handleEvent(message) {
|
|
346
370
|
const eventName = message.method;
|
|
347
|
-
if (eventName === '
|
|
371
|
+
if (eventName === 'unload') {
|
|
372
|
+
this.markRuntimeUnavailable();
|
|
373
|
+
}
|
|
374
|
+
else if (eventName === 'ready' && !this.runtimeUnavailable) {
|
|
348
375
|
this.resolveReadyOnce();
|
|
349
376
|
}
|
|
350
377
|
this.eventBus.emit(eventName, message.payload);
|
|
@@ -397,6 +424,22 @@ class MiniProgramBridgeClient {
|
|
|
397
424
|
this.handshakeRetryTimer = undefined;
|
|
398
425
|
}
|
|
399
426
|
}
|
|
427
|
+
markRuntimeUnavailable() {
|
|
428
|
+
if (this.runtimeUnavailable) {
|
|
429
|
+
return;
|
|
430
|
+
}
|
|
431
|
+
const error = this.getRuntimeUnavailableError();
|
|
432
|
+
this.runtimeUnavailable = true;
|
|
433
|
+
this.clearReadyTimers();
|
|
434
|
+
this.failReady(error);
|
|
435
|
+
this.rejectAllPending(error);
|
|
436
|
+
}
|
|
437
|
+
getRuntimeUnavailableError() {
|
|
438
|
+
if (!this.runtimeUnavailableError) {
|
|
439
|
+
this.runtimeUnavailableError = createSDKError('RUNTIME_UNAVAILABLE', '小程序运行时已卸载');
|
|
440
|
+
}
|
|
441
|
+
return this.runtimeUnavailableError;
|
|
442
|
+
}
|
|
400
443
|
rejectAllPending(error) {
|
|
401
444
|
this.pendingRequests.forEach(pending => {
|
|
402
445
|
clearTimeout(pending.timer);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@heybox/hb-sdk",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.14",
|
|
4
4
|
"description": "",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -116,9 +116,7 @@
|
|
|
116
116
|
"build:templates": "node scripts/copy-cli-templates.cjs",
|
|
117
117
|
"build:types": "tsc -p tsconfig.dts.json",
|
|
118
118
|
"check:boundary": "node scripts/check-boundary.cjs",
|
|
119
|
-
"check:docs-sync": "
|
|
120
|
-
"sync:agent-skills-payload": "node skill/scripts/sync-agent-skills-payload.mjs",
|
|
121
|
-
"check:agent-skills-payload": "node skill/scripts/sync-agent-skills-payload.mjs --check",
|
|
119
|
+
"check:docs-sync": "pnpm -w exec hbexec hb-sdk check",
|
|
122
120
|
"clean": "rimraf ./dist && rimraf ./types",
|
|
123
121
|
"test:unit": "NODE_OPTIONS='--conditions=heybox' vitest run",
|
|
124
122
|
"test:unit:coverage": "NODE_OPTIONS='--conditions=heybox' vitest run --coverage",
|
package/skill/SKILL.md
CHANGED
|
@@ -118,6 +118,7 @@ For host/runtime/protocol-maintenance code:
|
|
|
118
118
|
- `pnpm --filter @heybox/hb-sdk run check:boundary`
|
|
119
119
|
- `pnpm --filter @heybox/hb-sdk run test:unit`
|
|
120
120
|
- Verify `dist/cli.cjs` does not have any `require('cos-nodejs-sdk-v5')` left after `build:cli`; the boundary check enforces this automatically.
|
|
121
|
-
8. Verify
|
|
122
|
-
- `pnpm
|
|
123
|
-
- `pnpm
|
|
121
|
+
8. Verify the canonical payload before publishing:
|
|
122
|
+
- `pnpm exec hbexec hb-sdk sync`
|
|
123
|
+
- `pnpm exec hbexec hb-sdk check`
|
|
124
|
+
- For a release artifact, run `pnpm exec hbexec hb-sdk sync --out-dir <payload-dir>` and then `pnpm exec hbexec hb-sdk check-artifact --artifact-dir <payload-dir>`.
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
- packages/hb-sdk/src/protocol.ts
|
|
8
8
|
- packages/hb-sdk/README.md
|
|
9
|
-
- apps/
|
|
9
|
+
- apps/docs/hb-sdk/reference/index.md
|
|
10
10
|
|
|
11
11
|
## Contents
|
|
12
12
|
|
|
@@ -197,16 +197,16 @@ export type {
|
|
|
197
197
|
|
|
198
198
|
# Reference
|
|
199
199
|
|
|
200
|
-
Reference 由
|
|
200
|
+
Reference 由 `@heybox/hb-sdk` 的公开导出与源码注释自动生成,不重复 Guide 的接入流程。
|
|
201
201
|
|
|
202
202
|
| 导出面 | 说明 |
|
|
203
203
|
| --- | --- |
|
|
204
|
-
| [Root API](
|
|
205
|
-
| [Protocol API](
|
|
204
|
+
| [Root API](api-root.md) | 来自 `src/index.ts` 的默认导出、命名导出与公开能力。 |
|
|
205
|
+
| [Protocol API](#public-protocol-entrypoint) | 来自 `src/protocol.ts` 的协议常量、消息类型与 method 契约。 |
|
|
206
206
|
|
|
207
207
|
## 查询建议
|
|
208
208
|
|
|
209
|
-
- 想查业务接入路径:先看 [Guide](
|
|
209
|
+
- 想查业务接入路径:先看 [Guide](recipes.md)。
|
|
210
210
|
- 想查导出符号:从 Root API 或 Protocol API 进入对应分类页。
|
|
211
211
|
- 想看场景化用法:优先看 Guide / Recipes 页面中的“进一步阅读”。
|
|
212
212
|
|
|
@@ -214,5 +214,5 @@ Reference 由 `packages/hb-sdk` 的公开导出与源码注释自动生成,不
|
|
|
214
214
|
|
|
215
215
|
| 导出面 | Classes | Functions | Interfaces | Types | Constants |
|
|
216
216
|
| --- | ---: | ---: | ---: | ---: | ---: |
|
|
217
|
-
| Root API | 3 | 4 |
|
|
218
|
-
| Protocol API | 0 | 1 |
|
|
217
|
+
| Root API | 3 | 4 | 67 | 57 | 4 |
|
|
218
|
+
| Protocol API | 0 | 1 | 39 | 66 | 32 |
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
## Package metadata
|
|
20
20
|
|
|
21
21
|
- Package: `@heybox/hb-sdk`
|
|
22
|
-
- Version at generation time: `0.5.
|
|
22
|
+
- Version at generation time: `0.5.14`
|
|
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`
|
|
@@ -640,7 +640,7 @@ await network.request({
|
|
|
640
640
|
|
|
641
641
|
## 生命周期事件
|
|
642
642
|
|
|
643
|
-
|
|
643
|
+
SDK 实例创建后会自动开始与父容器握手。使用 `on()` 监听父容器派发的小程序事件时,默认单例会被懒创建并自动开始握手;`on()` 会返回取消监听函数,组件卸载或页面销毁时应及时调用。
|
|
644
644
|
|
|
645
645
|
```ts
|
|
646
646
|
import { on } from '@heybox/hb-sdk';
|
package/skill/references/cli.md
CHANGED
|
@@ -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/
|
|
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
|
|
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
|
-
`
|
|
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
|
|
|
@@ -4,42 +4,21 @@
|
|
|
4
4
|
|
|
5
5
|
## Sources
|
|
6
6
|
|
|
7
|
-
- apps/
|
|
8
|
-
- apps/
|
|
9
|
-
|
|
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
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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/
|
|
8
|
-
- apps/
|
|
9
|
-
- apps/
|
|
10
|
-
- apps/
|
|
11
|
-
- apps/
|
|
12
|
-
- apps/
|
|
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 或隔离多个上下文时,再使用 [独立实例](
|
|
79
|
+
需要控制 `timeout`、注入测试 window 或隔离多个上下文时,再使用 [独立实例](#custom-instance-recipe)。
|
|
80
80
|
|
|
81
81
|
## User and login
|
|
82
82
|
|
|
@@ -193,8 +193,8 @@ stop()
|
|
|
193
193
|
|
|
194
194
|
完整载荷与事件名见:
|
|
195
195
|
|
|
196
|
-
- [MiniProgramEventPayloadMap](
|
|
197
|
-
- [MiniProgramEventName](
|
|
196
|
+
- [MiniProgramEventPayloadMap](api-root.md)
|
|
197
|
+
- [MiniProgramEventName](api-root.md)
|
|
198
198
|
|
|
199
199
|
## 生命周期建议
|
|
200
200
|
|
|
@@ -5,12 +5,13 @@
|
|
|
5
5
|
## Sources
|
|
6
6
|
|
|
7
7
|
- packages/hb-sdk/README.md
|
|
8
|
-
- apps/
|
|
8
|
+
- apps/docs/hb-sdk/guide/auth.md
|
|
9
9
|
## Required boundaries
|
|
10
10
|
|
|
11
11
|
## 能力边界
|
|
12
12
|
|
|
13
|
-
-
|
|
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 和网络请求只开放稳定窄接口,不透传黑盒客户端内部协议参数。
|
|
@@ -89,6 +89,20 @@ function frontmatterless(markdown) {
|
|
|
89
89
|
return markdown.replace(/^---\n[\s\S]*?\n---\n/, '').trimEnd();
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
+
function rewriteBundledRecipeLinks(markdown) {
|
|
93
|
+
return markdown
|
|
94
|
+
.replaceAll('(../recipes/custom-instance)', '(#custom-instance-recipe)')
|
|
95
|
+
.replaceAll('(../reference/protocol/interfaces/MiniProgramEventPayloadMap)', '(api-root.md)')
|
|
96
|
+
.replaceAll('(../reference/protocol/types/#miniprogrameventname)', '(api-root.md)');
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function rewriteBundledProtocolIndexLinks(markdown) {
|
|
100
|
+
return markdown
|
|
101
|
+
.replaceAll('(./root/)', '(api-root.md)')
|
|
102
|
+
.replaceAll('(./protocol/)', '(#public-protocol-entrypoint)')
|
|
103
|
+
.replaceAll('(../guide/)', '(recipes.md)');
|
|
104
|
+
}
|
|
105
|
+
|
|
92
106
|
function contents(items) {
|
|
93
107
|
return [
|
|
94
108
|
'',
|
|
@@ -177,16 +191,14 @@ const viteEntry = read('packages/hb-sdk/src/vite/index.ts');
|
|
|
177
191
|
const cliEntry = read('packages/hb-sdk/src/cli/index.ts');
|
|
178
192
|
const cliTemplateReadme = read('packages/hb-sdk/src/cli/templates/vue3-vite-ts/README.md.ejs');
|
|
179
193
|
const readme = read('packages/hb-sdk/README.md');
|
|
180
|
-
const cliGuide = frontmatterless(read('apps/
|
|
181
|
-
const
|
|
182
|
-
const
|
|
183
|
-
const
|
|
184
|
-
const
|
|
185
|
-
const
|
|
186
|
-
const
|
|
187
|
-
const
|
|
188
|
-
const referenceHome = frontmatterless(read('apps/h5/docs/hb_sdk/src/.vuepress/public/llms/reference/README.md'));
|
|
189
|
-
|
|
194
|
+
const cliGuide = frontmatterless(read('apps/docs/hb-sdk/guide/cli.md'));
|
|
195
|
+
const quickStart = frontmatterless(read('apps/docs/hb-sdk/guide/quick-start.md'));
|
|
196
|
+
const authGuide = frontmatterless(read('apps/docs/hb-sdk/guide/auth.md'));
|
|
197
|
+
const lifecycleGuide = frontmatterless(read('apps/docs/hb-sdk/guide/lifecycle.md'));
|
|
198
|
+
const errorGuide = frontmatterless(read('apps/docs/hb-sdk/guide/error-handling.md'));
|
|
199
|
+
const loginGate = frontmatterless(read('apps/docs/hb-sdk/recipes/login-gate.md'));
|
|
200
|
+
const customInstance = frontmatterless(read('apps/docs/hb-sdk/recipes/custom-instance.md'));
|
|
201
|
+
const referenceHome = frontmatterless(read('apps/docs/hb-sdk/reference/index.md'));
|
|
190
202
|
const quickStartSection = extractSection(readme, '## 快速开始');
|
|
191
203
|
const runtimeEnvironment = extractSection(readme, '## 运行环境');
|
|
192
204
|
const publicCapabilities = extractSection(readme, '## 常用能力');
|
|
@@ -300,7 +312,7 @@ ${lifecycleEvents}
|
|
|
300
312
|
files.set('api-protocol.md', `${header('Protocol API reference', [
|
|
301
313
|
'packages/hb-sdk/src/protocol.ts',
|
|
302
314
|
'packages/hb-sdk/README.md',
|
|
303
|
-
'apps/
|
|
315
|
+
'apps/docs/hb-sdk/reference/index.md',
|
|
304
316
|
])}${contents([
|
|
305
317
|
['Host/runtime-only warning', 'hostruntime-only-warning'],
|
|
306
318
|
['Public protocol entrypoint', 'public-protocol-entrypoint'],
|
|
@@ -320,7 +332,7 @@ ${sdkRuntimeRelation}
|
|
|
320
332
|
|
|
321
333
|
## Generated reference index
|
|
322
334
|
|
|
323
|
-
${referenceHome}
|
|
335
|
+
${rewriteBundledProtocolIndexLinks(referenceHome)}
|
|
324
336
|
`);
|
|
325
337
|
|
|
326
338
|
files.set('cli.md', `${header('CLI reference', [
|
|
@@ -330,7 +342,7 @@ files.set('cli.md', `${header('CLI reference', [
|
|
|
330
342
|
'packages/hb-sdk/src/cli/commands/dev.ts',
|
|
331
343
|
'packages/hb-sdk/src/cli/commands/login.ts',
|
|
332
344
|
'packages/hb-sdk/src/cli/templates/vue3-vite-ts/README.md.ejs',
|
|
333
|
-
'apps/
|
|
345
|
+
'apps/docs/hb-sdk/guide/cli.md',
|
|
334
346
|
'packages/hb-sdk/README.md',
|
|
335
347
|
])}${contents([
|
|
336
348
|
['When to use the CLI', 'when-to-use-the-cli'],
|
|
@@ -463,12 +475,12 @@ ${fenced('md', cliTemplateReadme)}
|
|
|
463
475
|
`);
|
|
464
476
|
|
|
465
477
|
files.set('recipes.md', `${header('Recipes', [
|
|
466
|
-
'apps/
|
|
467
|
-
'apps/
|
|
468
|
-
'apps/
|
|
469
|
-
'apps/
|
|
470
|
-
'apps/
|
|
471
|
-
'apps/
|
|
478
|
+
'apps/docs/hb-sdk/guide/quick-start.md',
|
|
479
|
+
'apps/docs/hb-sdk/guide/auth.md',
|
|
480
|
+
'apps/docs/hb-sdk/guide/lifecycle.md',
|
|
481
|
+
'apps/docs/hb-sdk/guide/error-handling.md',
|
|
482
|
+
'apps/docs/hb-sdk/recipes/login-gate.md',
|
|
483
|
+
'apps/docs/hb-sdk/recipes/custom-instance.md',
|
|
472
484
|
])}${contents([
|
|
473
485
|
['Quick start', 'quick-start'],
|
|
474
486
|
['User and login', 'user-and-login'],
|
|
@@ -478,32 +490,32 @@ files.set('recipes.md', `${header('Recipes', [
|
|
|
478
490
|
['Custom instance recipe', 'custom-instance-recipe'],
|
|
479
491
|
])}## Quick start
|
|
480
492
|
|
|
481
|
-
${quickStart}
|
|
493
|
+
${rewriteBundledRecipeLinks(quickStart)}
|
|
482
494
|
|
|
483
495
|
## User and login
|
|
484
496
|
|
|
485
|
-
${authGuide}
|
|
497
|
+
${rewriteBundledRecipeLinks(authGuide)}
|
|
486
498
|
|
|
487
499
|
## Lifecycle events
|
|
488
500
|
|
|
489
|
-
${lifecycleGuide}
|
|
501
|
+
${rewriteBundledRecipeLinks(lifecycleGuide)}
|
|
490
502
|
|
|
491
503
|
## Error handling
|
|
492
504
|
|
|
493
|
-
${errorGuide}
|
|
505
|
+
${rewriteBundledRecipeLinks(errorGuide)}
|
|
494
506
|
|
|
495
507
|
## Login gate recipe
|
|
496
508
|
|
|
497
|
-
${loginGate}
|
|
509
|
+
${rewriteBundledRecipeLinks(loginGate)}
|
|
498
510
|
|
|
499
511
|
## Custom instance recipe
|
|
500
512
|
|
|
501
|
-
${customInstance}
|
|
513
|
+
${rewriteBundledRecipeLinks(customInstance)}
|
|
502
514
|
`);
|
|
503
515
|
|
|
504
516
|
files.set('safety-boundaries.md', `${header('Safety boundaries', [
|
|
505
517
|
'packages/hb-sdk/README.md',
|
|
506
|
-
'apps/
|
|
518
|
+
'apps/docs/hb-sdk/guide/auth.md',
|
|
507
519
|
])}## Required boundaries
|
|
508
520
|
|
|
509
521
|
${capabilityBoundaries}
|
|
@@ -521,18 +533,30 @@ ${capabilityBoundaries}
|
|
|
521
533
|
`);
|
|
522
534
|
|
|
523
535
|
files.set('llms-index.md', `${header('LLM documentation index', [
|
|
524
|
-
'apps/
|
|
525
|
-
'apps/
|
|
526
|
-
|
|
536
|
+
'apps/docs/hb-sdk/guide/**',
|
|
537
|
+
'apps/docs/hb-sdk/recipes/**',
|
|
538
|
+
'apps/docs/hb-sdk/reference/**',
|
|
539
|
+
'packages/hb-sdk/src/**',
|
|
540
|
+
])}## Offline references
|
|
541
|
+
|
|
542
|
+
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.
|
|
543
|
+
|
|
544
|
+
- Root SDK and Vite API: \`references/api-root.md\`
|
|
545
|
+
- Host/runtime protocol API: \`references/api-protocol.md\`
|
|
546
|
+
- CLI and local development: \`references/cli.md\`
|
|
547
|
+
- Common flows: \`references/recipes.md\`
|
|
548
|
+
- Security and capability limits: \`references/safety-boundaries.md\`
|
|
549
|
+
- Examples and evaluation: \`references/examples.md\`, \`references/smoke-evaluation.md\`
|
|
527
550
|
|
|
528
|
-
|
|
551
|
+
## Online supplement
|
|
529
552
|
|
|
530
|
-
|
|
553
|
+
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
554
|
`);
|
|
532
555
|
|
|
533
556
|
files.set('examples.md', `${header('Smoke examples and anti-examples', [
|
|
534
557
|
'packages/hb-sdk/README.md',
|
|
535
|
-
'apps/
|
|
558
|
+
'apps/docs/hb-sdk/guide/**',
|
|
559
|
+
'apps/docs/hb-sdk/recipes/**',
|
|
536
560
|
])}## Positive examples
|
|
537
561
|
|
|
538
562
|
### Minimal user info
|
|
@@ -70,6 +70,23 @@ function parseFrontmatter(markdown) {
|
|
|
70
70
|
return fields;
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
+
function validateLocalMarkdownLinks(filePath, markdown) {
|
|
74
|
+
const linkPattern = /\[[^\]]*\]\(([^)]+)\)/g;
|
|
75
|
+
for (const match of markdown.matchAll(linkPattern)) {
|
|
76
|
+
const rawTarget = match[1].trim().replace(/^<|>$/g, '');
|
|
77
|
+
if (/^(?:https?:|mailto:|#)/i.test(rawTarget)) continue;
|
|
78
|
+
|
|
79
|
+
const targetWithoutAnchor = rawTarget.split('#')[0];
|
|
80
|
+
if (!targetWithoutAnchor) continue;
|
|
81
|
+
|
|
82
|
+
const resolved = path.resolve(path.dirname(filePath), targetWithoutAnchor);
|
|
83
|
+
if (!existsSync(resolved)) {
|
|
84
|
+
const line = markdown.slice(0, match.index).split('\n').length;
|
|
85
|
+
fail(`Broken local Markdown link in ${skillRel(filePath)}:${line}: ${rawTarget}`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
73
90
|
const requiredFiles = [
|
|
74
91
|
'SKILL.md',
|
|
75
92
|
'skill.json',
|
|
@@ -180,6 +197,7 @@ const removedUserLoginPattern = /\b(?:hbSDK\.)?user\.login\s*\(/;
|
|
|
180
197
|
for (const file of textFiles) {
|
|
181
198
|
const relative = skillRel(file);
|
|
182
199
|
const content = read(file);
|
|
200
|
+
if (file.endsWith('.md')) validateLocalMarkdownLinks(file, content);
|
|
183
201
|
if (removedUserLoginPattern.test(content)) {
|
|
184
202
|
fail(`Removed API guidance found in ${relative}: use auth.login() instead of user.login().`);
|
|
185
203
|
}
|
package/skill/skill.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hb-sdk",
|
|
3
|
-
"skillVersion": "0.5.
|
|
3
|
+
"skillVersion": "0.5.14+skill.2ed2b210acdb",
|
|
4
4
|
"sdk": {
|
|
5
5
|
"package": "@heybox/hb-sdk",
|
|
6
|
-
"version": "0.5.
|
|
7
|
-
"compatibility": "0.5.
|
|
6
|
+
"version": "0.5.14",
|
|
7
|
+
"compatibility": "0.5.14"
|
|
8
8
|
},
|
|
9
9
|
"source": "https://open.xiaoheihe.cn/agent-skills/hb-sdk",
|
|
10
|
-
"integrity": "sha256-
|
|
10
|
+
"integrity": "sha256-2ed2b210acdb606888cde6fb80559ce26500c105b143914910b88b3d6b06eaf9"
|
|
11
11
|
}
|
package/types/core/client.d.ts
CHANGED
|
@@ -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 {};
|