flex-md 3.0.0 → 3.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/dist/__tests__/ofs.test.d.ts +1 -0
- package/dist/__tests__/ofs.test.js +51 -0
- package/dist/ofs/enricher.js +8 -0
- package/dist/ofs/stringify.js +10 -0
- package/dist/types.d.ts +3 -0
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { stringifyOutputFormatSpec } from "../ofs/stringify.js";
|
|
3
|
+
import { buildMarkdownGuidance } from "../ofs/enricher.js";
|
|
4
|
+
describe("OFS Object-to-Prompt Flow", () => {
|
|
5
|
+
const spec = {
|
|
6
|
+
description: "Standard report format for technical analysis.",
|
|
7
|
+
sections: [
|
|
8
|
+
{
|
|
9
|
+
name: "Summary",
|
|
10
|
+
kind: "text",
|
|
11
|
+
required: true,
|
|
12
|
+
description: "A brief summary of the topic.",
|
|
13
|
+
instruction: "Keep it under 3 sentences."
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
name: "Key Points",
|
|
17
|
+
kind: "list",
|
|
18
|
+
required: false,
|
|
19
|
+
description: "Important takeaways."
|
|
20
|
+
}
|
|
21
|
+
],
|
|
22
|
+
emptySectionValue: "N/A"
|
|
23
|
+
};
|
|
24
|
+
it("should stringify an OFS object correctly", () => {
|
|
25
|
+
const md = stringifyOutputFormatSpec(spec);
|
|
26
|
+
expect(md).toContain("## Output format (Markdown)");
|
|
27
|
+
expect(md).toContain("Standard report format for technical analysis.");
|
|
28
|
+
expect(md).toContain("- Summary — text (required)");
|
|
29
|
+
expect(md).toContain("Description: A brief summary of the topic.");
|
|
30
|
+
expect(md).toContain("Instruction: Keep it under 3 sentences.");
|
|
31
|
+
expect(md).toContain("- Key Points — list (optional)");
|
|
32
|
+
expect(md).toContain("Description: Important takeaways.");
|
|
33
|
+
expect(md).toContain("If a section is empty, write `N/A`.");
|
|
34
|
+
});
|
|
35
|
+
it("should build markdown guidance (L1) correctly", () => {
|
|
36
|
+
const guidance = buildMarkdownGuidance(spec, { level: 1 });
|
|
37
|
+
expect(guidance).toContain("Include these section headings somewhere");
|
|
38
|
+
expect(guidance).toContain("- Summary");
|
|
39
|
+
expect(guidance).toContain("Description: A brief summary of the topic.");
|
|
40
|
+
expect(guidance).toContain("Instruction: Keep it under 3 sentences.");
|
|
41
|
+
expect(guidance).toContain("- Key Points");
|
|
42
|
+
expect(guidance).toContain("Description: Important takeaways.");
|
|
43
|
+
});
|
|
44
|
+
it("should build markdown guidance (L3) correctly", () => {
|
|
45
|
+
const guidance = buildMarkdownGuidance(spec, { level: 3 });
|
|
46
|
+
expect(guidance).toContain("Return your entire answer inside a single ```markdown fenced block");
|
|
47
|
+
expect(guidance).toContain("- Summary");
|
|
48
|
+
expect(guidance).toContain("- Key Points (list)");
|
|
49
|
+
expect(guidance).toContain("Do not return JSON");
|
|
50
|
+
});
|
|
51
|
+
});
|
package/dist/ofs/enricher.js
CHANGED
|
@@ -31,6 +31,14 @@ export function buildMarkdownGuidance(spec, strict, opts) {
|
|
|
31
31
|
suffix = " (ordered list)";
|
|
32
32
|
}
|
|
33
33
|
lines.push(`- ${s.name}${suffix}`);
|
|
34
|
+
if (level >= 1) {
|
|
35
|
+
if (s.description) {
|
|
36
|
+
lines.push(` Description: ${s.description}`);
|
|
37
|
+
}
|
|
38
|
+
if (s.instruction) {
|
|
39
|
+
lines.push(` Instruction: ${s.instruction}`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
34
42
|
}
|
|
35
43
|
lines.push("");
|
|
36
44
|
// None Rule
|
package/dist/ofs/stringify.js
CHANGED
|
@@ -4,12 +4,22 @@
|
|
|
4
4
|
export function stringifyOutputFormatSpec(spec) {
|
|
5
5
|
const lines = [];
|
|
6
6
|
lines.push(`## Output format (Markdown)`);
|
|
7
|
+
if (spec.description) {
|
|
8
|
+
lines.push(spec.description);
|
|
9
|
+
lines.push("");
|
|
10
|
+
}
|
|
7
11
|
lines.push(`Include these sections somewhere (order does not matter):`);
|
|
8
12
|
lines.push("");
|
|
9
13
|
for (const s of spec.sections) {
|
|
10
14
|
const k = s.kind === "ordered_list" ? "ordered list" : (s.kind || "text");
|
|
11
15
|
const required = s.required === true ? " (required)" : (s.required === false ? " (optional)" : "");
|
|
12
16
|
lines.push(`- ${s.name} — ${k}${required}`);
|
|
17
|
+
if (s.description) {
|
|
18
|
+
lines.push(` Description: ${s.description}`);
|
|
19
|
+
}
|
|
20
|
+
if (s.instruction) {
|
|
21
|
+
lines.push(` Instruction: ${s.instruction}`);
|
|
22
|
+
}
|
|
13
23
|
}
|
|
14
24
|
const tables = spec.tables || [];
|
|
15
25
|
if (tables.length) {
|
package/dist/types.d.ts
CHANGED
|
@@ -86,6 +86,8 @@ export interface OutputSectionSpec {
|
|
|
86
86
|
kind?: SectionKind;
|
|
87
87
|
required?: boolean;
|
|
88
88
|
columns?: string[];
|
|
89
|
+
description?: string;
|
|
90
|
+
instruction?: string;
|
|
89
91
|
}
|
|
90
92
|
/**
|
|
91
93
|
* @deprecated Use OutputSectionSpec
|
|
@@ -101,6 +103,7 @@ export interface OfsTable {
|
|
|
101
103
|
required?: boolean;
|
|
102
104
|
}
|
|
103
105
|
export interface OutputFormatSpec {
|
|
106
|
+
description?: string;
|
|
104
107
|
sections: OutputSectionSpec[];
|
|
105
108
|
emptySectionValue?: string;
|
|
106
109
|
descriptorType?: "output_format_spec";
|
package/package.json
CHANGED