@earendil-works/pi-coding-agent 0.74.0 → 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.
Files changed (143) hide show
  1. package/CHANGELOG.md +57 -0
  2. package/README.md +9 -7
  3. package/dist/cli/args.d.ts.map +1 -1
  4. package/dist/cli/args.js +1 -0
  5. package/dist/cli/args.js.map +1 -1
  6. package/dist/config.d.ts.map +1 -1
  7. package/dist/config.js +13 -16
  8. package/dist/config.js.map +1 -1
  9. package/dist/core/agent-session.d.ts +1 -0
  10. package/dist/core/agent-session.d.ts.map +1 -1
  11. package/dist/core/agent-session.js +32 -17
  12. package/dist/core/agent-session.js.map +1 -1
  13. package/dist/core/bash-executor.d.ts.map +1 -1
  14. package/dist/core/bash-executor.js +1 -1
  15. package/dist/core/bash-executor.js.map +1 -1
  16. package/dist/core/compaction/compaction.d.ts +3 -3
  17. package/dist/core/compaction/compaction.d.ts.map +1 -1
  18. package/dist/core/compaction/compaction.js +25 -15
  19. package/dist/core/compaction/compaction.js.map +1 -1
  20. package/dist/core/model-registry.d.ts.map +1 -1
  21. package/dist/core/model-registry.js +1 -0
  22. package/dist/core/model-registry.js.map +1 -1
  23. package/dist/core/model-resolver.d.ts.map +1 -1
  24. package/dist/core/model-resolver.js +1 -0
  25. package/dist/core/model-resolver.js.map +1 -1
  26. package/dist/core/package-manager.d.ts +5 -0
  27. package/dist/core/package-manager.d.ts.map +1 -1
  28. package/dist/core/package-manager.js +81 -26
  29. package/dist/core/package-manager.js.map +1 -1
  30. package/dist/core/prompt-templates.d.ts.map +1 -1
  31. package/dist/core/prompt-templates.js +6 -4
  32. package/dist/core/prompt-templates.js.map +1 -1
  33. package/dist/core/provider-display-names.d.ts.map +1 -1
  34. package/dist/core/provider-display-names.js +1 -0
  35. package/dist/core/provider-display-names.js.map +1 -1
  36. package/dist/core/sdk.d.ts +1 -1
  37. package/dist/core/sdk.d.ts.map +1 -1
  38. package/dist/core/sdk.js +1 -1
  39. package/dist/core/sdk.js.map +1 -1
  40. package/dist/core/session-manager.d.ts +1 -1
  41. package/dist/core/session-manager.d.ts.map +1 -1
  42. package/dist/core/session-manager.js +39 -9
  43. package/dist/core/session-manager.js.map +1 -1
  44. package/dist/core/skills.d.ts.map +1 -1
  45. package/dist/core/skills.js +2 -5
  46. package/dist/core/skills.js.map +1 -1
  47. package/dist/core/system-prompt.d.ts.map +1 -1
  48. package/dist/core/system-prompt.js +3 -2
  49. package/dist/core/system-prompt.js.map +1 -1
  50. package/dist/core/tools/read.d.ts.map +1 -1
  51. package/dist/core/tools/read.js +2 -1
  52. package/dist/core/tools/read.js.map +1 -1
  53. package/dist/core/tools/render-utils.d.ts.map +1 -1
  54. package/dist/core/tools/render-utils.js +1 -1
  55. package/dist/core/tools/render-utils.js.map +1 -1
  56. package/dist/main.d.ts.map +1 -1
  57. package/dist/main.js +0 -10
  58. package/dist/main.js.map +1 -1
  59. package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -1
  60. package/dist/modes/interactive/components/bash-execution.js +1 -1
  61. package/dist/modes/interactive/components/bash-execution.js.map +1 -1
  62. package/dist/modes/interactive/components/config-selector.d.ts.map +1 -1
  63. package/dist/modes/interactive/components/config-selector.js +23 -1
  64. package/dist/modes/interactive/components/config-selector.js.map +1 -1
  65. package/dist/modes/interactive/components/extension-selector.d.ts +2 -0
  66. package/dist/modes/interactive/components/extension-selector.d.ts.map +1 -1
  67. package/dist/modes/interactive/components/extension-selector.js +6 -1
  68. package/dist/modes/interactive/components/extension-selector.js.map +1 -1
  69. package/dist/modes/interactive/components/keybinding-hints.d.ts +5 -0
  70. package/dist/modes/interactive/components/keybinding-hints.d.ts.map +1 -1
  71. package/dist/modes/interactive/components/keybinding-hints.js +19 -5
  72. package/dist/modes/interactive/components/keybinding-hints.js.map +1 -1
  73. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  74. package/dist/modes/interactive/components/settings-selector.js +3 -1
  75. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  76. package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
  77. package/dist/modes/interactive/components/tree-selector.js +2 -1
  78. package/dist/modes/interactive/components/tree-selector.js.map +1 -1
  79. package/dist/modes/interactive/interactive-mode.d.ts +12 -4
  80. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  81. package/dist/modes/interactive/interactive-mode.js +67 -27
  82. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  83. package/dist/modes/interactive/theme/dark.json +1 -1
  84. package/dist/modes/interactive/theme/light.json +1 -1
  85. package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
  86. package/dist/modes/interactive/theme/theme.js +3 -1
  87. package/dist/modes/interactive/theme/theme.js.map +1 -1
  88. package/dist/utils/ansi.d.ts +2 -0
  89. package/dist/utils/ansi.d.ts.map +1 -0
  90. package/dist/utils/ansi.js +52 -0
  91. package/dist/utils/ansi.js.map +1 -0
  92. package/dist/utils/html.d.ts +7 -0
  93. package/dist/utils/html.d.ts.map +1 -0
  94. package/dist/utils/html.js +40 -0
  95. package/dist/utils/html.js.map +1 -0
  96. package/dist/utils/mime.d.ts +1 -0
  97. package/dist/utils/mime.d.ts.map +1 -1
  98. package/dist/utils/mime.js +59 -16
  99. package/dist/utils/mime.js.map +1 -1
  100. package/dist/utils/paths.d.ts +2 -0
  101. package/dist/utils/paths.d.ts.map +1 -1
  102. package/dist/utils/paths.js +16 -0
  103. package/dist/utils/paths.js.map +1 -1
  104. package/dist/utils/syntax-highlight.d.ts +12 -0
  105. package/dist/utils/syntax-highlight.d.ts.map +1 -0
  106. package/dist/utils/syntax-highlight.js +118 -0
  107. package/dist/utils/syntax-highlight.js.map +1 -0
  108. package/dist/utils/tools-manager.d.ts.map +1 -1
  109. package/dist/utils/tools-manager.js +80 -8
  110. package/dist/utils/tools-manager.js.map +1 -1
  111. package/docs/custom-provider.md +58 -3
  112. package/docs/extensions.md +1 -1
  113. package/docs/index.md +7 -1
  114. package/docs/models.md +2 -2
  115. package/docs/packages.md +2 -2
  116. package/docs/providers.md +2 -0
  117. package/docs/sdk.md +24 -44
  118. package/docs/settings.md +1 -3
  119. package/docs/skills.md +3 -4
  120. package/docs/termux.md +3 -3
  121. package/docs/themes.md +2 -2
  122. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  123. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  124. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  125. package/examples/extensions/dynamic-resources/dynamic.json +1 -1
  126. package/examples/extensions/sandbox/package-lock.json +2 -2
  127. package/examples/extensions/sandbox/package.json +1 -1
  128. package/examples/extensions/with-deps/package-lock.json +2 -2
  129. package/examples/extensions/with-deps/package.json +1 -1
  130. package/examples/sdk/01-minimal.ts +14 -10
  131. package/examples/sdk/02-custom-model.ts +12 -8
  132. package/examples/sdk/03-custom-prompt.ts +24 -16
  133. package/examples/sdk/04-skills.ts +2 -2
  134. package/examples/sdk/05-tools.ts +8 -4
  135. package/examples/sdk/06-extensions.ts +11 -7
  136. package/examples/sdk/07-context-files.ts +2 -2
  137. package/examples/sdk/08-prompt-templates.ts +2 -2
  138. package/examples/sdk/09-api-keys-and-oauth.ts +8 -4
  139. package/examples/sdk/10-settings.ts +4 -4
  140. package/examples/sdk/11-sessions.ts +4 -0
  141. package/examples/sdk/12-full-control.ts +11 -7
  142. package/examples/sdk/README.md +5 -8
  143. package/package.json +8 -13
