@linxiraos/pi-agent-core 1.1.14 → 1.1.16
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/CHANGELOG.md +169 -26
- package/THIRD-PARTY-NOTICES.txt +54 -25
- package/dist/types/agent.d.ts +17 -4
- package/dist/types/append-only-context.d.ts +0 -4
- package/dist/types/compaction/anthropic.d.ts +108 -0
- package/dist/types/compaction/compaction-v2-streaming.d.ts +2 -2
- package/dist/types/compaction/compaction.d.ts +33 -18
- package/dist/types/compaction/entries.d.ts +2 -0
- package/dist/types/compaction/index.d.ts +1 -0
- package/dist/types/compaction/openai.d.ts +9 -8
- package/dist/types/index.d.ts +1 -0
- package/dist/types/speculative-execution.d.ts +63 -0
- package/dist/types/thinking.d.ts +1 -1
- package/dist/types/types.d.ts +212 -3
- package/package.json +10 -10
- package/src/agent-loop.ts +582 -86
- package/src/agent.ts +183 -38
- package/src/append-only-context.ts +122 -1
- package/src/compaction/anthropic.ts +310 -0
- package/src/compaction/compaction-v2-streaming.ts +4 -3
- package/src/compaction/compaction.ts +299 -131
- package/src/compaction/entries.ts +2 -0
- package/src/compaction/index.ts +1 -0
- package/src/compaction/openai.ts +17 -10
- package/src/compaction/prompts/anthropic-compaction-instructions.md +17 -0
- package/src/index.ts +2 -0
- package/src/proxy.ts +49 -8
- package/src/speculative-execution.ts +953 -0
- package/src/telemetry.ts +1 -0
- package/src/thinking.ts +1 -1
- package/src/tokenizer.ts +11 -2
- package/src/types.ts +232 -4
package/CHANGELOG.md
CHANGED
|
@@ -2,56 +2,199 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
-
## [1.1.
|
|
5
|
+
## [1.1.16] - 2026-09-19
|
|
6
6
|
|
|
7
|
-
-
|
|
7
|
+
- 上游 v18.2.5 同步:工具 schema 注入 stamp 记忆化、代理工具调用流式 JSON 解析。
|
|
8
8
|
|
|
9
|
-
## [
|
|
9
|
+
## [9.2.2] - 2026-01-31
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
### Added
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
- Added toolChoice option to AgentPromptOptions for controlling tool selection
|
|
14
14
|
|
|
15
|
-
-
|
|
15
|
+
## [8.2.0] - 2026-01-24
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
### Changed
|
|
18
18
|
|
|
19
|
-
-
|
|
19
|
+
- Updated TypeScript configuration for better publish-time configuration handling with tsconfig.publish.json
|
|
20
20
|
|
|
21
|
-
## [
|
|
21
|
+
## [8.0.0] - 2026-01-23
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
### Added
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
- Added `nonAbortable` option to tools to ignore abort signals during execution
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
## [6.8.0] - 2026-01-20
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
### Changed
|
|
30
30
|
|
|
31
|
-
-
|
|
32
|
-
- Fixed the session extension rebinding path so freshly prepared extensions bind without re-evaluating the module.
|
|
31
|
+
- Updated proxy stream processing to use utility function for reading lines
|
|
33
32
|
|
|
34
|
-
## [
|
|
33
|
+
## [6.2.0] - 2026-01-19
|
|
35
34
|
|
|
36
|
-
|
|
35
|
+
### Added
|
|
37
36
|
|
|
38
|
-
|
|
37
|
+
- Enhanced getToolContext to receive tool call batch information including batchId, index, total count, and tool call details
|
|
39
38
|
|
|
40
|
-
|
|
41
|
-
- 同步上游 OMP v18.0.9(`cc14e04f075d`)。
|
|
39
|
+
## [5.6.7] - 2026-01-18
|
|
42
40
|
|
|
43
|
-
|
|
41
|
+
### Fixed
|
|
44
42
|
|
|
45
|
-
-
|
|
43
|
+
- Added proper tool result messages for tool calls that are aborted or error out
|
|
44
|
+
- Ensured tool_use/tool_result pairing is maintained when tool execution fails
|
|
46
45
|
|
|
47
|
-
## [
|
|
46
|
+
## [4.6.0] - 2026-01-12
|
|
48
47
|
|
|
49
48
|
### Changed
|
|
50
49
|
|
|
51
|
-
-
|
|
50
|
+
- Modified assistant message handling to split messages around tool results for improved readability when using Cursor tools
|
|
51
|
+
|
|
52
|
+
### Fixed
|
|
53
|
+
|
|
54
|
+
- Fixed tool result ordering in Cursor mode by buffering results and emitting them at the correct position within assistant messages
|
|
55
|
+
|
|
56
|
+
## [4.3.0] - 2026-01-11
|
|
57
|
+
|
|
58
|
+
### Added
|
|
59
|
+
|
|
60
|
+
- Added `cursorExecHandlers` and `cursorOnToolResult` options for local tool execution with cursor-based streaming
|
|
61
|
+
- Added `emitExternalEvent` method to allow external event injection into the agent state
|
|
62
|
+
|
|
63
|
+
## [4.0.0] - 2026-01-10
|
|
64
|
+
|
|
65
|
+
### Added
|
|
66
|
+
|
|
67
|
+
- Added `popLastSteer()` and `popLastFollowUp()` methods to remove and return the last queued message (LIFO) for dequeue operations
|
|
68
|
+
- `thinkingBudgets` option on `Agent` and `AgentOptions` to customize token budgets per thinking level
|
|
69
|
+
- `sessionId` option on `Agent` to forward session identifiers to LLM providers for session-based caching
|
|
70
|
+
|
|
71
|
+
### Fixed
|
|
72
|
+
|
|
73
|
+
- `minimal` thinking level now maps to `minimal` reasoning effort instead of being treated as `low`
|
|
74
|
+
|
|
75
|
+
## [3.33.0] - 2026-01-08
|
|
76
|
+
|
|
77
|
+
### Fixed
|
|
78
|
+
|
|
79
|
+
- Ensured aborted assistant responses always include an error message for callers.
|
|
80
|
+
- Filtered thinking blocks from Cerebras request context to keep multi-turn prompts compatible.
|
|
81
|
+
|
|
82
|
+
## [3.21.0] - 2026-01-06
|
|
83
|
+
|
|
84
|
+
### Changed
|
|
85
|
+
|
|
86
|
+
- Switched from local `@linxiraos/pi-ai` to upstream `@mariozechner/pi-ai` package
|
|
87
|
+
|
|
88
|
+
### Added
|
|
89
|
+
|
|
90
|
+
- Added `sessionId` option for provider caching (e.g., OpenAI Codex session-based prompt caching)
|
|
91
|
+
- Added `sessionId` getter/setter on Agent class for runtime session switching
|
|
92
|
+
|
|
93
|
+
## [3.20.0] - 2026-01-06
|
|
94
|
+
|
|
95
|
+
### Breaking Changes
|
|
96
|
+
|
|
97
|
+
- Replaced `queueMessage`/`queueMode` with steering + follow-up queues: use `steer`, `setSteeringMode`, and `getSteeringMode` for mid-run interruptions, and `followUp`, `setFollowUpMode`, and `getFollowUpMode` for post-turn messages
|
|
98
|
+
- Agent loop callbacks now use `getSteeringMessages` and `getFollowUpMessages` instead of `getQueuedMessages`
|
|
99
|
+
|
|
100
|
+
### Added
|
|
101
|
+
|
|
102
|
+
- Added follow-up message queue support so new user messages can continue a run after the agent would otherwise stop
|
|
103
|
+
- Added `RenderResultOptions.spinnerFrame` for animated tool-result rendering
|
|
104
|
+
|
|
105
|
+
### Changed
|
|
106
|
+
|
|
107
|
+
- `prompt()` and `continue()` now throw when the agent is already streaming; use steering or follow-up queues instead
|
|
108
|
+
|
|
109
|
+
## [3.4.1337] - 2026-01-03
|
|
110
|
+
|
|
111
|
+
### Added
|
|
112
|
+
|
|
113
|
+
- Added `popMessage()` method to Agent class for removing and retrieving the last message
|
|
114
|
+
- Added abort signal checks during response streaming for faster interruption handling
|
|
115
|
+
|
|
116
|
+
### Fixed
|
|
117
|
+
|
|
118
|
+
- Fixed abort handling to properly return aborted message state when stream is interrupted mid-response
|
|
119
|
+
|
|
120
|
+
## [1.341.0] - 2026-01-03
|
|
121
|
+
|
|
122
|
+
### Added
|
|
123
|
+
|
|
124
|
+
- Added `interruptMode` option to control when queued messages interrupt tool execution.
|
|
125
|
+
- Implemented "immediate" mode (default) to check queue after each tool and interrupt remaining tools.
|
|
126
|
+
- Implemented "wait" mode to defer queue processing until the entire turn completes.
|
|
127
|
+
- Added getter and setter methods for `interruptMode` on Agent class.
|
|
128
|
+
|
|
129
|
+
## [1.337.1] - 2026-01-02
|
|
130
|
+
|
|
131
|
+
### Changed
|
|
132
|
+
|
|
133
|
+
- Forked to @oh-my-pi scope with unified versioning across all packages
|
|
134
|
+
|
|
135
|
+
## [1.337.0] - 2026-01-02
|
|
136
|
+
|
|
137
|
+
Initial release under @oh-my-pi scope. See previous releases at [badlogic/pi-mono](https://github.com/badlogic/pi-mono).
|
|
138
|
+
|
|
139
|
+
## [0.38.0] - 2026-01-08
|
|
140
|
+
|
|
141
|
+
### Added
|
|
142
|
+
|
|
143
|
+
- `thinkingBudgets` option on `Agent` and `AgentOptions` to customize token budgets per thinking level ([#529](https://github.com/badlogic/pi-mono/pull/529) by [@melihmucuk](https://github.com/melihmucuk))
|
|
144
|
+
|
|
145
|
+
## [0.37.3] - 2026-01-06
|
|
146
|
+
|
|
147
|
+
### Added
|
|
148
|
+
|
|
149
|
+
- `sessionId` option on `Agent` to forward session identifiers to LLM providers for session-based caching.
|
|
150
|
+
|
|
151
|
+
## [0.37.0] - 2026-01-05
|
|
152
|
+
|
|
153
|
+
### Fixed
|
|
154
|
+
|
|
155
|
+
- `minimal` thinking level now maps to `minimal` reasoning effort instead of being treated as `low`.
|
|
156
|
+
|
|
157
|
+
## [0.32.0] - 2026-01-03
|
|
158
|
+
|
|
159
|
+
### Breaking Changes
|
|
160
|
+
|
|
161
|
+
- **Queue API replaced with steer/followUp**: The `queueMessage()` method has been split into two methods with different delivery semantics ([#403](https://github.com/badlogic/pi-mono/issues/403)):
|
|
162
|
+
- `steer(msg)`: Interrupts the agent mid-run. Delivered after current tool execution, skips remaining tools.
|
|
163
|
+
- `followUp(msg)`: Waits until the agent finishes. Delivered only when there are no more tool calls or steering messages.
|
|
164
|
+
- **Queue mode renamed**: `queueMode` option renamed to `steeringMode`. Added new `followUpMode` option. Both control whether messages are delivered one-at-a-time or all at once.
|
|
165
|
+
- **AgentLoopConfig callbacks renamed**: `getQueuedMessages` split into `getSteeringMessages` and `getFollowUpMessages`.
|
|
166
|
+
- **Agent methods renamed**:
|
|
167
|
+
- `queueMessage()` → `steer()` and `followUp()`
|
|
168
|
+
- `clearMessageQueue()` → `clearSteeringQueue()`, `clearFollowUpQueue()`, `clearAllQueues()`
|
|
169
|
+
- `setQueueMode()`/`getQueueMode()` → `setSteeringMode()`/`getSteeringMode()` and `setFollowUpMode()`/`getFollowUpMode()`
|
|
170
|
+
|
|
171
|
+
### Fixed
|
|
172
|
+
|
|
173
|
+
- `prompt()` and `continue()` now throw if called while the agent is already streaming, preventing race conditions and corrupted state. Use `steer()` or `followUp()` to queue messages during streaming, or `await` the previous call.
|
|
174
|
+
|
|
175
|
+
## [0.31.0] - 2026-01-02
|
|
176
|
+
|
|
177
|
+
### Breaking Changes
|
|
178
|
+
|
|
179
|
+
- **Transport abstraction removed**: `ProviderTransport`, `AppTransport`, and `AgentTransport` interface have been removed. Use the `streamFn` option directly for custom streaming implementations.
|
|
180
|
+
- **Agent options renamed**:
|
|
181
|
+
- `transport` → removed (use `streamFn` instead)
|
|
182
|
+
- `messageTransformer` → `convertToLlm`
|
|
183
|
+
- `preprocessor` → `transformContext`
|
|
184
|
+
- **`AppMessage` renamed to `AgentMessage`**: All references to `AppMessage` have been renamed to `AgentMessage` for consistency.
|
|
185
|
+
- **`CustomMessages` renamed to `CustomAgentMessages`**: The declaration merging interface has been renamed.
|
|
186
|
+
- **`UserMessageWithAttachments` and `Attachment` types removed**: Attachment handling is now the responsibility of the `convertToLlm` function.
|
|
187
|
+
- **Agent loop moved from `@linxiraos/pi-ai`**: The `agentLoop`, `agentLoopContinue`, and related types have moved to this package. Import from `@linxiraos/pi-agent` instead.
|
|
188
|
+
|
|
189
|
+
### Added
|
|
52
190
|
|
|
53
|
-
|
|
191
|
+
- `streamFn` option on `Agent` for custom stream implementations. Default uses `streamSimple` from pi-ai.
|
|
192
|
+
- `streamProxy()` utility function for browser apps that need to proxy LLM calls through a backend server. Replaces the removed `AppTransport`.
|
|
193
|
+
- `getApiKey` option for dynamic API key resolution (useful for expiring OAuth tokens like GitHub Copilot).
|
|
194
|
+
- `agentLoop()` and `agentLoopContinue()` low-level functions for running the agent loop without the `Agent` class wrapper.
|
|
195
|
+
- New exported types: `AgentLoopConfig`, `AgentContext`, `AgentTool`, `AgentToolResult`, `AgentToolUpdateCallback`, `StreamFn`.
|
|
54
196
|
|
|
55
197
|
### Changed
|
|
56
198
|
|
|
57
|
-
-
|
|
199
|
+
- `Agent` constructor now has all options optional (empty options use defaults).
|
|
200
|
+
- `queueMessage()` is now synchronous (no longer returns a Promise).
|
package/THIRD-PARTY-NOTICES.txt
CHANGED
|
@@ -10843,7 +10843,7 @@ RUST RUNTIME DEPENDENCY LICENSES
|
|
|
10843
10843
|
|
|
10844
10844
|
Generated from Cargo.lock by cargo-about 0.8.2 in locked, offline, workspace, all-feature, all-target mode, then restricted using cargo metadata to normal and build edges reachable from the workspace (development-only edges are excluded). cargo-deny independently evaluates the complete all-target graph.
|
|
10845
10845
|
|
|
10846
|
-
Native Opus (
|
|
10846
|
+
Native Opus (opus/opusic-sys) and PCRE2 (pcre2/pcre2-sys) are covered by the exact crate license payloads below. inferno 0.12.8 is package-scoped as CDDL-1.0: its CDDL-covered source remains available in the locked crates.io source archive at https://crates.io/crates/inferno/0.12.8 and https://github.com/jonhoo/inferno. The full locked license text follows below.
|
|
10847
10847
|
|
|
10848
10848
|
-------------------------------------------------------------------------------
|
|
10849
10849
|
License: Apache License 2.0 (Apache-2.0)
|
|
@@ -12509,6 +12509,58 @@ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
|
12509
12509
|
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
12510
12510
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
12511
12511
|
|
|
12512
|
+
-------------------------------------------------------------------------------
|
|
12513
|
+
License: BSD 3-Clause "New" or "Revised" License (BSD-3-Clause)
|
|
12514
|
+
Used by:
|
|
12515
|
+
- opusic-sys 0.7.5 (https://github.com/DoumanAsh/opusic-sys)
|
|
12516
|
+
|
|
12517
|
+
Full license text:
|
|
12518
|
+
|
|
12519
|
+
Copyright 2001-2023 Xiph.Org, Skype Limited, Octasic,
|
|
12520
|
+
Jean-Marc Valin, Timothy B. Terriberry,
|
|
12521
|
+
CSIRO, Gregory Maxwell, Mark Borgerding,
|
|
12522
|
+
Erik de Castro Lopo, Mozilla, Amazon
|
|
12523
|
+
|
|
12524
|
+
Redistribution and use in source and binary forms, with or without
|
|
12525
|
+
modification, are permitted provided that the following conditions
|
|
12526
|
+
are met:
|
|
12527
|
+
|
|
12528
|
+
- Redistributions of source code must retain the above copyright
|
|
12529
|
+
notice, this list of conditions and the following disclaimer.
|
|
12530
|
+
|
|
12531
|
+
- Redistributions in binary form must reproduce the above copyright
|
|
12532
|
+
notice, this list of conditions and the following disclaimer in the
|
|
12533
|
+
documentation and/or other materials provided with the distribution.
|
|
12534
|
+
|
|
12535
|
+
- Neither the name of Internet Society, IETF or IETF Trust, nor the
|
|
12536
|
+
names of specific contributors, may be used to endorse or promote
|
|
12537
|
+
products derived from this software without specific prior written
|
|
12538
|
+
permission.
|
|
12539
|
+
|
|
12540
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
12541
|
+
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
12542
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
12543
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
|
12544
|
+
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
12545
|
+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
12546
|
+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
12547
|
+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
12548
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
12549
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
12550
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
12551
|
+
|
|
12552
|
+
Opus is subject to the royalty-free patent licenses which are
|
|
12553
|
+
specified at:
|
|
12554
|
+
|
|
12555
|
+
Xiph.Org Foundation:
|
|
12556
|
+
https://datatracker.ietf.org/ipr/1524/
|
|
12557
|
+
|
|
12558
|
+
Microsoft Corporation:
|
|
12559
|
+
https://datatracker.ietf.org/ipr/1914/
|
|
12560
|
+
|
|
12561
|
+
Broadcom Corporation:
|
|
12562
|
+
https://datatracker.ietf.org/ipr/1526/
|
|
12563
|
+
|
|
12512
12564
|
-------------------------------------------------------------------------------
|
|
12513
12565
|
License: BSD 3-Clause "New" or "Revised" License (BSD-3-Clause)
|
|
12514
12566
|
Used by:
|
|
@@ -13290,29 +13342,6 @@ jurisdiction of the Federal Courts of the Northern District of
|
|
|
13290
13342
|
California and the state courts of the State of California, with
|
|
13291
13343
|
venue lying in Santa Clara County, California.
|
|
13292
13344
|
|
|
13293
|
-
-------------------------------------------------------------------------------
|
|
13294
|
-
License: ISC License (ISC)
|
|
13295
|
-
Used by:
|
|
13296
|
-
- audiopus_sys 0.2.2 (https://github.com/lakelezz/audiopus_sys.git)
|
|
13297
|
-
|
|
13298
|
-
Full license text:
|
|
13299
|
-
|
|
13300
|
-
ISC License
|
|
13301
|
-
|
|
13302
|
-
Copyright (c) 2019, Lakelezz
|
|
13303
|
-
|
|
13304
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
13305
|
-
purpose with or without fee is hereby granted, provided that the above
|
|
13306
|
-
copyright notice and this permission notice appear in all copies.
|
|
13307
|
-
|
|
13308
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
13309
|
-
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
13310
|
-
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
13311
|
-
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
13312
|
-
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
13313
|
-
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
13314
|
-
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
13315
|
-
|
|
13316
13345
|
-------------------------------------------------------------------------------
|
|
13317
13346
|
License: ISC License (ISC)
|
|
13318
13347
|
Used by:
|
|
@@ -18734,7 +18763,7 @@ DEALINGS IN THE SOFTWARE.
|
|
|
18734
18763
|
-------------------------------------------------------------------------------
|
|
18735
18764
|
License: MIT License (MIT)
|
|
18736
18765
|
Used by:
|
|
18737
|
-
- opus 0.
|
|
18766
|
+
- opus 0.4.0 (https://github.com/SpaceManiac/opus-rs)
|
|
18738
18767
|
|
|
18739
18768
|
Full license text:
|
|
18740
18769
|
|
package/dist/types/agent.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { type ApiKey, type AssistantMessage, type AssistantMessageEvent, type Context, type CursorExecHandlers, type CursorToolResultHandler, type Effort, type ImageContent, type Message, type Model, type ProviderSessionState, type ServiceTier, type SimpleStreamOptions, type ThinkingBudgets, type ToolChoice } from "@linxiraos/pi-ai";
|
|
1
|
+
import { type ApiKey, type AssistantMessage, type AssistantMessageEvent, type Context, type CursorExecHandlers, type CursorToolResultHandler, type Effort, type ImageContent, type Message, type Model, type ProviderSessionState, type ServiceTier, type SimpleStreamOptions, type ThinkingBudgets, type ToolChoice, type ToolResultMessage } from "@linxiraos/pi-ai";
|
|
2
2
|
import type { Dialect } from "@linxiraos/pi-ai/dialect";
|
|
3
3
|
import type { HarmonyAuditEvent } from "@linxiraos/pi-ai/utils/harmony-leak";
|
|
4
4
|
import type { AppendOnlyContextManager } from "./append-only-context.js";
|
|
5
5
|
import { Tokenizer } from "./tokenizer.js";
|
|
6
|
-
import type { AgentBeforeModelCall, AgentEvent, AgentLoopConfig, AgentMessage, AgentState, AgentTool, AgentToolContext, AgentTurnEndContext, AsideMessage, StreamFn, ToolCallContext, ToolChoiceDirective } from "./types.js";
|
|
6
|
+
import type { AgentBeforeModelCall, AgentEvent, AgentLoopConfig, AgentMessage, AgentState, AgentTool, AgentToolContext, AgentTurnEndContext, AsideMessage, PrepareQueuedMessages, SpeculativeToolExecutionConfig, StreamFn, ToolCallContext, ToolChoiceDirective } from "./types.js";
|
|
7
7
|
export declare class AgentBusyError extends Error {
|
|
8
8
|
constructor(message?: string);
|
|
9
9
|
}
|
|
@@ -135,12 +135,20 @@ export interface AgentOptions {
|
|
|
135
135
|
* Use for deobfuscating secrets or rewriting arguments.
|
|
136
136
|
*/
|
|
137
137
|
transformToolCallArguments?: (args: Record<string, unknown>, toolName: string) => Record<string, unknown>;
|
|
138
|
+
/** Host authorization and telemetry for opt-in speculative tool execution. */
|
|
139
|
+
speculativeToolExecution?: SpeculativeToolExecutionConfig;
|
|
138
140
|
/**
|
|
139
141
|
* Resolve a tool call whose name matched no advertised tool. Lets hosts
|
|
140
142
|
* route calls to tools exposed through side transports (e.g. `xd://`
|
|
141
143
|
* device mounts) instead of failing with "Tool not found".
|
|
142
144
|
*/
|
|
143
|
-
resolveFallbackTool?: (name: string) => AgentTool<any> | undefined;
|
|
145
|
+
resolveFallbackTool?: (name: string, advertised: readonly AgentTool<any>[]) => AgentTool<any> | undefined;
|
|
146
|
+
/**
|
|
147
|
+
* Names routable by {@link resolveFallbackTool} that the advertised set
|
|
148
|
+
* omits (e.g. `xd://` device mounts), used only to suggest a target when a
|
|
149
|
+
* call misses.
|
|
150
|
+
*/
|
|
151
|
+
suggestFallbackToolNames?: () => Iterable<string>;
|
|
144
152
|
/** Enable intent tracing schema injection/stripping in the harness. */
|
|
145
153
|
intentTracing?: boolean;
|
|
146
154
|
/**
|
|
@@ -227,6 +235,8 @@ export declare class Agent {
|
|
|
227
235
|
#private;
|
|
228
236
|
streamFn: StreamFn;
|
|
229
237
|
getApiKey?: (model: Model) => Promise<ApiKey | undefined> | ApiKey | undefined;
|
|
238
|
+
/** Prepare actual queue deliveries after dequeue gates; commit runs only while ownership remains valid. */
|
|
239
|
+
prepareQueuedMessages?: PrepareQueuedMessages;
|
|
230
240
|
/**
|
|
231
241
|
* Hook invoked after tool arguments are validated and before execution.
|
|
232
242
|
* Reassign at any time to swap the implementation (e.g. on extension reload).
|
|
@@ -444,11 +454,14 @@ export declare class Agent {
|
|
|
444
454
|
/** Non-consuming view of the pending steering queue (insertion order, newest
|
|
445
455
|
* last). The session layer derives its queued-message display/count from
|
|
446
456
|
* this live view instead of a mirror, so the agent-core queue stays the
|
|
447
|
-
* single source of truth.
|
|
457
|
+
* single source of truth. Includes exclusively claimed originals while
|
|
458
|
+
* preparation is pending, so editor restoration can cancel their delivery. */
|
|
448
459
|
peekSteeringQueue(): readonly AgentMessage[];
|
|
449
460
|
/** Non-consuming view of the pending follow-up queue. See
|
|
450
461
|
* {@link peekSteeringQueue}. */
|
|
451
462
|
peekFollowUpQueue(): readonly AgentMessage[];
|
|
463
|
+
/** Nonblocking snapshot of the latest results, including provisional payloads while transforms are pending. */
|
|
464
|
+
getPendingToolResults(): readonly ToolResultMessage[];
|
|
452
465
|
get isAborting(): boolean;
|
|
453
466
|
/**
|
|
454
467
|
* Remove and return the last steering message from the queue (LIFO).
|
|
@@ -41,10 +41,6 @@ export declare class StablePrefix {
|
|
|
41
41
|
get fingerprint(): string;
|
|
42
42
|
get version(): number;
|
|
43
43
|
get built(): boolean;
|
|
44
|
-
/**
|
|
45
|
-
* Build or rebuild from live context.
|
|
46
|
-
* Returns `true` if the prefix actually changed (cache miss imminent).
|
|
47
|
-
*/
|
|
48
44
|
build(context: AgentContext, options: BuildOptions): boolean;
|
|
49
45
|
/** Force rebuild on the next `build()` call. */
|
|
50
46
|
invalidate(): void;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Anthropic server-side compaction (`compact-2026-01-12` beta).
|
|
3
|
+
*
|
|
4
|
+
* The compaction request is the live turn's own request shape — same system
|
|
5
|
+
* prompt, tools, and message history — plus the `compact_20260112` edit with
|
|
6
|
+
* `pause_after_compaction`. The API summarizes the prompt from the already
|
|
7
|
+
* cached prefix and stops; the summary arrives as a `compaction` block that
|
|
8
|
+
* the provider surfaces as an `anthropicCompaction` payload. The summary is
|
|
9
|
+
* plain text, so it doubles as the compaction entry's readable summary for
|
|
10
|
+
* every other provider, while the Anthropic provider replays it as a native
|
|
11
|
+
* block (the API drops everything that precedes it). The retained tail after
|
|
12
|
+
* the cut point is replayed from session entries exactly like a local summary.
|
|
13
|
+
*/
|
|
14
|
+
import type { AnthropicCompactionPayload, ApiKey, Effort, Message, Model, SimpleStreamOptions, Tool, Usage } from "@linxiraos/pi-ai";
|
|
15
|
+
import { type InstrumentedChatSpanOptions } from "../telemetry.js";
|
|
16
|
+
export declare const ANTHROPIC_COMPACTION_PRESERVE_KEY = "anthropicCompaction";
|
|
17
|
+
/** The API rejects a `compact_20260112` trigger below this many input tokens. */
|
|
18
|
+
export declare const ANTHROPIC_COMPACTION_MIN_TRIGGER_TOKENS = 50000;
|
|
19
|
+
/**
|
|
20
|
+
* Smallest context the native lane accepts. The trigger sits at the API
|
|
21
|
+
* floor, so a prompt that lands below it is answered instead of compacted;
|
|
22
|
+
* the margin over the floor absorbs the difference between the last reported
|
|
23
|
+
* context size and the compaction request's own input.
|
|
24
|
+
*/
|
|
25
|
+
export declare const ANTHROPIC_COMPACTION_MIN_CONTEXT_TOKENS = 55000;
|
|
26
|
+
/** Summary persisted under {@link ANTHROPIC_COMPACTION_PRESERVE_KEY}. */
|
|
27
|
+
export interface AnthropicCompactionPreserveData {
|
|
28
|
+
provider: string;
|
|
29
|
+
content: string;
|
|
30
|
+
/** Opaque provider state the API attached to the block; replayed verbatim. */
|
|
31
|
+
encryptedContent?: string;
|
|
32
|
+
/** Harness file metadata (`<files>` section) replayed after the native block. */
|
|
33
|
+
filesText?: string;
|
|
34
|
+
/** Model that wrote the summary. */
|
|
35
|
+
model?: string;
|
|
36
|
+
/** Prompt tokens the compaction request processed, for display. */
|
|
37
|
+
usedTokens?: number;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Whether a model compacts through the Anthropic compaction beta. Model
|
|
41
|
+
* eligibility is catalog policy (`compat.supportsServerCompaction`, the
|
|
42
|
+
* lineage the beta documents); endpoint eligibility is resolved the way the
|
|
43
|
+
* provider routes requests, so a Foundry or `ANTHROPIC_BASE_URL` reroute of a
|
|
44
|
+
* first-party model is excluded unless the route opted in with
|
|
45
|
+
* `remoteCompaction.enabled`.
|
|
46
|
+
*/
|
|
47
|
+
export declare function shouldUseAnthropicNativeCompaction(model: Model): model is Model<"anthropic-messages">;
|
|
48
|
+
export declare function getPreservedAnthropicCompactionData(preserveData: Record<string, unknown> | undefined): AnthropicCompactionPreserveData | undefined;
|
|
49
|
+
/** Set or strip the Anthropic compaction slot; a new compaction never inherits a stale summary. */
|
|
50
|
+
export declare function withAnthropicCompactionPreserveData(preserveData: Record<string, unknown> | undefined, compaction: AnthropicCompactionPreserveData | undefined): Record<string, unknown> | undefined;
|
|
51
|
+
/** Replay payload for a compaction summary the active model produced natively. */
|
|
52
|
+
export declare function getAnthropicCompactionPayload(preserveData: Record<string, unknown> | undefined): AnthropicCompactionPayload | undefined;
|
|
53
|
+
/**
|
|
54
|
+
* The retained tail as the model will see it, for the summarization
|
|
55
|
+
* instructions: how many of the conversation's final wire messages stay in
|
|
56
|
+
* context verbatim, and the role of the first. The compaction request carries
|
|
57
|
+
* the whole conversation so the prompt cache the live turn wrote is read, but
|
|
58
|
+
* the summary must cover only the history before that tail — the local
|
|
59
|
+
* summarizer never sees the tail, and the rebuilt context replays it after the
|
|
60
|
+
* summary. Counting mirrors the provider's message conversion (consecutive
|
|
61
|
+
* tool results collapse into one user message; developer messages are user
|
|
62
|
+
* messages). Structured for the prompt template, which renders the
|
|
63
|
+
* singular/plural wording; the description quotes no content: quoting the
|
|
64
|
+
* tail would hand the summarizer the very facts it must leave to the tail.
|
|
65
|
+
*/
|
|
66
|
+
export interface RetainedTailScope {
|
|
67
|
+
count: number;
|
|
68
|
+
role: "assistant" | "user";
|
|
69
|
+
}
|
|
70
|
+
export declare function describeRetainedTail(messages: readonly Message[]): RetainedTailScope | undefined;
|
|
71
|
+
/**
|
|
72
|
+
* Summarization prompt sent as the edit's `instructions`, which replace the
|
|
73
|
+
* API default entirely. The template lays out the retained-tail boundary
|
|
74
|
+
* first, so the summary covers only the history the rebuilt context drops,
|
|
75
|
+
* then the caller's extra context, the same structure prompt as the local
|
|
76
|
+
* summarizer, the caller's focus, and the tool-abstention clause the API
|
|
77
|
+
* recommends when tools are defined (a summarization pass that calls a tool
|
|
78
|
+
* yields no summary).
|
|
79
|
+
*/
|
|
80
|
+
export declare function buildAnthropicCompactionInstructions(basePrompt: string, customInstructions: string | undefined, extraContext: string | undefined, retainedTail: RetainedTailScope | undefined): string;
|
|
81
|
+
export interface AnthropicNativeCompactionRequest {
|
|
82
|
+
systemPrompt: string[];
|
|
83
|
+
messages: Message[];
|
|
84
|
+
tools?: Tool[];
|
|
85
|
+
instructions: string;
|
|
86
|
+
maxTokens: number;
|
|
87
|
+
reasoning?: Effort;
|
|
88
|
+
}
|
|
89
|
+
export interface AnthropicNativeCompactionResponse {
|
|
90
|
+
content: string;
|
|
91
|
+
encryptedContent?: string;
|
|
92
|
+
usage: Usage;
|
|
93
|
+
model: string;
|
|
94
|
+
}
|
|
95
|
+
export interface AnthropicNativeCompactionOptions extends Pick<SimpleStreamOptions, "initiatorOverride" | "metadata" | "fetch" | "sessionId" | "promptCacheKey" | "providerSessionState" | "maxInFlightRequests">, Pick<InstrumentedChatSpanOptions, "completeImpl" | "telemetry" | "retry"> {
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Run one compaction request and return the summary the API wrote, with the
|
|
99
|
+
* opaque `encrypted_content` the API attached for the replay. `completeSimple`
|
|
100
|
+
* resolves terminal failures as messages, so their classification is restored
|
|
101
|
+
* here: an aborted response is an `AbortError` (a cancellation, never a native
|
|
102
|
+
* failure) and an error response keeps its HTTP status, so auth and timeout
|
|
103
|
+
* handling downstream classify it the same way as the OpenAI lanes. A response
|
|
104
|
+
* without a summary is a native failure — the API answers the prompt instead
|
|
105
|
+
* when its input never reached the trigger, and returns an empty block when
|
|
106
|
+
* the model called a tool during summarization.
|
|
107
|
+
*/
|
|
108
|
+
export declare function requestAnthropicNativeCompaction(model: Model<"anthropic-messages">, apiKey: ApiKey, request: AnthropicNativeCompactionRequest, signal: AbortSignal | undefined, options: AnthropicNativeCompactionOptions): Promise<AnthropicNativeCompactionResponse>;
|
|
@@ -12,8 +12,8 @@ import { type OpenAICodexCompactionBody } from "@linxiraos/pi-ai/providers/opena
|
|
|
12
12
|
export declare const V2_RETAINED_MESSAGE_TOKEN_BUDGET = 64000;
|
|
13
13
|
/** Max retries for V2 streaming compaction on transient stream errors. */
|
|
14
14
|
export declare const V2_COMPACTION_MAX_RETRIES = 2;
|
|
15
|
-
/** Timeout for V2 streaming compaction (
|
|
16
|
-
export declare const V2_COMPACTION_TIMEOUT_MS =
|
|
15
|
+
/** Timeout for V2 streaming compaction (5 minutes, same as V1). */
|
|
16
|
+
export declare const V2_COMPACTION_TIMEOUT_MS = 300000;
|
|
17
17
|
/** Token usage reported by the streamed V2 Responses completion. */
|
|
18
18
|
export interface CompactionV2Usage {
|
|
19
19
|
inputTokens: number;
|
|
@@ -65,7 +65,11 @@ export declare const DEFAULT_RESERVE_TOKENS = 16384;
|
|
|
65
65
|
*/
|
|
66
66
|
export declare const MAX_SUMMARY_TOKENS = 16384;
|
|
67
67
|
export declare const DEFAULT_COMPACTION_SETTINGS: CompactionSettings;
|
|
68
|
-
/**
|
|
68
|
+
/**
|
|
69
|
+
* Whether a compaction candidate preserves provider-native transport under the
|
|
70
|
+
* effective settings: an OpenAI Responses compact route (V1 or streamed V2) or
|
|
71
|
+
* the Anthropic compaction beta.
|
|
72
|
+
*/
|
|
69
73
|
export declare function shouldUseProviderNativeCompaction(model: Model, settings: Pick<CompactionSettings, "remoteEnabled" | "remoteStreamingV2Enabled">): boolean;
|
|
70
74
|
/**
|
|
71
75
|
* Calculate total context tokens from usage.
|
|
@@ -120,6 +124,13 @@ export declare function shouldCompact(contextTokens: number, contextWindow: numb
|
|
|
120
124
|
*/
|
|
121
125
|
export declare function compactionContextTokens(providerContextTokens: number, storedConversationEstimate: number): number;
|
|
122
126
|
export declare function resolveThresholdTokens(contextWindow: number, settings: CompactionSettings): number;
|
|
127
|
+
/**
|
|
128
|
+
* True for entries that begin a conversational turn (a user request, a
|
|
129
|
+
* bash-execution card, a branch summary, or a custom user-role message).
|
|
130
|
+
* Compaction cut alignment, turn discovery, and the collapsed display
|
|
131
|
+
* transcript's orphan-head trim all share this boundary definition.
|
|
132
|
+
*/
|
|
133
|
+
export declare function isTurnStartEntry(entry: SessionEntry): boolean;
|
|
123
134
|
/**
|
|
124
135
|
* Find the user message (or bashExecution) that starts the turn containing the given entry index.
|
|
125
136
|
* Returns -1 if no turn start found before the index.
|
|
@@ -135,10 +146,11 @@ export interface CutPointResult {
|
|
|
135
146
|
isSplitTurn: boolean;
|
|
136
147
|
}
|
|
137
148
|
/**
|
|
138
|
-
* Find the
|
|
149
|
+
* Find the oldest complete recent-history suffix that fits `keepRecentTokens`.
|
|
139
150
|
*
|
|
140
|
-
*
|
|
141
|
-
*
|
|
151
|
+
* Walk backwards by valid cut points, measuring whole assistant/tool groups.
|
|
152
|
+
* Keep the newest group even when it alone exceeds the budget; never retain
|
|
153
|
+
* an additional older group that would push an otherwise fitting suffix over.
|
|
142
154
|
*
|
|
143
155
|
* Can cut at user OR assistant messages (never tool results). When cutting at an
|
|
144
156
|
* assistant message with tool calls, its tool results come after and will be kept.
|
|
@@ -290,6 +302,8 @@ export interface CompactionPreparation {
|
|
|
290
302
|
tokensBefore: number;
|
|
291
303
|
/** Summary from previous compaction, for iterative update */
|
|
292
304
|
previousSummary?: string;
|
|
305
|
+
/** ISO timestamp of the previous compaction entry, for iterative update */
|
|
306
|
+
previousSummaryTimestamp?: string;
|
|
293
307
|
/** Preserved opaque compaction payload from the previous compaction, if any. */
|
|
294
308
|
previousPreserveData?: Record<string, unknown>;
|
|
295
309
|
/** File operations extracted from messagesToSummarize */
|
|
@@ -298,24 +312,25 @@ export interface CompactionPreparation {
|
|
|
298
312
|
settings: CompactionSettings;
|
|
299
313
|
}
|
|
300
314
|
/**
|
|
301
|
-
* Whether
|
|
302
|
-
*
|
|
303
|
-
*
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
*
|
|
308
|
-
*
|
|
315
|
+
* Whether the active model's normal encoder can consume stored native history.
|
|
316
|
+
* Creating future compactions is a separate policy: disabling it does not disable
|
|
317
|
+
* Responses-family replay. Local summaries have no provider restriction.
|
|
318
|
+
*/
|
|
319
|
+
export declare function canReplayRemoteCompaction(preserveData: Record<string, unknown> | undefined, activeModel: Model): boolean;
|
|
320
|
+
/**
|
|
321
|
+
* Whether compaction preparation may reuse a native boundary instead of
|
|
322
|
+
* re-expanding its original messages. This is deliberately stricter than normal
|
|
323
|
+
* replay: the active model must both read the payload and remain eligible for
|
|
324
|
+
* native compaction under the current settings. Otherwise local summarization
|
|
325
|
+
* needs the originals, not an opaque placeholder.
|
|
309
326
|
*
|
|
310
|
-
*
|
|
311
|
-
*
|
|
312
|
-
* let the active model replay it, so keying reuse on "any candidate shares the
|
|
313
|
-
* provider" left a provider-switched session permanently context-less (#6343).
|
|
327
|
+
* Main-session preparation is judged against the active model, not any role
|
|
328
|
+
* candidate, so a provider switch cannot strand the original history (#6343).
|
|
314
329
|
*/
|
|
315
330
|
export declare function remotePreserveReusable(preserveData: Record<string, unknown> | undefined, activeModel: Model, settings: CompactionSettings): boolean;
|
|
316
331
|
/**
|
|
317
|
-
* Index of the newest compaction
|
|
318
|
-
* `-1` when none can.
|
|
332
|
+
* Index of the newest compaction boundary reusable under preparation policy,
|
|
333
|
+
* or `-1` when none can be reused (see {@link remotePreserveReusable}).
|
|
319
334
|
*
|
|
320
335
|
* A provider-native remote compaction (V2 or V1) stores an opaque replay payload
|
|
321
336
|
* and only a placeholder summary, so for any OTHER provider that entry
|
|
@@ -31,6 +31,8 @@ export interface CompactionEntry<T = unknown> extends SessionEntryBase {
|
|
|
31
31
|
shortSummary?: string;
|
|
32
32
|
firstKeptEntryId: string;
|
|
33
33
|
tokensBefore: number;
|
|
34
|
+
/** Last entry covered by native replay; later entries may precede the compaction record. */
|
|
35
|
+
providerReplayThroughEntryId?: string;
|
|
34
36
|
/** Extension-specific data (e.g., ArtifactIndex, version markers for structured compaction) */
|
|
35
37
|
details?: T;
|
|
36
38
|
/** Hook-provided data to persist across compaction */
|