@zhushanwen/pi-structured-output 6.2.1 → 6.2.3
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/package.json +2 -2
- package/src/render-result.ts +4 -23
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zhushanwen/pi-structured-output",
|
|
3
|
-
"version": "6.2.
|
|
3
|
+
"version": "6.2.3",
|
|
4
4
|
"description": "Structured output tool for Pi — workflow schema enforcement via pi's parameter layer; interactive mode validates self-reported schemas with Ajv",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.ts",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"ajv": "^8.17.0",
|
|
29
|
-
"@zhushanwen/extension-protocol": "0.
|
|
29
|
+
"@zhushanwen/extension-protocol": "0.24.0",
|
|
30
30
|
"@zhushanwen/pi-ext-guards": "0.5.0"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
package/src/render-result.ts
CHANGED
|
@@ -14,9 +14,9 @@
|
|
|
14
14
|
|
|
15
15
|
import type { Theme } from "@earendil-works/pi-coding-agent";
|
|
16
16
|
import { Text } from "@earendil-works/pi-tui";
|
|
17
|
-
import {
|
|
17
|
+
import { firstLine, resultContentText } from "@zhushanwen/extension-protocol";
|
|
18
18
|
|
|
19
|
-
/** 成功轮折叠态一行摘要(两种注册变体统一;错误轮走 firstLine(
|
|
19
|
+
/** 成功轮折叠态一行摘要(两种注册变体统一;错误轮走 firstLine(resultContentText))。 */
|
|
20
20
|
export const STRUCTURED_OUTPUT_SUMMARY = "Final result reported (schema validated)";
|
|
21
21
|
|
|
22
22
|
/**
|
|
@@ -27,25 +27,6 @@ export interface StructuredOutputRenderContext {
|
|
|
27
27
|
isError?: boolean;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
/** content[0] 的 text 纯文本(content 缺失或非 text 类型时兜底空串)。 */
|
|
31
|
-
/** unknown 值按字段名安全取值(index-signature 收窄,替代全可选结构断言)。 */
|
|
32
|
-
function fieldValue(v: unknown, key: string): unknown {
|
|
33
|
-
if (typeof v !== "object" || v === null) return undefined;
|
|
34
|
-
return (v as Record<string, unknown>)[key];
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function contentText(result: unknown): string {
|
|
38
|
-
const content = fieldValue(result, "content");
|
|
39
|
-
if (!Array.isArray(content)) return "";
|
|
40
|
-
return firstContentText({ content });
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/** 折叠态回退:content 文本取首行(保持一行摘要形态)。 */
|
|
44
|
-
function firstLine(text: string): string {
|
|
45
|
-
const idx = text.indexOf("\n");
|
|
46
|
-
return idx === -1 ? text : text.slice(0, idx);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
30
|
/**
|
|
50
31
|
* 折叠态(expanded=false):成功 = 固定一行摘要;错误 = content 首行(dim)。
|
|
51
32
|
* 展开态 = content 纯文本。context 可选——旧的三参调用(测试 / 历史 caller)按成功处理。
|
|
@@ -56,9 +37,9 @@ export function renderStructuredOutputResult(
|
|
|
56
37
|
theme: Theme,
|
|
57
38
|
context?: StructuredOutputRenderContext,
|
|
58
39
|
): Text {
|
|
59
|
-
if (options.expanded) return new Text(
|
|
40
|
+
if (options.expanded) return new Text(resultContentText(result), 0, 0);
|
|
60
41
|
const summary = context?.isError === true
|
|
61
|
-
? firstLine(
|
|
42
|
+
? firstLine(resultContentText(result))
|
|
62
43
|
: STRUCTURED_OUTPUT_SUMMARY;
|
|
63
44
|
return new Text(theme.fg("dim", summary), 0, 0);
|
|
64
45
|
}
|