@@ -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;
@@ -1927,8 +1942,8 @@ export class AgentSession {
1927
1942
  if (isContextOverflow(message, contextWindow))
1928
1943
  return false;
1929
1944
  const err = message.errorMessage;
1930
- // Match: overloaded_error, provider returned error, rate limit, 429, 500, 502, 503, 504, service unavailable, network/connection errors (including connection lost), WebSocket transport closes/errors, fetch failed, request ended without sending chunks, HTTP/2 closed before response, terminated, retry delay exceeded
1931
- return /overloaded|provider.?returned.?error|rate.?limit|too many requests|429|500|502|503|504|service.?unavailable|server.?error|internal.?error|network.?error|connection.?error|connection.?refused|connection.?lost|websocket.?closed|websocket.?error|other side closed|fetch failed|upstream.?connect|reset before headers|socket hang up|ended without|http2 request did not get a response|timed? out|timeout|terminated|retry delay/i.test(err);
1945
+ // Match: overloaded_error, provider returned error, rate limit, 429, 500, 502, 503, 504, service unavailable, network/connection errors (including connection lost), WebSocket transport closes/errors, fetch failed, premature stream endings, HTTP/2 closed before response, terminated, retry delay exceeded
1946
+ return /overloaded|provider.?returned.?error|rate.?limit|too many requests|429|500|502|503|504|service.?unavailable|server.?error|internal.?error|network.?error|connection.?error|connection.?refused|connection.?lost|websocket.?closed|websocket.?error|other side closed|fetch failed|upstream.?connect|reset before headers|socket hang up|ended without|stream ended before message_stop|http2 request did not get a response|timed? out|timeout|terminated|retry delay/i.test(err);
1932
1947
  }
1933
1948
  /**
1934
1949
  * Handle retryable errors with exponential backoff.