@pricening/pi-web 0.9.8 → 0.9.10
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/.next/BUILD_ID +1 -1
- package/.next/app-path-routes-manifest.json +12 -12
- package/.next/build-manifest.json +2 -2
- package/.next/prerender-manifest.json +3 -3
- package/.next/required-server-files.js +2 -2
- package/.next/required-server-files.json +2 -2
- package/.next/server/app/_global-error/page_client-reference-manifest.js +1 -1
- package/.next/server/app/_global-error.html +1 -1
- package/.next/server/app/_global-error.rsc +1 -1
- package/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
- package/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
- package/.next/server/app/_not-found.html +1 -1
- package/.next/server/app/_not-found.rsc +3 -3
- package/.next/server/app/_not-found.segments/_full.segment.rsc +3 -3
- package/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +3 -3
- package/.next/server/app/_not-found.segments/_tree.segment.rsc +2 -2
- package/.next/server/app/api/agent/[id]/events/route.js +2 -2
- package/.next/server/app/api/app-update/route.js +1 -1
- package/.next/server/app/api/auth/api-key/[provider]/route.js +1 -1
- package/.next/server/app/api/auth/login/[provider]/route.js +2 -2
- package/.next/server/app/api/auth/logout/[provider]/route.js +1 -1
- package/.next/server/app/api/auth/providers/route.js +1 -1
- package/.next/server/app/api/models/route.js +1 -1
- package/.next/server/app/api/plugins/check/route.js +1 -1
- package/.next/server/app/api/plugins/route.js +1 -1
- package/.next/server/app/api/provider-usage/query/route.js +1 -1
- package/.next/server/app/api/sessions/[id]/auto-name/route.js +4 -3
- package/.next/server/app/api/sessions/[id]/auto-name/route.js.nft.json +1 -1
- package/.next/server/app/api/sessions/[id]/route.js +1 -1
- package/.next/server/app/api/skills/install/route.js +1 -1
- package/.next/server/app/api/skills/search/route.js +1 -1
- package/.next/server/app/api/skills/update/route.js +1 -1
- package/.next/server/app/index.html +1 -1
- package/.next/server/app/index.rsc +5 -5
- package/.next/server/app/index.segments/__PAGE__.segment.rsc +5 -5
- package/.next/server/app/index.segments/_full.segment.rsc +5 -5
- package/.next/server/app/index.segments/_tree.segment.rsc +2 -2
- package/.next/server/app/login/page_client-reference-manifest.js +1 -1
- package/.next/server/app/login.html +1 -1
- package/.next/server/app/login.rsc +4 -4
- package/.next/server/app/login.segments/_full.segment.rsc +4 -4
- package/.next/server/app/login.segments/_tree.segment.rsc +2 -2
- package/.next/server/app/login.segments/login/__PAGE__.segment.rsc +4 -4
- package/.next/server/app/page.js +20 -20
- package/.next/server/app/page_client-reference-manifest.js +1 -1
- package/.next/server/app-paths-manifest.json +12 -12
- package/.next/server/chunks/2243.js +1 -1
- package/.next/server/chunks/3573.js +1 -1
- package/.next/server/chunks/4353.js +1 -0
- package/.next/server/chunks/5582.js +2 -2
- package/.next/server/chunks/6429.js +7 -5
- package/.next/server/instrumentation.js +1 -1
- package/.next/server/instrumentation.js.nft.json +1 -1
- package/.next/server/middleware-build-manifest.js +1 -1
- package/.next/server/next-font-manifest.js +1 -1
- package/.next/server/next-font-manifest.json +1 -1
- package/.next/server/pages/404.html +1 -1
- package/.next/server/pages/500.html +1 -1
- package/.next/server/server-reference-manifest.json +1 -1
- package/.next/static/chunks/1278-3bb20200f46a509d.js +1 -0
- package/.next/static/chunks/app/layout-815fddea152adfd1.js +1 -0
- package/.next/static/chunks/app/page-5d1e39cad0da02b2.js +283 -0
- package/.next/static/css/{f4a799a04a7a8a76.css → bcb1a8e544e62fd8.css} +1 -1
- package/.next/trace +40 -39
- package/.next/trace-build +1 -1
- package/README.ja.md +7 -130
- package/README.md +51 -123
- package/README.ru.md +7 -130
- package/README.zh-CN.md +51 -77
- package/bin/pi-web-node-args.js +11 -0
- package/bin/pi-web.js +3 -1
- package/next.config.ts +7 -0
- package/package.json +2 -2
- package/public/sw.js +23 -2
- package/public/sw.test.mjs +107 -1
- package/.next/server/chunks/2349.js +0 -1
- package/.next/static/chunks/1278-4e101e127edaae15.js +0 -1
- package/.next/static/chunks/app/layout-defc84c8112fb814.js +0 -1
- package/.next/static/chunks/app/page-89f22c7c0fc4ff07.js +0 -283
- /package/.next/static/{v2ujhGjLkjIUa9TUL8cVR → SW_diFgxch2hiN4O6LYY0}/_buildManifest.js +0 -0
- /package/.next/static/{v2ujhGjLkjIUa9TUL8cVR → SW_diFgxch2hiN4O6LYY0}/_ssgManifest.js +0 -0
package/README.zh-CN.md
CHANGED
|
@@ -1,57 +1,68 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @pricening/pi-web
|
|
2
2
|
|
|
3
|
-
[English](./README.md)
|
|
3
|
+
[English](./README.md)
|
|
4
4
|
|
|
5
|
-
[pi
|
|
5
|
+
这是 [agegr/pi-web](https://github.com/agegr/pi-web) 的**个人 fork**。上游是 [pi coding agent](https://github.com/earendil-works/pi) 的本地浏览器界面。
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
## 为什么要 fork
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
上游 Pi Web 本身很好,也非常活跃。这个仓库的目的是:**在跟得上上游的前提下,加上我自己要用的高级功能**,而不是等上游合并(历史上 pin / 收藏一类的会话组织 PR 都被关掉了,维护者计划另做一轮设计)。
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
| | |
|
|
12
|
+
|---|---|
|
|
13
|
+
| 上游 | [agegr/pi-web](https://github.com/agegr/pi-web)(只 fetch,不 push) |
|
|
14
|
+
| 本仓库 | [PriceNing/pi-web](https://github.com/PriceNing/pi-web) |
|
|
15
|
+
| npm 包 | **`@pricening/pi-web`**(不要装 `@agegr/pi-web`,否则补丁会被盖掉) |
|
|
16
|
+
| 上游基线 | `package.json` 的 `forkedFrom` |
|
|
12
17
|
|
|
13
|
-
|
|
14
|
-
- **两种分支方式**:**新会话**会从较早的消息创建独立会话文件;**从此处编辑**会在当前会话内创建分支。
|
|
15
|
-
- **项目文件工具**:浏览和上传文件、查看 Git Diff,并预览源码、Markdown、图片、音频、PDF 和 DOCX;文件变化后会自动刷新。
|
|
16
|
-
- **Git worktree**:从侧边栏切换 checkout,同时把同一仓库不同 worktree 的会话归在一起。
|
|
17
|
-
- **网页配置**:无需离开 Pi Web,即可管理 Provider 登录和 API Key、模型、模型测试、插件包及技能。
|
|
18
|
-
- **英文、简体中文和繁体中文界面**:Pi Web 首次打开时跟随浏览器语言,也可从顶部栏切换语言。
|
|
18
|
+
只想要官方行为,请直接用上游包。只有需要下面这些额外功能时才用本包。
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
同步、版本、发布与补丁纪律见 **[docs/FORK.md](./docs/FORK.md)**(维护规范,不是这篇 README 的重复)。
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
## 本 fork 多出来的功能
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
```
|
|
24
|
+
- **服务端置顶**(项目 / 会话)。数据在 `~/.pi/agent/pi-web/pins.json`,同一台 pi-web 服务器上的 PC / 手机 / Pad 看到的是同一份。置顶组在前,组内仍按最近活跃排。
|
|
25
|
+
- **项目归档**。侧栏里的「项目」只是会话按工作区聚出来的视图,不是 pi 里的独立对象。归档只是从侧栏藏起来,**不移动**会话文件。在 **设置 → 归档** 里取消归档,或删除这批聊天(不会删磁盘上的代码目录)。
|
|
27
26
|
|
|
28
|
-
|
|
27
|
+
其余能力与上游相同:与本地 pi CLI 共享 `~/.pi/agent`、同一套会话文件、同一套模型 / 登录 / 技能。
|
|
29
28
|
|
|
30
|
-
|
|
29
|
+
## 快速开始
|
|
31
30
|
|
|
32
|
-
|
|
31
|
+
需要 Node.js 22.19.0 或更高(`node --version`)。
|
|
33
32
|
|
|
34
33
|
```bash
|
|
35
|
-
npm install -g @
|
|
34
|
+
npm install -g @pricening/pi-web@latest --registry=https://registry.npmjs.org/
|
|
36
35
|
pi-web
|
|
37
36
|
```
|
|
38
37
|
|
|
39
|
-
|
|
38
|
+
或不装全局命令:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
npx @pricening/pi-web@latest --registry=https://registry.npmjs.org/
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
服务就绪后会尝试打开浏览器;没有打开就访问 [http://127.0.0.1:30141](http://127.0.0.1:30141)。默认只监听 `127.0.0.1`。
|
|
45
|
+
|
|
46
|
+
还没配模型时,打开 **模型(Models)** 面板登录或填 API Key。
|
|
47
|
+
|
|
48
|
+
更新:先 `Ctrl+C` 停掉再装同一条命令。卸载:`npm uninstall -g @pricening/pi-web`。
|
|
49
|
+
|
|
50
|
+
生产机请锁精确版本(Windows 用 `PI_WEB_PIN`,Linux 的 systemd 本来就不会 `npm update`)。不要每台机器都追 `@latest`,见 [docs/FORK.md §7](./docs/FORK.md)。
|
|
40
51
|
|
|
41
52
|
## 配置
|
|
42
53
|
|
|
43
|
-
|
|
54
|
+
命令行参数优先于对应环境变量。`--no-open` 或 `PI_WEB_NO_OPEN=1` 不自动开浏览器。`pi-web --help` 打印选项并退出。
|
|
44
55
|
|
|
45
|
-
| 参数或环境变量 | 用途 |
|
|
56
|
+
| 参数或环境变量 | 用途 | 默认 |
|
|
46
57
|
| --- | --- | --- |
|
|
47
58
|
| `--help`、`-h` | 打印启动选项并退出 | — |
|
|
48
|
-
| `--port
|
|
49
|
-
| `--hostname
|
|
59
|
+
| `--port` / `-p` / `PORT` | 端口 | `30141` |
|
|
60
|
+
| `--hostname` / `-H` / `PI_WEB_HOSTNAME` | 监听地址 | `127.0.0.1` |
|
|
50
61
|
| `--no-open` 或 `PI_WEB_NO_OPEN=1` | 不自动打开浏览器 | 自动打开 |
|
|
51
|
-
| `
|
|
52
|
-
| `
|
|
53
|
-
|
|
54
|
-
|
|
62
|
+
| `PI_WEB_SKIP_VERSION_CHECK=1` | 关闭更新检查 | 未设置 |
|
|
63
|
+
| `PI_WEB_ALLOWED_HOSTS` | 额外允许的主机名,逗号分隔,精确匹配 | 未设置 |
|
|
64
|
+
| `PI_WEB_PASSWORD` | 浏览器密码登录;API 可用用户名 `pi` 的 Basic Auth | 不启用 |
|
|
65
|
+
| `PI_WEB_IDLE_TIMEOUT_MS` | 会话空闲超时(毫秒);`0` 关闭 | `600000`(10 分钟) |
|
|
55
66
|
|
|
56
67
|
```bash
|
|
57
68
|
pi-web --help
|
|
@@ -60,43 +71,20 @@ pi-web -p 8080 -H 0.0.0.0 --no-open
|
|
|
60
71
|
|
|
61
72
|
### 远程访问
|
|
62
73
|
|
|
63
|
-
|
|
74
|
+
绑到非回环地址等于把可执行高权限操作的 agent 暴露出去。可信局域网请设足够长的随机密码:
|
|
64
75
|
|
|
65
76
|
```bash
|
|
66
77
|
PI_WEB_PASSWORD='足够长的随机密码' pi-web --hostname 0.0.0.0
|
|
67
78
|
```
|
|
68
79
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
### HTTP 代理
|
|
72
|
-
|
|
73
|
-
服务端的模型和 API 请求会读取标准的 `HTTP_PROXY`、`HTTPS_PROXY` 和 `NO_PROXY` 环境变量。
|
|
74
|
-
|
|
75
|
-
macOS 或 Linux:
|
|
76
|
-
|
|
77
|
-
```bash
|
|
78
|
-
HTTP_PROXY=http://127.0.0.1:7890 \
|
|
79
|
-
HTTPS_PROXY=http://127.0.0.1:7890 \
|
|
80
|
-
NO_PROXY=localhost,127.0.0.1 \
|
|
81
|
-
npx @agegr/pi-web@latest
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
Windows PowerShell:
|
|
85
|
-
|
|
86
|
-
```powershell
|
|
87
|
-
$env:HTTP_PROXY = "http://127.0.0.1:7890"
|
|
88
|
-
$env:HTTPS_PROXY = "http://127.0.0.1:7890"
|
|
89
|
-
$env:NO_PROXY = "localhost,127.0.0.1"
|
|
90
|
-
npx @agegr/pi-web@latest
|
|
91
|
-
```
|
|
80
|
+
密码认证不加密连接。不要用明文 HTTP 把 Pi Web 暴露到公网。
|
|
92
81
|
|
|
93
82
|
## 注意事项
|
|
94
83
|
|
|
95
|
-
-
|
|
96
|
-
-
|
|
97
|
-
-
|
|
98
|
-
-
|
|
99
|
-
- **Git worktree**:切换器何时显示、如何创建 worktree,以及删除会产生什么影响,见 [Pi Web 里的 Worktree](./docs/worktrees.zh-CN.md)。
|
|
84
|
+
- **智能体数据**:默认读 `~/.pi/agent`,会话在 `sessions/<编码后的工作目录>/<时间戳>_<uuid>.jsonl`。可用 `PI_CODING_AGENT_DIR` 改目录。
|
|
85
|
+
- **与本地 pi 共享**:模型、设置、凭据仍是 pi 的文件。本 fork 只在 `~/.pi/agent/pi-web/` 下写额外状态(`pins.json`、`archives.json`),不改 `settings.json` / `auth.json` / 会话 jsonl 内容。
|
|
86
|
+
- **文件访问**仅限已知的项目 / 会话根目录,不是通用文件浏览器。
|
|
87
|
+
- **Git worktree**:见 [Pi Web 里的 Worktree](./docs/worktrees.zh-CN.md)。
|
|
100
88
|
|
|
101
89
|
## 开发
|
|
102
90
|
|
|
@@ -105,7 +93,7 @@ npm install
|
|
|
105
93
|
npm run dev
|
|
106
94
|
```
|
|
107
95
|
|
|
108
|
-
|
|
96
|
+
开发服务器:[http://127.0.0.1:30141](http://127.0.0.1:30141)。检查:
|
|
109
97
|
|
|
110
98
|
```bash
|
|
111
99
|
npm test
|
|
@@ -113,24 +101,10 @@ node_modules/.bin/tsc --noEmit
|
|
|
113
101
|
npm run lint
|
|
114
102
|
```
|
|
115
103
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
贡献者文档:[国际化](./docs/i18n.md)和[发布流程](./docs/release.md)。
|
|
119
|
-
|
|
120
|
-
## 仓库结构
|
|
121
|
-
|
|
122
|
-
```text
|
|
123
|
-
app/ Next.js 界面和 API 路由
|
|
124
|
-
components/ React 界面组件
|
|
125
|
-
hooks/ 客户端状态和交互 hooks
|
|
126
|
-
lib/ 会话、智能体、模型、文件、Git 和安全逻辑
|
|
127
|
-
public/ 静态资源和 PWA 文件
|
|
128
|
-
bin/ npm CLI 入口及启动参数解析
|
|
129
|
-
docs/ 面向用户和贡献者的专题文档
|
|
130
|
-
```
|
|
104
|
+
日常开发**不要**跑 `next build` / `npm run build`(会污染 `.next/`,干扰 `npm run dev`)。构建放在 CI。
|
|
131
105
|
|
|
132
|
-
|
|
106
|
+
补丁纪律、版本与上游同步:[docs/FORK.md](./docs/FORK.md)。架构地图:[AGENTS.md](./AGENTS.md)。
|
|
133
107
|
|
|
134
108
|
## 许可证
|
|
135
109
|
|
|
136
|
-
[MIT](./LICENSE)
|
|
110
|
+
[MIT](./LICENSE),与上游相同。
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function getNextNodeArgs(nextBin, nextArgs, arch = process.arch) {
|
|
4
|
+
if (arch === "riscv64") {
|
|
5
|
+
return ["--no-wasm-lazy-compilation", nextBin, ...nextArgs];
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
return [nextBin, ...nextArgs];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
module.exports = { getNextNodeArgs };
|
package/bin/pi-web.js
CHANGED
|
@@ -18,6 +18,8 @@ const fs = require("fs");
|
|
|
18
18
|
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
19
19
|
const { getHelpText, parseLaunchOptions } = require("./pi-web-options");
|
|
20
20
|
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
21
|
+
const { getNextNodeArgs } = require("./pi-web-node-args");
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
21
23
|
const { wireChildProcessLifecycle } = require("./process-lifecycle");
|
|
22
24
|
|
|
23
25
|
let launchOptions;
|
|
@@ -81,7 +83,7 @@ nextArgs.push("-H", hostname);
|
|
|
81
83
|
|
|
82
84
|
// Always run next's JS entry with node directly — avoids .bin symlink issues
|
|
83
85
|
// and path-with-spaces problems on Windows when shell: true is used.
|
|
84
|
-
const child = spawn(process.execPath,
|
|
86
|
+
const child = spawn(process.execPath, getNextNodeArgs(nextBin, nextArgs), {
|
|
85
87
|
cwd: pkgDir,
|
|
86
88
|
stdio: ["inherit", "pipe", "inherit"],
|
|
87
89
|
env: { ...process.env, PI_WEB_HOSTNAME: hostname },
|
package/next.config.ts
CHANGED
|
@@ -13,6 +13,13 @@ try {
|
|
|
13
13
|
|
|
14
14
|
const nextConfig: NextConfig = {
|
|
15
15
|
outputFileTracingRoot: configDir,
|
|
16
|
+
experimental: {
|
|
17
|
+
// proxy.ts matches /api/:path*, and Next buffers the request body whenever
|
|
18
|
+
// a proxy is present, capped at 10 MB by default. The upload route accepts
|
|
19
|
+
// up to 100 MB per request, so raise the buffer above that or large uploads
|
|
20
|
+
// are truncated and fail with "Failed to parse body as FormData."
|
|
21
|
+
proxyClientMaxBodySize: "128mb",
|
|
22
|
+
},
|
|
16
23
|
// next/image is only used for the static logo, so the /_next/image optimizer
|
|
17
24
|
// (and its sharp/libheif attack surface, see GHSA-2xp9-vwfh-vxw4) is not needed.
|
|
18
25
|
images: { unoptimized: true },
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pricening/pi-web",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.10",
|
|
4
4
|
"description": "Web UI for the pi coding agent (fork of @agegr/pi-web with server-side pinned and archived projects)",
|
|
5
5
|
"homepage": "https://github.com/PriceNing/pi-web#readme",
|
|
6
6
|
"repository": {
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"forkedFrom": {
|
|
18
18
|
"name": "@agegr/pi-web",
|
|
19
19
|
"version": "0.9.1",
|
|
20
|
-
"commit": "
|
|
20
|
+
"commit": "1eb5e66a37c468aca7f0d338edb23de4fd84433e",
|
|
21
21
|
"url": "https://github.com/agegr/pi-web"
|
|
22
22
|
},
|
|
23
23
|
"license": "MIT",
|
package/public/sw.js
CHANGED
|
@@ -9,6 +9,11 @@ const PRECACHE_URLS = [
|
|
|
9
9
|
"/icons/icon-512.png",
|
|
10
10
|
"/icons/apple-touch-icon.png",
|
|
11
11
|
];
|
|
12
|
+
// A reachable port backed by a dead upstream accepts the connection and then
|
|
13
|
+
// never answers: fetch() neither resolves nor rejects, so the navigation hangs
|
|
14
|
+
// forever instead of falling back to offline.html. Bound every network wait.
|
|
15
|
+
const NAVIGATION_TIMEOUT_MS = 8000;
|
|
16
|
+
const ASSET_TIMEOUT_MS = 8000;
|
|
12
17
|
|
|
13
18
|
self.addEventListener("install", (event) => {
|
|
14
19
|
event.waitUntil(
|
|
@@ -46,7 +51,7 @@ self.addEventListener("fetch", (event) => {
|
|
|
46
51
|
|
|
47
52
|
if (request.mode === "navigate") {
|
|
48
53
|
event.respondWith(
|
|
49
|
-
|
|
54
|
+
fetchWithTimeout(request, NAVIGATION_TIMEOUT_MS).catch(async () => {
|
|
50
55
|
const fallback = await caches.match(OFFLINE_URL);
|
|
51
56
|
return fallback ?? Response.error();
|
|
52
57
|
}),
|
|
@@ -130,11 +135,27 @@ async function focusOrOpenWindow(targetUrl) {
|
|
|
130
135
|
await self.clients.openWindow(targetUrl);
|
|
131
136
|
}
|
|
132
137
|
|
|
138
|
+
/**
|
|
139
|
+
* Fetch with a ceiling on the wait for the response headers (time to first
|
|
140
|
+
* byte). The timer is cleared as soon as they arrive, so a response that
|
|
141
|
+
* streams a long body — Next.js streams SSR output — is never cut off
|
|
142
|
+
* mid-stream.
|
|
143
|
+
*/
|
|
144
|
+
async function fetchWithTimeout(request, timeoutMs) {
|
|
145
|
+
const controller = new AbortController();
|
|
146
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
147
|
+
try {
|
|
148
|
+
return await fetch(request, { signal: controller.signal });
|
|
149
|
+
} finally {
|
|
150
|
+
clearTimeout(timer);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
133
154
|
async function cacheFirst(request) {
|
|
134
155
|
const cached = await caches.match(request);
|
|
135
156
|
if (cached) return cached;
|
|
136
157
|
|
|
137
|
-
const response = await
|
|
158
|
+
const response = await fetchWithTimeout(request, ASSET_TIMEOUT_MS);
|
|
138
159
|
if (response.ok && response.type === "basic") {
|
|
139
160
|
const cache = await caches.open(STATIC_CACHE);
|
|
140
161
|
await cache.put(request, response.clone());
|
package/public/sw.test.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import assert from "node:assert/strict";
|
|
2
|
-
import test from "node:test";
|
|
2
|
+
import test, { mock } from "node:test";
|
|
3
3
|
|
|
4
4
|
const listeners = new Map();
|
|
5
5
|
globalThis.self = {
|
|
@@ -139,3 +139,109 @@ test("notification click opens a window and rejects cross-origin targets", async
|
|
|
139
139
|
|
|
140
140
|
assert.deepEqual(opened, ["https://pi.test/"]);
|
|
141
141
|
});
|
|
142
|
+
|
|
143
|
+
// A reachable port backed by a dead upstream answers nothing at all, so these
|
|
144
|
+
// tests drive fetch() with a stub that only settles once the worker aborts it.
|
|
145
|
+
function installOfflineStub() {
|
|
146
|
+
const offline = new Response("<!doctype html><title>Pi Web is offline</title>", {
|
|
147
|
+
status: 200,
|
|
148
|
+
headers: { "Content-Type": "text/html" },
|
|
149
|
+
});
|
|
150
|
+
globalThis.caches = {
|
|
151
|
+
match: async (request) => ((typeof request === "string" ? request : request.url).endsWith("/offline.html")
|
|
152
|
+
? offline
|
|
153
|
+
: undefined),
|
|
154
|
+
open: async () => ({ put: async () => {} }),
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function dispatchFetch(url, { mode = "cors", method = "GET" } = {}) {
|
|
159
|
+
let pending;
|
|
160
|
+
const request = new Request(url, { method });
|
|
161
|
+
Object.defineProperty(request, "mode", { value: mode });
|
|
162
|
+
listeners.get("fetch")({
|
|
163
|
+
request,
|
|
164
|
+
respondWith: (promise) => { pending = promise; },
|
|
165
|
+
});
|
|
166
|
+
return pending;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** fetch() that never settles until the signal it was handed is aborted. */
|
|
170
|
+
function installHungNetwork() {
|
|
171
|
+
let aborted = false;
|
|
172
|
+
globalThis.fetch = (_request, init) =>
|
|
173
|
+
new Promise((_resolve, reject) => {
|
|
174
|
+
init.signal.addEventListener("abort", () => {
|
|
175
|
+
aborted = true;
|
|
176
|
+
reject(new DOMException("The operation was aborted.", "AbortError"));
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
return () => aborted;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Let a handler's await chain reach its fetch (and schedule its timer) before
|
|
184
|
+
* the fake clock is ticked. setImmediate is not faked, unlike setTimeout.
|
|
185
|
+
*/
|
|
186
|
+
const flushMicrotasks = () => new Promise((resolve) => setImmediate(resolve));
|
|
187
|
+
|
|
188
|
+
test("a stalled navigation falls back to offline.html", async () => {
|
|
189
|
+
installOfflineStub();
|
|
190
|
+
const wasAborted = installHungNetwork();
|
|
191
|
+
|
|
192
|
+
mock.timers.enable({ apis: ["setTimeout"] });
|
|
193
|
+
try {
|
|
194
|
+
const pending = dispatchFetch("https://pi.test/", { mode: "navigate" });
|
|
195
|
+
await flushMicrotasks();
|
|
196
|
+
mock.timers.tick(8000);
|
|
197
|
+
const response = await pending;
|
|
198
|
+
|
|
199
|
+
assert.equal(wasAborted(), true, "a hung upstream must be aborted, not awaited forever");
|
|
200
|
+
assert.match(await response.text(), /Pi Web is offline/);
|
|
201
|
+
} finally {
|
|
202
|
+
mock.timers.reset();
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
test("a stalled static asset request is bounded as well", async () => {
|
|
207
|
+
installOfflineStub();
|
|
208
|
+
const wasAborted = installHungNetwork();
|
|
209
|
+
|
|
210
|
+
mock.timers.enable({ apis: ["setTimeout"] });
|
|
211
|
+
try {
|
|
212
|
+
const pending = dispatchFetch("https://pi.test/_next/static/chunks/app.js");
|
|
213
|
+
// cacheFirst awaits the cache lookup before it reaches the network.
|
|
214
|
+
await flushMicrotasks();
|
|
215
|
+
mock.timers.tick(8000);
|
|
216
|
+
|
|
217
|
+
assert.equal(wasAborted(), true);
|
|
218
|
+
await assert.rejects(pending, /abort/i);
|
|
219
|
+
} finally {
|
|
220
|
+
mock.timers.reset();
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
test("a response that arrives in time is not cut off mid-stream", async () => {
|
|
225
|
+
installOfflineStub();
|
|
226
|
+
let signal;
|
|
227
|
+
globalThis.fetch = async (_request, init) => {
|
|
228
|
+
signal = init.signal;
|
|
229
|
+
return new Response("<!doctype html><title>Pi Web</title>", {
|
|
230
|
+
status: 200,
|
|
231
|
+
headers: { "Content-Type": "text/html" },
|
|
232
|
+
});
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
mock.timers.enable({ apis: ["setTimeout"] });
|
|
236
|
+
try {
|
|
237
|
+
const response = await dispatchFetch("https://pi.test/", { mode: "navigate" });
|
|
238
|
+
// The budget only covers time to first byte: a long-lived body keeps
|
|
239
|
+
// streaming past it (Next.js streams its SSR payload).
|
|
240
|
+
mock.timers.tick(60000);
|
|
241
|
+
|
|
242
|
+
assert.equal(signal.aborted, false);
|
|
243
|
+
assert.match(await response.text(), /<title>Pi Web<\/title>/);
|
|
244
|
+
} finally {
|
|
245
|
+
mock.timers.reset();
|
|
246
|
+
}
|
|
247
|
+
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";exports.id=2349,exports.ids=[2349],exports.modules={42349:(a,b,c)=>{c.d(b,{configureHttpDispatcher:()=>l});var d=c(78474),e=c(9956);let f=globalThis,g=globalThis.fetch,h=()=>{};function i(a){return a instanceof d.EventEmitter&&d.EventEmitter.prototype.on.call(a,"error",h),a}function j(a,b){return i(new e.Client(a,b))}function k(a,b){return 1===b.connections?j(a,b):i(new e.Pool(a,{...b,factory:j}))}function l(a=3e5){if(f.__piWebHttpDispatcherConfigured)return;let b=function a(b){if("string"==typeof b){let c=b.trim();if("disabled"===c.toLowerCase())return 0;if(0===c.length)return;return a(Number(c))}if("number"==typeof b&&Number.isFinite(b)&&!(b<0))return Math.floor(b)}(a);if(void 0===b)throw Error(`Invalid HTTP idle timeout: ${String(a)}`);let c=i(new e.EnvHttpProxyAgent({allowH2:!1,bodyTimeout:b,headersTimeout:b,clientFactory:j,factory:k}));e.setGlobalDispatcher(c),globalThis.fetch===g&&e.install?.(),f.__piWebHttpDispatcherConfigured=!0}}};
|