@earendil-works/pi-coding-agent 0.74.1 → 0.75.0

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.
@@ -14,7 +14,7 @@
14
14
  */
15
15
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
16
16
  import { basename, dirname, resolve } from "node:path";
17
- import { clampThinkingLevel, cleanupSessionResources, getSupportedThinkingLevels, isContextOverflow, modelsAreEqual, resetApiProviders, } from "@earendil-works/pi-ai";
17
+ import { clampThinkingLevel, cleanupSessionResources, getSupportedThinkingLevels, isContextOverflow, modelsAreEqual, resetApiProviders, streamSimple, } from "@earendil-works/pi-ai";
18
18
  import { theme } from "../modes/interactive/theme/theme.js";
19
19
  import { stripFrontmatter } from "../utils/frontmatter.js";
20
20
  import { sleep } from "../utils/sleep.js";
@@ -158,6 +158,13 @@ export class AgentSession {
158
158
  }
159
159
  throw new Error(formatNoApiKeyFoundMessage(model.provider));
160
160
  }
161
+ async _getCompactionRequestAuth(model) {
162
+ if (this.agent.streamFn === streamSimple) {
163
+ return this._getRequiredRequestAuth(model);
164
+ }
165
+ const result = await this._modelRegistry.getApiKeyAndHeaders(model);
166
+ return result.ok ? { apiKey: result.apiKey, headers: result.headers } : {};
167
+ }
161
168
  /**
162
169
  * Install tool hooks once on the Agent instance.
163
170
  *
@@ -1251,7 +1258,7 @@ export class AgentSession {
1251
1258
  if (!this.model) {
1252
1259
  throw new Error(formatNoModelSelectedMessage());
1253
1260
  }
1254
- const { apiKey, headers } = await this._getRequiredRequestAuth(this.model);
1261
+ const { apiKey, headers } = await this._getCompactionRequestAuth(this.model);
1255
1262
  const pathEntries = this.sessionManager.getBranch();
1256
1263
  const settings = this.settingsManager.getCompactionSettings();
1257
1264
  const preparation = prepareCompaction(pathEntries, settings);
@@ -1294,7 +1301,7 @@ export class AgentSession {
1294
1301
  }
1295
1302
  else {
1296
1303
  // Generate compaction result
1297
- const result = await compact(preparation, this.model, apiKey, headers, customInstructions, this._compactionAbortController.signal, this.thinkingLevel);
1304
+ const result = await compact(preparation, this.model, apiKey, headers, customInstructions, this._compactionAbortController.signal, this.thinkingLevel, this.agent.streamFn);
1298
1305
  summary = result.summary;
1299
1306
  firstKeptEntryId = result.firstKeptEntryId;
1300
1307
  tokensBefore = result.tokensBefore;
@@ -1462,18 +1469,26 @@ export class AgentSession {
1462
1469
  });
1463
1470
  return;
1464
1471
  }
1465
- const authResult = await this._modelRegistry.getApiKeyAndHeaders(this.model);
1466
- if (!authResult.ok || !authResult.apiKey) {
1467
- this._emit({
1468
- type: "compaction_end",
1469
- reason,
1470
- result: undefined,
1471
- aborted: false,
1472
- willRetry: false,
1473
- });
1474
- return;
1472
+ let apiKey;
1473
+ let headers;
1474
+ if (this.agent.streamFn === streamSimple) {
1475
+ const authResult = await this._modelRegistry.getApiKeyAndHeaders(this.model);
1476
+ if (!authResult.ok || !authResult.apiKey) {
1477
+ this._emit({
1478
+ type: "compaction_end",
1479
+ reason,
1480
+ result: undefined,
1481
+ aborted: false,
1482
+ willRetry: false,
1483
+ });
1484
+ return;
1485
+ }
1486
+ apiKey = authResult.apiKey;
1487
+ headers = authResult.headers;
1488
+ }
1489
+ else {
1490
+ ({ apiKey, headers } = await this._getCompactionRequestAuth(this.model));
1475
1491
  }
1476
- const { apiKey, headers } = authResult;
1477
1492
  const pathEntries = this.sessionManager.getBranch();
1478
1493
  const preparation = prepareCompaction(pathEntries, settings);
1479
1494
  if (!preparation) {
@@ -1524,7 +1539,7 @@ export class AgentSession {
1524
1539
  }
1525
1540
  else {
1526
1541
  // Generate compaction result
1527
- const compactResult = await compact(preparation, this.model, apiKey, headers, undefined, this._autoCompactionAbortController.signal, this.thinkingLevel);
1542
+ const compactResult = await compact(preparation, this.model, apiKey, headers, undefined, this._autoCompactionAbortController.signal, this.thinkingLevel, this.agent.streamFn);
1528
1543
  summary = compactResult.summary;
1529
1544
  firstKeptEntryId = compactResult.firstKeptEntryId;
1530
1545
  tokensBefore = compactResult.tokensBefore;