schematex 0.8.2 → 0.9.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.
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var chunkHWNVSNDJ_cjs = require('../chunk-HWNVSNDJ.cjs');
3
+ var chunkHKOPXQYU_cjs = require('../chunk-HKOPXQYU.cjs');
4
4
  require('../chunk-UGB42BGK.cjs');
5
5
  require('../chunk-Q2YRJHFB.cjs');
6
6
  require('../chunk-JIJWGHRN.cjs');
@@ -31,7 +31,7 @@ var schematexTools = {
31
31
  listDiagrams: ai.tool({
32
32
  description: "List every Schematex diagram type with a tagline, 'use when' hint, domain cluster, and authoritative standard. Call this first to discover what's available.",
33
33
  inputSchema: zod.z.object({}),
34
- execute: async () => chunkHWNVSNDJ_cjs.listDiagrams()
34
+ execute: async () => chunkHKOPXQYU_cjs.listDiagrams()
35
35
  }),
36
36
  getSyntax: ai.tool({
37
37
  description: "Return syntax for one diagram type. Default `detail: canonical` is the compact first-shot generation path: canonical header, preferred forms, rules, and repair checks. Request `detail: reference` only for advanced forms or imported adapters after choosing a type.",
@@ -46,7 +46,7 @@ var schematexTools = {
46
46
  execute: async ({
47
47
  type,
48
48
  detail
49
- }) => chunkHWNVSNDJ_cjs.getSyntax(type, { detail })
49
+ }) => chunkHKOPXQYU_cjs.getSyntax(type, { detail })
50
50
  }),
51
51
  getExamples: ai.tool({
52
52
  description: "Return curated real-world DSL examples for a diagram type, each with scenario notes and tags. Use as few-shot context before generating DSL.",
@@ -56,7 +56,7 @@ var schematexTools = {
56
56
  preferFeatured: zod.z.boolean().optional().describe("Rank featured examples first."),
57
57
  maxComplexity: zod.z.number().int().min(1).max(5).optional().describe("Only return examples with complexity <= this value (1=simplest).")
58
58
  }),
59
- execute: async (args) => chunkHWNVSNDJ_cjs.getExamples(args.type, {
59
+ execute: async (args) => chunkHKOPXQYU_cjs.getExamples(args.type, {
60
60
  limit: args.limit,
61
61
  preferFeatured: args.preferFeatured,
62
62
  maxComplexity: args.maxComplexity
@@ -70,7 +70,7 @@ var schematexTools = {
70
70
  ),
71
71
  dsl: zod.z.string().describe("The DSL source text to validate.")
72
72
  }),
73
- execute: async ({ type, dsl }) => chunkHWNVSNDJ_cjs.validateDsl(type, dsl)
73
+ execute: async ({ type, dsl }) => chunkHKOPXQYU_cjs.validateDsl(type, dsl)
74
74
  }),
75
75
  renderDsl: ai.tool({
76
76
  description: "Render Schematex DSL to an SVG string. Returns { ok: true, svg } or { ok: false, errors }. Use when the caller needs the actual diagram output, not just validation.",
@@ -85,7 +85,7 @@ var schematexTools = {
85
85
  dsl,
86
86
  theme,
87
87
  padding
88
- }) => chunkHWNVSNDJ_cjs.renderDsl(type, dsl, { theme, padding })
88
+ }) => chunkHKOPXQYU_cjs.renderDsl(type, dsl, { theme, padding })
89
89
  })
90
90
  };
91
91
 
@@ -1,5 +1,5 @@
1
1
  import * as ai from 'ai';
2
- import { c as DiagramListItem, g as GetSyntaxResult, e as GetExamplesResult, V as ValidateDslResult, R as RenderDslResult } from '../tools-CVgUmiGP.cjs';
2
+ import { c as DiagramListItem, g as GetSyntaxResult, e as GetExamplesResult, V as ValidateDslResult, R as RenderDslResult } from '../tools-D5dkAqNy.cjs';
3
3
  import '../api-BDMaX1cT.cjs';
4
4
  import '../diagnostics-hObcaaFC.cjs';
5
5
 
