@skydiveai/pi-extensions 0.1.0-beta.2607 → 0.1.0-beta.2611

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 (2) hide show
  1. package/dist/index.mjs +30 -1
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -26,6 +26,7 @@ import { promisify } from "node:util";
26
26
  import { parse } from "yaml";
27
27
  import { getModels } from "@earendil-works/pi-ai";
28
28
  import { quote } from "shell-quote";
29
+ import { createHash } from "node:crypto";
29
30
  import { createWriteStream } from "node:fs";
30
31
  import { finished } from "node:stream/promises";
31
32
  import { createLocalBashOperations } from "@earendil-works/pi-coding-agent";
@@ -4477,6 +4478,33 @@ const toolCallEnvExtension = (pi) => {
4477
4478
  });
4478
4479
  };
4479
4480
  //#endregion
4481
+ //#region src/extensions/tool-history.ts
4482
+ function historyToolName(name) {
4483
+ if (/^[a-zA-Z0-9_-]{1,64}$/.test(name)) return name;
4484
+ return `invalid_tool_${createHash("sha256").update(name).digest("hex").slice(0, 32)}`;
4485
+ }
4486
+ /** Repair provider-bound history, never tool execution or persisted messages. */
4487
+ function repairToolHistory(messages) {
4488
+ if (!messages.some((message) => message.role === "assistant" && message.content.some((block) => block.type === "toolCall" && historyToolName(block.name) !== block.name) || message.role === "toolResult" && historyToolName(message.toolName) !== message.toolName)) return messages;
4489
+ return messages.map((message) => {
4490
+ if (message.role === "assistant") return {
4491
+ ...message,
4492
+ content: message.content.map((block) => block.type === "toolCall" ? {
4493
+ ...block,
4494
+ name: historyToolName(block.name)
4495
+ } : block)
4496
+ };
4497
+ if (message.role === "toolResult") return {
4498
+ ...message,
4499
+ toolName: historyToolName(message.toolName)
4500
+ };
4501
+ return message;
4502
+ });
4503
+ }
4504
+ const toolHistoryExtension = (pi) => {
4505
+ pi.on("context", ({ messages }) => ({ messages: repairToolHistory(messages) }));
4506
+ };
4507
+ //#endregion
4480
4508
  //#region src/extensions/background-tasks.ts
4481
4509
  /**
4482
4510
  * Background bash tasks as a pi extension.
@@ -5186,7 +5214,8 @@ function platformExtensions({ sessionId, channelContext }) {
5186
5214
  createSubagentExtension({ channelContext }),
5187
5215
  createProactiveResultExtension({ channelContext }),
5188
5216
  createContextManagementExtension(),
5189
- resourcePressureWarningExtension
5217
+ resourcePressureWarningExtension,
5218
+ toolHistoryExtension
5190
5219
  ];
5191
5220
  }
5192
5221
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skydiveai/pi-extensions",
3
- "version": "0.1.0-beta.2607",
3
+ "version": "0.1.0-beta.2611",
4
4
  "homepage": "https://skydive.com",
5
5
  "license": "MIT",
6
6
  "author": "Create, Inc.",