pi-openai-toolkit 0.3.0 → 0.4.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 +24 -3
- package/README_zh.md +24 -3
- package/package.json +79 -79
- package/src/config.ts +283 -273
- package/src/debug.ts +18 -7
- package/src/extension-runtime.ts +88 -52
- package/src/native-fallback.ts +2 -21
- package/src/runtime.ts +421 -283
- package/src/supported-environment.ts +5 -0
- package/src/types.ts +18 -0
- package/tsconfig.check.json +36 -36
package/README.md
CHANGED
|
@@ -17,12 +17,24 @@
|
|
|
17
17
|
|
|
18
18
|
## Installation
|
|
19
19
|
|
|
20
|
-
### Install
|
|
20
|
+
### Install the published package globally (recommended)
|
|
21
21
|
|
|
22
22
|
```bash
|
|
23
23
|
pi install npm:pi-openai-toolkit
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
+
This adds the package to Pi's global settings. Verify the installation with:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
pi list
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
To install it only for the current project, use:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
pi install npm:pi-openai-toolkit --local
|
|
36
|
+
```
|
|
37
|
+
|
|
26
38
|
### Git installation (alternative / development)
|
|
27
39
|
|
|
28
40
|
```bash
|
|
@@ -59,6 +71,12 @@ Configuration file location:
|
|
|
59
71
|
~/.pi/agent/extensions/pi-openai-toolkit/config.json
|
|
60
72
|
```
|
|
61
73
|
|
|
74
|
+
On Windows:
|
|
75
|
+
|
|
76
|
+
```text
|
|
77
|
+
C:\Users\<user>\.pi\agent\extensions\pi-openai-toolkit\config.json
|
|
78
|
+
```
|
|
79
|
+
|
|
62
80
|
### Example `config.json`
|
|
63
81
|
|
|
64
82
|
```json
|
|
@@ -66,6 +84,7 @@ Configuration file location:
|
|
|
66
84
|
"compaction": {
|
|
67
85
|
"enabled": true,
|
|
68
86
|
"allowCompactionContinuityBreak": false,
|
|
87
|
+
"remoteCompactModel": "uwoacrimson/gpt-5.6-luna",
|
|
69
88
|
"model": null,
|
|
70
89
|
"thinkingLevel": "off",
|
|
71
90
|
"responsesApis": [
|
|
@@ -94,13 +113,14 @@ Configuration file location:
|
|
|
94
113
|
|
|
95
114
|
- `enabled` (*boolean*, default: `true`): Enable or disable Remote Compaction.
|
|
96
115
|
- `allowCompactionContinuityBreak` (*boolean*, default: `false`): When `true`, allows restarting a fresh native opaque compaction chain from Pi's current session text if the latest compaction was made by another strategy (e.g. text summary).
|
|
97
|
-
- `
|
|
116
|
+
- `remoteCompactModel` (*string | null*, default: `null`): Model formatted as `provider/model-id` used only for the synthetic `remote_compaction_v2` request. Pi's active session model is not switched and resumes normal requests after compaction. The override must resolve to the same provider, Responses API identifier, and effective base URL as the active model. `null` preserves the current same-model path.
|
|
117
|
+
- `model` (*string | null*, default: `null`): Separate native text-summary fallback model formatted as `provider/model-id` (e.g. `"openai/gpt-4o-mini"`) used if remote v2 is unavailable or fails. If `null`, Pi uses its default current-model compaction path.
|
|
98
118
|
- `thinkingLevel` (*string*, default: `"off"`): Reasoning / thinking level passed to Pi native compaction fallback (`"off"`, `"minimal"`, `"low"`, `"medium"`, `"high"`, `"xhigh"`, `"max"`).
|
|
99
119
|
- `responsesApis` (*string[]*): Narrow the supported remote compaction API identifiers (subset of `["openai-responses", "openai-codex-responses"]`).
|
|
100
120
|
- `notifyOnLoad` (*boolean*, default: `false`): Show a notification banner on Pi startup.
|
|
101
121
|
- `debug` (*boolean*, default: `false`): Output diagnostics and write execution artifacts to disk.
|
|
102
122
|
- `logProviderPayloads` / `logCompactResponses` (*boolean*, default: `false`): Write raw provider request payloads and compact SSE event bodies to artifacts.
|
|
103
|
-
- `redactSensitiveData` (*boolean*, default: `true`):
|
|
123
|
+
- `redactSensitiveData` (*boolean*, default: `true`): Apply full sensitive-value redaction to debug artifacts. Authorization credentials, API keys/tokens, and opaque `encrypted_content` are always redacted even when this option is `false`.
|
|
104
124
|
- `artifactRoot` (*string*): Directory root for diagnostic artifacts. Relative paths resolve against the config directory.
|
|
105
125
|
|
|
106
126
|
#### `webSearch`
|
|
@@ -132,6 +152,7 @@ Content-Type: application/json
|
|
|
132
152
|
```
|
|
133
153
|
|
|
134
154
|
- **Validation Criteria**: Must return a valid SSE stream with `response.completed` (status `completed`) containing exactly one output item of `type: "compaction"` with non-empty `encrypted_content`.
|
|
155
|
+
- **Remote Model Override**: `compaction.remoteCompactModel` can assign a same-gateway Responses model as the checkpoint producer while the active model remains the consumer. Its registered model metadata, authentication, headers, and effective base URL are used only for the synthetic compact request. Existing and recursive checkpoints remain replayable by the active model.
|
|
135
156
|
- **Zero Loss Replay**: The opaque encrypted item is stored in `CompactionEntry.details.compactedWindow`. On subsequent requests, it is transparently prepended after fresh preamble instructions alongside live turns, eliminating lossy text re-summaries.
|
|
136
157
|
- **Graceful Multi-Tier Fallback**:
|
|
137
158
|
1. Compatible Responses endpoints → Remote v2 Opaque Compaction.
|
package/README_zh.md
CHANGED
|
@@ -17,12 +17,24 @@
|
|
|
17
17
|
|
|
18
18
|
## 安装使用
|
|
19
19
|
|
|
20
|
-
###
|
|
20
|
+
### 全局安装已发布版本(推荐)
|
|
21
21
|
|
|
22
22
|
```bash
|
|
23
23
|
pi install npm:pi-openai-toolkit
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
+
该命令会把工具包加入 Pi 的全局配置。可以使用以下命令确认安装成功:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
pi list
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
如果只想安装到当前项目,使用:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
pi install npm:pi-openai-toolkit --local
|
|
36
|
+
```
|
|
37
|
+
|
|
26
38
|
### Git 安装(替代 / 开发路径)
|
|
27
39
|
|
|
28
40
|
```bash
|
|
@@ -59,6 +71,12 @@ pi --no-extensions -e /本地绝对路径/pi-openai-toolkit/extensions/web-searc
|
|
|
59
71
|
~/.pi/agent/extensions/pi-openai-toolkit/config.json
|
|
60
72
|
```
|
|
61
73
|
|
|
74
|
+
Windows 下对应:
|
|
75
|
+
|
|
76
|
+
```text
|
|
77
|
+
C:\Users\<user>\.pi\agent\extensions\pi-openai-toolkit\config.json
|
|
78
|
+
```
|
|
79
|
+
|
|
62
80
|
### 配置示例
|
|
63
81
|
|
|
64
82
|
```json
|
|
@@ -66,6 +84,7 @@ pi --no-extensions -e /本地绝对路径/pi-openai-toolkit/extensions/web-searc
|
|
|
66
84
|
"compaction": {
|
|
67
85
|
"enabled": true,
|
|
68
86
|
"allowCompactionContinuityBreak": false,
|
|
87
|
+
"remoteCompactModel": "uwoacrimson/gpt-5.6-luna",
|
|
69
88
|
"model": null,
|
|
70
89
|
"thinkingLevel": "off",
|
|
71
90
|
"responsesApis": [
|
|
@@ -94,13 +113,14 @@ pi --no-extensions -e /本地绝对路径/pi-openai-toolkit/extensions/web-searc
|
|
|
94
113
|
|
|
95
114
|
- `enabled` (*boolean*, 默认 `true`): 是否启用远端无损压缩。
|
|
96
115
|
- `allowCompactionContinuityBreak` (*boolean*, 默认 `false`): 若最近一次历史压缩由其他方式(如文本摘要)生成,设为 `true` 允许直接从当前有效文本上下文重建密文压缩链。
|
|
97
|
-
- `
|
|
116
|
+
- `remoteCompactModel` (*string | null*, 默认 `null`): 仅用于 synthetic `remote_compaction_v2` 请求的模型,格式为 `"provider/model-id"`。Pi 不会切换当前会话模型,压缩完成后仍由原模型继续正常请求。覆盖模型必须与当前模型使用相同的 Provider、Responses API 标识符和实际生效的 Base URL。为 `null` 时保持当前模型执行远端压缩的原有行为。
|
|
117
|
+
- `model` (*string | null*, 默认 `null`): 独立的原生文本摘要降级模型,格式为 `"provider/model-id"`(例如 `"openai/gpt-4o-mini"`)。当 Remote v2 不可用或失败时使用;为 `null` 时进入 Pi 默认的当前模型压缩路径。
|
|
98
118
|
- `thinkingLevel` (*string*, 默认 `"off"`): 降级模型调用 Pi 原生压缩时的思考级别(`"off"`, `"minimal"`, `"low"`, `"medium"`, `"high"`, `"xhigh"`, `"max"`)。
|
|
99
119
|
- `responsesApis` (*string[]*): 允许尝试远端压缩的 API 标识符子集(从 `["openai-responses", "openai-codex-responses"]` 中选定)。
|
|
100
120
|
- `notifyOnLoad` (*boolean*, 默认 `false`): Pi 启动加载时是否弹出气泡提示。
|
|
101
121
|
- `debug` (*boolean*, 默认 `false`): 是否开启调试模式并记录诊断日志。
|
|
102
122
|
- `logProviderPayloads` / `logCompactResponses` (*boolean*, 默认 `false`): 是否在 Artifacts 中记录完整的 Provider 请求与 SSE 流事件体。
|
|
103
|
-
- `redactSensitiveData` (*boolean*, 默认 `true`):
|
|
123
|
+
- `redactSensitiveData` (*boolean*, 默认 `true`): 对调试日志应用完整的敏感值脱敏。即使设为 `false`,Authorization 凭据、API Key/Token 和 `encrypted_content` 密文也始终会被替换为 `[REDACTED]`。
|
|
104
124
|
- `artifactRoot` (*string*): 诊断日志存储根目录,支持 `~/` 路径。
|
|
105
125
|
|
|
106
126
|
#### `webSearch`(联网搜索配置)
|
|
@@ -132,6 +152,7 @@ Content-Type: application/json
|
|
|
132
152
|
```
|
|
133
153
|
|
|
134
154
|
- **校验标准**:接收 SSE 流并验证 `response.completed` 事件(状态为 `completed`),且返回且仅返回一个包含非空 `encrypted_content` 密文的 `type: "compaction"` 数据块。
|
|
155
|
+
- **远端压缩模型覆盖**:`compaction.remoteCompactModel` 可以让同一网关上的另一个 Responses 模型负责生成 checkpoint,而当前活动模型仍是 checkpoint 的消费者。synthetic 压缩请求会使用覆盖模型在注册表中的模型元数据、认证、请求头和实际 Base URL;旧 checkpoint、递归压缩 checkpoint 都仍由当前活动模型重放。
|
|
135
156
|
- **无损重放机制**:密文数据完整存入 `CompactionEntry.details.compactedWindow`。在后续对话中,插件会自动将密文插入在最新的系统指令之后与最新几轮消息之前,实现完全服务端无损上下文还原。
|
|
136
157
|
- **三级优雅降级**:
|
|
137
158
|
1. 支持的 Responses 端点 → 触发 Remote v2 密文无损压缩;
|
package/package.json
CHANGED
|
@@ -1,79 +1,79 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "pi-openai-toolkit",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"private": false,
|
|
5
|
-
"type": "module",
|
|
6
|
-
"description": "OpenAI-focused Pi toolkit providing remote Responses compaction and native Web Search.",
|
|
7
|
-
"author": "awoaCrim and contributors",
|
|
8
|
-
"license": "MIT",
|
|
9
|
-
"repository": {
|
|
10
|
-
"type": "git",
|
|
11
|
-
"url": "git+https://github.com/awoaCrim/pi-openai-toolkit.git"
|
|
12
|
-
},
|
|
13
|
-
"bugs": {
|
|
14
|
-
"url": "https://github.com/awoaCrim/pi-openai-toolkit/issues"
|
|
15
|
-
},
|
|
16
|
-
"homepage": "https://github.com/awoaCrim/pi-openai-toolkit#readme",
|
|
17
|
-
"publishConfig": {
|
|
18
|
-
"access": "public",
|
|
19
|
-
"registry": "https://registry.npmjs.org/"
|
|
20
|
-
},
|
|
21
|
-
"keywords": [
|
|
22
|
-
"pi-package",
|
|
23
|
-
"pi-extension",
|
|
24
|
-
"openai",
|
|
25
|
-
"compaction",
|
|
26
|
-
"web-search",
|
|
27
|
-
"codex",
|
|
28
|
-
"responses"
|
|
29
|
-
],
|
|
30
|
-
"pi": {
|
|
31
|
-
"extensions": [
|
|
32
|
-
"./extensions/compaction.ts",
|
|
33
|
-
"./extensions/web-search.ts"
|
|
34
|
-
]
|
|
35
|
-
},
|
|
36
|
-
"files": [
|
|
37
|
-
"extensions/compaction.ts",
|
|
38
|
-
"extensions/web-search.ts",
|
|
39
|
-
"src/compact-client.ts",
|
|
40
|
-
"src/config.ts",
|
|
41
|
-
"src/debug.ts",
|
|
42
|
-
"src/details-store.ts",
|
|
43
|
-
"src/extension-runtime.ts",
|
|
44
|
-
"src/native-fallback.ts",
|
|
45
|
-
"src/payload-rewrite.ts",
|
|
46
|
-
"src/provider-headers.ts",
|
|
47
|
-
"src/remote-v2-client.ts",
|
|
48
|
-
"src/request-context-cache.ts",
|
|
49
|
-
"src/runtime.ts",
|
|
50
|
-
"src/serializer.ts",
|
|
51
|
-
"src/supported-environment.ts",
|
|
52
|
-
"src/types.ts",
|
|
53
|
-
"src/web-search/extension.ts",
|
|
54
|
-
"src/web-search/payload.ts",
|
|
55
|
-
"src/web-search/prompt.ts",
|
|
56
|
-
"src/web-search/types.ts",
|
|
57
|
-
"README.md",
|
|
58
|
-
"README_zh.md",
|
|
59
|
-
"LICENSE",
|
|
60
|
-
"NOTICE",
|
|
61
|
-
"tsconfig.check.json"
|
|
62
|
-
],
|
|
63
|
-
"scripts": {
|
|
64
|
-
"test": "bun test",
|
|
65
|
-
"test:coverage": "bun test --coverage --coverage-reporter=text --coverage-reporter=lcov && node ./scripts/check-lcov.mjs ./coverage/lcov.info",
|
|
66
|
-
"test:pi": "bun test ./test/pi-smoke.test.ts",
|
|
67
|
-
"typecheck": "tsc -p tsconfig.check.json"
|
|
68
|
-
},
|
|
69
|
-
"peerDependencies": {
|
|
70
|
-
"@earendil-works/pi-agent-core": "*",
|
|
71
|
-
"@earendil-works/pi-ai": "*",
|
|
72
|
-
"@earendil-works/pi-coding-agent": ">=0.80.0"
|
|
73
|
-
},
|
|
74
|
-
"devDependencies": {
|
|
75
|
-
"@types/node": "24.12.4",
|
|
76
|
-
"bun": "1.2.23",
|
|
77
|
-
"typescript": "5.9.3"
|
|
78
|
-
}
|
|
79
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "pi-openai-toolkit",
|
|
3
|
+
"version": "0.4.1",
|
|
4
|
+
"private": false,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"description": "OpenAI-focused Pi toolkit providing remote Responses compaction and native Web Search.",
|
|
7
|
+
"author": "awoaCrim and contributors",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/awoaCrim/pi-openai-toolkit.git"
|
|
12
|
+
},
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/awoaCrim/pi-openai-toolkit/issues"
|
|
15
|
+
},
|
|
16
|
+
"homepage": "https://github.com/awoaCrim/pi-openai-toolkit#readme",
|
|
17
|
+
"publishConfig": {
|
|
18
|
+
"access": "public",
|
|
19
|
+
"registry": "https://registry.npmjs.org/"
|
|
20
|
+
},
|
|
21
|
+
"keywords": [
|
|
22
|
+
"pi-package",
|
|
23
|
+
"pi-extension",
|
|
24
|
+
"openai",
|
|
25
|
+
"compaction",
|
|
26
|
+
"web-search",
|
|
27
|
+
"codex",
|
|
28
|
+
"responses"
|
|
29
|
+
],
|
|
30
|
+
"pi": {
|
|
31
|
+
"extensions": [
|
|
32
|
+
"./extensions/compaction.ts",
|
|
33
|
+
"./extensions/web-search.ts"
|
|
34
|
+
]
|
|
35
|
+
},
|
|
36
|
+
"files": [
|
|
37
|
+
"extensions/compaction.ts",
|
|
38
|
+
"extensions/web-search.ts",
|
|
39
|
+
"src/compact-client.ts",
|
|
40
|
+
"src/config.ts",
|
|
41
|
+
"src/debug.ts",
|
|
42
|
+
"src/details-store.ts",
|
|
43
|
+
"src/extension-runtime.ts",
|
|
44
|
+
"src/native-fallback.ts",
|
|
45
|
+
"src/payload-rewrite.ts",
|
|
46
|
+
"src/provider-headers.ts",
|
|
47
|
+
"src/remote-v2-client.ts",
|
|
48
|
+
"src/request-context-cache.ts",
|
|
49
|
+
"src/runtime.ts",
|
|
50
|
+
"src/serializer.ts",
|
|
51
|
+
"src/supported-environment.ts",
|
|
52
|
+
"src/types.ts",
|
|
53
|
+
"src/web-search/extension.ts",
|
|
54
|
+
"src/web-search/payload.ts",
|
|
55
|
+
"src/web-search/prompt.ts",
|
|
56
|
+
"src/web-search/types.ts",
|
|
57
|
+
"README.md",
|
|
58
|
+
"README_zh.md",
|
|
59
|
+
"LICENSE",
|
|
60
|
+
"NOTICE",
|
|
61
|
+
"tsconfig.check.json"
|
|
62
|
+
],
|
|
63
|
+
"scripts": {
|
|
64
|
+
"test": "bun test",
|
|
65
|
+
"test:coverage": "bun test --coverage --coverage-reporter=text --coverage-reporter=lcov && node ./scripts/check-lcov.mjs ./coverage/lcov.info",
|
|
66
|
+
"test:pi": "bun test ./test/pi-smoke.test.ts",
|
|
67
|
+
"typecheck": "tsc -p tsconfig.check.json"
|
|
68
|
+
},
|
|
69
|
+
"peerDependencies": {
|
|
70
|
+
"@earendil-works/pi-agent-core": "*",
|
|
71
|
+
"@earendil-works/pi-ai": "*",
|
|
72
|
+
"@earendil-works/pi-coding-agent": ">=0.80.0"
|
|
73
|
+
},
|
|
74
|
+
"devDependencies": {
|
|
75
|
+
"@types/node": "24.12.4",
|
|
76
|
+
"bun": "1.2.23",
|
|
77
|
+
"typescript": "5.9.3"
|
|
78
|
+
}
|
|
79
|
+
}
|