@caupulican/pi-adaptative 0.75.6 → 0.75.7

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.
@@ -132,6 +132,7 @@ export class AgentSession {
132
132
  this._unsubscribeAgent = this.agent.subscribe(this._handleAgentEvent);
133
133
  this._installAgentToolHooks();
134
134
  this._installAgentContextTransform();
135
+ this._installAgentTurnRefresh();
135
136
  this._buildRuntime({
136
137
  activeToolNames: this._initialActiveToolNames,
137
138
  includeAllExtensionTools: true,
@@ -202,6 +203,30 @@ export class AgentSession {
202
203
  }
203
204
  };
204
205
  }
206
+ _installAgentTurnRefresh() {
207
+ const previousPrepareNextTurn = this.agent.prepareNextTurn?.bind(this.agent);
208
+ this.agent.prepareNextTurn = async (signal) => {
209
+ const previous = previousPrepareNextTurn ? await previousPrepareNextTurn(signal) : undefined;
210
+ const snapshot = this._createAgentContextSnapshot();
211
+ return {
212
+ ...previous,
213
+ context: {
214
+ ...(previous?.context ?? snapshot),
215
+ systemPrompt: snapshot.systemPrompt,
216
+ tools: snapshot.tools,
217
+ },
218
+ model: previous?.model ?? this.agent.state.model,
219
+ thinkingLevel: previous?.thinkingLevel ?? this.agent.state.thinkingLevel,
220
+ };
221
+ };
222
+ }
223
+ _createAgentContextSnapshot() {
224
+ return {
225
+ systemPrompt: this.agent.state.systemPrompt,
226
+ messages: this.agent.state.messages.slice(),
227
+ tools: this.agent.state.tools.slice(),
228
+ };
229
+ }
205
230
  _estimateCurrentContextTokens(messages) {
206
231
  const estimate = estimateContextTokens(messages);
207
232
  const compactionEntry = getLatestCompactionEntry(this.sessionManager.getBranch());
@@ -1877,12 +1902,9 @@ export class AgentSession {
1877
1902
  })();
1878
1903
  },
1879
1904
  reload: () => {
1880
- if (this.isStreaming) {
1881
- throw new Error("Cannot reload while the agent is streaming.");
1882
- }
1883
1905
  const actions = this._extensionCommandContextActions;
1884
- if (!actions) {
1885
- throw new Error("Reload is unavailable before extension command context is bound.");
1906
+ if (this.isStreaming || !actions) {
1907
+ return this.reload();
1886
1908
  }
1887
1909
  return actions.reload();
1888
1910
  },