@qilin-agent/experimental-webworker-runtime 3.1.5 → 3.1.6
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.i18n.yaml +4 -4
- package/README.md +3 -2
- package/README.zh.md +3 -2
- package/lib/client.js +93 -0
- package/lib/index.js +15 -2
- package/lib/types/client/text-viewer.d.ts +8 -0
- package/lib/types/shell/process/xdg-open.d.ts +11 -0
- package/lib/types/transport/frames.d.ts +8 -1
- package/lib/types/transport/tunnel.d.ts +6 -0
- package/lib/worker.js +66 -5
- package/package.json +24 -24
package/README.i18n.yaml
CHANGED
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
en: 4e53164159b5ce41
|
|
16
16
|
zh: 89582dc0294d0776
|
|
17
17
|
/qilin-agent-experimental-webworker-runtime/use-this-package:
|
|
18
|
-
en:
|
|
19
|
-
zh:
|
|
18
|
+
en: fd73a723abc1110e
|
|
19
|
+
zh: 1287e722ff7e0a83
|
|
20
20
|
/qilin-agent-experimental-webworker-runtime/model-experience:
|
|
21
21
|
en: 61fce9b4c7dc96e6
|
|
22
22
|
zh: dc2d931063a38327
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
en: ca75c51c89c2c9b0
|
|
25
25
|
zh: 64715dc7e6d02f71
|
|
26
26
|
/qilin-agent-experimental-webworker-runtime/known-limitations-and-deferred-work:
|
|
27
|
-
en:
|
|
28
|
-
zh:
|
|
27
|
+
en: 74b278c3ea3567cb
|
|
28
|
+
zh: 0d610d1457fc1c60
|
|
29
29
|
/qilin-agent-experimental-webworker-runtime/known-limitations-and-deferred-work/dev-note:
|
|
30
30
|
en: e67f633dc6fe7773
|
|
31
31
|
zh: e88aeb617ffb74ea
|
package/README.md
CHANGED
|
@@ -29,8 +29,8 @@ Three build artifacts and one source-owned process layer:
|
|
|
29
29
|
|
|
30
30
|
- **`lib/index.js` (assembly library)** — `createWorkerHost`/`startWorkerHost` mount the base image and any ordered data overlays (`storage/`), install the module loader (`module-system/`) and the `process` shim, boot the tree through the image's own `qilin-app-boot`, and hand the tunnel its serving seams. Overlays may replace files only under `home/` and `workspace/`; they cannot replace the base manifest, configuration, or modules. The image layout contract (`image-layout.ts`: virtual root, config/manifest paths, empty directories, the `lowered` wrapper-contract gate) is shared with the packer. Boot patches force the deployment-shaped rows: frontend serving off, JSONL session logs on the plaintext path, preset roots onto the image's `config/agent-presets`.
|
|
31
31
|
- **`lib/worker.js` (worker bundle)** — the assembly plus this package's Node-compatibility layer as one self-contained ES module. The module proxy table (`module-proxies.ts`) is the only platform fork: `node:*` builtins over VFS/tunnel/browser primitives, structural stubs that fail loud on the console for what a browser cannot do, and native/binary package replacements. `node:module` supplies `createRequire().resolve` and `.resolve.paths()` over the image package root, so unchanged packages can discover manifests without evaluating their modules. The global `process` shim carries Node detection fields including `title`, preventing Worker execution from entering DOM-only branches. The pack-time parser reports statically named module requests, including module-scope direct calls of the form `createRequire(import.meta.url)('pkg')` through a named `node:module` or `module` import, to the packer's reachability walk. Stored, CommonJS-obtained, and rebased `createRequire` calls require image entry seeds. VFS mutations drive `node:fs` callback, polling, and promise watchers; open descriptors retain file identity and access mode across rename, replacement, and unlink, `FileHandle.stat({ bigint: true })` reports the same device and inode identity as a path stat while the name still refers to that file, and `FileHandle.chmod()` updates the opened file identity; `readable-stream` supplies the stream state machine used by file streams and unchanged image packages such as Chokidar and readdirp. AsyncLocalStorage carries sync-stack causality across `await` through the snapshot/restore faces the pack-time lowering injects. The worker holds no compiler: an image the packer did not lower is refused at mount. The callback `fs.realpath.native` alias resolves within the mounted VFS and supports `util.promisify`.
|
|
32
|
-
- **`src/shell/` (the worker's own process layer)** — a browser worker cannot fork, so `node:child_process` is not a stub but an implementation: `spawn` starts the command in its own Web Worker — this same bundle, told by its first frame to be a shell process — and reports it through the `ChildProcess` surface the subprocess service consumes. The command runs off the host's thread, `SIGKILL` terminates it whatever it is doing, and it reaches the VFS only by message (the host serves those frames). Worker platform executables preserve native-package protocols such as Landlock without replacing their JavaScript packages or coupling their implementations to `node:child_process`; ordinary commands use the package's evaluator and coreutils command table. The grammar is `@yarnpkg/parsers`' `parseShell`, while `execSync`/`fork` still refuse because they need a real process.
|
|
33
|
-
- **`lib/client.js` (page half)** — startup has two independent stages. `chooseWorkerHostSource({ image?, fixtureManifest? })` optionally owns the boot barrier and fixture manifest: without `preview-fixture` it waits at the source chooser, while a valid query selects directly; either path returns ordered overlays. `connectWorkerHost(worker, { image?, overlays? })` remains the public base-runtime connector; callers that skip the chooser get an empty overlay list. `apps/web` invokes both and supplies its statically bundled Worker. The opening `init` frame carries the base and ordered overlay URLs, the boot payload delivers the structured index-injection table, and `applyIndexInjections` executes it before the shell entry runs. Script preload rows are advisory and skipped because `/plugins` resources resolve only through the tunnel; `loadBundle` fetches each combo on first demand, embeds its tunnel-only source map as a Base64 data URL, and executes the script as a Blob. The tunnel also exposes fetch-shaped transport, the independent file-upload carrier, and the API client. Request frames preserve Blob bodies through structured clone and transfer `ReadableStream<Uint8Array>` ownership. The Host Worker streams both forms into the route, so neither browser thread creates a complete byte array for a generic-file upload. A Remote stream's uplink crosses as `stream-uplink-item` / `stream-uplink-end` frames into an unbounded `TunnelUplink` that drops items arriving after `end`: the page and its worker are one trusted same-origin boundary, so the Host inbox cap does not apply.
|
|
32
|
+
- **`src/shell/` (the worker's own process layer)** — a browser worker cannot fork, so `node:child_process` is not a stub but an implementation: `spawn` starts the command in its own Web Worker — this same bundle, told by its first frame to be a shell process — and reports it through the `ChildProcess` surface the subprocess service consumes. The command runs off the host's thread, `SIGKILL` terminates it whatever it is doing, and it reaches the VFS only by message (the host serves those frames). Worker platform executables preserve native-package protocols such as Landlock without replacing their JavaScript packages or coupling their implementations to `node:child_process`; `xdg-open` sends one VFS text file to the page's read-only viewer, so desktop-opener actions such as **Open configuration file** show the file in the page; ordinary commands use the package's evaluator and coreutils command table. The grammar is `@yarnpkg/parsers`' `parseShell`, while `execSync`/`fork` still refuse because they need a real process.
|
|
33
|
+
- **`lib/client.js` (page half)** — startup has two independent stages. `chooseWorkerHostSource({ image?, fixtureManifest? })` optionally owns the boot barrier and fixture manifest: without `preview-fixture` it waits at the source chooser, while a valid query selects directly; either path returns ordered overlays. `connectWorkerHost(worker, { image?, overlays? })` remains the public base-runtime connector; callers that skip the chooser get an empty overlay list. `apps/web` invokes both and supplies its statically bundled Worker. The opening `init` frame carries the base and ordered overlay URLs, the boot payload delivers the structured index-injection table, and `applyIndexInjections` executes it before the shell entry runs. Script preload rows are advisory and skipped because `/plugins` resources resolve only through the tunnel; `loadBundle` fetches each combo on first demand, embeds its tunnel-only source map as a Base64 data URL, and executes the script as a Blob. The worker's unsolicited `view-text` frame opens the page's modal text viewer. The tunnel also exposes fetch-shaped transport, the independent file-upload carrier, and the API client. Request frames preserve Blob bodies through structured clone and transfer `ReadableStream<Uint8Array>` ownership. The Host Worker streams both forms into the route, so neither browser thread creates a complete byte array for a generic-file upload. A Remote stream's uplink crosses as `stream-uplink-item` / `stream-uplink-end` frames into an unbounded `TunnelUplink` that drops items arriving after `end`: the page and its worker are one trusted same-origin boundary, so the Host inbox cap does not apply.
|
|
34
34
|
|
|
35
35
|
Acceptance lives in `apps/web/tests/preview-boot.e2e.ts`, which serves the real built pages and drives the pre-boot chooser plus Worker activation in headless Chromium. The empty selection exercises first-run startup. The `vfs-example` overlay supplies ordinary workspace files and plaintext persistence artifacts for cold Workspace/Session discovery, tool presentation, subagent navigation, and history paging without a model request. The fixture generator owns current-generation logs and the projection cache; committed predecessor logs remain byte-identical alongside them. The chooser reserves WebFS as a separate user-authorized source; that provider does not read the built-in fixture.
|
|
36
36
|
|
|
@@ -54,6 +54,7 @@ None; this package neither assembles nor sends a provider request.
|
|
|
54
54
|
- **The worker composition writes plaintext session logs** (`compression: 'none'` boot patch): it carries no Zstandard codec, so exported logs are `.jsonl`, never `.jsonl.zstd`.
|
|
55
55
|
- **`node:dns/promises`, `node:vm`, `node:net`, `node:sqlite`, `node:worker_threads` are structural stubs**: every call reports its refusal on the console and throws. Rows needing native DNS, a real process, or realm isolation cannot run here.
|
|
56
56
|
- **Host package commands are unavailable**: `execa` reports an explicit worker-host refusal; the preview cannot run pnpm or install native dependencies.
|
|
57
|
+
- **pi-ai model requests are unavailable**: the replacement exposes a fixed subset of installed provider identifiers with no models, allowing the adapter to register configuration metadata. Its identifiers must stay valid when pi-ai is upgraded; inference entry points report an explicit worker-host refusal.
|
|
57
58
|
- **PTC Node programs are unavailable**: the process shim exposes `/qilin/bin/node` as its executable identity so the provider can activate, but the Worker has neither a Node executable nor `stripTypeScriptTypes`. Program execution fails before launching a child.
|
|
58
59
|
- **Office conversion requires a Node Host**: the LibreOffice kit replacement rejects converter creation with `unavailable`. The browser image excludes the kit and its engine dependencies; the Office preview reports that conversion is unavailable.
|
|
59
60
|
- **Filesystem watchers observe only the mounted VFS**: image seeding is silent and the VFS has no symlinks or external writers. `persistent`, `ref()`, and `unref()` preserve the Node API but cannot control a dedicated Worker's lifetime because browsers expose no ref-counted event loop.
|
package/README.zh.md
CHANGED
|
@@ -29,8 +29,8 @@ kind: "package-library"
|
|
|
29
29
|
|
|
30
30
|
- **`lib/index.js`(装配库)**——`createWorkerHost`/`startWorkerHost` 挂载基础镜像和按序排列的数据 overlays(`storage/`)、安装模块加载器(`module-system/`)与 `process` shim、经镜像自带的 `qilin-app-boot` 启动插件树,并把服务 seam 交给隧道。Overlay 只能替换 `home/` 与 `workspace/` 下的文件,不能替换基础 manifest、配置或模块。镜像布局契约(`image-layout.ts`:虚拟根、config/manifest 路径、空目录、`lowered` 包装契约门)与 packer 共享。boot patch 强制部署形态行:关前端静态服务、JSONL 会话日志走明文、preset 根指向镜像内 `config/agent-presets`。
|
|
31
31
|
- **`lib/worker.js`(worker 束)**——装配库加本包的 Node 兼容层,合成一个自含 ES module。模块代理表(`module-proxies.ts`)是唯一平台叉口:`node:*` 内建走 VFS、隧道和浏览器原语,浏览器做不到的走结构化 stub(调用即在 console 报错并抛出),native/binary 包则替换执行后端。`node:module` 在镜像 package 根之上提供 `createRequire().resolve` 与 `.resolve.paths()`,使未修改的包无需执行目标模块即可发现 manifest。全局 `process` shim 带有包括 `title` 在内的 Node 环境识别字段,避免 Worker 执行误入仅适用于 DOM 的分支。pack 期解析器会把名称静态可知的模块请求报告给 packer 的可达性遍历,其中包括通过 `node:module` 或 `module` 具名导入在模块作用域直接发起的 `createRequire(import.meta.url)('pkg')` 调用。保存、经 CommonJS 获取或另设基准的 `createRequire` 调用需要镜像入口种子。VFS mutation 驱动 `node:fs` 的 callback、polling 和 promise watcher;打开的 descriptor 在 rename、replacement 和 unlink 后仍保留文件身份与访问模式,只要文件名仍指向该文件,`FileHandle.stat({ bigint: true })` 报告的 device 与 inode 身份就与路径 stat 相同,`FileHandle.chmod()` 则更新打开文件身份的权限;`readable-stream` 提供文件流以及 Chokidar、readdirp 等未修改镜像包所用的流状态机。AsyncLocalStorage 经 pack 时降低注入的 snapshot/restore 面在 `await` 间携带同步栈因果。worker 不带编译器:packer 未降低的镜像在挂载时被拒。回调式 `fs.realpath.native` 别名在已挂载的 VFS 内解析路径,并支持 `util.promisify`。
|
|
32
|
-
- **`src/shell/`(worker 自己的进程层)**——浏览器 worker 无法 fork,所以 `node:child_process` 不是 stub 而是实现:`spawn` 把命令放进它自己的 Web Worker——就是这同一个束,由首帧告诉它「你是 shell 进程」——并以 subprocess 服务消费的 `ChildProcess` 面报告结果。命令不占宿主线程,`SIGKILL` 不管它在干什么都能终止它,而它只能靠消息触达 VFS(由宿主应答这些帧)。Worker 平台 executable 在不替换 JavaScript 包、也不把具体实现耦合进 `node:child_process` 的情况下保持 Landlock 等 native
|
|
33
|
-
- **`lib/client.js`(页面半)**——启动分为相互独立的两段。`chooseWorkerHostSource({ image?, fixtureManifest? })` 可选地拥有 boot barrier 与 fixture manifest:没有 `preview-fixture` 时停在来源选择面板,合法 query 则直接选择;两条路径都返回按序排列的 overlays。`connectWorkerHost(worker, { image?, overlays? })` 仍是公开的基础运行态连接器;调用方跳过选择器时 overlay 列表为空。`apps/web` 调用这两段并提供静态打包的 Worker。开局 `init` 帧携带基础镜像与按序排列的 overlay URL,boot 载荷送达结构化 index 注入表,`applyIndexInjections` 在壳入口运行前逐行执行。脚本 preload 行只是提示,因此会被跳过:`/plugins` 资源只能经 tunnel 解析,`loadBundle` 会在首次需要时获取 combo、把仅 tunnel 可达的 sourcemap 内嵌为 Base64 data URL,再以 Blob 执行脚本。Tunnel 还暴露 fetch 形式的传输、独立文件上传载体和 API 客户端。请求帧通过结构化克隆保留 Blob 请求体,并转移 `ReadableStream<Uint8Array>` 的所有权。Host Worker 将两种请求体都逐块送入路由,因此通用文件上传不会在任何浏览器线程创建完整字节数组。Remote 流的上行以 `stream-uplink-item` / `stream-uplink-end` 帧进入没有上限的 `TunnelUplink`,`end` 之后到达的项被丢弃:页面与其 worker 是同一个可信的同源边界,Host 的 inbox 上限在此不适用。
|
|
32
|
+
- **`src/shell/`(worker 自己的进程层)**——浏览器 worker 无法 fork,所以 `node:child_process` 不是 stub 而是实现:`spawn` 把命令放进它自己的 Web Worker——就是这同一个束,由首帧告诉它「你是 shell 进程」——并以 subprocess 服务消费的 `ChildProcess` 面报告结果。命令不占宿主线程,`SIGKILL` 不管它在干什么都能终止它,而它只能靠消息触达 VFS(由宿主应答这些帧)。Worker 平台 executable 在不替换 JavaScript 包、也不把具体实现耦合进 `node:child_process` 的情况下保持 Landlock 等 native 包协议;`xdg-open` 把一个 VFS 文本文件交给页面的只读查看器,因此 **打开配置文件** 等桌面打开操作会在页面内显示该文件;普通命令使用本包的求值器与 coreutils 命令表。语法来自 `@yarnpkg/parsers` 的 `parseShell`,而 `execSync`/`fork` 依然拒绝,因为它们需要真进程。
|
|
33
|
+
- **`lib/client.js`(页面半)**——启动分为相互独立的两段。`chooseWorkerHostSource({ image?, fixtureManifest? })` 可选地拥有 boot barrier 与 fixture manifest:没有 `preview-fixture` 时停在来源选择面板,合法 query 则直接选择;两条路径都返回按序排列的 overlays。`connectWorkerHost(worker, { image?, overlays? })` 仍是公开的基础运行态连接器;调用方跳过选择器时 overlay 列表为空。`apps/web` 调用这两段并提供静态打包的 Worker。开局 `init` 帧携带基础镜像与按序排列的 overlay URL,boot 载荷送达结构化 index 注入表,`applyIndexInjections` 在壳入口运行前逐行执行。脚本 preload 行只是提示,因此会被跳过:`/plugins` 资源只能经 tunnel 解析,`loadBundle` 会在首次需要时获取 combo、把仅 tunnel 可达的 sourcemap 内嵌为 Base64 data URL,再以 Blob 执行脚本。worker 主动发出的 `view-text` 帧会打开页面的模态文本查看器。Tunnel 还暴露 fetch 形式的传输、独立文件上传载体和 API 客户端。请求帧通过结构化克隆保留 Blob 请求体,并转移 `ReadableStream<Uint8Array>` 的所有权。Host Worker 将两种请求体都逐块送入路由,因此通用文件上传不会在任何浏览器线程创建完整字节数组。Remote 流的上行以 `stream-uplink-item` / `stream-uplink-end` 帧进入没有上限的 `TunnelUplink`,`end` 之后到达的项被丢弃:页面与其 worker 是同一个可信的同源边界,Host 的 inbox 上限在此不适用。
|
|
34
34
|
|
|
35
35
|
验收在 `apps/web/tests/preview-boot.e2e.ts`:静态服务真实构建页面,在 headless Chromium 里驱动 pre-boot 选择面板与 Worker 激活。空白选择验证首次启动;`vfs-example` overlay 提供普通 workspace 文件与明文 persistence 产物,无需模型请求即可验证 Workspace/Session 冷发现、工具呈现、subagent 导航和历史分页。fixture 生成器负责当前代日志与投影缓存;已提交的前代日志逐字节保持不变,与它们并存。选择面板为 WebFS 保留独立的用户授权来源;该 provider 不读取内置 fixture。
|
|
36
36
|
|
|
@@ -54,6 +54,7 @@ kind: "package-library"
|
|
|
54
54
|
- **worker 组合写明文会话日志**(`compression: 'none'` boot patch):不带 Zstandard 编解码器,导出日志是 `.jsonl`,不会是 `.jsonl.zstd`。
|
|
55
55
|
- **`node:dns/promises`、`node:vm`、`node:net`、`node:sqlite`、`node:worker_threads` 是结构化 stub**:每次调用在 console 报告拒绝并抛出。需要原生 DNS、真进程或真 realm 隔离的行在此无法运行。
|
|
56
56
|
- **宿主包管理命令不可用**:`execa` 明确报告 worker host 不支持该调用;预览无法运行 pnpm 或安装原生依赖。
|
|
57
|
+
- **pi-ai 模型请求不可用**:替换物暴露一组固定的已安装 provider 标识符且没有模型,适配器借此注册配置元数据。pi-ai 升级时这些标识符必须保持有效;推理入口会报出明确的 worker-host 拒绝。
|
|
57
58
|
- **PTC Node 程序不可用**:process shim 用 `/qilin/bin/node` 表示可执行文件身份,使 provider 能够激活,但 Worker 既没有 Node 可执行文件,也没有 `stripTypeScriptTypes`。程序执行会在启动子进程前失败。
|
|
58
59
|
- **Office 转换需要 Node Host**:LibreOffice kit 的替代模块以 `unavailable` 拒绝创建转换器。浏览器镜像排除 kit 及其引擎依赖;Office 预览提示转换不可用。
|
|
59
60
|
- **文件 watcher 只能观察已挂载的 VFS**:镜像 seed 不产生事件,VFS 也没有符号链接或外部写入方。`persistent`、`ref()` 和 `unref()` 保留 Node API,但浏览器没有引用计数事件循环,因此这些接口不能控制 dedicated Worker 的生存期。
|
package/lib/client.js
CHANGED
|
@@ -52,6 +52,96 @@ function parsePreviewFixtureManifest(value) {
|
|
|
52
52
|
};
|
|
53
53
|
}
|
|
54
54
|
//#endregion
|
|
55
|
+
//#region src/client/text-viewer.ts
|
|
56
|
+
/** Read-only text viewer the page shows when the worker's `xdg-open` names a VFS file. */
|
|
57
|
+
const VIEWER_STYLE = `
|
|
58
|
+
[data-preview-text-viewer] {
|
|
59
|
+
width: min(960px, calc(100vw - 32px));
|
|
60
|
+
height: min(720px, calc(100dvh - 32px));
|
|
61
|
+
padding: 0;
|
|
62
|
+
box-sizing: border-box;
|
|
63
|
+
border: 1px solid var(--dsw-alias-border-l2, rgb(0 0 0 / 10%));
|
|
64
|
+
border-radius: var(--dsw-radius-lg, 16px);
|
|
65
|
+
color: var(--dsw-alias-label-primary, #0f1115);
|
|
66
|
+
background: var(--dsw-alias-bg-base, #fff);
|
|
67
|
+
font-family: var(--dsw-font-family, inherit);
|
|
68
|
+
}
|
|
69
|
+
[data-preview-text-viewer][open] { display: flex; flex-direction: column; }
|
|
70
|
+
[data-preview-text-viewer]::backdrop { background: rgb(0 0 0 / 32%); }
|
|
71
|
+
[data-preview-text-viewer] header {
|
|
72
|
+
display: flex;
|
|
73
|
+
align-items: center;
|
|
74
|
+
gap: 12px;
|
|
75
|
+
padding: 12px 16px;
|
|
76
|
+
border-bottom: 1px solid var(--dsw-alias-border-l1, rgb(0 0 0 / 6%));
|
|
77
|
+
}
|
|
78
|
+
[data-preview-text-viewer] h2 {
|
|
79
|
+
flex: 1;
|
|
80
|
+
min-width: 0;
|
|
81
|
+
margin: 0;
|
|
82
|
+
overflow: hidden;
|
|
83
|
+
font-size: 14px;
|
|
84
|
+
line-height: 22px;
|
|
85
|
+
font-weight: 500;
|
|
86
|
+
text-overflow: ellipsis;
|
|
87
|
+
white-space: nowrap;
|
|
88
|
+
}
|
|
89
|
+
[data-preview-text-viewer] button {
|
|
90
|
+
height: 28px;
|
|
91
|
+
padding: 0 12px;
|
|
92
|
+
border: 1px solid var(--dsw-alias-border-l2, rgb(0 0 0 / 10%));
|
|
93
|
+
border-radius: var(--dsw-radius-sm, 8px);
|
|
94
|
+
color: inherit;
|
|
95
|
+
background: transparent;
|
|
96
|
+
font: inherit;
|
|
97
|
+
cursor: pointer;
|
|
98
|
+
}
|
|
99
|
+
[data-preview-text-viewer] pre {
|
|
100
|
+
flex: 1;
|
|
101
|
+
margin: 0;
|
|
102
|
+
padding: 16px;
|
|
103
|
+
overflow: auto;
|
|
104
|
+
background: var(--dsw-alias-markdown-code-block, transparent);
|
|
105
|
+
font: 13px/20px ui-monospace, SFMono-Regular, Menlo, monospace;
|
|
106
|
+
white-space: pre;
|
|
107
|
+
}
|
|
108
|
+
`;
|
|
109
|
+
/**
|
|
110
|
+
* Show one file in the page's modal viewer, replacing any file it already shows.
|
|
111
|
+
* @param path - Absolute VFS path used as the title.
|
|
112
|
+
* @param text - File contents, rendered as plain text.
|
|
113
|
+
*/
|
|
114
|
+
function showTextViewer(path, text) {
|
|
115
|
+
let dialog = document.querySelector("dialog[data-preview-text-viewer]");
|
|
116
|
+
if (dialog === null) {
|
|
117
|
+
const style = document.createElement("style");
|
|
118
|
+
style.textContent = VIEWER_STYLE;
|
|
119
|
+
document.head.append(style);
|
|
120
|
+
dialog = document.createElement("dialog");
|
|
121
|
+
dialog.dataset.previewTextViewer = "";
|
|
122
|
+
const header = document.createElement("header");
|
|
123
|
+
const title = document.createElement("h2");
|
|
124
|
+
const close = document.createElement("button");
|
|
125
|
+
close.type = "button";
|
|
126
|
+
close.textContent = "Close";
|
|
127
|
+
const shown = dialog;
|
|
128
|
+
close.addEventListener("click", () => {
|
|
129
|
+
shown.close();
|
|
130
|
+
});
|
|
131
|
+
dialog.addEventListener("keydown", (event) => {
|
|
132
|
+
event.stopPropagation();
|
|
133
|
+
});
|
|
134
|
+
header.append(title, close);
|
|
135
|
+
dialog.append(header, document.createElement("pre"));
|
|
136
|
+
document.body.append(dialog);
|
|
137
|
+
}
|
|
138
|
+
const title = dialog.querySelector("h2");
|
|
139
|
+
title.textContent = path;
|
|
140
|
+
title.title = path;
|
|
141
|
+
dialog.querySelector("pre").textContent = text;
|
|
142
|
+
if (!dialog.open) dialog.showModal();
|
|
143
|
+
}
|
|
144
|
+
//#endregion
|
|
55
145
|
//#region src/client/client.ts
|
|
56
146
|
/** Error carrying stream semantics across independently bundled Client code. */
|
|
57
147
|
var TunnelLogicalStreamError = class extends Error {
|
|
@@ -537,6 +627,9 @@ var WorkerTunnel = class {
|
|
|
537
627
|
controller.error(reason);
|
|
538
628
|
return;
|
|
539
629
|
}
|
|
630
|
+
case "view-text":
|
|
631
|
+
showTextViewer(frame.path, frame.text);
|
|
632
|
+
return;
|
|
540
633
|
case "stream-item":
|
|
541
634
|
case "stream-end":
|
|
542
635
|
case "stream-error": {
|
package/lib/index.js
CHANGED
|
@@ -1655,6 +1655,18 @@ var TunnelServer = class {
|
|
|
1655
1655
|
this.failure = message;
|
|
1656
1656
|
for (const frame of this.queue.splice(0)) this.refuse(frame, message);
|
|
1657
1657
|
}
|
|
1658
|
+
/**
|
|
1659
|
+
* Ask the page to show one text file in its read-only viewer.
|
|
1660
|
+
* @param path - Absolute VFS path the viewer names.
|
|
1661
|
+
* @param text - File contents.
|
|
1662
|
+
*/
|
|
1663
|
+
viewText(path, text) {
|
|
1664
|
+
this.send({
|
|
1665
|
+
t: "view-text",
|
|
1666
|
+
path,
|
|
1667
|
+
text
|
|
1668
|
+
});
|
|
1669
|
+
}
|
|
1658
1670
|
send(frame, transfer) {
|
|
1659
1671
|
this.port.postMessage(frame, transfer);
|
|
1660
1672
|
}
|
|
@@ -3396,10 +3408,11 @@ function createWorkerHost(options) {
|
|
|
3396
3408
|
const handler = connection.createSharedFetchHandler("/api");
|
|
3397
3409
|
const usage = loader.usage();
|
|
3398
3410
|
console.info(`webworker host: tree active (modules=${String(usage.modules)}, data overlays=${String(overlays.length)}, preset root overlay=${presetOverlay ? "applied" : "already in roster"}, direct lane=connection.createSharedFetchHandler, als causality=${options.alsCausality === void 0 ? "inert" : "snapshot/restore"}, image lowering=${LOWERING_VERSION})`);
|
|
3411
|
+
const peer = connection.browserPeer;
|
|
3399
3412
|
tunnel.serve({
|
|
3400
|
-
directFetch: (request) => handler.fetch(request),
|
|
3413
|
+
directFetch: (request) => handler.fetch(request, peer),
|
|
3401
3414
|
bootPayload: () => readBootPayload(ctx),
|
|
3402
|
-
openStream: (endpoint, payload, uplink, signal) => typertGateway.wireStream.open(endpoint, payload, uplink,
|
|
3415
|
+
openStream: (endpoint, payload, uplink, signal) => typertGateway.wireStream.open(endpoint, payload, uplink, peer, signal),
|
|
3403
3416
|
streamFailure: typertGateway.wireStream.failure
|
|
3404
3417
|
});
|
|
3405
3418
|
} catch (reason) {
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** Read-only text viewer the page shows when the worker's `xdg-open` names a VFS file. */
|
|
2
|
+
/**
|
|
3
|
+
* Show one file in the page's modal viewer, replacing any file it already shows.
|
|
4
|
+
* @param path - Absolute VFS path used as the title.
|
|
5
|
+
* @param text - File contents, rendered as plain text.
|
|
6
|
+
*/
|
|
7
|
+
export declare function showTextViewer(path: string, text: string): void;
|
|
8
|
+
//# sourceMappingURL=text-viewer.d.ts.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { VirtualExecutable } from './virtual-executables.ts';
|
|
2
|
+
/** Page-side display of one text file. */
|
|
3
|
+
export type TextViewer = (path: string, text: string) => void;
|
|
4
|
+
/**
|
|
5
|
+
* Install the page viewer `xdg-open` reports to; the worker host calls this once its tunnel exists.
|
|
6
|
+
* @param next - Viewer that forwards to the page.
|
|
7
|
+
*/
|
|
8
|
+
export declare function setTextViewer(next: TextViewer): void;
|
|
9
|
+
/** Virtual executable replacing the desktop opener with the page's text viewer. */
|
|
10
|
+
export declare const XDG_OPEN_EXECUTABLE: VirtualExecutable;
|
|
11
|
+
//# sourceMappingURL=xdg-open.d.ts.map
|
|
@@ -108,8 +108,15 @@ export interface TunnelStreamErrorFrame {
|
|
|
108
108
|
readonly message: string;
|
|
109
109
|
};
|
|
110
110
|
}
|
|
111
|
+
/** Worker request to show one VFS text file in the page's read-only viewer; no reply follows. */
|
|
112
|
+
export interface TunnelViewTextFrame {
|
|
113
|
+
readonly t: 'view-text';
|
|
114
|
+
/** Absolute VFS path, shown as the viewer title. */
|
|
115
|
+
readonly path: string;
|
|
116
|
+
readonly text: string;
|
|
117
|
+
}
|
|
111
118
|
/** Frames the worker emits. */
|
|
112
|
-
export type TunnelOutboundFrame = TunnelResponseFrame | TunnelResponseHeadFrame | TunnelResponseChunkFrame | TunnelResponseEndFrame | TunnelResponseErrorFrame | TunnelStreamItemFrame | TunnelStreamEndFrame | TunnelStreamErrorFrame;
|
|
119
|
+
export type TunnelOutboundFrame = TunnelViewTextFrame | TunnelResponseFrame | TunnelResponseHeadFrame | TunnelResponseChunkFrame | TunnelResponseEndFrame | TunnelResponseErrorFrame | TunnelStreamItemFrame | TunnelStreamEndFrame | TunnelStreamErrorFrame;
|
|
113
120
|
/**
|
|
114
121
|
* Validate a `postMessage` payload as a tunnel frame.
|
|
115
122
|
* @param data - Message data received by the worker.
|
|
@@ -107,6 +107,12 @@ export declare class TunnelServer {
|
|
|
107
107
|
* @param reason - Boot failure to report.
|
|
108
108
|
*/
|
|
109
109
|
fail(reason: unknown): void;
|
|
110
|
+
/**
|
|
111
|
+
* Ask the page to show one text file in its read-only viewer.
|
|
112
|
+
* @param path - Absolute VFS path the viewer names.
|
|
113
|
+
* @param text - File contents.
|
|
114
|
+
*/
|
|
115
|
+
viewText(path: string, text: string): void;
|
|
110
116
|
private send;
|
|
111
117
|
private refuse;
|
|
112
118
|
private dispatchFrame;
|
package/lib/worker.js
CHANGED
|
@@ -693,6 +693,50 @@ function installProcessGlobal(options) {
|
|
|
693
693
|
return shim;
|
|
694
694
|
}
|
|
695
695
|
//#endregion
|
|
696
|
+
//#region src/shell/process/xdg-open.ts
|
|
697
|
+
/**
|
|
698
|
+
* The Worker's `xdg-open`: hands one VFS text file to the page's read-only
|
|
699
|
+
* viewer, the only desktop a preview has. Exit statuses follow xdg-open(1):
|
|
700
|
+
* 1 usage, 2 missing file, 3 no viewer for the target, 4 action failed.
|
|
701
|
+
*/
|
|
702
|
+
let viewer;
|
|
703
|
+
/**
|
|
704
|
+
* Install the page viewer `xdg-open` reports to; the worker host calls this once its tunnel exists.
|
|
705
|
+
* @param next - Viewer that forwards to the page.
|
|
706
|
+
*/
|
|
707
|
+
function setTextViewer(next) {
|
|
708
|
+
viewer = next;
|
|
709
|
+
}
|
|
710
|
+
function exit(exitCode, stderr = "") {
|
|
711
|
+
return {
|
|
712
|
+
kind: "exit",
|
|
713
|
+
exitCode,
|
|
714
|
+
stdout: "",
|
|
715
|
+
stderr
|
|
716
|
+
};
|
|
717
|
+
}
|
|
718
|
+
/** Virtual executable replacing the desktop opener with the page's text viewer. */
|
|
719
|
+
const XDG_OPEN_EXECUTABLE = {
|
|
720
|
+
name: "xdg-open",
|
|
721
|
+
async prepare(args, context) {
|
|
722
|
+
if (args.length !== 1) return exit(1, "xdg-open: usage: xdg-open { file | URL }\n");
|
|
723
|
+
const path = resolve$2(context.cwd, args[0]);
|
|
724
|
+
const stats = await context.filesystem.stat(path);
|
|
725
|
+
if (stats === void 0) return exit(2, `xdg-open: file '${path}' does not exist\n`);
|
|
726
|
+
if (stats.directory) return exit(3, `xdg-open: no viewer for directory '${path}'\n`);
|
|
727
|
+
if (viewer === void 0) return exit(3, "xdg-open: no page viewer is attached\n");
|
|
728
|
+
try {
|
|
729
|
+
viewer(path, await context.filesystem.readText(path));
|
|
730
|
+
} catch (error) {
|
|
731
|
+
return exit(4, `xdg-open: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
732
|
+
}
|
|
733
|
+
return exit(0);
|
|
734
|
+
},
|
|
735
|
+
runSync() {
|
|
736
|
+
return { kind: "asynchronous" };
|
|
737
|
+
}
|
|
738
|
+
};
|
|
739
|
+
//#endregion
|
|
696
740
|
//#region src/transport/frames.ts
|
|
697
741
|
/**
|
|
698
742
|
* Validate a `postMessage` payload as a tunnel frame.
|
|
@@ -1098,6 +1142,18 @@ var TunnelServer = class {
|
|
|
1098
1142
|
this.failure = message;
|
|
1099
1143
|
for (const frame of this.queue.splice(0)) this.refuse(frame, message);
|
|
1100
1144
|
}
|
|
1145
|
+
/**
|
|
1146
|
+
* Ask the page to show one text file in its read-only viewer.
|
|
1147
|
+
* @param path - Absolute VFS path the viewer names.
|
|
1148
|
+
* @param text - File contents.
|
|
1149
|
+
*/
|
|
1150
|
+
viewText(path, text) {
|
|
1151
|
+
this.send({
|
|
1152
|
+
t: "view-text",
|
|
1153
|
+
path,
|
|
1154
|
+
text
|
|
1155
|
+
});
|
|
1156
|
+
}
|
|
1101
1157
|
send(frame, transfer) {
|
|
1102
1158
|
this.port.postMessage(frame, transfer);
|
|
1103
1159
|
}
|
|
@@ -2576,6 +2632,9 @@ function createWorkerHost(options) {
|
|
|
2576
2632
|
...options.privilegedMethods === void 0 ? {} : { privilegedMethods: options.privilegedMethods },
|
|
2577
2633
|
...options.unaryApiLane === void 0 ? {} : { unaryApiLane: options.unaryApiLane }
|
|
2578
2634
|
});
|
|
2635
|
+
setTextViewer((path, text) => {
|
|
2636
|
+
tunnel.viewText(path, text);
|
|
2637
|
+
});
|
|
2579
2638
|
let vfs;
|
|
2580
2639
|
let modules;
|
|
2581
2640
|
let context;
|
|
@@ -2636,10 +2695,11 @@ function createWorkerHost(options) {
|
|
|
2636
2695
|
const handler = connection.createSharedFetchHandler("/api");
|
|
2637
2696
|
const usage = loader.usage();
|
|
2638
2697
|
console.info(`webworker host: tree active (modules=${String(usage.modules)}, data overlays=${String(overlays.length)}, preset root overlay=${presetOverlay ? "applied" : "already in roster"}, direct lane=connection.createSharedFetchHandler, als causality=${options.alsCausality === void 0 ? "inert" : "snapshot/restore"}, image lowering=${LOWERING_VERSION})`);
|
|
2698
|
+
const peer = connection.browserPeer;
|
|
2639
2699
|
tunnel.serve({
|
|
2640
|
-
directFetch: (request) => handler.fetch(request),
|
|
2700
|
+
directFetch: (request) => handler.fetch(request, peer),
|
|
2641
2701
|
bootPayload: () => readBootPayload(ctx),
|
|
2642
|
-
openStream: (endpoint, payload, uplink, signal) => typertGateway.wireStream.open(endpoint, payload, uplink,
|
|
2702
|
+
openStream: (endpoint, payload, uplink, signal) => typertGateway.wireStream.open(endpoint, payload, uplink, peer, signal),
|
|
2643
2703
|
streamFailure: typertGateway.wireStream.failure
|
|
2644
2704
|
});
|
|
2645
2705
|
} catch (reason) {
|
|
@@ -20792,7 +20852,7 @@ const LANDLOCK_EXECUTABLE = {
|
|
|
20792
20852
|
//#endregion
|
|
20793
20853
|
//#region src/shell/process/virtual-executables.ts
|
|
20794
20854
|
/** Virtual executable registry used by the Worker process launcher. */
|
|
20795
|
-
const EXECUTABLES = new Map([[LANDLOCK_EXECUTABLE.name, LANDLOCK_EXECUTABLE]]);
|
|
20855
|
+
const EXECUTABLES = new Map([[LANDLOCK_EXECUTABLE.name, LANDLOCK_EXECUTABLE], [XDG_OPEN_EXECUTABLE.name, XDG_OPEN_EXECUTABLE]]);
|
|
20796
20856
|
/**
|
|
20797
20857
|
* Resolve a Worker platform executable by logical name.
|
|
20798
20858
|
* @param path - Bare name or executable path passed to `spawn`.
|
|
@@ -21656,12 +21716,13 @@ const createModels = notImplementedFail(MODULE$1, "createModels");
|
|
|
21656
21716
|
const getSupportedThinkingLevels = notImplementedFail(MODULE$1, "getSupportedThinkingLevels");
|
|
21657
21717
|
/** Context-overflow predicate (unavailable). */
|
|
21658
21718
|
const isContextOverflow = notImplementedFail(MODULE$1, "isContextOverflow");
|
|
21659
|
-
/**
|
|
21719
|
+
/** Preview provider ids, in catalog order. This fixed subset must use valid installed pi-ai
|
|
21720
|
+
* identifiers so the adapter can attach authentication metadata. */
|
|
21660
21721
|
const BUILTIN_PROVIDER_IDS = [
|
|
21661
21722
|
"amazon-bedrock",
|
|
21662
21723
|
"ant-ling",
|
|
21663
21724
|
"anthropic",
|
|
21664
|
-
"azure
|
|
21725
|
+
"azure",
|
|
21665
21726
|
"baseten",
|
|
21666
21727
|
"cerebras",
|
|
21667
21728
|
"cloudflare-ai-gateway",
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qilin-agent/experimental-webworker-runtime",
|
|
3
3
|
"description": "Browser-only harness runtime: in-memory VFS, module transform and loader, postMessage tunnel, and the dedicated Web Worker assembly, with the Node-compatibility layer that lets the host tree run unchanged",
|
|
4
|
-
"version": "3.1.
|
|
4
|
+
"version": "3.1.6",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -37,37 +37,37 @@
|
|
|
37
37
|
"buffer": "^6.0.3",
|
|
38
38
|
"picomatch": "^4.0.4",
|
|
39
39
|
"readable-stream": "^4.7.0",
|
|
40
|
-
"@qilin-agent/util-crypto": "3.1.
|
|
41
|
-
"@qilin-agent/client-web": "3.1.
|
|
40
|
+
"@qilin-agent/util-crypto": "3.1.6",
|
|
41
|
+
"@qilin-agent/client-web": "3.1.6"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
|
-
"@qilin-agent/
|
|
45
|
-
"@qilin-agent/
|
|
46
|
-
"@qilin-agent/
|
|
47
|
-
"@qilin-agent/
|
|
48
|
-
"@qilin-agent/
|
|
44
|
+
"@qilin-agent/client-connection": "3.1.6",
|
|
45
|
+
"@qilin-agent/host-webserver": "3.1.6",
|
|
46
|
+
"@qilin-agent/kylin": "~4.0.5",
|
|
47
|
+
"@qilin-agent/client-modules": "3.1.6",
|
|
48
|
+
"@qilin-agent/kylin-plugin-loader": "~1.0.6"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@types/picomatch": "^3.0.2",
|
|
52
52
|
"@types/readable-stream": "^4.0.24",
|
|
53
53
|
"chokidar": "^5.0.0",
|
|
54
|
-
"@qilin-agent/api-gateway": "3.1.
|
|
55
|
-
"@qilin-agent/
|
|
56
|
-
"@qilin-agent/
|
|
57
|
-
"@qilin-agent/client-
|
|
58
|
-
"@qilin-agent/
|
|
59
|
-
"@qilin-agent/
|
|
60
|
-
"@qilin-agent/kylin
|
|
61
|
-
"@qilin-agent/sandbox-local": "3.1.5",
|
|
62
|
-
"@qilin-agent/sandbox-policy": "3.1.5",
|
|
54
|
+
"@qilin-agent/api-gateway": "3.1.6",
|
|
55
|
+
"@qilin-agent/bash-sandbox": "3.1.6",
|
|
56
|
+
"@qilin-agent/client-file-upload": "3.1.6",
|
|
57
|
+
"@qilin-agent/client-connection": "3.1.6",
|
|
58
|
+
"@qilin-agent/host-webserver": "3.1.6",
|
|
59
|
+
"@qilin-agent/client-modules": "3.1.6",
|
|
60
|
+
"@qilin-agent/kylin": "~4.0.5",
|
|
63
61
|
"@qilin-agent/node-addon-system": "~0.1.2",
|
|
64
|
-
"@qilin-agent/
|
|
65
|
-
"@qilin-agent/
|
|
66
|
-
"@qilin-agent/
|
|
67
|
-
"@qilin-agent/
|
|
68
|
-
"@qilin-agent/
|
|
69
|
-
"@qilin-agent/
|
|
70
|
-
"@qilin-agent/
|
|
62
|
+
"@qilin-agent/kylin-plugin-loader": "~1.0.6",
|
|
63
|
+
"@qilin-agent/sandbox-local": "3.1.6",
|
|
64
|
+
"@qilin-agent/schedule": "3.1.6",
|
|
65
|
+
"@qilin-agent/session": "3.1.6",
|
|
66
|
+
"@qilin-agent/sandbox-policy": "3.1.6",
|
|
67
|
+
"@qilin-agent/session-projection": "3.1.6",
|
|
68
|
+
"@qilin-agent/subagent": "3.1.6",
|
|
69
|
+
"@qilin-agent/subprocess-local": "3.1.6",
|
|
70
|
+
"@qilin-agent/session-persistence-jsonl": "3.1.6"
|
|
71
71
|
},
|
|
72
72
|
"files": [
|
|
73
73
|
"lib/index.js",
|