@zhushanwen/pi-structured-output 6.1.3 → 6.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zhushanwen/pi-structured-output",
3
- "version": "6.1.3",
3
+ "version": "6.2.0",
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,16 +26,21 @@
26
26
  ],
27
27
  "dependencies": {
28
28
  "ajv": "^8.17.0",
29
+ "@zhushanwen/extension-protocol": "0.21.0",
29
30
  "@zhushanwen/pi-ext-guards": "0.5.0"
30
31
  },
31
32
  "peerDependencies": {
33
+ "@earendil-works/pi-ai": "^1.0.0",
32
34
  "@earendil-works/pi-coding-agent": "^1.0.0",
33
- "typebox": "1.3.27",
34
- "@earendil-works/pi-ai": "^1.0.0"
35
+ "@earendil-works/pi-tui": "^1.0.0",
36
+ "typebox": "1.3.27"
35
37
  },
36
38
  "peerDependenciesMeta": {
37
39
  "@earendil-works/pi-ai": {
38
40
  "optional": true
41
+ },
42
+ "@earendil-works/pi-tui": {
43
+ "optional": true
39
44
  }
40
45
  },
41
46
  "devDependencies": {
@@ -0,0 +1,38 @@
1
+ /**
2
+ * structured-output 工具的 TUI renderResult(折叠态一行摘要 / 展开态 content 纯文本)。
3
+ *
4
+ * 摘要不进 details:本工具的 result.details 是模型的结构化产出本体(workflow 引擎
5
+ * output-collector 的 extractParsedOutput 原样取走作 agent parsedOutput),混入 summary
6
+ * 键会污染产出契约(object 形态多出合同外字段、primitive 形态无处挂载)。因此折叠态
7
+ * 摘要 = 固定文案,不依赖数据。
8
+ */
9
+
10
+ import type { Theme } from "@earendil-works/pi-coding-agent";
11
+ import { Text } from "@earendil-works/pi-tui";
12
+ import { firstContentText } from "@zhushanwen/extension-protocol";
13
+
14
+ /** 折叠态一行摘要(两种注册变体统一;校验失败走 throw 不产出 result)。 */
15
+ export const STRUCTURED_OUTPUT_SUMMARY = "Final result reported (schema validated)";
16
+
17
+ /** content[0] 的 text 纯文本(content 缺失或非 text 类型时兜底空串)。 */
18
+ /** unknown 值按字段名安全取值(index-signature 收窄,替代全可选结构断言)。 */
19
+ function fieldValue(v: unknown, key: string): unknown {
20
+ if (typeof v !== "object" || v === null) return undefined;
21
+ return (v as Record<string, unknown>)[key];
22
+ }
23
+
24
+ function contentText(result: unknown): string {
25
+ const content = fieldValue(result, "content");
26
+ if (!Array.isArray(content)) return "";
27
+ return firstContentText({ content });
28
+ }
29
+
30
+ /** 折叠态(expanded=false)= 固定一行摘要(dim);展开态 = content 纯文本。 */
31
+ export function renderStructuredOutputResult(
32
+ result: unknown,
33
+ options: { expanded: boolean },
34
+ theme: Theme,
35
+ ): Text {
36
+ if (options.expanded) return new Text(contentText(result), 0, 0);
37
+ return new Text(theme.fg("dim", STRUCTURED_OUTPUT_SUMMARY), 0, 0);
38
+ }
@@ -18,10 +18,12 @@
18
18
  * 两变体的描述文本均被 prompt-quality.test.ts 文本断言锁定。
19
19
  */
20
20
 
21
+ import type { Theme } from "@earendil-works/pi-coding-agent";
21
22
  import { isRecord } from "@zhushanwen/pi-ext-guards";
22
23
  import { Type } from "typebox";
23
24
 
24
25
  import { executeStructuredOutput, isObjectRootSchema } from "./execute.js";
26
+ import { renderStructuredOutputResult } from "./render-result.js";
25
27
  import {
26
28
  assertJsonSchemaRoot,
27
29
  echo,
@@ -163,6 +165,12 @@ export function createWorkflowToolDefinition(envSchema: string) {
163
165
  // 「根是否 object」对称完成(与注册期包装判定同一函数 isObjectRootSchema)。
164
166
  return executeStructuredOutput({ data: params, authoritativeSchema: schema });
165
167
  },
168
+
169
+ // 摘要不进 details:details 是模型的结构化产出本体(workflow 引擎 extractParsedOutput
170
+ // 原样消费),折叠态摘要 = render-result 的固定文案。
171
+ renderResult(result: unknown, options: { expanded: boolean }, theme: Theme) {
172
+ return renderStructuredOutputResult(result, options, theme);
173
+ },
166
174
  };
167
175
  }
168
176
 
@@ -240,5 +248,10 @@ export function createDailyToolDefinition() {
240
248
  : params,
241
249
  );
242
250
  },
251
+
252
+ // 摘要不进 details:同 workflow 变体(details = 数据本体,parsedOutput 契约)
253
+ renderResult(result: unknown, options: { expanded: boolean }, theme: Theme) {
254
+ return renderStructuredOutputResult(result, options, theme);
255
+ },
243
256
  };
244
257
  }