@ai-slot/runtime 0.2.0 → 0.2.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/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # @ai-slot/runtime
2
2
 
3
+ **English** | [简体中文](https://github.com/iannil/ai-slot-component/blob/master/packages/runtime/README.zh-CN.md)
4
+
3
5
  Zero-dependency `<ai-slot>` Web Component runtime for [ai-slot-component](https://github.com/iannil/ai-slot-component#readme): wrap existing markup, fetch a validated component tree from the proxy, and render it through a registered adapter — with a guaranteed fallback to your original content.
4
6
 
5
7
  ## Install
@@ -26,9 +28,9 @@ npm install @ai-slot/runtime
26
28
 
27
29
  Element attributes: `src`, `name`, `renderer` (default `dom`), `editable`, `stream` (SSE skeleton → tree), `live` + `live-src` (invalidation push), `refresh-interval`, `fresh-only`.
28
30
 
29
- 卸载元素时,在途的加载结果会被忽略;同一实例重新挂载后会重新核对内容。`live` 通道每次成功连接也会核对一次,因此初次挂载的加载与连接后的核对可能并发读取,由最新一次加载结果决定显示内容。
31
+ When the element is disconnected, in-flight load results are ignored. Reconnecting the same instance triggers a content check. Every successful `live` connection also triggers a check, so the initial load and the connection check may read concurrently; the latest load determines what is displayed.
30
32
 
31
- `fresh-only` 是挂载前配置的可选管理内容边界:需先通过 `configureAiSlot({ registry })` 配置注册表,且服务端必须在通过校验的最终树响应 `meta.expiresAt` 中提供可信的 Unix 毫秒截止时间。缺失、非法、已过期或后续更新失败时,槽位恢复原始兜底;当前显示的树到期也会恢复。运行时使用访客本机时钟,并在页面重新可见时复核。后台标签页的定时器节流或错误的系统时钟可能延迟撤回,不能保证所有访客在截止毫秒立即消失。普通槽位保持原有行为,不要求期限元数据。属性和 `live` 一样应在挂载前配置。
33
+ `fresh-only` is an optional boundary for managed content, configured before mounting. First configure the registry with `configureAiSlot({ registry })`; the server must provide a trusted Unix millisecond deadline in `meta.expiresAt` of the validated final-tree response. Missing, invalid, or expired deadlines, and failed subsequent updates, restore the original fallback. The currently displayed tree also falls back when it expires. The runtime uses the visitor’s local clock and rechecks when the page becomes visible again. Background-tab timer throttling or an incorrect system clock may delay removal; immediate removal at the deadline millisecond cannot be guaranteed for every visitor. Ordinary slots retain their existing behavior and do not require expiry metadata. Like `live`, configure this attribute before mounting.
32
34
 
33
35
  Wire format APIs: `registerWireFormat(id, format)` / `unregisterWireFormat(id)` plug alternative wire formats into the fetch pipeline. Failures are observed via `onFailure` as `FetchFailure { stage: "http-non-ok" | "parse" | "validate" | "fetch-error", message }` — set it globally in `configureAiSlot` or per call on `fetchComponentTree`. The silent-fallback behavior never changes; the hook is observation only.
34
36
 
@@ -0,0 +1,45 @@
1
+ # @ai-slot/runtime
2
+
3
+ [English](https://github.com/iannil/ai-slot-component/blob/master/packages/runtime/README.md) | **简体中文**
4
+
5
+ [ai-slot-component](https://github.com/iannil/ai-slot-component#readme) 的 `<ai-slot>` Web Component 运行时:包裹原有标记,从代理获取经过校验的组件树,再由已注册的适配器渲染;失败时回退到原始内容。
6
+
7
+ ## 安装
8
+
9
+ ```bash
10
+ npm install @ai-slot/runtime
11
+ ```
12
+
13
+ ## 用法
14
+
15
+ ```html
16
+ <ai-slot name="hero" src="/ai-render/hero" editable stream live>
17
+ <h1>原始内容,保留在页面中作为兜底</h1>
18
+ </ai-slot>
19
+
20
+ <script type="module">
21
+ import { configureAiSlot, registerRenderer } from "@ai-slot/runtime";
22
+ import { createDomRenderer } from "@ai-slot/adapter-dom";
23
+
24
+ registerRenderer("dom", createDomRenderer(components));
25
+ configureAiSlot({ registry, onFailure: (f) => console.debug(f) });
26
+ </script>
27
+ ```
28
+
29
+ 元素属性:`src`、`name`、`renderer`(默认 `dom`)、`editable`、`stream`(SSE 骨架 → 终树)、`live` + `live-src`(失效推送)、`refresh-interval`、`fresh-only`。
30
+
31
+ 卸载元素时,在途的加载结果会被忽略;同一实例重新挂载后会重新核对内容。`live` 通道每次成功连接也会核对一次,因此初次挂载的加载与连接后的核对可能并发读取,由最新一次加载结果决定显示内容。
32
+
33
+ `fresh-only` 是挂载前配置的可选管理内容边界:需先通过 `configureAiSlot({ registry })` 配置注册表,且服务端必须在通过校验的最终树响应 `meta.expiresAt` 中提供可信的 Unix 毫秒截止时间。缺失、非法、已过期或后续更新失败时,槽位恢复原始兜底;当前显示的树到期也会恢复。运行时使用访客本机时钟,并在页面重新可见时复核。后台标签页的定时器节流或错误的系统时钟可能延迟撤回,不能保证所有访客在截止毫秒立即消失。普通槽位保持原有行为,不要求期限元数据。属性和 `live` 一样应在挂载前配置。
34
+
35
+ 传输格式 API:`registerWireFormat(id, format)` / `unregisterWireFormat(id)` 可将其他传输格式接入请求流水线。通过 `onFailure` 观测失败,类型为 `FetchFailure { stage: "http-non-ok" | "parse" | "validate" | "fetch-error", message }`;可在 `configureAiSlot` 中全局配置,也可在每次 `fetchComponentTree` 调用中配置。该钩子仅用于观测,不改变静默回退行为。
36
+
37
+ > 注册必须在导入 runtime 的同一个模块图中同步完成,因为自定义元素升级是同步的。
38
+
39
+ ## 文档
40
+
41
+ - [项目介绍](https://github.com/iannil/ai-slot-component#readme) — 完整属性表和框架示例
42
+
43
+ ## 许可证
44
+
45
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-slot/runtime",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "license": "MIT",
5
5
  "description": "Zero-dependency <ai-slot> Web Component runtime for AI-enhanced pages with guaranteed fallback.",
6
6
  "keywords": [
@@ -32,7 +32,7 @@
32
32
  "registry": "https://registry.npmjs.org/"
33
33
  },
34
34
  "dependencies": {
35
- "@ai-slot/registry": "0.1.1"
35
+ "@ai-slot/registry": "0.1.2"
36
36
  },
37
37
  "devDependencies": {
38
38
  "jsdom": "^25.0.0",