@jhh96/light-app-bridge 1.2.1 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -1
- package/dist/lightAppBridge.d.ts +19 -0
- package/dist/lightAppBridge.js +7 -2
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { default } from './lightAppBridge';
|
|
2
2
|
export { createBridge } from './lightAppBridge';
|
|
3
|
-
export type { BridgeRole, BindMode, EnvelopeType, Envelope, BridgeOptions, SendOptions, MessageHandler } from './lightAppBridge';
|
|
3
|
+
export type { BridgeRole, BindMode, ReportMode, EnvelopeType, Envelope, BridgeOptions, SendOptions, MessageHandler } from './lightAppBridge';
|
package/dist/lightAppBridge.d.ts
CHANGED
|
@@ -30,6 +30,17 @@ export type BridgeRole = 'plugin' | 'lightapp';
|
|
|
30
30
|
* 向新窗口探测握手(成功即切换绑定;失败——如未集成 SDK——保持旧绑定)。
|
|
31
31
|
*/
|
|
32
32
|
export type BindMode = 'fixed' | 'dynamic';
|
|
33
|
+
/**
|
|
34
|
+
* 指令执行结果的上报模式(轻应用角色语义声明,默认 'plugin'):
|
|
35
|
+
* - plugin 默认。轻应用不在本窗口回传 ai-controller,执行结果随 reply 返回
|
|
36
|
+
* 插件窗口,由插件统一上报。reply 无需额外字段。
|
|
37
|
+
* - self 轻应用业务自行 POST ai-controller/callback(如需 AI 闭环),
|
|
38
|
+
* 并在 onMessage 的 reply 上带 result_reported: true,
|
|
39
|
+
* 插件据此跳过补报,避免双重上报。
|
|
40
|
+
* 纯语义声明:SDK 不执行上报,读取方是插件侧业务代码(经 reply 字段判定),
|
|
41
|
+
* 两 SDK 间零依赖。
|
|
42
|
+
*/
|
|
43
|
+
export type ReportMode = 'plugin' | 'self';
|
|
33
44
|
/** 信封类型 */
|
|
34
45
|
export type EnvelopeType = 'hello' | 'ack' | 'req' | 'res' | 'ping' | 'pong';
|
|
35
46
|
/** 消息信封:所有跨窗口通信的统一包装 */
|
|
@@ -51,6 +62,13 @@ export interface BridgeOptions {
|
|
|
51
62
|
* dynamic:轮询 getContentContext 跟随当前激活的轻应用窗口切换绑定。
|
|
52
63
|
*/
|
|
53
64
|
bindMode?: BindMode;
|
|
65
|
+
/**
|
|
66
|
+
* 结果上报模式(轻应用角色语义声明),默认 'plugin':
|
|
67
|
+
* 'plugin'=结果交插件统一上报(reply 无需额外字段);
|
|
68
|
+
* 'self'=业务自行上报并在 reply 带 result_reported: true。
|
|
69
|
+
* SDK 不执行上报,仅存为实例属性 reportMode 供业务读取。
|
|
70
|
+
*/
|
|
71
|
+
reportMode?: ReportMode;
|
|
54
72
|
/** dynamic 模式轮询 getContentContext 的间隔(ms),默认 2000 */
|
|
55
73
|
dynamicPollInterval?: number;
|
|
56
74
|
/** dynamic 模式迁移探测窗口:向新窗口发 hello 等 ack 的时长(ms),默认 3000 */
|
|
@@ -94,6 +112,7 @@ export default class LightAppBridge {
|
|
|
94
112
|
timeout: number;
|
|
95
113
|
handshakeTimeout: number;
|
|
96
114
|
bindMode: BindMode;
|
|
115
|
+
reportMode: ReportMode;
|
|
97
116
|
dynamicPollInterval: number;
|
|
98
117
|
migrateProbeTimeout: number;
|
|
99
118
|
pingInterval: number;
|
package/dist/lightAppBridge.js
CHANGED
|
@@ -212,6 +212,7 @@ export default class LightAppBridge {
|
|
|
212
212
|
this.timeout = options.timeout != null ? options.timeout : DEFAULT_TIMEOUT;
|
|
213
213
|
this.handshakeTimeout = options.handshakeTimeout != null ? options.handshakeTimeout : DEFAULT_HANDSHAKE_TIMEOUT;
|
|
214
214
|
this.bindMode = options.bindMode === 'dynamic' ? 'dynamic' : DEFAULT_BIND_MODE;
|
|
215
|
+
this.reportMode = options.reportMode === 'self' ? 'self' : 'plugin';
|
|
215
216
|
this.dynamicPollInterval = options.dynamicPollInterval != null ? options.dynamicPollInterval : DEFAULT_DYNAMIC_POLL_INTERVAL;
|
|
216
217
|
this.migrateProbeTimeout = options.migrateProbeTimeout != null ? options.migrateProbeTimeout : DEFAULT_MIGRATE_PROBE_TIMEOUT;
|
|
217
218
|
this.pingInterval = options.pingInterval != null ? options.pingInterval : DEFAULT_PING_INTERVAL;
|
|
@@ -333,8 +334,12 @@ export default class LightAppBridge {
|
|
|
333
334
|
this._log('recv← 忽略非本SDK消息: from=' + fromId);
|
|
334
335
|
return;
|
|
335
336
|
}
|
|
336
|
-
|
|
337
|
-
|
|
337
|
+
// ping/pong 是心跳噪音(默认 10s 一对),debug 日志跳过——生命周期关键
|
|
338
|
+
// 日志(pong 超时/恢复/兜底探测/失联)仍保留在 _pingOnce/_probeAlive 内
|
|
339
|
+
if (envelope.type !== 'ping' && envelope.type !== 'pong') {
|
|
340
|
+
this._log('recv← type=' + envelope.type + ' id=' + envelope.id +
|
|
341
|
+
' from=' + fromId + ' data=' + debugPayload(envelope.data));
|
|
342
|
+
}
|
|
338
343
|
switch (envelope.type) {
|
|
339
344
|
case 'hello':
|
|
340
345
|
this._onHello(fromId);
|