@paretools/shared 0.13.1 → 0.14.1
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/dist/output.d.ts +7 -2
- package/dist/output.d.ts.map +1 -1
- package/dist/output.js +50 -8
- package/dist/output.js.map +1 -1
- package/package.json +1 -1
package/dist/output.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ZodType } from "zod";
|
|
1
2
|
import type { ToolOutput } from "./types.js";
|
|
2
3
|
/**
|
|
3
4
|
* Creates the dual-output response that every pare tool returns.
|
|
@@ -27,8 +28,11 @@ export declare function estimateTokens(text: string): number;
|
|
|
27
28
|
* @param compactMap - Projects full data into a compact shape.
|
|
28
29
|
* @param compactFormat - Formatter for compact data.
|
|
29
30
|
* @param forceFullSchema - When true, skip auto-detection and return full data.
|
|
31
|
+
* @param outputSchema - Optional Zod schema. In dev mode (NODE_ENV !== 'production' or PARE_DEBUG set),
|
|
32
|
+
* the structured output is validated against this schema before returning. Mismatches throw a
|
|
33
|
+
* descriptive error, catching compact-map bugs during development/testing rather than in production.
|
|
30
34
|
*/
|
|
31
|
-
export declare function compactDualOutput<T, C>(data: T, rawStdout: string, humanFormat: (d: T) => string, compactMap: (d: T) => C, compactFormat: (d: C) => string, forceFullSchema: boolean): ToolOutput<T | C>;
|
|
35
|
+
export declare function compactDualOutput<T, C>(data: T, rawStdout: string, humanFormat: (d: T) => string, compactMap: (d: T) => C, compactFormat: (d: C) => string, forceFullSchema: boolean, outputSchema?: ZodType): ToolOutput<T | C>;
|
|
32
36
|
/**
|
|
33
37
|
* Creates a dual-output response where the formatter receives the full internal
|
|
34
38
|
* data (with extra fields for human-readable output) while structuredContent
|
|
@@ -54,6 +58,7 @@ export declare function strippedDualOutput<T, S>(data: T, humanFormat: (d: T) =>
|
|
|
54
58
|
* @param compactMap - Projects full data into a compact shape (for compact mode).
|
|
55
59
|
* @param compactFormat - Formatter for compact data.
|
|
56
60
|
* @param forceFullSchema - When true, skip auto-detection and return full data.
|
|
61
|
+
* @param outputSchema - Optional Zod schema for dev-mode validation (see compactDualOutput).
|
|
57
62
|
*/
|
|
58
|
-
export declare function strippedCompactDualOutput<T, S, C>(data: T, rawStdout: string, humanFormat: (d: T) => string, schemaMap: (d: T) => S, compactMap: (d: T) => C, compactFormat: (d: C) => string, forceFullSchema: boolean): ToolOutput<S | C>;
|
|
63
|
+
export declare function strippedCompactDualOutput<T, S, C>(data: T, rawStdout: string, humanFormat: (d: T) => string, schemaMap: (d: T) => S, compactMap: (d: T) => C, compactFormat: (d: C) => string, forceFullSchema: boolean, outputSchema?: ZodType): ToolOutput<S | C>;
|
|
59
64
|
//# sourceMappingURL=output.d.ts.map
|
package/dist/output.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../src/output.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../src/output.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AACnC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AA+B7C;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,WAAW,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,MAAM,GAAG,UAAU,CAAC,CAAC,CAAC,CAKnF;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,CAAC,EACpC,IAAI,EAAE,CAAC,EACP,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,MAAM,EAC7B,UAAU,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,EACvB,aAAa,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,MAAM,EAC/B,eAAe,EAAE,OAAO,EACxB,YAAY,CAAC,EAAE,OAAO,GACrB,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,CAoBnB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,CAAC,EACrC,IAAI,EAAE,CAAC,EACP,WAAW,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,MAAM,EAC7B,SAAS,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,GACrB,UAAU,CAAC,CAAC,CAAC,CAKf;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,yBAAyB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAC/C,IAAI,EAAE,CAAC,EACP,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,MAAM,EAC7B,SAAS,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,EACtB,UAAU,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,EACvB,aAAa,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,MAAM,EAC/B,eAAe,EAAE,OAAO,EACxB,YAAY,CAAC,EAAE,OAAO,GACrB,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,CAoBnB"}
|
package/dist/output.js
CHANGED
|
@@ -1,3 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns true when dev-mode validation should run.
|
|
3
|
+
* Active when NODE_ENV is NOT 'production' or PARE_DEBUG is set.
|
|
4
|
+
*/
|
|
5
|
+
function isDevMode() {
|
|
6
|
+
return process.env.NODE_ENV !== "production" || !!process.env.PARE_DEBUG;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Validates `data` against a Zod `outputSchema` in dev mode.
|
|
10
|
+
* Throws a descriptive error when the data does not match the schema,
|
|
11
|
+
* helping developers catch compact-map / schema mismatches early.
|
|
12
|
+
*
|
|
13
|
+
* No-ops in production (NODE_ENV=production without PARE_DEBUG).
|
|
14
|
+
*/
|
|
15
|
+
function devValidate(data, outputSchema, label) {
|
|
16
|
+
if (!outputSchema || !isDevMode())
|
|
17
|
+
return;
|
|
18
|
+
const result = outputSchema.safeParse(data);
|
|
19
|
+
if (!result.success) {
|
|
20
|
+
const issues = result.error.issues
|
|
21
|
+
.map((i) => ` - ${i.path.join(".")}: ${i.message}`)
|
|
22
|
+
.join("\n");
|
|
23
|
+
throw new Error(`compactDualOutput (${label}): structured output does not match outputSchema.\n` +
|
|
24
|
+
`Validation errors:\n${issues}`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
1
27
|
/**
|
|
2
28
|
* Creates the dual-output response that every pare tool returns.
|
|
3
29
|
*
|
|
@@ -33,18 +59,27 @@ export function estimateTokens(text) {
|
|
|
33
59
|
* @param compactMap - Projects full data into a compact shape.
|
|
34
60
|
* @param compactFormat - Formatter for compact data.
|
|
35
61
|
* @param forceFullSchema - When true, skip auto-detection and return full data.
|
|
62
|
+
* @param outputSchema - Optional Zod schema. In dev mode (NODE_ENV !== 'production' or PARE_DEBUG set),
|
|
63
|
+
* the structured output is validated against this schema before returning. Mismatches throw a
|
|
64
|
+
* descriptive error, catching compact-map bugs during development/testing rather than in production.
|
|
36
65
|
*/
|
|
37
|
-
export function compactDualOutput(data, rawStdout, humanFormat, compactMap, compactFormat, forceFullSchema) {
|
|
66
|
+
export function compactDualOutput(data, rawStdout, humanFormat, compactMap, compactFormat, forceFullSchema, outputSchema) {
|
|
38
67
|
if (forceFullSchema) {
|
|
39
|
-
|
|
68
|
+
const out = dualOutput(data, humanFormat);
|
|
69
|
+
devValidate(out.structuredContent, outputSchema, "full");
|
|
70
|
+
return out;
|
|
40
71
|
}
|
|
41
72
|
const structuredTokens = estimateTokens(JSON.stringify(data));
|
|
42
73
|
const rawTokens = estimateTokens(rawStdout);
|
|
43
74
|
if (structuredTokens >= rawTokens) {
|
|
44
75
|
const compact = compactMap(data);
|
|
45
|
-
|
|
76
|
+
const out = dualOutput(compact, compactFormat);
|
|
77
|
+
devValidate(out.structuredContent, outputSchema, "compact");
|
|
78
|
+
return out;
|
|
46
79
|
}
|
|
47
|
-
|
|
80
|
+
const out = dualOutput(data, humanFormat);
|
|
81
|
+
devValidate(out.structuredContent, outputSchema, "full");
|
|
82
|
+
return out;
|
|
48
83
|
}
|
|
49
84
|
/**
|
|
50
85
|
* Creates a dual-output response where the formatter receives the full internal
|
|
@@ -76,17 +111,24 @@ export function strippedDualOutput(data, humanFormat, schemaMap) {
|
|
|
76
111
|
* @param compactMap - Projects full data into a compact shape (for compact mode).
|
|
77
112
|
* @param compactFormat - Formatter for compact data.
|
|
78
113
|
* @param forceFullSchema - When true, skip auto-detection and return full data.
|
|
114
|
+
* @param outputSchema - Optional Zod schema for dev-mode validation (see compactDualOutput).
|
|
79
115
|
*/
|
|
80
|
-
export function strippedCompactDualOutput(data, rawStdout, humanFormat, schemaMap, compactMap, compactFormat, forceFullSchema) {
|
|
116
|
+
export function strippedCompactDualOutput(data, rawStdout, humanFormat, schemaMap, compactMap, compactFormat, forceFullSchema, outputSchema) {
|
|
81
117
|
if (forceFullSchema) {
|
|
82
|
-
|
|
118
|
+
const out = strippedDualOutput(data, humanFormat, schemaMap);
|
|
119
|
+
devValidate(out.structuredContent, outputSchema, "full");
|
|
120
|
+
return out;
|
|
83
121
|
}
|
|
84
122
|
const structuredTokens = estimateTokens(JSON.stringify(data));
|
|
85
123
|
const rawTokens = estimateTokens(rawStdout);
|
|
86
124
|
if (structuredTokens >= rawTokens) {
|
|
87
125
|
const compact = compactMap(data);
|
|
88
|
-
|
|
126
|
+
const out = dualOutput(compact, compactFormat);
|
|
127
|
+
devValidate(out.structuredContent, outputSchema, "compact");
|
|
128
|
+
return out;
|
|
89
129
|
}
|
|
90
|
-
|
|
130
|
+
const out = strippedDualOutput(data, humanFormat, schemaMap);
|
|
131
|
+
devValidate(out.structuredContent, outputSchema, "full");
|
|
132
|
+
return out;
|
|
91
133
|
}
|
|
92
134
|
//# sourceMappingURL=output.js.map
|
package/dist/output.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"output.js","sourceRoot":"","sources":["../src/output.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"output.js","sourceRoot":"","sources":["../src/output.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,SAAS,SAAS;IAChB,OAAO,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,IAAI,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC;AAC3E,CAAC;AAED;;;;;;GAMG;AACH,SAAS,WAAW,CAAI,IAAO,EAAE,YAAiC,EAAE,KAAa;IAC/E,IAAI,CAAC,YAAY,IAAI,CAAC,SAAS,EAAE;QAAE,OAAO;IAC1C,MAAM,MAAM,GAAG,YAAY,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IAC5C,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACpB,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,MAAM;aAC/B,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC;aACnD,IAAI,CAAC,IAAI,CAAC,CAAC;QACd,MAAM,IAAI,KAAK,CACb,sBAAsB,KAAK,qDAAqD;YAC9E,uBAAuB,MAAM,EAAE,CAClC,CAAC;IACJ,CAAC;AACH,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,UAAU,CAAI,IAAO,EAAE,WAA6B;IAClE,OAAO;QACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC;Q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