@caupulican/pi-adaptative 0.80.73 → 0.80.75

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.
Files changed (33) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/dist/core/agent-session.d.ts +10 -0
  3. package/dist/core/agent-session.d.ts.map +1 -1
  4. package/dist/core/agent-session.js +42 -6
  5. package/dist/core/agent-session.js.map +1 -1
  6. package/dist/core/compaction/compaction.d.ts +22 -0
  7. package/dist/core/compaction/compaction.d.ts.map +1 -1
  8. package/dist/core/compaction/compaction.js +31 -3
  9. package/dist/core/compaction/compaction.js.map +1 -1
  10. package/dist/core/memory/providers/file-store.d.ts.map +1 -1
  11. package/dist/core/memory/providers/file-store.js +33 -2
  12. package/dist/core/memory/providers/file-store.js.map +1 -1
  13. package/dist/core/resource-loader.d.ts +19 -1
  14. package/dist/core/resource-loader.d.ts.map +1 -1
  15. package/dist/core/resource-loader.js +69 -5
  16. package/dist/core/resource-loader.js.map +1 -1
  17. package/dist/core/settings-manager.d.ts +6 -0
  18. package/dist/core/settings-manager.d.ts.map +1 -1
  19. package/dist/core/settings-manager.js +8 -0
  20. package/dist/core/settings-manager.js.map +1 -1
  21. package/dist/modes/interactive/interactive-mode.d.ts +5 -0
  22. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  23. package/dist/modes/interactive/interactive-mode.js +41 -12
  24. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  25. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  26. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  27. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  28. package/examples/extensions/sandbox/package-lock.json +2 -2
  29. package/examples/extensions/sandbox/package.json +1 -1
  30. package/examples/extensions/with-deps/package-lock.json +2 -2
  31. package/examples/extensions/with-deps/package.json +1 -1
  32. package/npm-shrinkwrap.json +12 -12
  33. package/package.json +4 -4
@@ -39,7 +39,7 @@ import { FileStoreProvider } from "./memory/providers/file-store.js";
39
39
  import { TranscriptRecallProvider } from "./memory/providers/transcript-recall.js";
40
40
  import { compactToolResultDetailsForRetention } from "./message-retention.js";
41
41
  import { createCustomMessage } from "./messages.js";
42
- import { resolveProfileModelSettings } from "./model-resolver.js";
42
+ import { resolveCliModel, resolveProfileModelSettings } from "./model-resolver.js";
43
43
  import { expandPromptTemplate } from "./prompt-templates.js";
44
44
  import { stripResourceProfileBlocks } from "./resource-profile-blocks.js";
45
45
  import { classifyToolTrust, UNTRUSTED_BOUNDARY_SYSTEM_RULE, wrapUntrustedText } from "./security/untrusted-boundary.js";
@@ -219,6 +219,39 @@ export class AgentSession {
219
219
  const result = await this._modelRegistry.getApiKeyAndHeaders(model);
220
220
  return result.ok ? { apiKey: result.apiKey, headers: result.headers } : {};
221
221
  }
