@mammothb/pi-shared 1.0.0 → 1.1.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.
- package/index.ts +7 -0
- package/package.json +7 -2
- package/src/extract-text-content.ts +16 -0
- package/src/get-expand-key.ts +6 -0
- package/src/is-text-content.ts +5 -0
- package/src/render-error.ts +7 -0
package/index.ts
CHANGED
|
@@ -1 +1,8 @@
|
|
|
1
1
|
export { expandTilde } from "./src/expand-tilde.js";
|
|
2
|
+
export {
|
|
3
|
+
extractTextContent,
|
|
4
|
+
firstTextBlock,
|
|
5
|
+
} from "./src/extract-text-content.js";
|
|
6
|
+
export { getExpandKey } from "./src/get-expand-key.js";
|
|
7
|
+
export { isTextContent } from "./src/is-text-content.js";
|
|
8
|
+
export { renderError } from "./src/render-error.js";
|
package/package.json
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mammothb/pi-shared",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Shared utilities for pi extensions",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
7
7
|
"index.ts",
|
|
8
8
|
"src"
|
|
9
|
-
]
|
|
9
|
+
],
|
|
10
|
+
"peerDependencies": {
|
|
11
|
+
"@earendil-works/pi-ai": "*",
|
|
12
|
+
"@earendil-works/pi-coding-agent": "*",
|
|
13
|
+
"@earendil-works/pi-tui": "*"
|
|
14
|
+
}
|
|
10
15
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { AgentToolResult } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { isTextContent } from "./is-text-content.js";
|
|
3
|
+
|
|
4
|
+
/** Join all text blocks from a tool result into a single string. */
|
|
5
|
+
export function extractTextContent(result: AgentToolResult): string {
|
|
6
|
+
return result.content
|
|
7
|
+
.filter(isTextContent)
|
|
8
|
+
.map((c) => c.text)
|
|
9
|
+
.join("\n");
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** Get the first text block from a tool result, or empty string. */
|
|
13
|
+
export function firstTextBlock(result: AgentToolResult): string {
|
|
14
|
+
const block = result.content[0];
|
|
15
|
+
return block?.type === "text" ? block.text : "";
|
|
16
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Theme } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { Text } from "@earendil-works/pi-tui";
|
|
3
|
+
|
|
4
|
+
/** Render a tool error — used as an early return in renderResult. */
|
|
5
|
+
export function renderError(rawText: string, theme: Theme): Text {
|
|
6
|
+
return new Text(theme.fg("error", rawText), 0, 0);
|
|
7
|
+
}
|