@@ -7,7 +7,7 @@ declare const schematexTools: {
7
7
  readonly listDiagrams: ai.Tool<{}, DiagramListItem[]>;
8
8
  readonly getSyntax: ai.Tool<{
9
9
  type: string;
10
- detail?: "reference" | "canonical" | undefined;
10
+ detail?: "canonical" | "reference" | undefined;
11
11
  }, GetSyntaxResult>;
12
12
  readonly getExamples: ai.Tool<{
13
13
  type: string;
@@ -1,5 +1,5 @@
1
1
  import * as ai from 'ai';
2
- import { c as DiagramListItem, g as GetSyntaxResult, e as GetExamplesResult, V as ValidateDslResult, R as RenderDslResult } from '../tools-CbBjmZVr.js';
2
+ import { c as DiagramListItem, g as GetSyntaxResult, e as GetExamplesResult, V as ValidateDslResult, R as RenderDslResult } from '../tools-BbTuTWs_.js';
3
3
  import '../api-OED2jUVj.js';
4
4
  import '../diagnostics-hObcaaFC.js';
5
5
 
@@ -7,7 +7,7 @@ declare const schematexTools: {
7
7
  readonly listDiagrams: ai.Tool<{}, DiagramListItem[]>;
8
8
  readonly getSyntax: ai.Tool<{
9
9
  type: string;
10
- detail?: "reference" | "canonical" | undefined;
10
+ detail?: "canonical" | "reference" | undefined;
11
11
  }, GetSyntaxResult>;
12
12
  readonly getExamples: ai.Tool<{
13
13
  type: string;
package/dist/ai/ai-sdk.js CHANGED
@@ -1,4 +1,4 @@
1
- import { renderDsl, validateDsl, getExamples, getSyntax, listDiagrams } from '../chunk-FLDHD4RM.js';
1
+ import { renderDsl, validateDsl, getExamples, getSyntax, listDiagrams } from '../chunk-PR6IAGVP.js';
2
2
  import '../chunk-LM5X7ZNR.js';
3
3
  import '../chunk-E3CAJGJM.js';
4
4
  import '../chunk-T3GV7OVF.js';
package/dist/ai/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var chunkHWNVSNDJ_cjs = require('../chunk-HWNVSNDJ.cjs');
3
+ var chunkHKOPXQYU_cjs = require('../chunk-HKOPXQYU.cjs');
4
4
  require('../chunk-UGB42BGK.cjs');
5
5
  require('../chunk-Q2YRJHFB.cjs');
6
6
  require('../chunk-JIJWGHRN.cjs');
@@ -25,51 +25,90 @@ require('../chunk-NZT5P2XZ.cjs');
25
25
  require('../chunk-VHDSPI6A.cjs');
26
26
  require('../chunk-3WNW5Y7P.cjs');
27
27
 
28
-
28
+ // src/ai/prompt-context.ts
29
+ function buildPromptContext(type, opts = {}) {
30
+ const resolved = chunkHKOPXQYU_cjs.resolveDiagramType(type) ?? type;
31
+ const detail = opts.detail ?? "canonical";
32
+ const limit = opts.examples ?? 2;
33
+ const { type: canonical, name, standard, syntax } = chunkHKOPXQYU_cjs.getSyntax(resolved, {
34
+ detail
35
+ });
36
+ const parts = [
37
+ `# ${name} (${canonical})`,
38
+ `Standard: ${standard}`,
39
+ "",
40
+ syntax.content
41
+ ];
42
+ let exampleCount = 0;
43
+ if (limit > 0) {
44
+ const examples = chunkHKOPXQYU_cjs.getExamples(canonical, {
45
+ preferFeatured: opts.preferFeatured ?? true,
46
+ limit,
47
+ maxComplexity: opts.maxComplexity
48
+ }).examples;
49
+ exampleCount = examples.length;
50
+ if (examples.length > 0) {
51
+ parts.push("", "## Worked examples");
52
+ for (const ex of examples) {
53
+ parts.push("", `### ${ex.title}`);
54
+ if (ex.description) parts.push(ex.description);
55
+ parts.push("```", ex.dsl.trim(), "```");
56
+ }
57
+ }
58
+ }
59
+ return {
60
+ type: canonical,
61
+ name,
62
+ standard,
63
+ text: parts.join("\n"),
64
+ exampleCount
65
+ };
66
+ }
29
67
 
30
68
  Object.defineProperty(exports, "DIAGRAM_REGISTRY", {
31
69
  enumerable: true,
32
- get: function () { return chunkHWNVSNDJ_cjs.DIAGRAM_REGISTRY; }
70
+ get: function () { return chunkHKOPXQYU_cjs.DIAGRAM_REGISTRY; }
33
71
  });
34
72
  Object.defineProperty(exports, "DIAGRAM_SINCE", {
35
73
  enumerable: true,
36
- get: function () { return chunkHWNVSNDJ_cjs.DIAGRAM_SINCE; }
74
+ get: function () { return chunkHKOPXQYU_cjs.DIAGRAM_SINCE; }
37
75
  });
38
76
  Object.defineProperty(exports, "getAllDiagramTypes", {
39
77
  enumerable: true,
40
- get: function () { return chunkHWNVSNDJ_cjs.getAllDiagramTypes; }
78
+ get: function () { return chunkHKOPXQYU_cjs.getAllDiagramTypes; }
41
79
  });
42
80
  Object.defineProperty(exports, "getDiagramMeta", {
43
81
  enumerable: true,
44
- get: function () { return chunkHWNVSNDJ_cjs.getDiagramMeta; }
82
+ get: function () { return chunkHKOPXQYU_cjs.getDiagramMeta; }
45
83
  });
46
84
  Object.defineProperty(exports, "getDiagramSince", {
47
85
  enumerable: true,
48
- get: function () { return chunkHWNVSNDJ_cjs.getDiagramSince; }
86
+ get: function () { return chunkHKOPXQYU_cjs.getDiagramSince; }
49
87
  });
50
88
  Object.defineProperty(exports, "getExamples", {
51
89
  enumerable: true,
52
- get: function () { return chunkHWNVSNDJ_cjs.getExamples; }
90
+ get: function () { return chunkHKOPXQYU_cjs.getExamples; }
53
91
  });
54
92
  Object.defineProperty(exports, "getSyntax", {
55
93
  enumerable: true,
56
- get: function () { return chunkHWNVSNDJ_cjs.getSyntax; }
94
+ get: function () { return chunkHKOPXQYU_cjs.getSyntax; }
57
95
  });
58
96
  Object.defineProperty(exports, "listDiagrams", {
59
97
  enumerable: true,
60
- get: function () { return chunkHWNVSNDJ_cjs.listDiagrams; }
98
+ get: function () { return chunkHKOPXQYU_cjs.listDiagrams; }
61
99
  });
62
100
  Object.defineProperty(exports, "renderDsl", {
63
101
  enumerable: true,
64
- get: function () { return chunkHWNVSNDJ_cjs.renderDsl; }
102
+ get: function () { return chunkHKOPXQYU_cjs.renderDsl; }
65
103
  });
66
104
  Object.defineProperty(exports, "resolveDiagramType", {
67
105
  enumerable: true,
68
- get: function () { return chunkHWNVSNDJ_cjs.resolveDiagramType; }
106
+ get: function () { return chunkHKOPXQYU_cjs.resolveDiagramType; }
69
107
  });
70
108
  Object.defineProperty(exports, "validateDsl", {
71
109
  enumerable: true,
72
- get: function () { return chunkHWNVSNDJ_cjs.validateDsl; }
110
+ get: function () { return chunkHKOPXQYU_cjs.validateDsl; }
73
111
  });
112
+ exports.buildPromptContext = buildPromptContext;
74
113
  //# sourceMappingURL=index.cjs.map
75
114
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"index.cjs"}
1
+ {"version":3,"sources":["../../src/ai/prompt-context.ts"],"names":["resolveDiagramType","getSyntax","getExamples"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4CO,SAAS,kBAAA,CACd,IAAA,EACA,IAAA,GAAkC,EAAC,EACpB;AACf,EAAA,MAAM,QAAA,GAAWA,oCAAA,CAAmB,IAAI,CAAA,IAAK,IAAA;AAC7C,EAAA,MAAM,MAAA,GAAuB,KAAK,MAAA,IAAU,WAAA;AAC5C,EAAA,MAAM,KAAA,GAAQ,KAAK,QAAA,IAAY,CAAA;AAE/B,EAAA,MAAM,EAAE,MAAM,SAAA,EAAW,IAAA,EAAM,UAAU,MAAA,EAAO,GAAIC,4BAAU,QAAA,EAAU;AAAA,IACtE;AAAA,GACD,CAAA;AAED,EAAA,MAAM,KAAA,GAAkB;AAAA,IACtB,CAAA,EAAA,EAAK,IAAI,CAAA,EAAA,EAAK,SAAS,CAAA,CAAA,CAAA;AAAA,IACvB,aAAa,QAAQ,CAAA,CAAA;AAAA,IACrB,EAAA;AAAA,IACA,MAAA,CAAO;AAAA,GACT;AAEA,EAAA,IAAI,YAAA,GAAe,CAAA;AACnB,EAAA,IAAI,QAAQ,CAAA,EAAG;AACb,IAAA,MAAM,QAAA,GAAWC,8BAAY,SAAA,EAAW;AAAA,MACtC,cAAA,EAAgB,KAAK,cAAA,IAAkB,IAAA;AAAA,MACvC,KAAA;AAAA,MACA,eAAe,IAAA,CAAK;AAAA,KACrB,CAAA,CAAE,QAAA;AACH,IAAA,YAAA,GAAe,QAAA,CAAS,MAAA;AACxB,IAAA,IAAI,QAAA,CAAS,SAAS,CAAA,EAAG;AACvB,MAAA,KAAA,CAAM,IAAA,CAAK,IAAI,oBAAoB,CAAA;AACnC,MAAA,KAAA,MAAW,MAAM,QAAA,EAAU;AACzB,QAAA,KAAA,CAAM,IAAA,CAAK,EAAA,EAAI,CAAA,IAAA,EAAO,EAAA,CAAG,KAAK,CAAA,CAAE,CAAA;AAChC,QAAA,IAAI,EAAA,CAAG,WAAA,EAAa,KAAA,CAAM,IAAA,CAAK,GAAG,WAAW,CAAA;AAC7C,QAAA,KAAA,CAAM,KAAK,KAAA,EAAO,EAAA,CAAG,GAAA,CAAI,IAAA,IAAQ,KAAK,CAAA;AAAA,MACxC;AAAA,IACF;AAAA,EACF;AAEA,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,SAAA;AAAA,IACN,IAAA;AAAA,IACA,QAAA;AAAA,IACA,IAAA,EAAM,KAAA,CAAM,IAAA,CAAK,IAAI,CAAA;AAAA,IACrB;AAAA,GACF;AACF","file":"index.cjs","sourcesContent":["/**\n * Prompt-context builder — a convenience wrapper for single-shot LLM callers.\n *\n * Agentic callers can keep using `getSyntax` + `getExamples` as separate tool\n * round-trips. But a high-volume single-shot caller (e.g. a product backend\n * generating DSL with one model call, no tool loop) just wants ONE inject-ready\n * block: the canonical grammar card plus a couple of worked few-shot examples.\n *\n * This adds no new knowledge — it stitches `getSyntax(detail: \"canonical\")` and\n * `getExamples(preferFeatured)` into one string so the caller doesn't have to\n * know the recipe. Both primitives remain exported and usable on their own.\n */\nimport { resolveDiagramType } from \"./registry\";\nimport { getExamples, getSyntax } from \"./tools\";\nimport type { SyntaxDetail } from \"./syntax\";\n\nexport interface BuildPromptContextOptions {\n /** How many few-shot examples to embed. Default 2. Set 0 to omit examples. */\n examples?: number;\n /** Syntax detail level. Default `\"canonical\"` (the compact first-shot card). */\n detail?: SyntaxDetail;\n /** Prefer `featured: true` examples first. Default true. */\n preferFeatured?: boolean;\n /** Cap embedded example complexity (1–5). */\n maxComplexity?: number;\n}\n\nexport interface PromptContext {\n type: string;\n name: string;\n standard: string;\n /** One inject-ready markdown block: grammar card + worked examples. */\n text: string;\n /** Number of examples embedded in `text`. */\n exampleCount: number;\n}\n\n/**\n * Build a single inject-ready prompt block for one diagram type.\n *\n * @example\n * const ctx = buildPromptContext(\"genogram\");\n * const systemPrompt = `Generate Schematex DSL.\\n\\n${ctx.text}`;\n */\nexport function buildPromptContext(\n type: string,\n opts: BuildPromptContextOptions = {}\n): PromptContext {\n const resolved = resolveDiagramType(type) ?? type;\n const detail: SyntaxDetail = opts.detail ?? \"canonical\";\n const limit = opts.examples ?? 2;\n\n const { type: canonical, name, standard, syntax } = getSyntax(resolved, {\n detail,\n });\n\n const parts: string[] = [\n `# ${name} (${canonical})`,\n `Standard: ${standard}`,\n \"\",\n syntax.content,\n ];\n\n let exampleCount = 0;\n if (limit > 0) {\n const examples = getExamples(canonical, {\n preferFeatured: opts.preferFeatured ?? true,\n limit,\n maxComplexity: opts.maxComplexity,\n }).examples;\n exampleCount = examples.length;\n if (examples.length > 0) {\n parts.push(\"\", \"## Worked examples\");\n for (const ex of examples) {\n parts.push(\"\", `### ${ex.title}`);\n if (ex.description) parts.push(ex.description);\n parts.push(\"```\", ex.dsl.trim(), \"```\");\n }\n }\n }\n\n return {\n type: canonical,\n name,\n standard,\n text: parts.join(\"\\n\"),\n exampleCount,\n };\n}\n"]}
@@ -1,7 +1,36 @@
1
- export { D as DIAGRAM_REGISTRY, a as DIAGRAM_SINCE, b as DiagramCluster, c as DiagramListItem, d as DiagramMeta, E as Example, G as GetExamplesOptions, e as GetExamplesResult, f as GetSyntaxOptions, g as GetSyntaxResult, R as RenderDslResult, S as SchematexValidationError, h as SyntaxDetail, i as SyntaxDoc, V as ValidateDslResult, j as getAllDiagramTypes, k as getDiagramMeta, l as getDiagramSince, m as getExamples, n as getSyntax, o as listDiagrams, r as renderDsl, p as resolveDiagramType, v as validateDsl } from '../tools-CVgUmiGP.cjs';
1
+ import { S as SyntaxDetail } from '../tools-D5dkAqNy.cjs';
2
+ export { D as DIAGRAM_REGISTRY, a as DIAGRAM_SINCE, b as DiagramCluster, c as DiagramListItem, d as DiagramMeta, E as Example, G as GetExamplesOptions, e as GetExamplesResult, f as GetSyntaxOptions, g as GetSyntaxResult, R as RenderDslResult, h as SchematexValidationError, i as SyntaxDoc, V as ValidateDslResult, j as getAllDiagramTypes, k as getDiagramMeta, l as getDiagramSince, m as getExamples, n as getSyntax, o as listDiagrams, r as renderDsl, p as resolveDiagramType, v as validateDsl } from '../tools-D5dkAqNy.cjs';
2
3
  import { a as DiagramType } from '../diagnostics-hObcaaFC.cjs';
3
4
  import '../api-BDMaX1cT.cjs';
4
5
 
6
+ interface BuildPromptContextOptions {
7
+ /** How many few-shot examples to embed. Default 2. Set 0 to omit examples. */
8
+ examples?: number;
9
+ /** Syntax detail level. Default `"canonical"` (the compact first-shot card). */
10
+ detail?: SyntaxDetail;
11
+ /** Prefer `featured: true` examples first. Default true. */
12
+ preferFeatured?: boolean;
13
+ /** Cap embedded example complexity (1–5). */
14
+ maxComplexity?: number;
15
+ }
16
+ interface PromptContext {
17
+ type: string;
18
+ name: string;
19
+ standard: string;
20
+ /** One inject-ready markdown block: grammar card + worked examples. */
21
+ text: string;
22
+ /** Number of examples embedded in `text`. */
23
+ exampleCount: number;
24
+ }
25
+ /**
26
+ * Build a single inject-ready prompt block for one diagram type.
27
+ *
28
+ * @example
29
+ * const ctx = buildPromptContext("genogram");
30
+ * const systemPrompt = `Generate Schematex DSL.\n\n${ctx.text}`;
31
+ */
32
+ declare function buildPromptContext(type: string, opts?: BuildPromptContextOptions): PromptContext;
33
+
5
34
  interface GenerationProfile {
6
35
  /** Canonical type id from `listDiagrams()`. */
7
36
  type: DiagramType;
@@ -9,6 +38,12 @@ interface GenerationProfile {
9
38
  header: string;
10
39
  /** Short name for the preferred authoring mode when a parser has several. */
11
40
  mode: string;
41
+ /**
42
+ * Compact one-line vocabulary — the full set of keywords / operators / tokens
43
+ * the parser accepts, so a single-shot caller sees the whole surface without
44
+ * fetching the `reference` syntax. Optional.
45
+ */
46
+ keywords?: string;
12
47
  /** Forms that cover most first-shot generations for this type. */
13
48
  forms: readonly string[];
14
49
  /** Short grammar choices the model should make by default. */
@@ -19,4 +54,4 @@ interface GenerationProfile {
19
54
  repair: readonly string[];
20
55
  }
21
56
 
22
- export { DiagramType, type GenerationProfile };
57
+ export { type BuildPromptContextOptions, DiagramType, type GenerationProfile, type PromptContext, SyntaxDetail, buildPromptContext };
@@ -1,7 +1,36 @@
1
- export { D as DIAGRAM_REGISTRY, a as DIAGRAM_SINCE, b as DiagramCluster, c as DiagramListItem, d as DiagramMeta, E as Example, G as GetExamplesOptions, e as GetExamplesResult, f as GetSyntaxOptions, g as GetSyntaxResult, R as RenderDslResult, S as SchematexValidationError, h as SyntaxDetail, i as SyntaxDoc, V as ValidateDslResult, j as getAllDiagramTypes, k as getDiagramMeta, l as getDiagramSince, m as getExamples, n as getSyntax, o as listDiagrams, r as renderDsl, p as resolveDiagramType, v as validateDsl } from '../tools-CbBjmZVr.js';
1
+ import { S as SyntaxDetail } from '../tools-BbTuTWs_.js';
2
+ export { D as DIAGRAM_REGISTRY, a as DIAGRAM_SINCE, b as DiagramCluster, c as DiagramListItem, d as DiagramMeta, E as Example, G as GetExamplesOptions, e as GetExamplesResult, f as GetSyntaxOptions, g as GetSyntaxResult, R as RenderDslResult, h as SchematexValidationError, i as SyntaxDoc, V as ValidateDslResult, j as getAllDiagramTypes, k as getDiagramMeta, l as getDiagramSince, m as getExamples, n as getSyntax, o as listDiagrams, r as renderDsl, p as resolveDiagramType, v as validateDsl } from '../tools-BbTuTWs_.js';
2
3
  import { a as DiagramType } from '../diagnostics-hObcaaFC.js';
3
4
  import '../api-OED2jUVj.js';
4
5
 
6
+ interface BuildPromptContextOptions {
7
+ /** How many few-shot examples to embed. Default 2. Set 0 to omit examples. */
8
+ examples?: number;
9
+ /** Syntax detail level. Default `"canonical"` (the compact first-shot card). */
10
+ detail?: SyntaxDetail;
11
+ /** Prefer `featured: true` examples first. Default true. */
12
+ preferFeatured?: boolean;
13
+ /** Cap embedded example complexity (1–5). */
14
+ maxComplexity?: number;
15
+ }
16
+ interface PromptContext {
17
+ type: string;
18
+ name: string;
19
+ standard: string;
20
+ /** One inject-ready markdown block: grammar card + worked examples. */
21
+ text: string;
22
+ /** Number of examples embedded in `text`. */
23
+ exampleCount: number;
24
+ }
25
+ /**
26
+ * Build a single inject-ready prompt block for one diagram type.
27
+ *
28
+ * @example
29
+ * const ctx = buildPromptContext("genogram");
30
+ * const systemPrompt = `Generate Schematex DSL.\n\n${ctx.text}`;
31
+ */
32
+ declare function buildPromptContext(type: string, opts?: BuildPromptContextOptions): PromptContext;
33
+
5
34
  interface GenerationProfile {
6
35
  /** Canonical type id from `listDiagrams()`. */
7
36
  type: DiagramType;
@@ -9,6 +38,12 @@ interface GenerationProfile {
9
38
  header: string;
10
39
  /** Short name for the preferred authoring mode when a parser has several. */
11
40
  mode: string;
41
+ /**
42
+ * Compact one-line vocabulary — the full set of keywords / operators / tokens
43
+ * the parser accepts, so a single-shot caller sees the whole surface without
44
+ * fetching the `reference` syntax. Optional.
45
+ */
46
+ keywords?: string;
12
47
  /** Forms that cover most first-shot generations for this type. */
13
48
  forms: readonly string[];
14
49
  /** Short grammar choices the model should make by default. */
@@ -19,4 +54,4 @@ interface GenerationProfile {
19
54
  repair: readonly string[];
20
55
  }
21
56
 
22
- export { DiagramType, type GenerationProfile };
57
+ export { type BuildPromptContextOptions, DiagramType, type GenerationProfile, type PromptContext, SyntaxDetail, buildPromptContext };
package/dist/ai/index.js CHANGED
@@ -1,4 +1,5 @@
1
- export { DIAGRAM_REGISTRY, DIAGRAM_SINCE, getAllDiagramTypes, getDiagramMeta, getDiagramSince, getExamples, getSyntax, listDiagrams, renderDsl, resolveDiagramType, validateDsl } from '../chunk-FLDHD4RM.js';
1
+ import { resolveDiagramType, getSyntax, getExamples } from '../chunk-PR6IAGVP.js';
2
+ export { DIAGRAM_REGISTRY, DIAGRAM_SINCE, getAllDiagramTypes, getDiagramMeta, getDiagramSince, getExamples, getSyntax, listDiagrams, renderDsl, resolveDiagramType, validateDsl } from '../chunk-PR6IAGVP.js';
2
3
  import '../chunk-LM5X7ZNR.js';
3
4
  import '../chunk-E3CAJGJM.js';
4
5
  import '../chunk-T3GV7OVF.js';
@@ -22,5 +23,47 @@ import '../chunk-PIV2A3HG.js';
22
23
  import '../chunk-UK6HF6PE.js';
23
24
  import '../chunk-TO6PNBT3.js';
24
25
  import '../chunk-SYYBKDL7.js';
26
+
27
+ // src/ai/prompt-context.ts
28
+ function buildPromptContext(type, opts = {}) {
29
+ const resolved = resolveDiagramType(type) ?? type;
30
+ const detail = opts.detail ?? "canonical";
31
+ const limit = opts.examples ?? 2;
32
+ const { type: canonical, name, standard, syntax } = getSyntax(resolved, {
33
+ detail
34
+ });
35
+ const parts = [
36
+ `# ${name} (${canonical})`,
37
+ `Standard: ${standard}`,
38
+ "",
39
+ syntax.content
40
+ ];
41
+ let exampleCount = 0;
42
+ if (limit > 0) {
43
+ const examples = getExamples(canonical, {
44
+ preferFeatured: opts.preferFeatured ?? true,
45
+ limit,
46
+ maxComplexity: opts.maxComplexity
47
+ }).examples;
48
+ exampleCount = examples.length;
49
+ if (examples.length > 0) {
50
+ parts.push("", "## Worked examples");
51
+ for (const ex of examples) {
52
+ parts.push("", `### ${ex.title}`);
53
+ if (ex.description) parts.push(ex.description);
54
+ parts.push("```", ex.dsl.trim(), "```");
55
+ }
56
+ }
57
+ }
58
+ return {
59
+ type: canonical,
60
+ name,
61
+ standard,
62
+ text: parts.join("\n"),
63
+ exampleCount
64
+ };
65
+ }
66
+
67
+ export { buildPromptContext };
25
68
  //# sourceMappingURL=index.js.map
26
69
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
1
+ {"version":3,"sources":["../../src/ai/prompt-context.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA4CO,SAAS,kBAAA,CACd,IAAA,EACA,IAAA,GAAkC,EAAC,EACpB;AACf,EAAA,MAAM,QAAA,GAAW,kBAAA,CAAmB,IAAI,CAAA,IAAK,IAAA;AAC7C,EAAA,MAAM,MAAA,GAAuB,KAAK,MAAA,IAAU,WAAA;AAC5C,EAAA,MAAM,KAAA,GAAQ,KAAK,QAAA,IAAY,CAAA;AAE/B,EAAA,MAAM,EAAE,MAAM,SAAA,EAAW,IAAA,EAAM,UAAU,MAAA,EAAO,GAAI,UAAU,QAAA,EAAU;AAAA,IACtE;AAAA,GACD,CAAA;AAED,EAAA,MAAM,KAAA,GAAkB;AAAA,IACtB,CAAA,EAAA,EAAK,IAAI,CAAA,EAAA,EAAK,SAAS,CAAA,CAAA,CAAA;AAAA,IACvB,aAAa,QAAQ,CAAA,CAAA;AAAA,IACrB,EAAA;AAAA,IACA,MAAA,CAAO;AAAA,GACT;AAEA,EAAA,IAAI,YAAA,GAAe,CAAA;AACnB,EAAA,IAAI,QAAQ,CAAA,EAAG;AACb,IAAA,MAAM,QAAA,GAAW,YAAY,SAAA,EAAW;AAAA,MACtC,cAAA,EAAgB,KAAK,cAAA,IAAkB,IAAA;AAAA,MACvC,KAAA;AAAA,MACA,eAAe,IAAA,CAAK;AAAA,KACrB,CAAA,CAAE,QAAA;AACH,IAAA,YAAA,GAAe,QAAA,CAAS,MAAA;AACxB,IAAA,IAAI,QAAA,CAAS,SAAS,CAAA,EAAG;AACvB,MAAA,KAAA,CAAM,IAAA,CAAK,IAAI,oBAAoB,CAAA;AACnC,MAAA,KAAA,MAAW,MAAM,QAAA,EAAU;AACzB,QAAA,KAAA,CAAM,IAAA,CAAK,EAAA,EAAI,CAAA,IAAA,EAAO,EAAA,CAAG,KAAK,CAAA,CAAE,CAAA;AAChC,QAAA,IAAI,EAAA,CAAG,WAAA,EAAa,KAAA,CAAM,IAAA,CAAK,GAAG,WAAW,CAAA;AAC7C,QAAA,KAAA,CAAM,KAAK,KAAA,EAAO,EAAA,CAAG,GAAA,CAAI,IAAA,IAAQ,KAAK,CAAA;AAAA,MACxC;AAAA,IACF;AAAA,EACF;AAEA,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,SAAA;AAAA,IACN,IAAA;AAAA,IACA,QAAA;AAAA,IACA,IAAA,EAAM,KAAA,CAAM,IAAA,CAAK,IAAI,CAAA;AAAA,IACrB;AAAA,GACF;AACF","file":"index.js","sourcesContent":["/**\n * Prompt-context builder — a convenience wrapper for single-shot LLM callers.\n *\n * Agentic callers can keep using `getSyntax` + `getExamples` as separate tool\n * round-trips. But a high-volume single-shot caller (e.g. a product backend\n * generating DSL with one model call, no tool loop) just wants ONE inject-ready\n * block: the canonical grammar card plus a couple of worked few-shot examples.\n *\n * This adds no new knowledge — it stitches `getSyntax(detail: \"canonical\")` and\n * `getExamples(preferFeatured)` into one string so the caller doesn't have to\n * know the recipe. Both primitives remain exported and usable on their own.\n */\nimport { resolveDiagramType } from \"./registry\";\nimport { getExamples, getSyntax } from \"./tools\";\nimport type { SyntaxDetail } from \"./syntax\";\n\nexport interface BuildPromptContextOptions {\n /** How many few-shot examples to embed. Default 2. Set 0 to omit examples. */\n examples?: number;\n /** Syntax detail level. Default `\"canonical\"` (the compact first-shot card). */\n detail?: SyntaxDetail;\n /** Prefer `featured: true` examples first. Default true. */\n preferFeatured?: boolean;\n /** Cap embedded example complexity (1–5). */\n maxComplexity?: number;\n}\n\nexport interface PromptContext {\n type: string;\n name: string;\n standard: string;\n /** One inject-ready markdown block: grammar card + worked examples. */\n text: string;\n /** Number of examples embedded in `text`. */\n exampleCount: number;\n}\n\n/**\n * Build a single inject-ready prompt block for one diagram type.\n *\n * @example\n * const ctx = buildPromptContext(\"genogram\");\n * const systemPrompt = `Generate Schematex DSL.\\n\\n${ctx.text}`;\n */\nexport function buildPromptContext(\n type: string,\n opts: BuildPromptContextOptions = {}\n): PromptContext {\n const resolved = resolveDiagramType(type) ?? type;\n const detail: SyntaxDetail = opts.detail ?? \"canonical\";\n const limit = opts.examples ?? 2;\n\n const { type: canonical, name, standard, syntax } = getSyntax(resolved, {\n detail,\n });\n\n const parts: string[] = [\n `# ${name} (${canonical})`,\n `Standard: ${standard}`,\n \"\",\n syntax.content,\n ];\n\n let exampleCount = 0;\n if (limit > 0) {\n const examples = getExamples(canonical, {\n preferFeatured: opts.preferFeatured ?? true,\n limit,\n maxComplexity: opts.maxComplexity,\n }).examples;\n exampleCount = examples.length;\n if (examples.length > 0) {\n parts.push(\"\", \"## Worked examples\");\n for (const ex of examples) {\n parts.push(\"\", `### ${ex.title}`);\n if (ex.description) parts.push(ex.description);\n parts.push(\"```\", ex.dsl.trim(), \"```\");\n }\n }\n }\n\n return {\n type: canonical,\n name,\n standard,\n text: parts.join(\"\\n\"),\n exampleCount,\n };\n}\n"]}