@dp-bohrium/widget-sdk 0.8.0 → 0.10.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/AGENTS.md +1 -1
- package/CHANGELOG.md +25 -0
- package/README.md +0 -7
- package/assets/schemas/widget-manifest.schema.json +0 -12
- package/assets/schemas/widget-runtime-contracts.schema.json +906 -272
- 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-BJWUB8Nq.mjs} +1308 -516
- package/dist/index.d.ts +2 -2
- package/dist/index.js +53 -17
- package/dist/protocol/development-guards.d.ts +9 -0
- package/dist/protocol/generated-development-policy.d.ts +22 -0
- package/dist/protocol/generated-host-runtime-config.d.ts +0 -22
- package/dist/protocol/generated-manifest.d.ts +0 -8
- package/dist/protocol/generated-plugin-manifest.d.ts +0 -8
- package/dist/protocol/generated-runtime-contracts.d.ts +230 -128
- package/dist/protocol/index.d.ts +7 -2
- 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-Bn_ee8xy.js} +39 -5
- package/dist/widget-recovery-BF_sSUZX.js +472 -0
- package/dist/widget.d.ts +1 -41
- package/llms.txt +13 -1
- package/package.json +1 -1
- package/schemas/widget-manifest.schema.json +0 -12
- package/schemas/widget-runtime-contracts.schema.json +906 -272
- package/conformance/bridge/tasks-list-request.json +0 -17
- package/conformance/bridge/tasks-watch-request.json +0 -18
- package/dist/widget-events-gsKJbjqg.js +0 -65
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export type { CompileWidgetPluginManifestOptions } from "./manifest.js";
|
|
2
2
|
export { compileWidgetPluginManifest } from "./manifest.js";
|
|
3
|
-
export type { CapabilityRequest, CapabilityResult, FileDownloadResult, FileMutationId, FilePreviewContent, FilePreviewRenderRequest, FileReadInput, FileReadResult, FileReference, FileRevision, FileWriteInput, FileWriteResult, GrantedCapability, JsonValue, PanelContent, PanelRenderRequest, RenderRequest, RenderState,
|
|
3
|
+
export type { CapabilityRequest, CapabilityResult, FileDownloadResult, FileMutationId, FilePreviewContent, FilePreviewRenderRequest, FileReadInput, FileReadResult, FileReference, FileRevision, FileWriteInput, FileWriteResult, GrantedCapability, JsonValue, PanelContent, PanelRenderRequest, RenderRequest, RenderState, Theme, ThemeMode, WidgetActivationEvent, WidgetActivationEvents, WidgetContribution, WidgetError, WidgetErrorCode, WidgetEventName, WidgetFilePreviewContribution, WidgetLiveEvent, WidgetNetworkFetchInput, WidgetNetworkFetchOutput, WidgetPanelContribution, WidgetPluginContributions, WidgetPluginManifest, WidgetToolPhase, } from "./protocol/index.js";
|
|
4
4
|
export { isWidgetActivationEvent, isWidgetEventName, WIDGET_ACTIVATION_EVENTS, WIDGET_EVENT_NAMES, } from "./protocol/index.js";
|
|
5
5
|
export type { HostUserEmail, HostUserEmailResult, HostUserProfile, HostUserProfileResult, WidgetHostUserClient, } from "./runtime/service.js";
|
|
6
|
-
export type { FileDownloadCapabilityResult, FileReadCapabilityResult, FileWriteCapabilityResult,
|
|
6
|
+
export type { FileDownloadCapabilityResult, FileReadCapabilityResult, FileWriteCapabilityResult, UiStateReadCapabilityResult, UiStateWriteCapabilityResult, WidgetActivation, WidgetCapabilityApi, WidgetContext, WidgetDisposable, WidgetEventApi, WidgetFileApi, WidgetHandle, WidgetHostOptions, WidgetModule, WidgetRenderContext, WidgetRenderHandler, WidgetUiApi, WidgetUiStateApi, } from "./widget.js";
|
|
7
7
|
export { runWidgetHost } from "./widget.js";
|
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-Bn_ee8xy.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) {
|
|
@@ -315,16 +316,6 @@ function createContext(client, payload, renderHandlers, lifetime) {
|
|
|
315
316
|
input
|
|
316
317
|
}, options)
|
|
317
318
|
},
|
|
318
|
-
tasks: {
|
|
319
|
-
list: (input = {}, options) => client.requestCapability({
|
|
320
|
-
operation: "tasks.list",
|
|
321
|
-
input
|
|
322
|
-
}, options),
|
|
323
|
-
watch: (input, options) => client.requestCapability({
|
|
324
|
-
operation: "tasks.watch",
|
|
325
|
-
input
|
|
326
|
-
}, options)
|
|
327
|
-
},
|
|
328
319
|
network: client.network,
|
|
329
320
|
services: client.services,
|
|
330
321
|
hostUser: client.hostUser,
|
|
@@ -368,6 +359,7 @@ function createContext(client, payload, renderHandlers, lifetime) {
|
|
|
368
359
|
function createWidgetRuntime(module, options = {}) {
|
|
369
360
|
let client;
|
|
370
361
|
const renderHandlers = /* @__PURE__ */ new Set();
|
|
362
|
+
let latestRenderRevision = 0;
|
|
371
363
|
const reportCleanupError = (error) => options.onCleanupError?.(toStartupError(error));
|
|
372
364
|
const lifetime = createWidgetLifetime(reportCleanupError);
|
|
373
365
|
let activation;
|
|
@@ -393,6 +385,16 @@ function createWidgetRuntime(module, options = {}) {
|
|
|
393
385
|
retryable: false,
|
|
394
386
|
correlationId: request.requestId
|
|
395
387
|
};
|
|
388
|
+
let location = null;
|
|
389
|
+
try {
|
|
390
|
+
location = error instanceof Error ? /(?:\/__widget\/guest\/[^/]+\/|\/assets\/)([a-zA-Z0-9_./-]+):(\d+):(\d+)/u.exec(error.stack ?? "") : null;
|
|
391
|
+
} catch {}
|
|
392
|
+
const projected = projectWidgetRuntimeDiagnostic(failure, update ? "update" : "render", location?.[1] ? [{
|
|
393
|
+
file: location[1],
|
|
394
|
+
line: Number(location[2]),
|
|
395
|
+
column: Number(location[3])
|
|
396
|
+
}] : void 0);
|
|
397
|
+
const diagnostic = isWidgetGuestDiagnostic(projected) ? projected : projectWidgetRuntimeDiagnostic(failure, update ? "update" : "render");
|
|
396
398
|
writeLocalDiagnostic("[Widget 渲染失败]", failure, error);
|
|
397
399
|
for (const observer of [options.events?.onError, options.onError]) try {
|
|
398
400
|
Promise.resolve(observer?.(failure)).catch((observerError) => {
|
|
@@ -401,6 +403,7 @@ function createWidgetRuntime(module, options = {}) {
|
|
|
401
403
|
} catch (observerError) {
|
|
402
404
|
writeLocalDiagnostic("[Widget 诊断回调失败]", observerError);
|
|
403
405
|
}
|
|
406
|
+
return diagnostic;
|
|
404
407
|
}
|
|
405
408
|
function runDeactivation() {
|
|
406
409
|
if (deactivation) return deactivation;
|
|
@@ -438,18 +441,51 @@ function createWidgetRuntime(module, options = {}) {
|
|
|
438
441
|
return activation;
|
|
439
442
|
},
|
|
440
443
|
onRender(request, update) {
|
|
444
|
+
latestRenderRevision = request.revision;
|
|
441
445
|
const renderContext = {
|
|
442
446
|
phase: update ? "update" : "initial",
|
|
443
447
|
signal: lifetime.signal
|
|
444
448
|
};
|
|
445
|
-
|
|
446
|
-
|
|
449
|
+
const handlers = [...renderHandlers];
|
|
450
|
+
let reported = false;
|
|
451
|
+
const reportResult = (diagnostic) => {
|
|
452
|
+
if (lifetime.signal.aborted || !handlers.length || reported) return;
|
|
453
|
+
reported = true;
|
|
447
454
|
try {
|
|
448
|
-
|
|
455
|
+
if (request.revision !== latestRenderRevision) client.reportRenderResult({
|
|
456
|
+
requestId: request.requestId,
|
|
457
|
+
revision: request.revision,
|
|
458
|
+
outcome: "superseded"
|
|
459
|
+
});
|
|
460
|
+
else if (diagnostic) client.reportRenderResult({
|
|
461
|
+
requestId: request.requestId,
|
|
462
|
+
revision: request.revision,
|
|
463
|
+
outcome: "failed",
|
|
464
|
+
diagnostic: {
|
|
465
|
+
...diagnostic,
|
|
466
|
+
correlationId: request.requestId,
|
|
467
|
+
phase: update ? "update" : "render"
|
|
468
|
+
}
|
|
469
|
+
});
|
|
470
|
+
else client.reportRenderResult({
|
|
471
|
+
requestId: request.requestId,
|
|
472
|
+
revision: request.revision,
|
|
473
|
+
outcome: "handled"
|
|
474
|
+
});
|
|
475
|
+
} catch (reason) {
|
|
476
|
+
writeLocalDiagnostic("[Widget 诊断发送失败]", reason);
|
|
477
|
+
}
|
|
478
|
+
};
|
|
479
|
+
Promise.all(handlers.map(async (handler) => {
|
|
480
|
+
if (lifetime.signal.aborted) return;
|
|
481
|
+
try {
|
|
482
|
+
await handler(request, renderContext);
|
|
449
483
|
} catch (error) {
|
|
450
|
-
reportRenderFailure(error, request, update);
|
|
484
|
+
reportResult(reportRenderFailure(error, request, update));
|
|
451
485
|
}
|
|
452
|
-
}
|
|
486
|
+
})).then(() => reportResult()).catch((reason) => {
|
|
487
|
+
writeLocalDiagnostic("[Widget 诊断发送失败]", reason);
|
|
488
|
+
});
|
|
453
489
|
},
|
|
454
490
|
onDispose: dispose
|
|
455
491
|
}
|
|
@@ -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
|
+
};
|
|
@@ -134,20 +134,6 @@ export type GrantedCapability = ({
|
|
|
134
134
|
pageSize: number;
|
|
135
135
|
minPollMs: number;
|
|
136
136
|
};
|
|
137
|
-
} | {
|
|
138
|
-
name: "tasks.list";
|
|
139
|
-
limits: {
|
|
140
|
-
callsPerMinute: number;
|
|
141
|
-
pageSize: number;
|
|
142
|
-
minPollMs: number;
|
|
143
|
-
};
|
|
144
|
-
} | {
|
|
145
|
-
name: "tasks.watch";
|
|
146
|
-
limits: {
|
|
147
|
-
callsPerMinute: number;
|
|
148
|
-
pageSize: number;
|
|
149
|
-
minPollMs: number;
|
|
150
|
-
};
|
|
151
137
|
} | {
|
|
152
138
|
name: "ui.state";
|
|
153
139
|
limits: {
|
|
@@ -366,7 +352,6 @@ export interface PanelContributionConfig {
|
|
|
366
352
|
export interface RequestedCapabilities {
|
|
367
353
|
files?: FilesCapabilityRequest;
|
|
368
354
|
events?: EventsCapabilityRequest;
|
|
369
|
-
tasks?: TasksCapabilityRequest;
|
|
370
355
|
state?: StateCapabilityRequest;
|
|
371
356
|
actions?: ActionsCapabilityRequest;
|
|
372
357
|
network?: NetworkCapabilityRequest;
|
|
@@ -393,13 +378,6 @@ export interface EventsCapabilityRequest {
|
|
|
393
378
|
*/
|
|
394
379
|
topics: [string, ...(string)[]];
|
|
395
380
|
}
|
|
396
|
-
/**
|
|
397
|
-
* 任务发现与观察能力的申请;list / watch 至少显式申请一项,已申请项固定为 true。
|
|
398
|
-
*/
|
|
399
|
-
export interface TasksCapabilityRequest {
|
|
400
|
-
list?: true;
|
|
401
|
-
watch?: true;
|
|
402
|
-
}
|
|
403
381
|
/**
|
|
404
382
|
* 受限 UI 状态读写能力的申请;read / write 分别声明。
|
|
405
383
|
*/
|
|
@@ -105,7 +105,6 @@ export interface PanelContributionConfig {
|
|
|
105
105
|
export interface RequestedCapabilities {
|
|
106
106
|
files?: FilesCapabilityRequest;
|
|
107
107
|
events?: EventsCapabilityRequest;
|
|
108
|
-
tasks?: TasksCapabilityRequest;
|
|
109
108
|
state?: StateCapabilityRequest;
|
|
110
109
|
actions?: ActionsCapabilityRequest;
|
|
111
110
|
network?: NetworkCapabilityRequest;
|
|
@@ -132,13 +131,6 @@ export interface EventsCapabilityRequest {
|
|
|
132
131
|
*/
|
|
133
132
|
topics: [string, ...(string)[]];
|
|
134
133
|
}
|
|
135
|
-
/**
|
|
136
|
-
* 任务发现与观察能力的申请;list / watch 至少显式申请一项,已申请项固定为 true。
|
|
137
|
-
*/
|
|
138
|
-
export interface TasksCapabilityRequest {
|
|
139
|
-
list?: true;
|
|
140
|
-
watch?: true;
|
|
141
|
-
}
|
|
142
134
|
/**
|
|
143
135
|
* 受限 UI 状态读写能力的申请;read / write 分别声明。
|
|
144
136
|
*/
|
|
@@ -89,7 +89,6 @@ export interface WidgetFilePreviewContribution {
|
|
|
89
89
|
export interface RequestedCapabilities {
|
|
90
90
|
files?: FilesCapabilityRequest;
|
|
91
91
|
events?: EventsCapabilityRequest;
|
|
92
|
-
tasks?: TasksCapabilityRequest;
|
|
93
92
|
state?: StateCapabilityRequest;
|
|
94
93
|
actions?: ActionsCapabilityRequest;
|
|
95
94
|
network?: NetworkCapabilityRequest;
|
|
@@ -116,13 +115,6 @@ export interface EventsCapabilityRequest {
|
|
|
116
115
|
*/
|
|
117
116
|
topics: [string, ...(string)[]];
|
|
118
117
|
}
|
|
119
|
-
/**
|
|
120
|
-
* 任务发现与观察能力的申请;list / watch 至少显式申请一项,已申请项固定为 true。
|
|
121
|
-
*/
|
|
122
|
-
export interface TasksCapabilityRequest {
|
|
123
|
-
list?: true;
|
|
124
|
-
watch?: true;
|
|
125
|
-
}
|
|
126
118
|
/**
|
|
127
119
|
* 受限 UI 状态读写能力的申请;read / write 分别声明。
|
|
128
120
|
*/
|