@dp-bohrium/widget-sdk 0.8.0 → 0.9.0
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 +19 -0
- package/assets/schemas/widget-runtime-contracts.schema.json +906 -0
- package/assets/toolchain.json +8 -8
- package/conformance/development-diagnostics.json +128 -0
- package/dist/cli.mjs +184 -14
- package/dist/compatibility/testing.js +1 -1
- package/dist/contracts.js +3 -2
- package/dist/development-guards-COvBR0G1.js +136 -0
- package/dist/{dsh-BlpXm2Bv.mjs → dsh-BL6cMLrg.mjs} +1151 -3
- package/dist/index.js +53 -7
- package/dist/protocol/development-guards.d.ts +9 -0
- package/dist/protocol/generated-development-policy.d.ts +22 -0
- package/dist/protocol/generated-runtime-contracts.d.ts +241 -0
- package/dist/protocol/index.d.ts +5 -0
- package/dist/protocol/widget-recovery.d.ts +19 -0
- package/dist/{protocol-endpoint-CDz-YDGT.js → protocol-endpoint-DbT0OJNu.js} +5 -0
- package/dist/runtime/bootstrap.d.ts +3 -1
- package/dist/runtime/client.d.ts +5 -1
- package/dist/runtime/index.js +2 -2
- package/dist/runtime/protocol-endpoint.d.ts +5 -5
- package/dist/runtime/transport.d.ts +9 -9
- package/dist/{runtime-D2xmZVSb.js → runtime-9g5MfsgK.js} +39 -5
- package/dist/widget-recovery-BF_sSUZX.js +472 -0
- package/llms.txt +13 -1
- package/package.json +1 -1
- package/schemas/widget-runtime-contracts.schema.json +906 -0
- package/dist/widget-events-gsKJbjqg.js +0 -65
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { i as createWidgetClient, l as WIDGET_SDK_VERSION } from "./runtime-
|
|
2
|
-
import {
|
|
1
|
+
import { i as createWidgetClient, l as WIDGET_SDK_VERSION } from "./runtime-9g5MfsgK.js";
|
|
2
|
+
import { a as projectWidgetRuntimeDiagnostic, c as WIDGET_EVENT_NAMES, d as isWidgetActivationEvent, l as isWidgetEventName, u as WIDGET_ACTIVATION_EVENTS } from "./widget-recovery-BF_sSUZX.js";
|
|
3
|
+
import { n as isWidgetGuestDiagnostic } from "./development-guards-COvBR0G1.js";
|
|
3
4
|
//#region src/manifest.ts
|
|
4
5
|
function compiledContribution(contribution) {
|
|
5
6
|
switch (contribution.type) {
|
|
@@ -368,6 +369,7 @@ function createContext(client, payload, renderHandlers, lifetime) {
|
|
|
368
369
|
function createWidgetRuntime(module, options = {}) {
|
|
369
370
|
let client;
|
|
370
371
|
const renderHandlers = /* @__PURE__ */ new Set();
|
|
372
|
+
let latestRenderRevision = 0;
|
|
371
373
|
const reportCleanupError = (error) => options.onCleanupError?.(toStartupError(error));
|
|
372
374
|
const lifetime = createWidgetLifetime(reportCleanupError);
|
|
373
375
|
let activation;
|
|
@@ -393,6 +395,16 @@ function createWidgetRuntime(module, options = {}) {
|
|
|
393
395
|
retryable: false,
|
|
394
396
|
correlationId: request.requestId
|
|
395
397
|
};
|
|
398
|
+
let location = null;
|
|
399
|
+
try {
|
|
400
|
+
location = error instanceof Error ? /(?:\/__widget\/guest\/[^/]+\/|\/assets\/)([a-zA-Z0-9_./-]+):(\d+):(\d+)/u.exec(error.stack ?? "") : null;
|
|
401
|
+
} catch {}
|
|
402
|
+
const projected = projectWidgetRuntimeDiagnostic(failure, update ? "update" : "render", location?.[1] ? [{
|
|
403
|
+
file: location[1],
|
|
404
|
+
line: Number(location[2]),
|
|
405
|
+
column: Number(location[3])
|
|
406
|
+
}] : void 0);
|
|
407
|
+
const diagnostic = isWidgetGuestDiagnostic(projected) ? projected : projectWidgetRuntimeDiagnostic(failure, update ? "update" : "render");
|
|
396
408
|
writeLocalDiagnostic("[Widget 渲染失败]", failure, error);
|
|
397
409
|
for (const observer of [options.events?.onError, options.onError]) try {
|
|
398
410
|
Promise.resolve(observer?.(failure)).catch((observerError) => {
|
|
@@ -401,6 +413,7 @@ function createWidgetRuntime(module, options = {}) {
|
|
|
401
413
|
} catch (observerError) {
|
|
402
414
|
writeLocalDiagnostic("[Widget 诊断回调失败]", observerError);
|
|
403
415
|
}
|
|
416
|
+
return diagnostic;
|
|
404
417
|
}
|
|
405
418
|
function runDeactivation() {
|
|
406
419
|
if (deactivation) return deactivation;
|
|
@@ -438,18 +451,51 @@ function createWidgetRuntime(module, options = {}) {
|
|
|
438
451
|
return activation;
|
|
439
452
|
},
|
|
440
453
|
onRender(request, update) {
|
|
454
|
+
latestRenderRevision = request.revision;
|
|
441
455
|
const renderContext = {
|
|
442
456
|
phase: update ? "update" : "initial",
|
|
443
457
|
signal: lifetime.signal
|
|
444
458
|
};
|
|
445
|
-
|
|
446
|
-
|
|
459
|
+
const handlers = [...renderHandlers];
|
|
460
|
+
let reported = false;
|
|
461
|
+
const reportResult = (diagnostic) => {
|
|
462
|
+
if (lifetime.signal.aborted || !handlers.length || reported) return;
|
|
463
|
+
reported = true;
|
|
447
464
|
try {
|
|
448
|
-
|
|
465
|
+
if (request.revision !== latestRenderRevision) client.reportRenderResult({
|
|
466
|
+
requestId: request.requestId,
|
|
467
|
+
revision: request.revision,
|
|
468
|
+
outcome: "superseded"
|
|
469
|
+
});
|
|
470
|
+
else if (diagnostic) client.reportRenderResult({
|
|
471
|
+
requestId: request.requestId,
|
|
472
|
+
revision: request.revision,
|
|
473
|
+
outcome: "failed",
|
|
474
|
+
diagnostic: {
|
|
475
|
+
...diagnostic,
|
|
476
|
+
correlationId: request.requestId,
|
|
477
|
+
phase: update ? "update" : "render"
|
|
478
|
+
}
|
|
479
|
+
});
|
|
480
|
+
else client.reportRenderResult({
|
|
481
|
+
requestId: request.requestId,
|
|
482
|
+
revision: request.revision,
|
|
483
|
+
outcome: "handled"
|
|
484
|
+
});
|
|
485
|
+
} catch (reason) {
|
|
486
|
+
writeLocalDiagnostic("[Widget 诊断发送失败]", reason);
|
|
487
|
+
}
|
|
488
|
+
};
|
|
489
|
+
Promise.all(handlers.map(async (handler) => {
|
|
490
|
+
if (lifetime.signal.aborted) return;
|
|
491
|
+
try {
|
|
492
|
+
await handler(request, renderContext);
|
|
449
493
|
} catch (error) {
|
|
450
|
-
reportRenderFailure(error, request, update);
|
|
494
|
+
reportResult(reportRenderFailure(error, request, update));
|
|
451
495
|
}
|
|
452
|
-
}
|
|
496
|
+
})).then(() => reportResult()).catch((reason) => {
|
|
497
|
+
writeLocalDiagnostic("[Widget 诊断发送失败]", reason);
|
|
498
|
+
});
|
|
453
499
|
},
|
|
454
500
|
onDispose: dispose
|
|
455
501
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { WidgetDevelopmentDiagnostic, WidgetDevelopmentOffer, WidgetRenderResult } from "./generated-runtime-contracts.js";
|
|
2
|
+
/** 与源头 Schema 同源限额的轻量边界判定,不加载 AJV 或 Runtime。 */
|
|
3
|
+
export declare function isWidgetGuestDiagnostic(value: unknown): value is WidgetDevelopmentDiagnostic & {
|
|
4
|
+
source: "sdk";
|
|
5
|
+
};
|
|
6
|
+
/** offer 只声明解析能力;实际 iframe 来源与 attempt 由 Host 校验。 */
|
|
7
|
+
export declare function isWidgetDevelopmentOffer(value: unknown): value is WidgetDevelopmentOffer;
|
|
8
|
+
/** 失败回执仍需 Host 再匹配实际已发送的 request/revision。 */
|
|
9
|
+
export declare function isWidgetRenderResult(value: unknown): value is WidgetRenderResult;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** GENERATED FILE. Do not edit directly. */
|
|
2
|
+
export declare const widgetDevelopmentPolicy: {
|
|
3
|
+
readonly required: readonly ["schemaVersion", "source", "code", "phase", "operation", "severity", "message"];
|
|
4
|
+
readonly keys: readonly ["schemaVersion", "source", "code", "sourceCode", "phase", "sourcePhase", "operation", "severity", "message", "retryable", "correlationId", "diagnostics", "io"];
|
|
5
|
+
readonly textMax: {
|
|
6
|
+
readonly code: 96;
|
|
7
|
+
readonly sourceCode: 96;
|
|
8
|
+
readonly sourcePhase: 96;
|
|
9
|
+
readonly operation: 96;
|
|
10
|
+
readonly message: 1024;
|
|
11
|
+
readonly field: 128;
|
|
12
|
+
readonly expected: 256;
|
|
13
|
+
readonly observed: 256;
|
|
14
|
+
readonly file: 256;
|
|
15
|
+
readonly excerpt: 1024;
|
|
16
|
+
};
|
|
17
|
+
readonly maxDetails: 8;
|
|
18
|
+
readonly phases: readonly ["discovery", "build", "config", "load", "handshake", "render", "update", "capability", "dispose"];
|
|
19
|
+
readonly severities: readonly ["warning", "request-error", "instance-failure"];
|
|
20
|
+
readonly identifierPattern: "^[A-Za-z][A-Za-z0-9_.-]*$";
|
|
21
|
+
readonly filePattern: "^(?!/)(?!.*\\\\)(?!.*:)(?!.*(?:^|/)\\.{1,2}(?:/|$))[^\\u0000-\\u001f]+$";
|
|
22
|
+
};
|
|
@@ -545,6 +545,124 @@ export type HostUserServiceRequest = ({
|
|
|
545
545
|
action: "email.read";
|
|
546
546
|
payload: HostUserEmailReadInput;
|
|
547
547
|
});
|
|
548
|
+
/**
|
|
549
|
+
* 受控字段诊断或工程相对源码位置;不携带原始对象。
|
|
550
|
+
*/
|
|
551
|
+
export type WidgetDiagnosticDetail = ({
|
|
552
|
+
field: string;
|
|
553
|
+
expected?: string;
|
|
554
|
+
observed?: string;
|
|
555
|
+
} | {
|
|
556
|
+
file: string;
|
|
557
|
+
line: number;
|
|
558
|
+
column: number;
|
|
559
|
+
excerpt?: string;
|
|
560
|
+
});
|
|
561
|
+
/**
|
|
562
|
+
* 保留 transport、HTTP 与非法响应事实;不包含 URL 或原始响应。
|
|
563
|
+
*/
|
|
564
|
+
export type WidgetDiagnosticIO = ({
|
|
565
|
+
kind: ("transport" | "invalid-response");
|
|
566
|
+
sourceCode?: string;
|
|
567
|
+
} | {
|
|
568
|
+
kind: "http";
|
|
569
|
+
status: number;
|
|
570
|
+
sourceCode?: string;
|
|
571
|
+
});
|
|
572
|
+
/**
|
|
573
|
+
* 恢复动作的语义及类型化参数;可信宿主绑定已有工具,不包含任意命令。
|
|
574
|
+
*/
|
|
575
|
+
export type WidgetRecoveryAction = ({
|
|
576
|
+
id: "inspect";
|
|
577
|
+
params: {
|
|
578
|
+
area: ("toolchain" | "host-bridge" | "configuration" | "bundle" | "handshake" | "render" | "capability" | "lease" | "operation-outcome" | "runtime");
|
|
579
|
+
};
|
|
580
|
+
} | {
|
|
581
|
+
id: "wait";
|
|
582
|
+
params: {
|
|
583
|
+
milestone: ("budget-reset" | "connection-restored");
|
|
584
|
+
retryAfterMs?: number;
|
|
585
|
+
};
|
|
586
|
+
} | {
|
|
587
|
+
id: "edit-project";
|
|
588
|
+
params: {
|
|
589
|
+
evidence: "diagnostics";
|
|
590
|
+
};
|
|
591
|
+
} | {
|
|
592
|
+
id: "build-project";
|
|
593
|
+
params: {
|
|
594
|
+
target: "current-project";
|
|
595
|
+
};
|
|
596
|
+
} | {
|
|
597
|
+
id: "refresh-preview";
|
|
598
|
+
params: {
|
|
599
|
+
target: "current-project";
|
|
600
|
+
};
|
|
601
|
+
} | {
|
|
602
|
+
id: "verify-scenario";
|
|
603
|
+
params: {
|
|
604
|
+
target: ("current-attempt" | "next-built-generation");
|
|
605
|
+
scenarioId?: string;
|
|
606
|
+
};
|
|
607
|
+
} | {
|
|
608
|
+
id: "request-external-action";
|
|
609
|
+
params: {
|
|
610
|
+
reason: ("authorization" | "host-support" | "host-start" | "credentials");
|
|
611
|
+
};
|
|
612
|
+
} | {
|
|
613
|
+
id: "stop-preview";
|
|
614
|
+
params: {
|
|
615
|
+
target: "current-preview";
|
|
616
|
+
};
|
|
617
|
+
});
|
|
618
|
+
/**
|
|
619
|
+
* 经 offer/connect 显式选择的开发扩展;不授予 capability。
|
|
620
|
+
*/
|
|
621
|
+
export type WidgetDevelopmentExtension = "development-diagnostics-v1";
|
|
622
|
+
/**
|
|
623
|
+
* 仅表示受管渲染处理器的处理结果,不代表视觉或业务验收。
|
|
624
|
+
*/
|
|
625
|
+
export type WidgetRenderResult = ({
|
|
626
|
+
requestId: string;
|
|
627
|
+
revision: number;
|
|
628
|
+
outcome: ("handled" | "superseded");
|
|
629
|
+
} | {
|
|
630
|
+
requestId: string;
|
|
631
|
+
revision: number;
|
|
632
|
+
outcome: "failed";
|
|
633
|
+
diagnostic: WidgetRenderFailureDiagnostic;
|
|
634
|
+
});
|
|
635
|
+
/**
|
|
636
|
+
* 失败处理回执的 SDK 请求诊断;接收方还须匹配当前 requestId。
|
|
637
|
+
*/
|
|
638
|
+
export type WidgetRenderFailureDiagnostic = (WidgetGuestDiagnostic & {
|
|
639
|
+
correlationId: string;
|
|
640
|
+
phase?: ("render" | "update");
|
|
641
|
+
});
|
|
642
|
+
/**
|
|
643
|
+
* Guest 仅声明 SDK 诊断事实,不得冒充 Host 或工具链。
|
|
644
|
+
*/
|
|
645
|
+
export type WidgetGuestDiagnostic = (WidgetDevelopmentDiagnostic & {
|
|
646
|
+
source: "sdk";
|
|
647
|
+
});
|
|
648
|
+
/**
|
|
649
|
+
* 扩展 profile 下的 Widget → Host 消息;原 WidgetToHostMessage 不扩展。
|
|
650
|
+
*/
|
|
651
|
+
export type WidgetDevelopmentMessage = (WidgetToHostMessage | WidgetDiagnosticMessage | WidgetRenderResultMessage);
|
|
652
|
+
/**
|
|
653
|
+
* 经协商的开发扩展 Bridge 消息;仍受现有通道与消息预算约束。
|
|
654
|
+
*/
|
|
655
|
+
export type WidgetDiagnosticMessage = (BridgeEnvelopeBase & {
|
|
656
|
+
type: "diagnostic";
|
|
657
|
+
payload: WidgetGuestDiagnostic;
|
|
658
|
+
});
|
|
659
|
+
/**
|
|
660
|
+
* 经协商的开发扩展 Bridge 消息;仍受现有通道与消息预算约束。
|
|
661
|
+
*/
|
|
662
|
+
export type WidgetRenderResultMessage = (BridgeEnvelopeBase & {
|
|
663
|
+
type: "render-result";
|
|
664
|
+
payload: WidgetRenderResult;
|
|
665
|
+
});
|
|
548
666
|
/**
|
|
549
667
|
* Runtime 契约的汇总根容器;仅用于代码生成与符合性校验,不直接对外签发。
|
|
550
668
|
*/
|
|
@@ -585,6 +703,14 @@ export interface WidgetRuntimeContracts {
|
|
|
585
703
|
hostUserEmailReadInput?: HostUserEmailReadInput;
|
|
586
704
|
hostUserEmailReadOutput?: HostUserEmailReadOutput;
|
|
587
705
|
hostUserServiceRequest?: HostUserServiceRequest;
|
|
706
|
+
widgetDevelopmentDiagnostic?: WidgetDevelopmentDiagnostic;
|
|
707
|
+
widgetRecoveryContext?: WidgetRecoveryContext;
|
|
708
|
+
widgetRecoveryPlan?: WidgetRecoveryPlan;
|
|
709
|
+
widgetRecoveryRule?: WidgetRecoveryRule;
|
|
710
|
+
widgetDevelopmentOffer?: WidgetDevelopmentOffer;
|
|
711
|
+
widgetDevelopmentConnect?: WidgetDevelopmentConnect;
|
|
712
|
+
widgetRenderResult?: WidgetRenderResult;
|
|
713
|
+
widgetDevelopmentMessage?: WidgetDevelopmentMessage;
|
|
588
714
|
}
|
|
589
715
|
/**
|
|
590
716
|
* 渲染请求公共字段:schemaVersion、requestId、instanceId、revision、state、context。
|
|
@@ -1222,3 +1348,118 @@ export interface HostUserProfileReadOutput {
|
|
|
1222
1348
|
export interface HostUserEmailReadOutput {
|
|
1223
1349
|
email: (string | null);
|
|
1224
1350
|
}
|
|
1351
|
+
/**
|
|
1352
|
+
* 可信出口的标准诊断;恢复指令和 scope 由宿主另行生成。
|
|
1353
|
+
*/
|
|
1354
|
+
export interface WidgetDevelopmentDiagnostic {
|
|
1355
|
+
schemaVersion: 1;
|
|
1356
|
+
source: ("sdk" | "host" | "toolchain");
|
|
1357
|
+
code: string;
|
|
1358
|
+
sourceCode?: string;
|
|
1359
|
+
phase: ("discovery" | "build" | "config" | "load" | "handshake" | "render" | "update" | "capability" | "dispose");
|
|
1360
|
+
sourcePhase?: string;
|
|
1361
|
+
operation: string;
|
|
1362
|
+
severity: ("warning" | "request-error" | "instance-failure");
|
|
1363
|
+
message: string;
|
|
1364
|
+
retryable?: boolean;
|
|
1365
|
+
correlationId?: string;
|
|
1366
|
+
/**
|
|
1367
|
+
* @maxItems 8
|
|
1368
|
+
*/
|
|
1369
|
+
diagnostics?: [] | [WidgetDiagnosticDetail] | [WidgetDiagnosticDetail, WidgetDiagnosticDetail] | [WidgetDiagnosticDetail, WidgetDiagnosticDetail, WidgetDiagnosticDetail] | [WidgetDiagnosticDetail, WidgetDiagnosticDetail, WidgetDiagnosticDetail, WidgetDiagnosticDetail] | [WidgetDiagnosticDetail, WidgetDiagnosticDetail, WidgetDiagnosticDetail, WidgetDiagnosticDetail, WidgetDiagnosticDetail] | [WidgetDiagnosticDetail, WidgetDiagnosticDetail, WidgetDiagnosticDetail, WidgetDiagnosticDetail, WidgetDiagnosticDetail, WidgetDiagnosticDetail] | [WidgetDiagnosticDetail, WidgetDiagnosticDetail, WidgetDiagnosticDetail, WidgetDiagnosticDetail, WidgetDiagnosticDetail, WidgetDiagnosticDetail, WidgetDiagnosticDetail] | [WidgetDiagnosticDetail, WidgetDiagnosticDetail, WidgetDiagnosticDetail, WidgetDiagnosticDetail, WidgetDiagnosticDetail, WidgetDiagnosticDetail, WidgetDiagnosticDetail, WidgetDiagnosticDetail];
|
|
1370
|
+
io?: WidgetDiagnosticIO;
|
|
1371
|
+
}
|
|
1372
|
+
/**
|
|
1373
|
+
* 复用工具执行结果语义的可信恢复上下文;缺失字段表示未知,不能授权重放。
|
|
1374
|
+
*/
|
|
1375
|
+
export interface WidgetRecoveryContext {
|
|
1376
|
+
progress?: WidgetRecoveryProgress;
|
|
1377
|
+
executionState?: ("not_started" | "finished" | "partial" | "unknown");
|
|
1378
|
+
mayHaveExecuted?: boolean;
|
|
1379
|
+
}
|
|
1380
|
+
/**
|
|
1381
|
+
* 可信宿主观察到的恢复进展;重复故障无新证据时不能重复同一修复。
|
|
1382
|
+
*/
|
|
1383
|
+
export interface WidgetRecoveryProgress {
|
|
1384
|
+
repeated: boolean;
|
|
1385
|
+
hasNewEvidence: boolean;
|
|
1386
|
+
}
|
|
1387
|
+
/**
|
|
1388
|
+
* 可信宿主选择的恢复计划;不能由 Guest 的诊断 payload 指定。
|
|
1389
|
+
*/
|
|
1390
|
+
export interface WidgetRecoveryPlan {
|
|
1391
|
+
progress?: WidgetRecoveryProgress;
|
|
1392
|
+
schemaVersion: 1;
|
|
1393
|
+
ruleId: string;
|
|
1394
|
+
ruleVersion: number;
|
|
1395
|
+
disposition: ("retry" | "repair" | "inspect" | "external-action" | "stop");
|
|
1396
|
+
nextAction: WidgetRecoveryAction;
|
|
1397
|
+
verification: WidgetRecoveryVerification;
|
|
1398
|
+
guidance: string;
|
|
1399
|
+
/**
|
|
1400
|
+
* 首项动作完成后的有限恢复步骤;宿主逐步验证前置条件,不原样盲目重放。
|
|
1401
|
+
*
|
|
1402
|
+
* @maxItems 8
|
|
1403
|
+
*/
|
|
1404
|
+
followUpActions: [] | [WidgetRecoveryAction] | [WidgetRecoveryAction, WidgetRecoveryAction] | [WidgetRecoveryAction, WidgetRecoveryAction, WidgetRecoveryAction] | [WidgetRecoveryAction, WidgetRecoveryAction, WidgetRecoveryAction, WidgetRecoveryAction] | [WidgetRecoveryAction, WidgetRecoveryAction, WidgetRecoveryAction, WidgetRecoveryAction, WidgetRecoveryAction] | [WidgetRecoveryAction, WidgetRecoveryAction, WidgetRecoveryAction, WidgetRecoveryAction, WidgetRecoveryAction, WidgetRecoveryAction] | [WidgetRecoveryAction, WidgetRecoveryAction, WidgetRecoveryAction, WidgetRecoveryAction, WidgetRecoveryAction, WidgetRecoveryAction, WidgetRecoveryAction] | [WidgetRecoveryAction, WidgetRecoveryAction, WidgetRecoveryAction, WidgetRecoveryAction, WidgetRecoveryAction, WidgetRecoveryAction, WidgetRecoveryAction, WidgetRecoveryAction];
|
|
1405
|
+
}
|
|
1406
|
+
/**
|
|
1407
|
+
* 恢复复验目标;下一成功构建须在取得回执后绑定实际产物。
|
|
1408
|
+
*/
|
|
1409
|
+
export interface WidgetRecoveryVerification {
|
|
1410
|
+
target: ("current-attempt" | "next-built-generation" | "original-operation");
|
|
1411
|
+
milestone: ("diagnostics-updated" | "render-handled" | "scenario-passed" | "operation-confirmed");
|
|
1412
|
+
scenarioId?: string;
|
|
1413
|
+
}
|
|
1414
|
+
/**
|
|
1415
|
+
* 公共恢复规则目录条目;空 codes 仅用于显式 unknown 回退。
|
|
1416
|
+
*/
|
|
1417
|
+
export interface WidgetRecoveryRule {
|
|
1418
|
+
id: string;
|
|
1419
|
+
version: number;
|
|
1420
|
+
/**
|
|
1421
|
+
* @minItems 1
|
|
1422
|
+
* @maxItems 3
|
|
1423
|
+
*/
|
|
1424
|
+
sources: [("sdk" | "host" | "toolchain")] | [("sdk" | "host" | "toolchain"), ("sdk" | "host" | "toolchain")] | [("sdk" | "host" | "toolchain"), ("sdk" | "host" | "toolchain"), ("sdk" | "host" | "toolchain")];
|
|
1425
|
+
/**
|
|
1426
|
+
* @maxItems 64
|
|
1427
|
+
*/
|
|
1428
|
+
codes: string[];
|
|
1429
|
+
disposition: ("retry" | "repair" | "inspect" | "external-action" | "stop");
|
|
1430
|
+
nextAction: WidgetRecoveryAction;
|
|
1431
|
+
verification: WidgetRecoveryVerification;
|
|
1432
|
+
guidance: string;
|
|
1433
|
+
/**
|
|
1434
|
+
* 首项动作完成后的有限恢复步骤;宿主逐步验证前置条件,不原样盲目重放。
|
|
1435
|
+
*
|
|
1436
|
+
* @maxItems 8
|
|
1437
|
+
*/
|
|
1438
|
+
followUpActions: [] | [WidgetRecoveryAction] | [WidgetRecoveryAction, WidgetRecoveryAction] | [WidgetRecoveryAction, WidgetRecoveryAction, WidgetRecoveryAction] | [WidgetRecoveryAction, WidgetRecoveryAction, WidgetRecoveryAction, WidgetRecoveryAction] | [WidgetRecoveryAction, WidgetRecoveryAction, WidgetRecoveryAction, WidgetRecoveryAction, WidgetRecoveryAction] | [WidgetRecoveryAction, WidgetRecoveryAction, WidgetRecoveryAction, WidgetRecoveryAction, WidgetRecoveryAction, WidgetRecoveryAction] | [WidgetRecoveryAction, WidgetRecoveryAction, WidgetRecoveryAction, WidgetRecoveryAction, WidgetRecoveryAction, WidgetRecoveryAction, WidgetRecoveryAction] | [WidgetRecoveryAction, WidgetRecoveryAction, WidgetRecoveryAction, WidgetRecoveryAction, WidgetRecoveryAction, WidgetRecoveryAction, WidgetRecoveryAction, WidgetRecoveryAction];
|
|
1439
|
+
}
|
|
1440
|
+
/**
|
|
1441
|
+
* 独立于旧 bootstrap-ready 的支持声明,接收方仍须校验 frame 来源和挂载尝试。
|
|
1442
|
+
*/
|
|
1443
|
+
export interface WidgetDevelopmentOffer {
|
|
1444
|
+
type: "widget-bootstrap-offer";
|
|
1445
|
+
protocolVersion: 1;
|
|
1446
|
+
/**
|
|
1447
|
+
* @minItems 1
|
|
1448
|
+
* @maxItems 1
|
|
1449
|
+
*/
|
|
1450
|
+
extensions: [WidgetDevelopmentExtension];
|
|
1451
|
+
}
|
|
1452
|
+
/**
|
|
1453
|
+
* 仅在收到当前 iframe 合法 offer 后使用的扩展 connect;旧形状保持不变。
|
|
1454
|
+
*/
|
|
1455
|
+
export interface WidgetDevelopmentConnect {
|
|
1456
|
+
type: "widget-host-connect";
|
|
1457
|
+
protocolVersion: 1;
|
|
1458
|
+
channelId: string;
|
|
1459
|
+
initPayload: InitPayload;
|
|
1460
|
+
/**
|
|
1461
|
+
* @minItems 1
|
|
1462
|
+
* @maxItems 1
|
|
1463
|
+
*/
|
|
1464
|
+
extensions: [WidgetDevelopmentExtension];
|
|
1465
|
+
}
|
package/dist/protocol/index.d.ts
CHANGED
|
@@ -41,3 +41,8 @@ export type BridgeEnvelope<TType extends string = string, TPayload = unknown> =
|
|
|
41
41
|
};
|
|
42
42
|
/** 可加载绑定与降级绑定的联合,即 Host Runtime Config 中一条 binding 的两种结果。 */
|
|
43
43
|
export type ResolvedWidgetBinding = LoadableBinding | FallbackBinding;
|
|
44
|
+
export { isWidgetDevelopmentOffer, isWidgetGuestDiagnostic, isWidgetRenderResult, } from "./development-guards.js";
|
|
45
|
+
export type { WidgetDevelopmentConnect, WidgetDevelopmentDiagnostic, WidgetDevelopmentExtension, WidgetDevelopmentMessage, WidgetDevelopmentOffer, WidgetDiagnosticDetail, WidgetDiagnosticIO, WidgetDiagnosticMessage, WidgetGuestDiagnostic, WidgetRecoveryAction, WidgetRecoveryContext, WidgetRecoveryPlan, WidgetRecoveryProgress, WidgetRecoveryRule, WidgetRecoveryVerification, WidgetRenderResult, WidgetRenderResultMessage, } from "./generated-runtime-contracts.js";
|
|
46
|
+
export { createWidgetRecoveryPlan, findWidgetRecoveryRule, projectWidgetCapabilityDiagnostic, projectWidgetRuntimeDiagnostic, projectWidgetToolchainDiagnostic, selectWidgetDevelopmentExtensions, WIDGET_RECOVERY_RULES, } from "./widget-recovery.js";
|
|
47
|
+
/** SDK 运行层使用的已协商消息;旧 WidgetProtocolMessage 联合保持不变。 */
|
|
48
|
+
export type WidgetRuntimeProtocolMessage = WidgetProtocolMessage | import("./generated-runtime-contracts.js").WidgetDevelopmentMessage;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { CapabilityResult, WidgetDevelopmentDiagnostic, WidgetDevelopmentExtension, WidgetDevelopmentOffer, WidgetError, WidgetGuestDiagnostic, WidgetRecoveryContext, WidgetRecoveryPlan, WidgetRecoveryRule } from "./generated-runtime-contracts.js";
|
|
2
|
+
/** 包含 unknown 与操作核对规则,Agent 可按 plan.ruleId 定位每个实际计划。 */
|
|
3
|
+
export declare const WIDGET_RECOVERY_RULES: readonly WidgetRecoveryRule[];
|
|
4
|
+
/** 根据稳定码选择通用规则;未知码明确走排查,不匹配自由文本。 */
|
|
5
|
+
export declare function findWidgetRecoveryRule(diagnostic: Pick<WidgetDevelopmentDiagnostic, "source" | "code">): WidgetRecoveryRule;
|
|
6
|
+
/** 纯规则选择,不运行工具;宿主仍须校验实际能力、权限、scope 与恢复预算。 */
|
|
7
|
+
export declare function createWidgetRecoveryPlan(diagnostic: WidgetDevelopmentDiagnostic, context?: WidgetRecoveryContext): WidgetRecoveryPlan;
|
|
8
|
+
/** 只投影已校验的稳定字段;Guest message、context 和恢复文字不进入可信诊断。 */
|
|
9
|
+
export declare function projectWidgetRuntimeDiagnostic(error: WidgetError, operation: string, diagnostics?: WidgetDevelopmentDiagnostic["diagnostics"]): WidgetGuestDiagnostic;
|
|
10
|
+
/** 能力拒绝只影响当前请求;不把它投影为实例终态。 */
|
|
11
|
+
export declare function projectWidgetCapabilityDiagnostic(failure: Extract<CapabilityResult, {
|
|
12
|
+
ok: false;
|
|
13
|
+
}>, operation: string): WidgetDevelopmentDiagnostic;
|
|
14
|
+
/** 工程错误仅提取稳定 code;原始 stdout/stderr 由可信工具单独脱敏投影。 */
|
|
15
|
+
export declare function projectWidgetToolchainDiagnostic(error: {
|
|
16
|
+
code: string;
|
|
17
|
+
}, operation: string, phase: "discovery" | "build" | "config"): WidgetDevelopmentDiagnostic;
|
|
18
|
+
/** 仅选择双方声明的扩展;实际 frame 来源和当前 attempt 仍由 Host 校验。 */
|
|
19
|
+
export declare function selectWidgetDevelopmentExtensions(offer: WidgetDevelopmentOffer | undefined, supported: readonly WidgetDevelopmentExtension[]): readonly WidgetDevelopmentExtension[];
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import { n as isWidgetGuestDiagnostic, r as isWidgetRenderResult } from "./development-guards-COvBR0G1.js";
|
|
1
2
|
//#region src/runtime/transport.ts
|
|
2
3
|
const protocolMessageTypes = /* @__PURE__ */ new Set([
|
|
4
|
+
"diagnostic",
|
|
5
|
+
"render-result",
|
|
3
6
|
"init",
|
|
4
7
|
"render",
|
|
5
8
|
"update",
|
|
@@ -25,6 +28,8 @@ function isFiniteNonNegative(value) {
|
|
|
25
28
|
}
|
|
26
29
|
function isProtocolPayload(type, payload) {
|
|
27
30
|
switch (type) {
|
|
31
|
+
case "diagnostic": return isWidgetGuestDiagnostic(payload);
|
|
32
|
+
case "render-result": return isWidgetRenderResult(payload);
|
|
28
33
|
case "init": return hasRequiredKeys(payload, [
|
|
29
34
|
"instanceId",
|
|
30
35
|
"locale",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CapabilityRequest, CapabilityResult, InitPayload, PresentationCapabilityResult, RegionCapabilityResult, RenderRequest, WidgetError, WidgetLiveEvent } from "../protocol/index.js";
|
|
1
|
+
import type { CapabilityRequest, CapabilityResult, InitPayload, PresentationCapabilityResult, RegionCapabilityResult, RenderRequest, WidgetError, WidgetGuestDiagnostic, WidgetLiveEvent, WidgetRenderResult } from "../protocol/index.js";
|
|
2
2
|
import { type PresentationFocusDirection, type PresentationSurface, type RegionName, type WidgetCapabilityRequestOptions, type WidgetClientEvents, type WidgetClientState } from "./client.js";
|
|
3
3
|
import { type SubscribeWidgetEventsOptions, type WidgetEventSubscription, type WidgetToolHooks } from "./events.js";
|
|
4
4
|
import type { WidgetNetworkClient } from "./network.js";
|
|
@@ -109,6 +109,8 @@ export declare class WidgetRuntimeClient {
|
|
|
109
109
|
private stopPresentationKeyboard;
|
|
110
110
|
dispose(): void;
|
|
111
111
|
private receiveConnection;
|
|
112
|
+
reportDevelopmentDiagnostic(diagnostic: WidgetGuestDiagnostic): void;
|
|
113
|
+
reportRenderResult(result: WidgetRenderResult): void;
|
|
112
114
|
private requireClient;
|
|
113
115
|
private removeConnectionListener;
|
|
114
116
|
private failConnection;
|
package/dist/runtime/client.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CapabilityRequest, CapabilityResult, GrantedCapability, InitPayload, PresentationCapabilityRequest, PresentationCapabilityResult, RegionCapabilityRequest, RegionCapabilityResult, RenderRequest, WidgetError, WidgetLiveEvent } from "../protocol/index.js";
|
|
1
|
+
import type { CapabilityRequest, CapabilityResult, GrantedCapability, InitPayload, PresentationCapabilityRequest, PresentationCapabilityResult, RegionCapabilityRequest, RegionCapabilityResult, RenderRequest, WidgetError, WidgetGuestDiagnostic, WidgetLiveEvent, WidgetRenderResult } from "../protocol/index.js";
|
|
2
2
|
import { type WidgetNetworkClient } from "./network.js";
|
|
3
3
|
import type { WidgetTransport } from "./transport.js";
|
|
4
4
|
export type WidgetClientState = "created" | "waiting-ready" | "ready" | "disposed";
|
|
@@ -8,6 +8,7 @@ export interface WidgetClientOptions {
|
|
|
8
8
|
widgetSdkVersion: string;
|
|
9
9
|
hostApiVersion?: 1;
|
|
10
10
|
initialPayload?: InitPayload;
|
|
11
|
+
developmentDiagnostics?: boolean;
|
|
11
12
|
handshakeTimeoutMs?: number;
|
|
12
13
|
capabilityTimeoutMs?: number;
|
|
13
14
|
createMessageId?: () => string;
|
|
@@ -48,6 +49,7 @@ export declare class WidgetClient {
|
|
|
48
49
|
private readonly endpoint;
|
|
49
50
|
private readonly widgetSdkVersion;
|
|
50
51
|
private readonly channelId;
|
|
52
|
+
private readonly developmentDiagnostics;
|
|
51
53
|
private readonly handshakeTimeoutMs;
|
|
52
54
|
private readonly capabilityTimeoutMs;
|
|
53
55
|
private readonly createMessageId;
|
|
@@ -81,6 +83,8 @@ export declare class WidgetClient {
|
|
|
81
83
|
private receive;
|
|
82
84
|
private initialize;
|
|
83
85
|
private initializeAsync;
|
|
86
|
+
reportDevelopmentDiagnostic(diagnostic: WidgetGuestDiagnostic): void;
|
|
87
|
+
reportRenderResult(result: WidgetRenderResult): void;
|
|
84
88
|
private send;
|
|
85
89
|
private assertUsable;
|
|
86
90
|
private acceptsRender;
|
package/dist/runtime/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { a as isWidgetHostConnectMessage, c as WidgetClient, i as createWidgetClient, l as WIDGET_SDK_VERSION, n as WIDGET_HOST_CONNECT, o as PRESENTATION_CONFIRMATION_TIMEOUT_MS, r as WidgetRuntimeClient, s as REGION_CONFIRMATION_TIMEOUT_MS, t as WIDGET_BOOTSTRAP_READY } from "../runtime-
|
|
2
|
-
import { i as isWidgetProtocolMessage, r as MessagePortTransport } from "../protocol-endpoint-
|
|
1
|
+
import { a as isWidgetHostConnectMessage, c as WidgetClient, i as createWidgetClient, l as WIDGET_SDK_VERSION, n as WIDGET_HOST_CONNECT, o as PRESENTATION_CONFIRMATION_TIMEOUT_MS, r as WidgetRuntimeClient, s as REGION_CONFIRMATION_TIMEOUT_MS, t as WIDGET_BOOTSTRAP_READY } from "../runtime-9g5MfsgK.js";
|
|
2
|
+
import { i as isWidgetProtocolMessage, r as MessagePortTransport } from "../protocol-endpoint-DbT0OJNu.js";
|
|
3
3
|
export { MessagePortTransport, PRESENTATION_CONFIRMATION_TIMEOUT_MS, REGION_CONFIRMATION_TIMEOUT_MS, WIDGET_BOOTSTRAP_READY, WIDGET_HOST_CONNECT, WIDGET_SDK_VERSION, WidgetClient, WidgetRuntimeClient, createWidgetClient, isWidgetHostConnectMessage, isWidgetProtocolMessage };
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { WidgetRuntimeProtocolMessage } from "../protocol/index.js";
|
|
2
2
|
import { type WidgetTransport } from "./transport.js";
|
|
3
3
|
declare const envelopeFields: readonly ["protocolVersion", "channelId", "messageId", "sequence"];
|
|
4
4
|
type EnvelopeField = (typeof envelopeFields)[number];
|
|
5
|
-
export type ProtocolMessageBody<TMessage extends
|
|
6
|
-
interface ProtocolEndpointOptions<TInbound extends
|
|
5
|
+
export type ProtocolMessageBody<TMessage extends WidgetRuntimeProtocolMessage> = TMessage extends WidgetRuntimeProtocolMessage ? Omit<TMessage, EnvelopeField> : never;
|
|
6
|
+
interface ProtocolEndpointOptions<TInbound extends WidgetRuntimeProtocolMessage> {
|
|
7
7
|
transport: WidgetTransport;
|
|
8
8
|
channelId: string;
|
|
9
9
|
createMessageId: () => string;
|
|
10
|
-
acceptsInbound: (message:
|
|
10
|
+
acceptsInbound: (message: WidgetRuntimeProtocolMessage) => message is TInbound;
|
|
11
11
|
onMessage: (message: TInbound) => void;
|
|
12
12
|
onError?: (error: Error) => void;
|
|
13
13
|
}
|
|
14
|
-
export declare class ProtocolEndpoint<TInbound extends
|
|
14
|
+
export declare class ProtocolEndpoint<TInbound extends WidgetRuntimeProtocolMessage, TOutbound extends WidgetRuntimeProtocolMessage> {
|
|
15
15
|
private readonly transport;
|
|
16
16
|
private readonly channelId;
|
|
17
17
|
private readonly createMessageId;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { WidgetRuntimeProtocolMessage } from "../protocol/index.js";
|
|
2
2
|
export interface WidgetTransport {
|
|
3
|
-
send(message:
|
|
4
|
-
onMessage(listener: (message:
|
|
3
|
+
send(message: WidgetRuntimeProtocolMessage): void;
|
|
4
|
+
onMessage(listener: (message: WidgetRuntimeProtocolMessage) => void): () => void;
|
|
5
5
|
onError?(listener: (error: Error) => void): () => void;
|
|
6
6
|
close(): void;
|
|
7
7
|
}
|
|
@@ -9,7 +9,7 @@ export interface WidgetTransport {
|
|
|
9
9
|
export interface WidgetMessagePort {
|
|
10
10
|
onmessage: ((event: MessageEvent<unknown>) => void) | null;
|
|
11
11
|
onmessageerror?: ((event: MessageEvent<unknown>) => void) | null;
|
|
12
|
-
postMessage(message:
|
|
12
|
+
postMessage(message: WidgetRuntimeProtocolMessage): void;
|
|
13
13
|
start?: () => void;
|
|
14
14
|
close(): void;
|
|
15
15
|
}
|
|
@@ -17,14 +17,14 @@ export interface WidgetMessagePort {
|
|
|
17
17
|
* Performs the inexpensive checks that are possible at the transport edge.
|
|
18
18
|
* Payload-specific validation stays with the contract/conformance layer.
|
|
19
19
|
*/
|
|
20
|
-
export declare function isWidgetProtocolMessage(value: unknown): value is
|
|
20
|
+
export declare function isWidgetProtocolMessage(value: unknown): value is WidgetRuntimeProtocolMessage;
|
|
21
21
|
export declare class MemoryTransport implements WidgetTransport {
|
|
22
22
|
private peer?;
|
|
23
23
|
private readonly listeners;
|
|
24
24
|
private closed;
|
|
25
25
|
static pair(): readonly [MemoryTransport, MemoryTransport];
|
|
26
|
-
send(message:
|
|
27
|
-
onMessage(listener: (message:
|
|
26
|
+
send(message: WidgetRuntimeProtocolMessage): void;
|
|
27
|
+
onMessage(listener: (message: WidgetRuntimeProtocolMessage) => void): () => void;
|
|
28
28
|
onError(): () => void;
|
|
29
29
|
close(): void;
|
|
30
30
|
}
|
|
@@ -35,8 +35,8 @@ export declare class MessagePortTransport implements WidgetTransport {
|
|
|
35
35
|
private readonly errorListeners;
|
|
36
36
|
private closed;
|
|
37
37
|
constructor(port: WidgetMessagePort);
|
|
38
|
-
send(message:
|
|
39
|
-
onMessage(listener: (message:
|
|
38
|
+
send(message: WidgetRuntimeProtocolMessage): void;
|
|
39
|
+
onMessage(listener: (message: WidgetRuntimeProtocolMessage) => void): () => void;
|
|
40
40
|
onError(listener: (error: Error) => void): () => void;
|
|
41
41
|
private reportError;
|
|
42
42
|
close(): void;
|