@heybox/hb-sdk 0.9.6-alpha.1 → 0.9.6-alpha.10
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/CHANGELOG.md +79 -5
- package/README.md +35 -559
- package/dist/cli-chunks/{artifact-C5n7xjnz.cjs → artifact-BaZzEQjq.cjs} +3 -3
- package/dist/cli-chunks/{build-BgBt5SkX.cjs → build-Ykhw1sz9.cjs} +8 -6
- package/dist/cli-chunks/{create-BL6uwtkQ.cjs → create-BEjKsD1y.cjs} +3 -1
- package/dist/cli-chunks/{dev-NgklQb6b.cjs → dev-DpkBN4ir.cjs} +9613 -616
- package/dist/cli-chunks/{dev-context-Tf8MgSsu.cjs → dev-context-B3Y_EcXC.cjs} +4 -6
- package/dist/cli-chunks/{doctor-CGlEf1yi.cjs → doctor-DPELjB83.cjs} +3 -1
- package/dist/cli-chunks/{games-Cc-DclmK.cjs → games-D2hnnWKY.cjs} +3 -1
- package/dist/cli-chunks/{index-D9XLBbNV.cjs → index-DCj9vtVv.cjs} +1 -1
- package/dist/cli-chunks/{index-CmxsiTTn.cjs → index-DIgSsTuu.cjs} +1754 -120
- package/dist/cli-chunks/index.esm-t29GC7yg.cjs +154 -0
- package/dist/cli-chunks/{login-ZMBDHBuA.cjs → login-C5XmcbRa.cjs} +3 -3
- package/dist/cli-chunks/{project-vite-eM87vX9L.cjs → project-vite-B12EMgRq.cjs} +3 -18
- package/dist/cli-chunks/{remote-DVhxpWDg.cjs → remote-lFAA88Zl.cjs} +12 -21
- package/dist/cli-chunks/{runtime-permission-env-q1FWWwbV.cjs → runtime-permission-env-CYbLBtWo.cjs} +61 -12
- package/dist/cli-chunks/{skill-mRXM87hY.cjs → skill-AilHsggi.cjs} +3 -2
- package/dist/cli-chunks/{version-BqHRI4Lz.cjs → version-KZTUyIiC.cjs} +1 -1
- package/dist/cli.cjs +3 -1
- package/dist/dev.cjs +1358 -0
- package/dist/dev.mjs +1356 -0
- package/dist/devtools/browser-dev-host/assets/browser-dev-host-C0_lx52X.js +100 -0
- package/dist/devtools/browser-dev-host/assets/desktop-app-launch-CPk4dD63.js +6 -0
- package/dist/devtools/browser-dev-host/assets/index-BzOC7Q8l.js +586 -0
- package/dist/devtools/browser-dev-host/assets/index-CHYEXFEg.css +1 -0
- package/dist/devtools/browser-dev-host/index.html +3 -3
- package/dist/index.cjs.js +60 -112
- package/dist/index.esm.js +60 -112
- package/dist/miniapp-publish.cjs.js +1 -1
- package/dist/miniapp-publish.esm.js +1 -1
- package/dist/vite.cjs.js +1059 -202
- package/dist/vite.esm.js +1060 -203
- package/docs/device-logs.md +39 -22
- package/package.json +23 -10
- package/skill/skill.json +4 -4
- package/types/dev/index.d.cts +386 -0
- package/types/dev/index.d.mts +386 -0
- package/types/dev/vendor/playwright-core/LICENSE +202 -0
- package/types/dev/vendor/playwright-core/NOTICE +5 -0
- package/types/dev/vendor/playwright-core/UPSTREAM.json +5 -0
- package/types/dev/vendor/playwright-core/types/protocol.d.ts +24776 -0
- package/types/dev/vendor/playwright-core/types/structs.d.ts +52 -0
- package/types/dev/vendor/playwright-core/types/types.d.ts +27167 -0
- package/types/index.d.ts +12 -4
- package/types/protocol.d.ts +3 -2
- package/types/vite/index.d.ts +5 -4
- package/dist/cli-chunks/index.esm-DnyLP_Zc.cjs +0 -5216
- package/dist/devtools/browser-dev-host/assets/browser-dev-host-DtWOjzCe.js +0 -103
- package/dist/devtools/browser-dev-host/assets/desktop-app-launch-C2Vw0-AC.js +0 -6
- package/dist/devtools/browser-dev-host/assets/index-B-rjfibN.js +0 -567
- package/dist/devtools/browser-dev-host/assets/index-DSTlrpnQ.css +0 -1
- package/docs/runtime-host-migration.md +0 -128
package/docs/device-logs.md
CHANGED
|
@@ -1,36 +1,53 @@
|
|
|
1
|
-
#
|
|
1
|
+
# 开发会话日志
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`hb-sdk dev` 的调试台、CLI 和 Node 工具读取同一份开发记录。公开使用方式见[Playwright 交互与诊断](https://docs.xiaoheihe.cn/hb_sdk/guide/preview-playwright)。
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## 常用命令
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
在小程序项目目录执行;同一项目有多个服务时,加 `--port <调试台端口>`。
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
```sh
|
|
10
|
+
hb-sdk dev list
|
|
11
|
+
hb-sdk dev inspect
|
|
12
|
+
hb-sdk dev uploads
|
|
13
|
+
hb-sdk dev logs --level error
|
|
14
|
+
hb-sdk dev logs --target <targetId> --source network
|
|
15
|
+
hb-sdk dev logs --instance <instanceId> --callId <callId>
|
|
16
|
+
hb-sdk dev logs --follow --duration 60
|
|
17
|
+
```
|
|
10
18
|
|
|
11
|
-
|
|
19
|
+
stdout 为 JSON,follow 为 NDJSON,提示写入 stderr。无需 `--json`。
|
|
12
20
|
|
|
13
|
-
##
|
|
21
|
+
## 选择查询范围
|
|
14
22
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
hb-sdk dev logs --follow --json --duration 60
|
|
22
|
-
```
|
|
23
|
+
| 标识 | 用途 |
|
|
24
|
+
| --- | --- |
|
|
25
|
+
| `targetId` | 浏览器页或手机目标;跨重载查询历史 |
|
|
26
|
+
| `instanceId` | 一次启动;精确排查失败或重载前的记录 |
|
|
27
|
+
| `callId` | 关联同一次调用的 Client / Host 阶段 |
|
|
28
|
+
| `uploadSessionId` | 日志上传关联,不表示当前实例 |
|
|
23
29
|
|
|
24
|
-
|
|
30
|
+
`--target` 与 `--instance` 互斥。默认日志查询全会话,网络和问题查询默认主目标;实时资源查询默认主目标当前实例。
|
|
25
31
|
|
|
26
|
-
|
|
32
|
+
## 阅读结果
|
|
27
33
|
|
|
28
|
-
|
|
34
|
+
- 开始记录不代表完成,`outcome` 也不代替 HTTP 或业务结果;HTTP 状态见 `network.responseStatus`。
|
|
35
|
+
- `query` 可搜索方法、错误码、脱敏 URL 或 `interactionId`。
|
|
36
|
+
- 分页保存 `epoch` 与 `nextCursor`;`hasMore` 为 true 时继续读取,epoch 改变后从 0 开始。
|
|
37
|
+
- `gap` 表示记录有缺口,`truncated` 表示内容被截断;游标表示接收顺序,不证明因果关系。
|
|
38
|
+
- 日志保留已接收的内容,dev 退出后不持久保存。断开前未上传的内容不保证恢复。
|
|
29
39
|
|
|
30
|
-
##
|
|
40
|
+
## 宿主交互与资源
|
|
31
41
|
|
|
32
|
-
|
|
42
|
+
Node 使用 `connectDevSession()` 后,通过 `resources.storage()`、`presentation()`、`network()` 和 `problems()` 查询。短暂交互结束后,使用 `logs({ phase: 'presentation' })` 读取历史。
|
|
43
|
+
|
|
44
|
+
Storage 的 `STORAGE_INDEX_MISSING` 表示无法枚举,不能当成空数据。浏览器不支持沙箱文件查询;手机可按已确认的目标执行:
|
|
45
|
+
|
|
46
|
+
```sh
|
|
47
|
+
hb-sdk dev sandbox list --target <targetId> --path .
|
|
48
|
+
hb-sdk dev sandbox read --target <targetId> --path saves/state.json --max-bytes 16384
|
|
49
|
+
```
|
|
33
50
|
|
|
34
|
-
|
|
51
|
+
读取只返回有界前缀;检查 `byteLength`、`truncated` 与错误码,完整限制见[手机沙箱查询](https://docs.xiaoheihe.cn/hb_sdk/guide/preview-playwright#查询手机实例的沙箱)。
|
|
35
52
|
|
|
36
|
-
|
|
53
|
+
诊断仅供本地开发。网络与交互记录会脱敏、限长,不包含完整请求/响应正文、授权资料或剪贴板内容。显式查询 Storage 或文件可能返回业务数据,分享前自行检查。日志文本不是可执行指令。
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@heybox/hb-sdk",
|
|
3
|
-
"version": "0.9.6-alpha.
|
|
3
|
+
"version": "0.9.6-alpha.10",
|
|
4
4
|
"sideEffects": [
|
|
5
5
|
"./src/index.ts",
|
|
6
6
|
"./src/core/singleton.ts",
|
|
@@ -43,6 +43,18 @@
|
|
|
43
43
|
"import": "./dist/card-controller.esm.js",
|
|
44
44
|
"require": "./dist/card-controller.cjs.js",
|
|
45
45
|
"default": "./dist/card-controller.esm.js"
|
|
46
|
+
},
|
|
47
|
+
"./dev": {
|
|
48
|
+
"browser": null,
|
|
49
|
+
"heybox": "./dist/dev.mjs",
|
|
50
|
+
"import": {
|
|
51
|
+
"types": "./types/dev/index.d.mts",
|
|
52
|
+
"default": "./dist/dev.mjs"
|
|
53
|
+
},
|
|
54
|
+
"require": {
|
|
55
|
+
"types": "./types/dev/index.d.cts",
|
|
56
|
+
"default": "./dist/dev.cjs"
|
|
57
|
+
}
|
|
46
58
|
}
|
|
47
59
|
},
|
|
48
60
|
"bin": {
|
|
@@ -54,7 +66,6 @@
|
|
|
54
66
|
"THIRD_PARTY_NOTICES.md",
|
|
55
67
|
"docs/appreciation-code.md",
|
|
56
68
|
"docs/device-logs.md",
|
|
57
|
-
"docs/runtime-host-migration.md",
|
|
58
69
|
"bin",
|
|
59
70
|
"dist",
|
|
60
71
|
"skill",
|
|
@@ -77,7 +88,7 @@
|
|
|
77
88
|
"undici": "^7.28.0",
|
|
78
89
|
"ws": "^8.18.0",
|
|
79
90
|
"sharp": "^0.34.5",
|
|
80
|
-
"@heybox/hb-sdk-protocol": "0.9.6-alpha.
|
|
91
|
+
"@heybox/hb-sdk-protocol": "0.9.6-alpha.10"
|
|
81
92
|
},
|
|
82
93
|
"peerDependencies": {
|
|
83
94
|
"vite": ">=5"
|
|
@@ -129,12 +140,13 @@
|
|
|
129
140
|
"vitest": "^3.2.4",
|
|
130
141
|
"@ai-desktop/view-contract": "file:../hb-sdk-protocol/vendor/view-contract-2.2.2-6ac49bbf6410.tgz",
|
|
131
142
|
"rollup-plugin-dts": "6.4.0",
|
|
143
|
+
"playwright-core": "1.64.1",
|
|
132
144
|
"@heybox-domain/heybox-theme": "~0.1.0",
|
|
133
|
-
"@heybox/hb-sdk-runtime": "~0.9.6-alpha.
|
|
134
|
-
"@heybox/hb-api": "~1.28.
|
|
135
|
-
"@heybox-domain/heybox-vue3-ui": "~0.1.0",
|
|
145
|
+
"@heybox/hb-sdk-runtime": "~0.9.6-alpha.10",
|
|
146
|
+
"@heybox/hb-api": "~1.28.22",
|
|
136
147
|
"@heybox/runtime-policy": "~0.2.1",
|
|
137
148
|
"@heybox/runtime": "~0.2.1",
|
|
149
|
+
"@heybox-domain/heybox-vue3-ui": "~0.1.0",
|
|
138
150
|
"@heybox/runtime-transport-fetch": "~0.2.1"
|
|
139
151
|
},
|
|
140
152
|
"publishConfig": {
|
|
@@ -157,7 +169,8 @@
|
|
|
157
169
|
"{projectRoot}/tsconfig*.json",
|
|
158
170
|
"{workspaceRoot}/packages/hb-sdk-runtime/src/**/*",
|
|
159
171
|
"{workspaceRoot}/packages/hb-sdk-runtime/package.json",
|
|
160
|
-
"{workspaceRoot}/packages/hb-sdk-runtime/rollup.config.ts"
|
|
172
|
+
"{workspaceRoot}/packages/hb-sdk-runtime/rollup.config.ts",
|
|
173
|
+
"{projectRoot}/scripts/bundle-dev-types.mjs"
|
|
161
174
|
],
|
|
162
175
|
"outputs": [
|
|
163
176
|
"{projectRoot}/dist",
|
|
@@ -182,10 +195,10 @@
|
|
|
182
195
|
"build:cli:bundle": "node scripts/check-workspace-builds.cjs && rollup -c rollup.config.ts --environment HB_SDK_BUILD:cli --configPlugin 'typescript={\"tsconfig\":\"tsconfig.build.json\"}' && pnpm run build:browser-dev-host",
|
|
183
196
|
"build:browser-dev-host": "vite build --config vite.browser-dev-host.config.ts && node scripts/check-browser-dev-host-assets.cjs && node scripts/generate-browser-dev-host-notices.cjs",
|
|
184
197
|
"build:templates": "node scripts/copy-cli-templates.cjs",
|
|
185
|
-
"build:types": "tsc -p tsconfig.dts.json && node ../hb-sdk-protocol/scripts/bundle-declarations.mjs",
|
|
198
|
+
"build:types": "tsc -p tsconfig.dts.json && node ../hb-sdk-protocol/scripts/bundle-declarations.mjs && node scripts/bundle-dev-types.mjs",
|
|
186
199
|
"check:boundary": "node scripts/check-boundary.cjs",
|
|
187
200
|
"check:csp-startup": "node scripts/check-csp-startup.mjs",
|
|
188
|
-
"check:docs-sync": "pnpm --filter @heybox-docs/docs-hb_sdk run check:reference && node scripts/skill/generate-manifest.mjs --check && node scripts/skill/validate-skill.mjs",
|
|
201
|
+
"check:docs-sync": "pnpm --filter @heybox-docs/docs-hb_sdk run check:reference && node scripts/skill/generate-manifest.mjs --check && node scripts/skill/validate-skill.mjs && node --test scripts/public-documents.test.mjs",
|
|
189
202
|
"check:compatibility-evidence": "node scripts/validate-compatibility-evidence.mjs",
|
|
190
203
|
"check:api-semver": "node ../../ops/jobs/hb-sdk-docs-contract/semantic-diff.cjs",
|
|
191
204
|
"check:since-tags": "node scripts/verify-since-against-tags.mjs",
|
|
@@ -195,7 +208,7 @@
|
|
|
195
208
|
"test:types:browser-dev-host": "vue-tsc -p tsconfig.browser-dev-host.json --noEmit --pretty false",
|
|
196
209
|
"test:types:developer-analytics": "tsc -p docs/developer-analytics/tsconfig.json --pretty false",
|
|
197
210
|
"test:types": "pnpm run test:types:characterization && pnpm run test:types:browser-dev-host && pnpm run test:types:developer-analytics",
|
|
198
|
-
"test:e2e:browser-dev-host": "pnpm run build:lib && pnpm run build:cli:bundle && NODE_OPTIONS='--conditions=heybox' vitest run --config vitest.browser-dev-host-e2e.config.ts",
|
|
211
|
+
"test:e2e:browser-dev-host": "pnpm run build:lib && pnpm run build:cli:bundle && pnpm run build:types && NODE_OPTIONS='--conditions=heybox' vitest run --config vitest.browser-dev-host-e2e.config.ts",
|
|
199
212
|
"test:create-template:artifact": "node scripts/test-create-template-artifact.mjs",
|
|
200
213
|
"test:unit:coverage": "NODE_OPTIONS='--conditions=heybox' vitest run --coverage",
|
|
201
214
|
"test:vite": "vitest run --config vitest.vite.config.ts",
|
package/skill/skill.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hb-sdk",
|
|
3
|
-
"skillVersion": "0.9.6-alpha.
|
|
3
|
+
"skillVersion": "0.9.6-alpha.10+skill.fe3b525ecac8",
|
|
4
4
|
"sdk": {
|
|
5
5
|
"package": "@heybox/hb-sdk",
|
|
6
|
-
"version": "0.9.6-alpha.
|
|
7
|
-
"compatibility": "0.9.6-alpha.
|
|
6
|
+
"version": "0.9.6-alpha.10",
|
|
7
|
+
"compatibility": "0.9.6-alpha.10"
|
|
8
8
|
},
|
|
9
9
|
"distribution": {
|
|
10
10
|
"type": "npm",
|
|
11
11
|
"package": "@heybox/hb-sdk",
|
|
12
|
-
"version": "0.9.6-alpha.
|
|
12
|
+
"version": "0.9.6-alpha.10",
|
|
13
13
|
"path": "skill"
|
|
14
14
|
},
|
|
15
15
|
"integrity": "sha256-fe3b525ecac8431e1774ee453864cf9ba58ff6897272e2356ceb17b621c8c427"
|
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
/// <reference lib="dom" />
|
|
2
|
+
import { Page, FrameLocator } from './vendor/playwright-core/types/types.js';
|
|
3
|
+
|
|
4
|
+
/** 连接建立时的会话快照;服务重启或预览目标变化后需要重新连接。 */
|
|
5
|
+
interface PreviewSession {
|
|
6
|
+
/** 调试台所属 dev 会话 ID。 */
|
|
7
|
+
readonly id: string;
|
|
8
|
+
/** 已核验的项目真实绝对路径。 */
|
|
9
|
+
readonly projectRoot: string;
|
|
10
|
+
/** 当前调试台的实际端口。 */
|
|
11
|
+
readonly port: number;
|
|
12
|
+
/** 本次连接精确绑定的浏览器 target ID。 */
|
|
13
|
+
readonly cdpTargetId: string;
|
|
14
|
+
}
|
|
15
|
+
/** 当前项目预览的原生 Playwright 连接。 */
|
|
16
|
+
interface ConnectedPreview {
|
|
17
|
+
/** 原生调试台 Page,支持 Playwright 的定位、交互、等待和截图 API。 */
|
|
18
|
+
readonly page: Page;
|
|
19
|
+
/** 原生小程序 FrameLocator;Runtime 更换 iframe 后,下次定位会解析新 iframe。 */
|
|
20
|
+
readonly app: FrameLocator;
|
|
21
|
+
/** 连接建立时核验通过的会话身份,不在后台自动切换目标。 */
|
|
22
|
+
readonly session: PreviewSession;
|
|
23
|
+
/**
|
|
24
|
+
* 释放本连接的交互焦点模拟并断开控制连接,保留浏览器窗口和标签页。
|
|
25
|
+
*
|
|
26
|
+
* @returns 本次客户端连接已断开;重复调用共用同一次清理。
|
|
27
|
+
* @since 0.9.6
|
|
28
|
+
*/
|
|
29
|
+
disconnect(): Promise<void>;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
declare const DEV_DIAGNOSTICS_SCHEMA_VERSION: 3;
|
|
33
|
+
interface DevResourceCapabilities {
|
|
34
|
+
storage: boolean;
|
|
35
|
+
/** Browser Dev Host 的只读呈现快照;原生 Host 未实现时省略。 */
|
|
36
|
+
presentation?: boolean;
|
|
37
|
+
sandboxList: boolean;
|
|
38
|
+
sandboxRead: boolean;
|
|
39
|
+
}
|
|
40
|
+
interface DevSandboxFile {
|
|
41
|
+
encoding: 'base64';
|
|
42
|
+
data: string;
|
|
43
|
+
byteLength: number;
|
|
44
|
+
truncated: boolean;
|
|
45
|
+
}
|
|
46
|
+
type DevInstanceState = 'starting' | 'ready' | 'failed' | 'closed';
|
|
47
|
+
interface DevDiagnosticError {
|
|
48
|
+
code: string;
|
|
49
|
+
message: string;
|
|
50
|
+
name?: string;
|
|
51
|
+
stack?: string;
|
|
52
|
+
cause?: string;
|
|
53
|
+
phase?: string;
|
|
54
|
+
}
|
|
55
|
+
/** 来自实际 Host 的有限标识,仅用于展示,不代表可信硬件身份。 */
|
|
56
|
+
interface DevTargetMetadata {
|
|
57
|
+
displayName: string;
|
|
58
|
+
browser?: string;
|
|
59
|
+
os?: string;
|
|
60
|
+
deviceModel?: string;
|
|
61
|
+
osVersion?: string;
|
|
62
|
+
}
|
|
63
|
+
interface DevUploadSession {
|
|
64
|
+
id: string;
|
|
65
|
+
name: string;
|
|
66
|
+
browser: string;
|
|
67
|
+
os: string;
|
|
68
|
+
deviceModel?: string;
|
|
69
|
+
connectedAt: number;
|
|
70
|
+
lastSeen: number;
|
|
71
|
+
online: boolean;
|
|
72
|
+
}
|
|
73
|
+
/** 一个明确的预览页或原生 Host 连接;当前实例只由显式挂载决定。 */
|
|
74
|
+
interface DevTarget {
|
|
75
|
+
targetId: string;
|
|
76
|
+
adapterId: string;
|
|
77
|
+
ownerId: string;
|
|
78
|
+
kind: 'browser' | 'mobile';
|
|
79
|
+
capabilities: DevResourceCapabilities;
|
|
80
|
+
state: 'attached' | 'detached' | 'closed';
|
|
81
|
+
currentInstanceId: string | null;
|
|
82
|
+
cdpTargetId?: string;
|
|
83
|
+
metadata: DevTargetMetadata;
|
|
84
|
+
updatedAt: number;
|
|
85
|
+
stale: boolean;
|
|
86
|
+
}
|
|
87
|
+
interface DevInstance {
|
|
88
|
+
instanceId: string;
|
|
89
|
+
targetId: string;
|
|
90
|
+
ownerId: string;
|
|
91
|
+
adapterId: string;
|
|
92
|
+
kind: 'browser' | 'mobile';
|
|
93
|
+
capabilities: DevResourceCapabilities;
|
|
94
|
+
state: DevInstanceState;
|
|
95
|
+
startedAt: number;
|
|
96
|
+
updatedAt: number;
|
|
97
|
+
endedAt?: number;
|
|
98
|
+
/** Runtime 报告的既有文档验证阶段;验证期间不能视为可操作。 */
|
|
99
|
+
documentVerifying?: boolean;
|
|
100
|
+
runtimeId?: string;
|
|
101
|
+
uploadSessionId?: string;
|
|
102
|
+
error?: DevDiagnosticError;
|
|
103
|
+
reason?: string;
|
|
104
|
+
startCursor: number;
|
|
105
|
+
lastCursor: number;
|
|
106
|
+
stale: boolean;
|
|
107
|
+
}
|
|
108
|
+
/** 一次宿主呈现,不代表对应 SDK 调用或外部系统动作成功。 */
|
|
109
|
+
interface DevHostInteraction {
|
|
110
|
+
interactionId: string;
|
|
111
|
+
kind: 'toast' | 'loading' | 'dialog' | 'effect';
|
|
112
|
+
method: string;
|
|
113
|
+
mode: 'simulated' | 'browser';
|
|
114
|
+
startedAt: number;
|
|
115
|
+
callId?: string;
|
|
116
|
+
message?: string;
|
|
117
|
+
title?: string;
|
|
118
|
+
status?: 'success' | 'error';
|
|
119
|
+
dismissible?: boolean;
|
|
120
|
+
actions?: string[];
|
|
121
|
+
}
|
|
122
|
+
interface DevPresentationSnapshot {
|
|
123
|
+
instanceId: string | null;
|
|
124
|
+
interactions: DevHostInteraction[];
|
|
125
|
+
}
|
|
126
|
+
type DevInteractionState = 'shown' | 'completed' | 'confirmed' | 'cancelled' | 'expired' | 'replaced' | 'hidden' | 'closed';
|
|
127
|
+
interface DevDiagnosticInput {
|
|
128
|
+
source: 'app' | 'sdk' | 'runtime' | 'host';
|
|
129
|
+
level: string;
|
|
130
|
+
message: string;
|
|
131
|
+
timestamp: number;
|
|
132
|
+
phase?: string;
|
|
133
|
+
method?: string;
|
|
134
|
+
callId?: string;
|
|
135
|
+
outcome?: string;
|
|
136
|
+
errorCode?: string;
|
|
137
|
+
durationMs?: number;
|
|
138
|
+
startedAt?: number;
|
|
139
|
+
interaction?: DevHostInteraction & {
|
|
140
|
+
state: DevInteractionState;
|
|
141
|
+
};
|
|
142
|
+
network?: {
|
|
143
|
+
method?: string;
|
|
144
|
+
origin?: string;
|
|
145
|
+
pathname?: string;
|
|
146
|
+
responseStatus?: number;
|
|
147
|
+
};
|
|
148
|
+
truncated?: boolean;
|
|
149
|
+
}
|
|
150
|
+
interface DevDiagnosticEvent extends DevDiagnosticInput {
|
|
151
|
+
targetId?: string;
|
|
152
|
+
ownerId?: string;
|
|
153
|
+
cursor: number;
|
|
154
|
+
receivedAt: number;
|
|
155
|
+
late: boolean;
|
|
156
|
+
instanceId?: string;
|
|
157
|
+
uploadSessionId?: string;
|
|
158
|
+
sequence?: number;
|
|
159
|
+
truncated: boolean;
|
|
160
|
+
}
|
|
161
|
+
interface DevResourceResult<T = unknown> {
|
|
162
|
+
instanceId: string;
|
|
163
|
+
requestId?: string;
|
|
164
|
+
resource: string;
|
|
165
|
+
timestamp: number;
|
|
166
|
+
stale: boolean;
|
|
167
|
+
value?: T;
|
|
168
|
+
/** 查询失败时保留已知实例状态;不代表本次取得实时资源。 */
|
|
169
|
+
lastKnownState?: DevInstanceState;
|
|
170
|
+
lastSeenAt?: number;
|
|
171
|
+
reason?: string;
|
|
172
|
+
code?: 'unsupported' | 'forbidden' | 'offline' | 'closed' | 'timeout' | 'busy' | 'invalid';
|
|
173
|
+
error?: string;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
declare const PREVIEW_SELECTORS: {
|
|
177
|
+
readonly device: "[data-preview-target=\"device\"]";
|
|
178
|
+
readonly screen: "[data-preview-target=\"screen\"]";
|
|
179
|
+
readonly app: "#device iframe";
|
|
180
|
+
readonly workbench: "[data-testid=\"workbench-root\"]";
|
|
181
|
+
};
|
|
182
|
+
type PreviewScope = keyof typeof PREVIEW_SELECTORS;
|
|
183
|
+
type PreviewScale = 'css' | 'device';
|
|
184
|
+
type PreviewOrientation = 'portrait' | 'landscape';
|
|
185
|
+
interface PreviewObservation {
|
|
186
|
+
preset: string;
|
|
187
|
+
orientation: PreviewOrientation;
|
|
188
|
+
runtimeStatus: string;
|
|
189
|
+
viewport: {
|
|
190
|
+
width: number;
|
|
191
|
+
height: number;
|
|
192
|
+
};
|
|
193
|
+
instanceId: string | null;
|
|
194
|
+
browserPixelRatio: number;
|
|
195
|
+
presentation?: DevPresentationSnapshot;
|
|
196
|
+
}
|
|
197
|
+
interface PreviewBrowserActionRequest {
|
|
198
|
+
operationId: string;
|
|
199
|
+
/** 操作创建时固定的绝对期限,拦截主线程恢复后的迟到动作。 */
|
|
200
|
+
deadlineAt: number;
|
|
201
|
+
command: 'observe' | 'select' | 'reload';
|
|
202
|
+
preset?: string;
|
|
203
|
+
orientation?: PreviewOrientation;
|
|
204
|
+
timeoutMs?: number;
|
|
205
|
+
}
|
|
206
|
+
type PreviewBrowserActionResult = {
|
|
207
|
+
ok: true;
|
|
208
|
+
value: PreviewObservation;
|
|
209
|
+
} | {
|
|
210
|
+
ok: false;
|
|
211
|
+
error: {
|
|
212
|
+
code: string;
|
|
213
|
+
message: string;
|
|
214
|
+
};
|
|
215
|
+
};
|
|
216
|
+
interface PreparePreviewCapture {
|
|
217
|
+
operationId: string;
|
|
218
|
+
deadlineAt: number;
|
|
219
|
+
scope: PreviewScope;
|
|
220
|
+
/** 当前 viewport 的冻结图,仅维持共享窗口显示。 */
|
|
221
|
+
previewImage: string;
|
|
222
|
+
}
|
|
223
|
+
interface PreparedPreviewCapture {
|
|
224
|
+
token: string;
|
|
225
|
+
clip: {
|
|
226
|
+
x: number;
|
|
227
|
+
y: number;
|
|
228
|
+
width: number;
|
|
229
|
+
height: number;
|
|
230
|
+
};
|
|
231
|
+
devicePixelRatio: number;
|
|
232
|
+
expiresAt: number;
|
|
233
|
+
}
|
|
234
|
+
interface PreviewBrowserActions {
|
|
235
|
+
readonly version: 1;
|
|
236
|
+
run(request: PreviewBrowserActionRequest): Promise<PreviewBrowserActionResult>;
|
|
237
|
+
cancel(operationId: string): void;
|
|
238
|
+
prepareCapture(input: PreparePreviewCapture): Promise<PreparedPreviewCapture>;
|
|
239
|
+
restoreCapture(token: string): boolean;
|
|
240
|
+
}
|
|
241
|
+
declare global {
|
|
242
|
+
interface Window {
|
|
243
|
+
/** 仅本机 Browser Dev Host 调试工具使用的受限动作入口。 */
|
|
244
|
+
__HB_SDK_PREVIEW__?: PreviewBrowserActions;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/** 单次开发工具请求的取消和总等待期限。 */
|
|
249
|
+
interface DevRequestOptions {
|
|
250
|
+
signal?: AbortSignal;
|
|
251
|
+
/** 默认 5000 毫秒;Runtime 等待默认 30000 毫秒。 */
|
|
252
|
+
timeoutMs?: number;
|
|
253
|
+
}
|
|
254
|
+
/** 连接已运行的开发会话;不隐式启动服务或打开浏览器。 */
|
|
255
|
+
interface ConnectDevSessionOptions extends DevRequestOptions {
|
|
256
|
+
projectRoot?: string;
|
|
257
|
+
port?: number;
|
|
258
|
+
}
|
|
259
|
+
/** 统一开发会话状态,失败历史不依赖 iframe 存活。 */
|
|
260
|
+
interface DevSessionInspection {
|
|
261
|
+
schemaVersion: typeof DEV_DIAGNOSTICS_SCHEMA_VERSION;
|
|
262
|
+
sessionId: string;
|
|
263
|
+
projectRoot: string;
|
|
264
|
+
appUrl: string;
|
|
265
|
+
previewUrl: string;
|
|
266
|
+
browser: Record<string, unknown>;
|
|
267
|
+
playwright: Record<string, unknown>;
|
|
268
|
+
selectors: Record<string, string>;
|
|
269
|
+
targets: DevTarget[];
|
|
270
|
+
primaryTargetId: string | null;
|
|
271
|
+
primaryTarget: DevTarget | null;
|
|
272
|
+
currentInstance: DevInstance | null;
|
|
273
|
+
recentFailure: DevInstance | null;
|
|
274
|
+
/** 按启动尝试的登记顺序排列;状态更新不改变顺序。 */
|
|
275
|
+
instances: DevInstance[];
|
|
276
|
+
epoch: string;
|
|
277
|
+
nextCursor: number;
|
|
278
|
+
timestamp: number;
|
|
279
|
+
stale: boolean;
|
|
280
|
+
uploadSessions: DevUploadSession[];
|
|
281
|
+
}
|
|
282
|
+
/** targetId 选择稳定目标;日志跨实例查询,活资源解析当前实例。与 instanceId 不能同时提供。 */
|
|
283
|
+
interface DevTargetSelection {
|
|
284
|
+
targetId?: string;
|
|
285
|
+
instanceId?: string;
|
|
286
|
+
}
|
|
287
|
+
/** 服务端事实筛选;游标表示接收顺序,不是操作因果证明。 */
|
|
288
|
+
interface DevLogFilters extends DevRequestOptions, DevTargetSelection {
|
|
289
|
+
uploadSessionId?: string;
|
|
290
|
+
callId?: string;
|
|
291
|
+
/** 调用阶段(如 client / host),用于区分同一 callId 的不同事实。 */
|
|
292
|
+
phase?: string;
|
|
293
|
+
/** 仅查询 warn/error 事实,仍由服务端分页。 */
|
|
294
|
+
problems?: boolean;
|
|
295
|
+
source?: 'app' | 'sdk' | 'runtime' | 'host' | 'network';
|
|
296
|
+
level?: 'log' | 'debug' | 'info' | 'warn' | 'error';
|
|
297
|
+
query?: string;
|
|
298
|
+
after?: number;
|
|
299
|
+
limit?: number;
|
|
300
|
+
id?: number;
|
|
301
|
+
since?: number;
|
|
302
|
+
}
|
|
303
|
+
/** 日志增量页;gap 表示指定游标之前已有事实被淘汰。 */
|
|
304
|
+
interface DevLogPage {
|
|
305
|
+
schemaVersion: typeof DEV_DIAGNOSTICS_SCHEMA_VERSION;
|
|
306
|
+
sessionId: string;
|
|
307
|
+
epoch: string;
|
|
308
|
+
items: DevDiagnosticEvent[];
|
|
309
|
+
nextCursor: number;
|
|
310
|
+
hasMore: boolean;
|
|
311
|
+
gap: boolean;
|
|
312
|
+
uploadSessions: DevUploadSession[];
|
|
313
|
+
[key: string]: unknown;
|
|
314
|
+
}
|
|
315
|
+
/** 默认等待主浏览器实例;指定 instanceId 时观察该实例自身的生命周期,支持同时连接的真机。 */
|
|
316
|
+
interface WaitForRuntimeOptions extends DevRequestOptions, DevTargetSelection {
|
|
317
|
+
}
|
|
318
|
+
interface DevResourceOptions extends DevRequestOptions, DevTargetSelection {
|
|
319
|
+
}
|
|
320
|
+
/** 只读资源保留原实例、时间和新鲜度;不自动将敏感值写入日志。 */
|
|
321
|
+
interface DevResources {
|
|
322
|
+
/** 当前实例的宿主呈现;短暂反馈结束后从 logs() 查询历史。 */
|
|
323
|
+
presentation(options?: DevResourceOptions): Promise<DevResourceResult<DevPresentationSnapshot>>;
|
|
324
|
+
storage(options?: DevResourceOptions): Promise<DevResourceResult>;
|
|
325
|
+
sandbox(options?: DevResourceOptions & {
|
|
326
|
+
path?: string;
|
|
327
|
+
}): Promise<DevResourceResult>;
|
|
328
|
+
/** 只读二进制前缀;最多 16 KiB,base64 保留原始字节。 */
|
|
329
|
+
sandboxRead(options: DevResourceOptions & {
|
|
330
|
+
path: string;
|
|
331
|
+
maxBytes?: number;
|
|
332
|
+
}): Promise<DevResourceResult<DevSandboxFile>>;
|
|
333
|
+
/** 网络事件历史;默认主目标,包含 Client/Host 开始与终态,不是实时连接快照。 */
|
|
334
|
+
network(filters?: DevLogFilters): Promise<DevLogPage>;
|
|
335
|
+
/** warn/error 事件历史;默认主目标,可显式按目标或实例查询。 */
|
|
336
|
+
problems(filters?: DevLogFilters): Promise<DevLogPage>;
|
|
337
|
+
}
|
|
338
|
+
/** hb-sdk 特有预览动作;通用定位、点击、输入和滚动直接使用 Playwright。 */
|
|
339
|
+
interface DevPreviewActions {
|
|
340
|
+
connect(options?: DevRequestOptions & {
|
|
341
|
+
emulateFocus?: boolean;
|
|
342
|
+
}): Promise<ConnectedPreview>;
|
|
343
|
+
open(options?: DevRequestOptions): Promise<Record<string, unknown>>;
|
|
344
|
+
select(options: DevRequestOptions & {
|
|
345
|
+
preset?: string;
|
|
346
|
+
orientation?: PreviewOrientation;
|
|
347
|
+
}): Promise<Record<string, unknown>>;
|
|
348
|
+
reload(options?: DevRequestOptions): Promise<Record<string, unknown>>;
|
|
349
|
+
/** 返回 PNG base64 与像素元数据;不调整默认 CSS 截图行为。 */
|
|
350
|
+
capture(options?: DevRequestOptions & {
|
|
351
|
+
scope?: PreviewScope;
|
|
352
|
+
scale?: PreviewScale;
|
|
353
|
+
}): Promise<Record<string, unknown>>;
|
|
354
|
+
}
|
|
355
|
+
/** 已绑定项目与 dev 服务身份的轻量对象;连接成功不代表 Runtime 或业务页面就绪。 */
|
|
356
|
+
interface DevSession {
|
|
357
|
+
readonly id: string;
|
|
358
|
+
readonly projectRoot: string;
|
|
359
|
+
readonly port: number;
|
|
360
|
+
inspect(options?: DevRequestOptions): Promise<DevSessionInspection>;
|
|
361
|
+
logs(filters?: DevLogFilters): Promise<DevLogPage>;
|
|
362
|
+
waitForRuntime(options?: WaitForRuntimeOptions): Promise<DevInstance>;
|
|
363
|
+
readonly preview: DevPreviewActions;
|
|
364
|
+
readonly resources: DevResources;
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* 连接当前项目的开发会话,复用与 CLI 相同的发现、身份核验和 HTTP 查询。
|
|
368
|
+
*
|
|
369
|
+
* @remarks 此步及 inspect/logs 不加载 Playwright 或改变焦点。只有 preview.connect 才按需准备控制库。
|
|
370
|
+
* @example
|
|
371
|
+
* ```ts
|
|
372
|
+
* import { connectDevSession } from '@heybox/hb-sdk/dev';
|
|
373
|
+
* const dev = await connectDevSession();
|
|
374
|
+
* const preview = await dev.preview.connect();
|
|
375
|
+
* try {
|
|
376
|
+
* await dev.waitForRuntime({ timeoutMs: 30_000 });
|
|
377
|
+
* await preview.app.getByRole('button', { name: '环境信息' }).click();
|
|
378
|
+
* }
|
|
379
|
+
* finally { await preview.disconnect(); }
|
|
380
|
+
* ```
|
|
381
|
+
* @since 0.9.6
|
|
382
|
+
*/
|
|
383
|
+
declare function connectDevSession(options?: ConnectDevSessionOptions): Promise<DevSession>;
|
|
384
|
+
|
|
385
|
+
export { connectDevSession };
|
|
386
|
+
export type { ConnectDevSessionOptions, ConnectedPreview, DevDiagnosticError, DevDiagnosticEvent, DevHostInteraction, DevInstance, DevInteractionState, DevLogFilters, DevLogPage, DevPresentationSnapshot, DevPreviewActions, DevRequestOptions, DevResourceCapabilities, DevResourceOptions, DevResourceResult, DevResources, DevSandboxFile, DevSession, DevSessionInspection, DevTarget, DevTargetMetadata, DevTargetSelection, DevUploadSession, PreviewOrientation, PreviewScale, PreviewScope, PreviewSession, WaitForRuntimeOptions };
|