@xpert-ai/plugin-sdk 3.37.0 → 3.38.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/artifact-document.cjs.js +1 -1
- package/artifact-document.esm.js +1 -1
- package/docs/README.md +87 -0
- package/docs/artifact-documents.md +1 -1
- package/index.cjs.js +345 -102
- package/index.esm.js +338 -104
- package/model-provider.cjs.js +3 -0
- package/model-provider.esm.js +3 -1
- package/package.json +2 -2
- package/src/index.d.ts +1 -0
- package/src/lib/artifact-document/host.d.ts +2 -0
- package/src/lib/core/index.d.ts +2 -0
- package/src/lib/core/named-provider.registry.d.ts +9 -0
- package/src/lib/core/provider-registration.d.ts +9 -0
- package/src/lib/project-pipeline/adapters.d.ts +3 -2
- package/src/lib/rag/capability/knowledgebase-documents.d.ts +9 -0
- package/src/lib/runtime/capabilities/conversation.d.ts +8 -0
- package/src/lib/runtime/capabilities/index.d.ts +1 -0
- package/src/lib/sandbox/file-edit-command.d.ts +2 -1
- package/src/lib/sandbox/file-edits.d.ts +1 -0
- package/src/lib/sandbox/protocol.d.ts +7 -1
- package/src/lib/strategy.d.ts +8 -2
- package/src/lib/widgets/index.d.ts +2 -0
- package/src/lib/widgets/message-widget-provider/index.d.ts +3 -0
- package/src/lib/widgets/message-widget-provider/provider.decorator.d.ts +2 -0
- package/src/lib/widgets/message-widget-provider/provider.registry.d.ts +7 -0
- package/src/lib/widgets/message-widget-provider/types.d.ts +16 -0
- package/src/lib/widgets/widget-action/action.decorator.d.ts +2 -0
- package/src/lib/widgets/widget-action/action.registry.d.ts +8 -0
- package/src/lib/widgets/widget-action/index.d.ts +3 -0
- package/src/lib/widgets/widget-action/types.d.ts +19 -0
package/artifact-document.cjs.js
CHANGED
|
@@ -701,7 +701,7 @@ const diagnosticSchema = v3.z.object({
|
|
|
701
701
|
const latest = new Map();
|
|
702
702
|
const hostWindow = frame.ownerDocument.defaultView;
|
|
703
703
|
let connected = false, disposed = false, requests = 0, started = Date.now();
|
|
704
|
-
frame.setAttribute('sandbox', 'allow-scripts');
|
|
704
|
+
frame.setAttribute('sandbox', options.allowDownloads === true ? 'allow-scripts allow-downloads' : 'allow-scripts');
|
|
705
705
|
frame.referrerPolicy = 'no-referrer';
|
|
706
706
|
// Host UI observers cannot leave query accounting stuck or alter protocol completion.
|
|
707
707
|
const observe = (callback, value)=>{
|
package/artifact-document.esm.js
CHANGED
|
@@ -699,7 +699,7 @@ const diagnosticSchema = z.object({
|
|
|
699
699
|
const latest = new Map();
|
|
700
700
|
const hostWindow = frame.ownerDocument.defaultView;
|
|
701
701
|
let connected = false, disposed = false, requests = 0, started = Date.now();
|
|
702
|
-
frame.setAttribute('sandbox', 'allow-scripts');
|
|
702
|
+
frame.setAttribute('sandbox', options.allowDownloads === true ? 'allow-scripts allow-downloads' : 'allow-scripts');
|
|
703
703
|
frame.referrerPolicy = 'no-referrer';
|
|
704
704
|
// Host UI observers cannot leave query accounting stuck or alter protocol completion.
|
|
705
705
|
const observe = (callback, value)=>{
|
package/docs/README.md
CHANGED
|
@@ -26,6 +26,93 @@ Run `nx test plugin-sdk` to execute the unit tests via [Jest](https://jestjs.io)
|
|
|
26
26
|
|
|
27
27
|
[Plugin Permission Design Guide](./en/PERMISSIONS.md)
|
|
28
28
|
|
|
29
|
+
## Provider registries
|
|
30
|
+
|
|
31
|
+
Use `BaseStrategyRegistry` for discovery, plugin lifecycle events, scope precedence and lookup. `findByName(name, organizationId?)` returns `undefined` for an unavailable registration; `get` requires a match. The base class cancels its bus subscription when the module is destroyed. Existing registry naming and replacement policies remain unchanged.
|
|
32
|
+
|
|
33
|
+
Opt into `NamedProviderRegistry<T>` when a provider category requires plugin-qualified names, implementation validation and rejection of a different live instance with the same name in the same scope. Pair it with `definePluginRegistration` so ownership and duplicate declarations are also checked before module initialization. An existing instance may be registered again; replacement requires removing the previous registration first. Rejected dynamic registrations are logged without replacing the existing instance or preventing later lifecycle events. Initial discovery errors still fail module initialization.
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
const REPORT_RENDERER = 'EXAMPLE_REPORT_RENDERER'
|
|
37
|
+
export const ReportRenderer = definePluginRegistration(REPORT_RENDERER, 'report renderer')
|
|
38
|
+
|
|
39
|
+
interface ReportRendererApi {
|
|
40
|
+
render(input: string): string
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
@Injectable()
|
|
44
|
+
export class ReportRendererRegistry extends NamedProviderRegistry<ReportRendererApi> {
|
|
45
|
+
constructor(discovery: DiscoveryService, reflector: Reflector) {
|
|
46
|
+
super(REPORT_RENDERER, discovery, reflector)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
protected isProvider(instance: object): instance is ReportRendererApi {
|
|
50
|
+
return 'render' in instance && typeof instance.render === 'function'
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Import `NamedProviderRegistry` and `definePluginRegistration` from `@xpert-ai/plugin-sdk`, `Injectable` from `@nestjs/common`, and `DiscoveryService` / `Reflector` from `@nestjs/core`. Register the registry in a module with the host's discovery and strategy bus providers. A plugin implementation can use `@ReportRenderer('@example/reports:preview')`; its name belongs to that installing plugin. `findByName(name, organizationId?)` uses the base class's scoped lookup. The two Widget registries use this same opt-in layer and provide only their own interface validation and action resolution.
|
|
56
|
+
|
|
57
|
+
## A2UI Widget actions
|
|
58
|
+
|
|
59
|
+
Declare one action provider per Widget type in your plugin's Nest module. Its `actions` map contains named handlers that share the provider's dependencies. For `@example/dashboard:review`, the local action `publish` has the full name `@example/dashboard:review.publish`. Use that full name in both the A2UI button action and the containing surface's `serverActions`.
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
@WidgetActionProvider('@example/dashboard:review')
|
|
63
|
+
export class DashboardReviewActions implements IWidgetActionProvider {
|
|
64
|
+
constructor(private readonly dashboards: DashboardService) {}
|
|
65
|
+
|
|
66
|
+
readonly actions = {
|
|
67
|
+
publish: {
|
|
68
|
+
execute: async (context: WidgetActionContext) => {
|
|
69
|
+
await this.dashboards.publishFromWidget(context)
|
|
70
|
+
return { refresh: 'thread' as const }
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
cancel: {
|
|
74
|
+
execute: async (context: WidgetActionContext) => {
|
|
75
|
+
await this.dashboards.cancelReviewFromWidget(context)
|
|
76
|
+
return { refresh: 'thread' as const }
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
@Module({ providers: [DashboardService, DashboardReviewActions] })
|
|
83
|
+
export class DashboardPluginModule {}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Import `WidgetActionProvider`, `IWidgetActionProvider` and `WidgetActionContext` from `@xpert-ai/plugin-sdk`. Each map entry implements `IWidgetActionHandler`; local names contain only letters, digits, underscores or hyphens. The host resolves the exact provider namespace and an explicitly declared own action. It does not invoke arbitrary provider methods or inherited object properties. Registration and unloading apply to the whole action set.
|
|
87
|
+
|
|
88
|
+
The host checks thread access, the assistant message and the current action declaration restored from a server-issued Widget reference. Client-editable message content cannot authorize an action. The domain service validates the form, authorizes the caller for the target resource and handles repeated submissions. An action entry for a dynamically reconstructed card can set `widgetSource: 'receipt'`. Its `execute` handler must then verify the thread, assistant message, Widget ID and allowed operation against its own server record before changing state. Message rendering and action handling remain separate contracts; register both providers in the same business module.
|
|
89
|
+
|
|
90
|
+
Both decorators declare a registration category and name. Before Nest constructs providers, the host checks the name against the installing plugin and rejects duplicate names within a category and installation scope. New plugin-owned named strategies can use `definePluginRegistration(metadataKey, kind)` for the same preflight.
|
|
91
|
+
|
|
92
|
+
### Publish and restore a dynamic card
|
|
93
|
+
|
|
94
|
+
Register a `@MessageWidgetProvider` alongside the action provider in the plugin module. Calling `publishWidget()` during an active reply emits a Widget block at that point in the message stream, after its reference is persisted. The host binds the calling execution and thread, saves the block's position in the reply, and starts a separate text block for subsequent text. A producer that already knows the persisted assistant message may specify `messageId` in that thread. Both forms use a stable Widget ID from the domain record. Reissuing the same binding updates the original block without moving it. References without a streamed position remain recoverable at the end of the reply.
|
|
95
|
+
|
|
96
|
+
```ts
|
|
97
|
+
@MessageWidgetProvider('@example/dashboard:review')
|
|
98
|
+
export class DashboardReviewCards implements IMessageWidgetProvider {
|
|
99
|
+
constructor(private readonly dashboards: DashboardService) {}
|
|
100
|
+
|
|
101
|
+
issue(capabilities: RuntimeCapabilityRegistry, widgetId: string) {
|
|
102
|
+
return capabilities.require(ConversationRuntimeCapability).publishWidget(this, {
|
|
103
|
+
widgetId,
|
|
104
|
+
provider: '@example/dashboard:review'
|
|
105
|
+
})
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
resolve(references: readonly MessageWidgetReference[]) {
|
|
109
|
+
return this.dashboards.reviewWidgetsForCurrentViewer(references)
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Import the capability, provider and types from `@xpert-ai/plugin-sdk`. Pass the registry from the current middleware invocation. Add `DashboardReviewCards` and the action provider to the same module's providers. Live publication, message completion, history reads and reconnect snapshots call `resolve` with the issued references for that provider and restore each card at its original position. Return authorized `{ messageId, widget }` pairs with the original Widget IDs and current `serverActions`. To show a card in restricted sessions, explicitly set `visibleInRestrictedSessions = true` and return only fields safe for that viewer. Provider resolution is bounded to two seconds; unavailable cards are omitted without blocking the reply indefinitely. Unloading the provider hides its cards. Reinstalling the owning provider can restore them from the same references.
|
|
115
|
+
|
|
29
116
|
## Decorator-driven business Tools
|
|
30
117
|
|
|
31
118
|
Use `@XpertToolProvider()` on one injectable business class and `@XpertTool()` on its methods when the same domain operation should be available as an Agent Middleware Tool, a host-native MCP Tool, or both. Register only the decorated class in the plugin Nest module; the host expands it into one native Toolset and the declared Middleware groups.
|
|
@@ -80,7 +80,7 @@ renderUnavailable(round.failures)
|
|
|
80
80
|
|
|
81
81
|
## 隔离边界
|
|
82
82
|
|
|
83
|
-
HTML
|
|
83
|
+
HTML 默认在 `sandbox="allow-scripts"` 内执行。可信宿主可以在挂载时指定 `allowDownloads: true`,允许该文档发起文件下载;同源、表单和弹窗仍受沙箱限制。内容前缀首先安装 CSP,允许内联 JS/CSS 和 data/blob 图片。默认拒绝外部资源;可信宿主可显式开启上述 HTTPS 资源白名单。数据网络请求、子 iframe、worker、eval、对象和表单始终拒绝。宿主页额外的 frame-src 策略拒绝文档自身导航。
|
|
84
84
|
|
|
85
85
|
HTML 格式验证不是 sanitizer,也不证明业务正确性。Agent 代码仍可画出错误图形或阻塞自己的文档;业务口径、数值与实际页面都需要验收。该能力不提供后端写操作、任意网络代理或自动推送。
|
|
86
86
|
|