@zhushanwen/pi-structured-output 5.1.4 → 5.1.5
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 +3 -2
- package/src/loop-gate.ts +18 -2
- package/src/text-primitives.ts +3 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zhushanwen/pi-structured-output",
|
|
3
|
-
"version": "5.1.
|
|
3
|
+
"version": "5.1.5",
|
|
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",
|
|
@@ -24,7 +24,8 @@
|
|
|
24
24
|
"index.ts"
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"ajv": "^8.17.0"
|
|
27
|
+
"ajv": "^8.17.0",
|
|
28
|
+
"@zhushanwen/pi-ext-guards": "0.3.0"
|
|
28
29
|
},
|
|
29
30
|
"peerDependencies": {
|
|
30
31
|
"@earendil-works/pi-coding-agent": "^0.84.4",
|
package/src/loop-gate.ts
CHANGED
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
*/
|
|
42
42
|
|
|
43
43
|
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
44
|
+
import { guardStaleCtx, toErrorMessage } from "@zhushanwen/pi-ext-guards";
|
|
44
45
|
|
|
45
46
|
import { isPlainObject, isToolExecutionEndEvent } from "./schema-guards.js";
|
|
46
47
|
import {
|
|
@@ -558,8 +559,23 @@ export function setupLoopGate(pi: PiAPI, options: LoopGateOptions = {}): LoopGat
|
|
|
558
559
|
|
|
559
560
|
options.onTerminal?.();
|
|
560
561
|
writeTerminatedLog(pi, gate);
|
|
561
|
-
ctx
|
|
562
|
-
|
|
562
|
+
// stale ctx 防御(crash-resilience D1):abort/shutdown 均在 pi assertActive 面
|
|
563
|
+
// (PS-30,runner.js createContext)——session 替换窗口触发 terminal 时无人接的
|
|
564
|
+
// 同步 throw 会经 async handler 变 rejected Promise 杀 pi 进程。stale 静默跳过
|
|
565
|
+
// 优雅退出(此时进程的存在意义已随 session 替换消失),armForceExitTeardown 的
|
|
566
|
+
// 15s 硬退兜底保持武装——自清理语义不丢。非 stale 错误原样上抛(守卫不吞真实 bug)。
|
|
567
|
+
guardStaleCtx(() => {
|
|
568
|
+
ctx.abort();
|
|
569
|
+
ctx.shutdown();
|
|
570
|
+
}, {
|
|
571
|
+
label: "structured-output:terminal-teardown",
|
|
572
|
+
onStale: (error) => {
|
|
573
|
+
process.stderr.write(
|
|
574
|
+
`[structured-output gate] terminal teardown skipped (stale ctx, session replaced): `
|
|
575
|
+
+ `${toErrorMessage(error)}; force-exit timer stays armed.\n`,
|
|
576
|
+
);
|
|
577
|
+
},
|
|
578
|
+
});
|
|
563
579
|
armForceExitTeardown();
|
|
564
580
|
});
|
|
565
581
|
|
package/src/text-primitives.ts
CHANGED
|
@@ -40,10 +40,9 @@ export function truncateText(text: string, max: number): string {
|
|
|
40
40
|
*
|
|
41
41
|
* Pi 框架在参数层校验失败(immediate 路径)与 execute 抛错时,均构造
|
|
42
42
|
* `{ content: [{ type: "text", text }] }` 塞进 result.content[0].text
|
|
43
|
-
* (agent-loop.js createErrorToolResult
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
* steer 回灌文本。
|
|
43
|
+
* (agent-loop.js createErrorToolResult;SDK 事件结构里没有独立 errorMessage 字段,
|
|
44
|
+
* 错误文本只能从 result.content 里取)。loop-gate(D3)复用本函数提取签名原料,
|
|
45
|
+
* workflow-hook 取 steer 回灌文本。
|
|
47
46
|
* 这里防御性取多种结构,取不到就返回 undefined(调用方降级为通用提示)。
|
|
48
47
|
*/
|
|
49
48
|
export function extractToolErrorText(result: unknown): string | undefined {
|