222
+ /**
223
+ * Resolve the model used to SUMMARIZE during compaction (cost guard, #30). A compaction summary is an
224
+ * extraction task — it does not need the main (expensive) model. Selection:
225
+ * - an explicit `compaction.model` setting wins, but only if its provider is authed (else fall back);
226
+ * - `"auto"` (default) picks the CHEAPEST authed model whose context window can hold a compaction
227
+ * (capability floor), and ONLY if it is strictly cheaper than the session model — so we never
228
+ * downgrade to an equally-priced but weaker summarizer (agy's floor: don't degrade the checkpoint);
229
+ * - otherwise the session model is used (safe default).
230
+ */
231
+ _resolveCompactionModel(sessionModel) {
232
+ const setting = this.settingsManager.getCompactionModel();
233
+ if (setting && setting !== "auto") {
234
+ const resolved = resolveCliModel({ cliModel: setting, modelRegistry: this._modelRegistry });
235
+ if (resolved.model && this._modelRegistry.hasConfiguredAuth(resolved.model))
236
+ return resolved.model;
237
+ return sessionModel; // configured but unusable → don't break compaction
238
+ }
239
+ // "auto": cheapest authed model that can summarize a large context AND is cheaper than the session
240
+ // model. The context-window floor keeps a tiny local model from being picked for a big summary.
241
+ const FLOOR_CONTEXT = 64_000;
242
+ const sessionInputCost = sessionModel.cost?.input ?? Number.POSITIVE_INFINITY;
243
+ let best;
244
+ for (const m of this._modelRegistry.getAvailable()) {
245
+ if ((m.contextWindow ?? 0) < FLOOR_CONTEXT)
246
+ continue;
247
+ const cost = m.cost?.input ?? Number.POSITIVE_INFINITY;
248
+ if (cost >= sessionInputCost)
249
+ continue; // only ever pick something cheaper than the session model
250
+ if (!best || cost < (best.cost?.input ?? Number.POSITIVE_INFINITY))
251
+ best = m;
252
+ }
253
+ return best ?? sessionModel;
254
+ }
222
255
  /**
223
256
  * Install tool hooks once on the Agent instance.
224
257
  *
@@ -1676,7 +1709,8 @@ export class AgentSession {
1676
1709
  if (!this.model) {
1677
1710
  throw new Error(formatNoModelSelectedMessage());
1678
1711
  }
1679
- const { apiKey, headers } = await this._getCompactionRequestAuth(this.model);
1712
+ const compactionModel = this._resolveCompactionModel(this.model);
1713
+ const { apiKey, headers } = await this._getCompactionRequestAuth(compactionModel);
1680
1714
  const pathEntries = this.sessionManager.getBranch();
1681
1715
  const settings = this.settingsManager.getCompactionSettings();
1682
1716
  const preparation = prepareCompaction(pathEntries, settings);
@@ -1719,7 +1753,7 @@ export class AgentSession {
1719
1753
  }
1720
1754
  else {
1721
1755
  // Generate compaction result
1722
- const result = await compact(preparation, this.model, apiKey, headers, customInstructions, this._compactionAbortController.signal, this.thinkingLevel, this.agent.streamFn);
1756
+ const result = await compact(preparation, compactionModel, apiKey, headers, customInstructions, this._compactionAbortController.signal, this.thinkingLevel, this.agent.streamFn);
1723
1757
  summary = result.summary;
1724
1758
  firstKeptEntryId = result.firstKeptEntryId;
1725
1759
  tokensBefore = result.tokensBefore;
@@ -1897,10 +1931,12 @@ export class AgentSession {
1897
1931
  });
1898
1932
  return false;
1899
1933
  }
1934
+ // Summarize with the cheap auxiliary model when available (cost guard, #30).
1935
+ const compactionModel = this._resolveCompactionModel(this.model);
1900
1936
  let apiKey;
1901
1937
  let headers;
1902
1938
  if (this.agent.streamFn === streamSimple) {
1903
- const authResult = await this._modelRegistry.getApiKeyAndHeaders(this.model);
1939
+ const authResult = await this._modelRegistry.getApiKeyAndHeaders(compactionModel);
1904
1940
  if (!authResult.ok || !authResult.apiKey) {
1905
1941
  this._emit({
1906
1942
  type: "compaction_end",
@@ -1915,7 +1951,7 @@ export class AgentSession {
1915
1951
  headers = authResult.headers;
1916
1952
  }
1917
1953
  else {
1918
- ({ apiKey, headers } = await this._getCompactionRequestAuth(this.model));
1954
+ ({ apiKey, headers } = await this._getCompactionRequestAuth(compactionModel));
1919
1955
  }
1920
1956
  const pathEntries = this.sessionManager.getBranch();
1921
1957
  const preparation = prepareCompaction(pathEntries, settings);
@@ -1967,7 +2003,7 @@ export class AgentSession {
1967
2003
  }
1968
2004
  else {
1969
2005
  // Generate compaction result
1970
- const compactResult = await compact(preparation, this.model, apiKey, headers, undefined, this._autoCompactionAbortController.signal, this.thinkingLevel, this.agent.streamFn);
2006
+ const compactResult = await compact(preparation, compactionModel, apiKey, headers, undefined, this._autoCompactionAbortController.signal, this.thinkingLevel, this.agent.streamFn);
1971
2007
  summary = compactResult.summary;
1972
2008
  firstKeptEntryId = compactResult.firstKeptEntryId;
1973
2009
  tokensBefore = compactResult.tokensBefore;