@deepagents/text2sql 0.2.3 → 0.3.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.
Files changed (139) hide show
  1. package/dist/index.d.ts +7 -9
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +879 -2730
  4. package/dist/index.js.map +4 -4
  5. package/dist/lib/adapters/adapter.d.ts +72 -10
  6. package/dist/lib/adapters/adapter.d.ts.map +1 -1
  7. package/dist/lib/adapters/grounding.ticket.d.ts +21 -0
  8. package/dist/lib/adapters/grounding.ticket.d.ts.map +1 -0
  9. package/dist/lib/adapters/groundings/column-stats.grounding.d.ts +32 -0
  10. package/dist/lib/adapters/groundings/column-stats.grounding.d.ts.map +1 -0
  11. package/dist/lib/adapters/groundings/constraint.grounding.d.ts +31 -0
  12. package/dist/lib/adapters/groundings/constraint.grounding.d.ts.map +1 -0
  13. package/dist/lib/adapters/groundings/context.d.ts +41 -0
  14. package/dist/lib/adapters/groundings/context.d.ts.map +1 -0
  15. package/dist/lib/adapters/groundings/grounding.d.ts +8 -0
  16. package/dist/lib/adapters/groundings/grounding.d.ts.map +1 -0
  17. package/dist/lib/adapters/groundings/grounding.js +507 -0
  18. package/dist/lib/adapters/groundings/grounding.js.map +7 -0
  19. package/dist/lib/adapters/groundings/indexes.grounding.d.ts +30 -0
  20. package/dist/lib/adapters/groundings/indexes.grounding.d.ts.map +1 -0
  21. package/dist/lib/adapters/groundings/info.grounding.d.ts +29 -0
  22. package/dist/lib/adapters/groundings/info.grounding.d.ts.map +1 -0
  23. package/dist/lib/adapters/groundings/low-cardinality.grounding.d.ts +35 -0
  24. package/dist/lib/adapters/groundings/low-cardinality.grounding.d.ts.map +1 -0
  25. package/dist/lib/adapters/groundings/report.grounding.d.ts +38 -0
  26. package/dist/lib/adapters/groundings/report.grounding.d.ts.map +1 -0
  27. package/dist/lib/adapters/groundings/row-count.grounding.d.ts +30 -0
  28. package/dist/lib/adapters/groundings/row-count.grounding.d.ts.map +1 -0
  29. package/dist/lib/adapters/groundings/table.grounding.d.ts +61 -0
  30. package/dist/lib/adapters/groundings/table.grounding.d.ts.map +1 -0
  31. package/dist/lib/adapters/groundings/view.grounding.d.ts +57 -0
  32. package/dist/lib/adapters/groundings/view.grounding.d.ts.map +1 -0
  33. package/dist/lib/adapters/postgres/column-stats.postgres.grounding.d.ts +12 -0
  34. package/dist/lib/adapters/postgres/column-stats.postgres.grounding.d.ts.map +1 -0
  35. package/dist/lib/adapters/postgres/constraint.postgres.grounding.d.ts +11 -0
  36. package/dist/lib/adapters/postgres/constraint.postgres.grounding.d.ts.map +1 -0
  37. package/dist/lib/adapters/postgres/index.d.ts +43 -0
  38. package/dist/lib/adapters/postgres/index.d.ts.map +1 -0
  39. package/dist/lib/adapters/postgres/index.js +1646 -0
  40. package/dist/lib/adapters/postgres/index.js.map +7 -0
  41. package/dist/lib/adapters/postgres/indexes.postgres.grounding.d.ts +15 -0
  42. package/dist/lib/adapters/postgres/indexes.postgres.grounding.d.ts.map +1 -0
  43. package/dist/lib/adapters/postgres/info.postgres.grounding.d.ts +11 -0
  44. package/dist/lib/adapters/postgres/info.postgres.grounding.d.ts.map +1 -0
  45. package/dist/lib/adapters/postgres/low-cardinality.postgres.grounding.d.ts +14 -0
  46. package/dist/lib/adapters/postgres/low-cardinality.postgres.grounding.d.ts.map +1 -0
  47. package/dist/lib/adapters/postgres/postgres.d.ts +27 -0
  48. package/dist/lib/adapters/postgres/postgres.d.ts.map +1 -0
  49. package/dist/lib/adapters/postgres/row-count.postgres.grounding.d.ts +11 -0
  50. package/dist/lib/adapters/postgres/row-count.postgres.grounding.d.ts.map +1 -0
  51. package/dist/lib/adapters/postgres/table.postgres.grounding.d.ts +21 -0
  52. package/dist/lib/adapters/postgres/table.postgres.grounding.d.ts.map +1 -0
  53. package/dist/lib/adapters/postgres/view.postgres.grounding.d.ts +16 -0
  54. package/dist/lib/adapters/postgres/view.postgres.grounding.d.ts.map +1 -0
  55. package/dist/lib/adapters/sqlite/column-stats.sqlite.grounding.d.ts +12 -0
  56. package/dist/lib/adapters/sqlite/column-stats.sqlite.grounding.d.ts.map +1 -0
  57. package/dist/lib/adapters/sqlite/constraint.sqlite.grounding.d.ts +15 -0
  58. package/dist/lib/adapters/sqlite/constraint.sqlite.grounding.d.ts.map +1 -0
  59. package/dist/lib/adapters/sqlite/index.d.ts +43 -0
  60. package/dist/lib/adapters/sqlite/index.d.ts.map +1 -0
  61. package/dist/lib/adapters/sqlite/index.js +1219 -0
  62. package/dist/lib/adapters/sqlite/index.js.map +7 -0
  63. package/dist/lib/adapters/sqlite/indexes.sqlite.grounding.d.ts +11 -0
  64. package/dist/lib/adapters/sqlite/indexes.sqlite.grounding.d.ts.map +1 -0
  65. package/dist/lib/adapters/sqlite/info.sqlite.grounding.d.ts +11 -0
  66. package/dist/lib/adapters/sqlite/info.sqlite.grounding.d.ts.map +1 -0
  67. package/dist/lib/adapters/sqlite/low-cardinality.sqlite.grounding.d.ts +14 -0
  68. package/dist/lib/adapters/sqlite/low-cardinality.sqlite.grounding.d.ts.map +1 -0
  69. package/dist/lib/adapters/sqlite/row-count.sqlite.grounding.d.ts +11 -0
  70. package/dist/lib/adapters/sqlite/row-count.sqlite.grounding.d.ts.map +1 -0
  71. package/dist/lib/adapters/sqlite/sqlite.d.ts +26 -0
  72. package/dist/lib/adapters/sqlite/sqlite.d.ts.map +1 -0
  73. package/dist/lib/adapters/sqlite/table.sqlite.grounding.d.ts +17 -0
  74. package/dist/lib/adapters/sqlite/table.sqlite.grounding.d.ts.map +1 -0
  75. package/dist/lib/adapters/sqlite/view.sqlite.grounding.d.ts +12 -0
  76. package/dist/lib/adapters/sqlite/view.sqlite.grounding.d.ts.map +1 -0
  77. package/dist/lib/adapters/sqlserver/column-stats.sqlserver.grounding.d.ts +12 -0
  78. package/dist/lib/adapters/sqlserver/column-stats.sqlserver.grounding.d.ts.map +1 -0
  79. package/dist/lib/adapters/sqlserver/constraint.sqlserver.grounding.d.ts +11 -0
  80. package/dist/lib/adapters/sqlserver/constraint.sqlserver.grounding.d.ts.map +1 -0
  81. package/dist/lib/adapters/sqlserver/index.d.ts +43 -0
  82. package/dist/lib/adapters/sqlserver/index.d.ts.map +1 -0
  83. package/dist/lib/adapters/sqlserver/index.js +1699 -0
  84. package/dist/lib/adapters/sqlserver/index.js.map +7 -0
  85. package/dist/lib/adapters/sqlserver/indexes.sqlserver.grounding.d.ts +15 -0
  86. package/dist/lib/adapters/sqlserver/indexes.sqlserver.grounding.d.ts.map +1 -0
  87. package/dist/lib/adapters/sqlserver/info.sqlserver.grounding.d.ts +11 -0
  88. package/dist/lib/adapters/sqlserver/info.sqlserver.grounding.d.ts.map +1 -0
  89. package/dist/lib/adapters/sqlserver/low-cardinality.sqlserver.grounding.d.ts +14 -0
  90. package/dist/lib/adapters/sqlserver/low-cardinality.sqlserver.grounding.d.ts.map +1 -0
  91. package/dist/lib/adapters/sqlserver/row-count.sqlserver.grounding.d.ts +11 -0
  92. package/dist/lib/adapters/sqlserver/row-count.sqlserver.grounding.d.ts.map +1 -0
  93. package/dist/lib/adapters/sqlserver/sqlserver.d.ts +27 -0
  94. package/dist/lib/adapters/sqlserver/sqlserver.d.ts.map +1 -0
  95. package/dist/lib/adapters/sqlserver/table.sqlserver.grounding.d.ts +21 -0
  96. package/dist/lib/adapters/sqlserver/table.sqlserver.grounding.d.ts.map +1 -0
  97. package/dist/lib/adapters/sqlserver/view.sqlserver.grounding.d.ts +16 -0
  98. package/dist/lib/adapters/sqlserver/view.sqlserver.grounding.d.ts.map +1 -0
  99. package/dist/lib/agents/suggestions.agents.d.ts +0 -2
  100. package/dist/lib/agents/suggestions.agents.d.ts.map +1 -1
  101. package/dist/lib/agents/teachables.agent.d.ts +0 -3
  102. package/dist/lib/agents/teachables.agent.d.ts.map +1 -1
  103. package/dist/lib/agents/text2sql.agent.d.ts +69 -29
  104. package/dist/lib/agents/text2sql.agent.d.ts.map +1 -1
  105. package/dist/lib/file-cache.d.ts +12 -0
  106. package/dist/lib/file-cache.d.ts.map +1 -0
  107. package/dist/lib/instructions.d.ts +3 -0
  108. package/dist/lib/instructions.d.ts.map +1 -0
  109. package/dist/lib/instructions.js +386 -0
  110. package/dist/lib/instructions.js.map +7 -0
  111. package/dist/lib/memory/memory.prompt.d.ts +3 -0
  112. package/dist/lib/memory/memory.prompt.d.ts.map +1 -0
  113. package/dist/lib/memory/memory.store.d.ts +5 -0
  114. package/dist/lib/memory/memory.store.d.ts.map +1 -0
  115. package/dist/lib/memory/sqlite.store.d.ts +14 -0
  116. package/dist/lib/memory/sqlite.store.d.ts.map +1 -0
  117. package/dist/lib/memory/store.d.ts +40 -0
  118. package/dist/lib/memory/store.d.ts.map +1 -0
  119. package/dist/lib/prompt.d.ts +1 -6
  120. package/dist/lib/prompt.d.ts.map +1 -1
  121. package/dist/lib/sql.d.ts +26 -35
  122. package/dist/lib/sql.d.ts.map +1 -1
  123. package/dist/lib/teach/teachables.d.ts +184 -13
  124. package/dist/lib/teach/teachables.d.ts.map +1 -1
  125. package/dist/lib/teach/teachings.d.ts.map +1 -1
  126. package/dist/lib/teach/xml.d.ts.map +1 -1
  127. package/package.json +38 -4
  128. package/dist/lib/adapters/postgres.d.ts +0 -31
  129. package/dist/lib/adapters/postgres.d.ts.map +0 -1
  130. package/dist/lib/adapters/resolveTables.spec.d.ts +0 -2
  131. package/dist/lib/adapters/resolveTables.spec.d.ts.map +0 -1
  132. package/dist/lib/adapters/sqlite.d.ts +0 -30
  133. package/dist/lib/adapters/sqlite.d.ts.map +0 -1
  134. package/dist/lib/adapters/sqlserver.d.ts +0 -31
  135. package/dist/lib/adapters/sqlserver.d.ts.map +0 -1
  136. package/dist/lib/agents/brief.agent.d.ts +0 -21
  137. package/dist/lib/agents/brief.agent.d.ts.map +0 -1
  138. package/dist/lib/memory/user-profile.d.ts +0 -39
  139. package/dist/lib/memory/user-profile.d.ts.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"text2sql.agent.d.ts","sourceRoot":"","sources":["../../../src/lib/agents/text2sql.agent.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,IAAI,EAAQ,MAAM,IAAI,CAAC;AAWrC,OAAO,KAAK,EAAW,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAGrE,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC;AAsKlE,eAAO,MAAM,YAAY;SAzDhB,MAAM;;mBAEI,aAAa;aACnB,MAAM;iBACF,MAAM;qBACF,cAAc;eACpB,MAAM;kBACH,MAAM;;mBALL,aAAa;aACnB,MAAM;iBACF,MAAM;qBACF,cAAc;eACpB,MAAM;kBACH,MAAM;EAwEtB,CAAC;AAEH,eAAO,MAAM,gBAAgB;SAjFpB,MAAM;;mBAEI,aAAa;aACnB,MAAM;iBACF,MAAM;qBACF,cAAc;eACpB,MAAM;kBACH,MAAM;;mBALL,aAAa;aACnB,MAAM;iBACF,MAAM;qBACF,cAAc;eACpB,MAAM;kBACH,MAAM;EA8EtB,CAAC"}
1
+ {"version":3,"file":"text2sql.agent.d.ts","sourceRoot":"","sources":["../../../src/lib/agents/text2sql.agent.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,IAAI,EAAQ,MAAM,IAAI,CAAC;AAarC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAEjE,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC;AAmHlE,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgEvB,CAAC;AAgCF,eAAO,MAAM,aAAa,wIAqBxB,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,KAAK;SACT,MAAM;;mBAGI,MAAM;eACV,MAAM;aACR,eAAe;aACf,MAAM;;mBAHA,MAAM;eACV,MAAM;aACR,eAAe;aACf,MAAM;EAiBjB,CAAC"}
@@ -0,0 +1,12 @@
1
+ export declare class FileCache {
2
+ path: string;
3
+ constructor(watermark: string, extension?: string);
4
+ get(): Promise<string | null>;
5
+ set(content: string): Promise<void>;
6
+ }
7
+ export declare class JsonCache<T> extends FileCache {
8
+ constructor(watermark: string);
9
+ read(): Promise<T | null>;
10
+ write(data: T): Promise<void>;
11
+ }
12
+ //# sourceMappingURL=file-cache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-cache.d.ts","sourceRoot":"","sources":["../../src/lib/file-cache.ts"],"names":[],"mappings":"AAMA,qBAAa,SAAS;IACb,IAAI,EAAE,MAAM,CAAC;gBACR,SAAS,EAAE,MAAM,EAAE,SAAS,SAAS;IAK3C,GAAG;IAOT,GAAG,CAAC,OAAO,EAAE,MAAM;CAGpB;AAED,qBAAa,SAAS,CAAC,CAAC,CAAE,SAAQ,SAAS;gBAC7B,SAAS,EAAE,MAAM;IAIvB,IAAI,IAAI,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC;IAQ/B,KAAK,CAAC,IAAI,EAAE,CAAC;CAGd"}
@@ -0,0 +1,3 @@
1
+ export * from './teach/teachables.ts';
2
+ export { default } from './teach/teachables.ts';
3
+ //# sourceMappingURL=instructions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"instructions.d.ts","sourceRoot":"","sources":["../../src/lib/instructions.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC"}
@@ -0,0 +1,386 @@
1
+ // packages/text2sql/src/lib/teach/xml.ts
2
+ function wrapBlock(tag, children) {
3
+ const content = children.filter((child) => Boolean(child)).join("\n");
4
+ if (!content) {
5
+ return "";
6
+ }
7
+ return `<${tag}>
8
+ ${indentBlock(content, 2)}
9
+ </${tag}>`;
10
+ }
11
+ function list(tag, values, childTag) {
12
+ if (!values.length) {
13
+ return "";
14
+ }
15
+ const children = values.map((value) => leaf(childTag, value)).join("\n");
16
+ return `<${tag}>
17
+ ${indentBlock(children, 2)}
18
+ </${tag}>`;
19
+ }
20
+ function leaf(tag, value) {
21
+ const safe = escapeXml(value);
22
+ if (safe.includes("\n")) {
23
+ return `<${tag}>
24
+ ${indentBlock(safe, 2)}
25
+ </${tag}>`;
26
+ }
27
+ return `<${tag}>${safe}</${tag}>`;
28
+ }
29
+ function indentBlock(text, spaces) {
30
+ if (!text.trim()) {
31
+ return "";
32
+ }
33
+ const padding = " ".repeat(spaces);
34
+ return text.split("\n").map((line) => line.length ? padding + line : padding).join("\n");
35
+ }
36
+ function escapeXml(value) {
37
+ if (value == null) {
38
+ return "";
39
+ }
40
+ return value.replaceAll(/&/g, "&amp;").replaceAll(/</g, "&lt;").replaceAll(/>/g, "&gt;").replaceAll(/"/g, "&quot;").replaceAll(/'/g, "&apos;");
41
+ }
42
+
43
+ // packages/text2sql/src/lib/teach/teachables.ts
44
+ function term(name, definition) {
45
+ return {
46
+ type: "term",
47
+ format: () => wrapBlock("term", [leaf("name", name), leaf("definition", definition)])
48
+ };
49
+ }
50
+ function hint(text) {
51
+ return {
52
+ type: "hint",
53
+ format: () => leaf("hint", text)
54
+ };
55
+ }
56
+ function guardrail(input) {
57
+ const { rule, reason, action } = input;
58
+ return {
59
+ type: "guardrail",
60
+ format: () => wrapBlock("guardrail", [
61
+ leaf("rule", rule),
62
+ reason ? leaf("reason", reason) : "",
63
+ action ? leaf("action", action) : ""
64
+ ])
65
+ };
66
+ }
67
+ function explain(input) {
68
+ const { concept, explanation, therefore } = input;
69
+ return {
70
+ type: "explain",
71
+ format: () => wrapBlock("explanation", [
72
+ leaf("concept", concept),
73
+ leaf("details", explanation),
74
+ therefore ? leaf("therefore", therefore) : ""
75
+ ])
76
+ };
77
+ }
78
+ function example(input) {
79
+ const { question, answer, note } = input;
80
+ return {
81
+ type: "example",
82
+ format: () => wrapBlock("example", [
83
+ leaf("question", question),
84
+ leaf("answer", answer),
85
+ note ? leaf("note", note) : ""
86
+ ])
87
+ };
88
+ }
89
+ function clarification(input) {
90
+ const { when, ask, reason } = input;
91
+ return {
92
+ type: "clarification",
93
+ format: () => wrapBlock("clarification", [
94
+ leaf("when", when),
95
+ leaf("ask", ask),
96
+ leaf("reason", reason)
97
+ ])
98
+ };
99
+ }
100
+ function workflow(input) {
101
+ const { task, steps, triggers, notes } = input;
102
+ return {
103
+ type: "workflow",
104
+ format: () => wrapBlock("workflow", [
105
+ leaf("task", task),
106
+ triggers?.length ? list("triggers", triggers, "trigger") : "",
107
+ list("steps", steps, "step"),
108
+ notes ? leaf("notes", notes) : ""
109
+ ])
110
+ };
111
+ }
112
+ function quirk(input) {
113
+ const { issue, workaround } = input;
114
+ return {
115
+ type: "quirk",
116
+ format: () => wrapBlock("quirk", [
117
+ leaf("issue", issue),
118
+ leaf("workaround", workaround)
119
+ ])
120
+ };
121
+ }
122
+ function styleGuide(input) {
123
+ const { prefer, never, always } = input;
124
+ return {
125
+ type: "styleGuide",
126
+ format: () => wrapBlock("style_guide", [
127
+ leaf("prefer", prefer),
128
+ always ? leaf("always", always) : "",
129
+ never ? leaf("never", never) : ""
130
+ ])
131
+ };
132
+ }
133
+ function analogy(input) {
134
+ const { concept, relationship, insight, therefore, pitfall } = input;
135
+ return {
136
+ type: "analogy",
137
+ format: () => wrapBlock("analogy", [
138
+ list("concepts", concept, "concept"),
139
+ leaf("relationship", relationship),
140
+ insight ? leaf("insight", insight) : "",
141
+ therefore ? leaf("therefore", therefore) : "",
142
+ pitfall ? leaf("pitfall", pitfall) : ""
143
+ ])
144
+ };
145
+ }
146
+ function glossary(entries) {
147
+ return {
148
+ type: "glossary",
149
+ format: () => wrapBlock(
150
+ "glossary",
151
+ Object.entries(entries).map(
152
+ ([term2, sql]) => wrapBlock("entry", [leaf("term", term2), leaf("sql", sql)])
153
+ )
154
+ )
155
+ };
156
+ }
157
+ function identity(input) {
158
+ const { name, role } = input;
159
+ return {
160
+ type: "identity",
161
+ format: () => wrapBlock("identity", [
162
+ name ? leaf("name", name) : "",
163
+ role ? leaf("role", role) : ""
164
+ ])
165
+ };
166
+ }
167
+ function persona(input) {
168
+ const { name, role, tone } = input;
169
+ return {
170
+ type: "persona",
171
+ format: () => wrapBlock("persona", [
172
+ leaf("name", name),
173
+ leaf("role", role),
174
+ leaf("tone", tone)
175
+ ])
176
+ };
177
+ }
178
+ function alias(termName, meaning) {
179
+ return {
180
+ type: "alias",
181
+ format: () => wrapBlock("alias", [leaf("term", termName), leaf("meaning", meaning)])
182
+ };
183
+ }
184
+ function preference(aspect, value) {
185
+ return {
186
+ type: "preference",
187
+ format: () => wrapBlock("preference", [leaf("aspect", aspect), leaf("value", value)])
188
+ };
189
+ }
190
+ function context(description) {
191
+ return {
192
+ type: "context",
193
+ format: () => leaf("context", description)
194
+ };
195
+ }
196
+ function correction(subject, clarification2) {
197
+ return {
198
+ type: "correction",
199
+ format: () => wrapBlock("correction", [
200
+ leaf("subject", subject),
201
+ leaf("clarification", clarification2)
202
+ ])
203
+ };
204
+ }
205
+ function teachable(tag, ...teachables) {
206
+ return {
207
+ type: "user_profile",
208
+ format: () => toInstructions(tag, ...teachables)
209
+ };
210
+ }
211
+ function toInstructions(tag, ...teachables) {
212
+ if (!teachables.length) {
213
+ return "";
214
+ }
215
+ const grouped = /* @__PURE__ */ new Map();
216
+ for (const teachable2 of teachables) {
217
+ const existing = grouped.get(teachable2.type) ?? [];
218
+ existing.push(teachable2);
219
+ grouped.set(teachable2.type, existing);
220
+ }
221
+ const definedTypes = new Set(SECTION_ORDER.map((s) => s.type));
222
+ const sections = SECTION_ORDER.map(({ type, tag: tag2 }) => {
223
+ const items = grouped.get(type);
224
+ if (!items?.length) {
225
+ return "";
226
+ }
227
+ const renderedItems = items.map((item) => item.format().trim()).filter(Boolean).map((item) => indentBlock(item, 2)).join("\n");
228
+ if (!renderedItems.length) {
229
+ return "";
230
+ }
231
+ return `<${tag2}>
232
+ ${renderedItems}
233
+ </${tag2}>`;
234
+ }).filter((section) => Boolean(section));
235
+ for (const [type, items] of grouped) {
236
+ if (definedTypes.has(type)) {
237
+ continue;
238
+ }
239
+ const renderedItems = items.map((item) => item.format().trim()).filter(Boolean).map((item) => indentBlock(item, 2)).join("\n");
240
+ if (renderedItems.length) {
241
+ sections.push(renderedItems);
242
+ }
243
+ }
244
+ if (!sections.length) {
245
+ return "";
246
+ }
247
+ const content = indentBlock(sections.join("\n"), 2);
248
+ return `<${tag}>
249
+ ${content}
250
+ </${tag}>`;
251
+ }
252
+ var SECTION_ORDER = [
253
+ // User context (render first - most important for personalization)
254
+ { type: "identity", tag: "identity" },
255
+ { type: "persona", tag: "persona" },
256
+ { type: "context", tag: "user_context" },
257
+ { type: "preference", tag: "user_preferences" },
258
+ { type: "alias", tag: "user_vocabulary" },
259
+ { type: "correction", tag: "user_corrections" },
260
+ // Domain knowledge
261
+ { type: "guardrail", tag: "guardrails" },
262
+ { type: "styleGuide", tag: "style_guides" },
263
+ { type: "hint", tag: "hints" },
264
+ { type: "clarification", tag: "clarifications" },
265
+ { type: "workflow", tag: "workflows" },
266
+ { type: "quirk", tag: "quirks" },
267
+ { type: "term", tag: "terminology" },
268
+ { type: "explain", tag: "explanations" },
269
+ { type: "analogy", tag: "analogies" },
270
+ { type: "glossary", tag: "glossary" },
271
+ { type: "example", tag: "examples" }
272
+ ];
273
+ function toTeachables(generated) {
274
+ return generated.map((item) => {
275
+ switch (item.type) {
276
+ case "persona":
277
+ return persona({ name: item.name, role: item.role, tone: item.tone });
278
+ case "term":
279
+ return term(item.name, item.definition);
280
+ case "hint":
281
+ return hint(item.text);
282
+ case "guardrail":
283
+ return guardrail({
284
+ rule: item.rule,
285
+ reason: item.reason,
286
+ action: item.action
287
+ });
288
+ case "explain":
289
+ return explain({
290
+ concept: item.concept,
291
+ explanation: item.explanation,
292
+ therefore: item.therefore
293
+ });
294
+ case "example":
295
+ return example({
296
+ question: item.question,
297
+ answer: item.answer,
298
+ note: item.note
299
+ });
300
+ case "clarification":
301
+ return clarification({
302
+ when: item.when,
303
+ ask: item.ask,
304
+ reason: item.reason
305
+ });
306
+ case "workflow":
307
+ return workflow({
308
+ task: item.task,
309
+ steps: item.steps,
310
+ triggers: item.triggers,
311
+ notes: item.notes
312
+ });
313
+ case "quirk":
314
+ return quirk({
315
+ issue: item.issue,
316
+ workaround: item.workaround
317
+ });
318
+ case "styleGuide":
319
+ return styleGuide({
320
+ prefer: item.prefer,
321
+ never: item.never,
322
+ always: item.always
323
+ });
324
+ case "analogy":
325
+ return analogy({
326
+ concept: item.concept,
327
+ relationship: item.relationship,
328
+ insight: item.insight,
329
+ therefore: item.therefore,
330
+ pitfall: item.pitfall
331
+ });
332
+ case "glossary":
333
+ return glossary(item.entries);
334
+ // User-specific teachable types
335
+ case "identity":
336
+ return identity({ name: item.name, role: item.role });
337
+ case "alias":
338
+ return alias(item.term, item.meaning);
339
+ case "preference":
340
+ return preference(item.aspect, item.value);
341
+ case "context":
342
+ return context(item.description);
343
+ case "correction":
344
+ return correction(item.subject, item.clarification);
345
+ }
346
+ });
347
+ }
348
+ var teachables_default = {
349
+ persona,
350
+ term,
351
+ hint,
352
+ guardrail,
353
+ explain,
354
+ example,
355
+ clarification,
356
+ workflow,
357
+ quirk,
358
+ styleGuide,
359
+ analogy,
360
+ glossary,
361
+ teachable
362
+ };
363
+ export {
364
+ alias,
365
+ analogy,
366
+ clarification,
367
+ context,
368
+ correction,
369
+ teachables_default as default,
370
+ example,
371
+ explain,
372
+ glossary,
373
+ guardrail,
374
+ hint,
375
+ identity,
376
+ persona,
377
+ preference,
378
+ quirk,
379
+ styleGuide,
380
+ teachable,
381
+ term,
382
+ toInstructions,
383
+ toTeachables,
384
+ workflow
385
+ };
386
+ //# sourceMappingURL=instructions.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/lib/teach/xml.ts", "../../src/lib/teach/teachables.ts"],
4
+ "sourcesContent": ["export function wrapBlock(tag: string, children: string[]): string {\n const content = children\n .filter((child): child is string => Boolean(child))\n .join('\\n');\n if (!content) {\n return '';\n }\n return `<${tag}>\\n${indentBlock(content, 2)}\\n</${tag}>`;\n}\n\nexport function list(tag: string, values: string[], childTag: string): string {\n if (!values.length) {\n return '';\n }\n const children = values.map((value) => leaf(childTag, value)).join('\\n');\n return `<${tag}>\\n${indentBlock(children, 2)}\\n</${tag}>`;\n}\n\nexport function leaf(tag: string, value: string): string {\n const safe = escapeXml(value);\n if (safe.includes('\\n')) {\n return `<${tag}>\\n${indentBlock(safe, 2)}\\n</${tag}>`;\n }\n return `<${tag}>${safe}</${tag}>`;\n}\n\nexport function indentBlock(text: string, spaces: number): string {\n if (!text.trim()) {\n return '';\n }\n const padding = ' '.repeat(spaces);\n return text\n .split('\\n')\n .map((line) => (line.length ? padding + line : padding))\n .join('\\n');\n}\n\nexport function escapeXml(value: string): string {\n if (value == null) {\n return '';\n }\n return value\n .replaceAll(/&/g, '&amp;')\n .replaceAll(/</g, '&lt;')\n .replaceAll(/>/g, '&gt;')\n .replaceAll(/\"/g, '&quot;')\n .replaceAll(/'/g, '&apos;');\n}\n", "import { indentBlock, leaf, list, wrapBlock } from './xml.ts';\n\nexport interface Teachables {\n type:\n | 'term'\n | 'hint'\n | 'guardrail'\n | 'explain'\n | 'example'\n | 'clarification'\n | 'workflow'\n | 'quirk'\n | 'styleGuide'\n | 'analogy'\n | 'glossary'\n | 'user_profile'\n // User-specific teachable types\n | 'identity'\n | 'persona'\n | 'alias'\n | 'preference'\n | 'context'\n | 'correction';\n format: () => string;\n}\nexport type GeneratedTeachable =\n | { type: 'term'; name: string; definition: string }\n | { type: 'hint'; text: string }\n | { type: 'guardrail'; rule: string; reason?: string; action?: string }\n | {\n type: 'explain';\n concept: string;\n explanation: string;\n therefore?: string;\n }\n | { type: 'example'; question: string; answer: string; note?: string }\n | { type: 'clarification'; when: string; ask: string; reason: string }\n | {\n type: 'workflow';\n task: string;\n steps: string[];\n triggers?: string[];\n notes?: string;\n }\n | { type: 'quirk'; issue: string; workaround: string }\n | { type: 'styleGuide'; prefer: string; never?: string; always?: string }\n | {\n type: 'analogy';\n concept: string[];\n relationship: string;\n insight?: string;\n therefore?: string;\n pitfall?: string;\n }\n | { type: 'glossary'; entries: Record<string, string> }\n // User-specific teachable types\n | { type: 'identity'; name?: string; role?: string }\n | { type: 'persona'; name: string; role: string; tone: string }\n | { type: 'alias'; term: string; meaning: string }\n | { type: 'preference'; aspect: string; value: string }\n | { type: 'context'; description: string }\n | { type: 'correction'; subject: string; clarification: string };\n\n/**\n * Teach the system domain-specific vocabulary and business terminology.\n *\n * Use this to define simple, direct mappings between business terms and their meanings.\n * The system will understand these terms when users mention them in queries.\n *\n * @param name - The business term or acronym to define\n * @param definition - What the term means in your domain\n *\n * @example\n * // Logistics/Transportation dataset\n * term(\"deadhead miles\", \"distance driven with empty truck between deliveries\")\n * term(\"dwell time\", \"total time a truck spends at a loading dock or warehouse\")\n * term(\"LTL\", \"less than truckload - shipment that doesn't fill entire truck\")\n *\n * @example\n * // Education/University dataset\n * term(\"matriculation\", \"students who completed enrollment and started classes\")\n * term(\"DFW rate\", \"percentage of students receiving D, F, or Withdrawal in a course\")\n * term(\"cohort\", \"group of students who entered the same semester or academic year\")\n *\n * @example\n * // Finance/Banking dataset\n * term(\"NPL\", \"non-performing loan - loan past due 90+ days\")\n * term(\"basis points\", \"one hundredth of a percentage point (1% = 100 bps)\")\n * term(\"AUM\", \"assets under management - total market value of client investments\")\n */\nexport function term(name: string, definition: string): Teachables {\n return {\n type: 'term',\n format: () =>\n wrapBlock('term', [leaf('name', name), leaf('definition', definition)]),\n };\n}\n\n/**\n * Teach the system behavioral rules and constraints that should always apply.\n *\n * Use this for business logic, data quality rules, or query preferences that should\n * be automatically applied to all relevant queries. Hints are injected as constraints\n * in the system prompt.\n *\n * @param text - The rule or constraint to follow (use imperative language)\n *\n * @example\n * // Manufacturing/Supply Chain dataset\n * hint(\"Always exclude work orders with status = 'simulation' from production metrics\")\n * hint(\"When calculating OEE (overall equipment effectiveness), only count scheduled production time\")\n * hint(\"Defect rates should be calculated per batch, not per individual unit, for consistency\")\n *\n * @example\n * // Real Estate/Property dataset\n * hint(\"Never include properties with listing_status = 'draft' in market analysis\")\n * hint(\"Always filter out duplicate MLS listings - use the earliest listing_date for each property_id\")\n * hint(\"Square footage comparisons must specify if including or excluding basement/garage\")\n *\n * @example\n * // Social Media/Content Platform dataset\n * hint(\"Engagement metrics should exclude bot accounts identified by is_verified_human = false\")\n * hint(\"View counts reset daily - always use cumulative_views for historical analysis\")\n * hint(\"Default content filters to published_status = 'public' unless analyzing drafts\")\n */\nexport function hint(text: string): Teachables {\n return {\n type: 'hint',\n format: () => leaf('hint', text),\n };\n}\n\n/**\n * Define hard guardrails, safety rules, and compliance boundaries the system must enforce.\n *\n * Use this for \"never do\" rules, sensitive data handling, and required behaviors when\n * certain conditions occur. Guardrails should be explicit and action oriented.\n *\n * @param input.rule - The guardrail or restriction to enforce\n * @param input.reason - Why this guardrail exists (compliance, security, performance)\n * @param input.action - What to do when this guardrail is triggered (block, ask, sanitize)\n *\n * @example\n * // Healthcare dataset\n * guardrail({\n * rule: \"Never return PHI like SSN, MRN, or full address in query results\",\n * reason: \"HIPAA compliance\",\n * action: \"If asked, state that identifiable patient data cannot be shared; offer de-identified aggregates instead\"\n * })\n *\n * @example\n * // Finance dataset\n * guardrail({\n * rule: \"Block any query exposing employee-level compensation by name\",\n * reason: \"Confidential payroll data\",\n * action: \"Provide ranges grouped by department or level instead of individual salaries\"\n * })\n *\n * @example\n * // E-commerce dataset\n * guardrail({\n * rule: \"Warn when a query would scan more than 10 million rows; require a narrower date range\",\n * reason: \"Performance and cost control\",\n * action: \"Ask the user to add filters (recent timeframe, specific categories) before proceeding\"\n * })\n */\nexport function guardrail(input: {\n rule: string;\n reason?: string;\n action?: string;\n}): Teachables {\n const { rule, reason, action } = input;\n return {\n type: 'guardrail',\n format: () =>\n wrapBlock('guardrail', [\n leaf('rule', rule),\n reason ? leaf('reason', reason) : '',\n action ? leaf('action', action) : '',\n ]),\n };\n}\n\n/**\n * Teach the system a rich understanding of a single concept using metaphors and explanations.\n *\n * Use this when a simple term definition isn't enough - when you need to convey deeper\n * understanding about how to think about and calculate a metric or concept.\n *\n * @param input.concept - The concept being explained\n * @param input.explanation - A metaphor or detailed explanation (often using real-world comparisons)\n * @param input.therefore - Optional actionable instruction based on this understanding\n *\n * @example\n * // Gaming/Entertainment dataset\n * explain({\n * concept: \"daily active users to monthly active users ratio\",\n * explanation: \"like measuring how many club members visit daily vs just once a month - shows stickiness\",\n * therefore: \"Calculate as DAU / MAU, where higher ratio (closer to 1) means more engaged user base\"\n * })\n *\n * @example\n * // HR/Employee Management dataset\n * explain({\n * concept: \"time to fill\",\n * explanation: \"like measuring how long a house sits on the market - from posting job to accepting offer\",\n * therefore: \"Calculate as days between job_posted_date and offer_accepted_date, exclude cancelled requisitions\"\n * })\n *\n * @example\n * // Telecommunications dataset\n * explain({\n * concept: \"network congestion ratio\",\n * explanation: \"like rush hour traffic density - measures actual usage vs total capacity at peak times\",\n * therefore: \"Calculate as (peak_hour_bandwidth_used / total_bandwidth_capacity) during busiest hour of day\"\n * })\n */\nexport function explain(input: {\n concept: string;\n explanation: string;\n therefore?: string;\n}): Teachables {\n const { concept, explanation, therefore } = input;\n return {\n type: 'explain',\n format: () =>\n wrapBlock('explanation', [\n leaf('concept', concept),\n leaf('details', explanation),\n therefore ? leaf('therefore', therefore) : '',\n ]),\n };\n}\n\n/**\n * Teach the system through concrete examples of question \u2192 SQL pairs.\n *\n * Use this for few-shot learning - show the system exactly how to translate\n * specific types of questions into SQL queries. Great for establishing patterns\n * and handling domain-specific query structures.\n *\n * @param input.question - The natural language question or request\n * @param input.answer - The correct answer that responds to the question\n * @param input.note - Optional note or explanation about the example\n *\n * @example\n * // Energy/Utilities dataset\n * example({\n * question: \"show me peak demand hours for the last week\",\n * answer: \"SELECT DATE_TRUNC('hour', reading_timestamp) as hour, MAX(consumption_kwh) as peak_demand FROM meter_readings WHERE reading_timestamp >= CURRENT_DATE - INTERVAL '7 days' GROUP BY hour ORDER BY peak_demand DESC LIMIT 10\"\n * })\n *\n * @example\n * // Agriculture/Farm Management dataset\n * example({\n * question: \"what is the average yield per acre by crop type this season\",\n * answer: \"SELECT crop_type, AVG(harvest_quantity / field_acres) as yield_per_acre FROM harvests WHERE harvest_date >= '2024-01-01' GROUP BY crop_type ORDER BY yield_per_acre DESC\"\n * })\n *\n * @example\n * // Travel/Hospitality dataset\n * example({\n * question: \"show me hotel occupancy rate for this month\",\n * answer: \"SELECT hotel_name, (SUM(occupied_rooms) / SUM(total_rooms)) * 100 as occupancy_rate FROM daily_occupancy WHERE date >= DATE_TRUNC('month', CURRENT_DATE) GROUP BY hotel_id, hotel_name ORDER BY occupancy_rate DESC\",\n * note: \"Occupancy rate is a percentage - multiply by 100 for readable output\"\n * })\n */\nexport function example(input: {\n question: string;\n answer: string;\n note?: string;\n}): Teachables {\n const { question, answer, note } = input;\n return {\n type: 'example',\n format: () =>\n wrapBlock('example', [\n leaf('question', question),\n leaf('answer', answer),\n note ? leaf('note', note) : '',\n ]),\n };\n}\n\n/**\n * Teach the system when and what to ask for clarification.\n *\n * Use this to handle ambiguous terms or situations where the system should\n * proactively ask the user for more information before generating a query.\n * Makes the system more conversational and precise.\n *\n * @param input.when - The condition or trigger that should prompt clarification\n * @param input.ask - The question to ask the user\n * @param input.reason - Why this clarification is necessary (helps system understand importance)\n *\n * @example\n * // Marketing/Advertising dataset\n * clarification({\n * when: \"user asks for 'conversion rate'\",\n * ask: \"Which conversion: click-to-lead, lead-to-opportunity, or opportunity-to-customer?\",\n * reason: \"Conversion rate means different things at each funnel stage - need to specify which metric\"\n * })\n *\n * @example\n * // Food Delivery dataset\n * clarification({\n * when: \"user asks about 'delivery time'\",\n * ask: \"Do you mean estimated time at order, actual delivery time, or time from kitchen to door?\",\n * reason: \"Multiple time metrics exist - estimated vs actual impacts customer satisfaction differently\"\n * })\n *\n * @example\n * // Fitness/Gym Management dataset\n * clarification({\n * when: \"user mentions 'active members'\",\n * ask: \"Do you mean paid memberships or members who actually visited in last 30 days?\",\n * reason: \"Many paid members don't use facilities - different metrics for revenue vs utilization\"\n * })\n */\nexport function clarification(input: {\n when: string;\n ask: string;\n reason: string;\n}): Teachables {\n const { when, ask, reason } = input;\n return {\n type: 'clarification',\n format: () =>\n wrapBlock('clarification', [\n leaf('when', when),\n leaf('ask', ask),\n leaf('reason', reason),\n ]),\n };\n}\n\n/**\n * Teach the system multi-step analytical processes that can't be solved with a single query.\n *\n * Use this for complex analytical tasks that require multiple CTEs, sequential logic,\n * or specific methodologies. Workflows teach the system HOW to approach a type of analysis.\n *\n * @param input.task - Name of the analytical task\n * @param input.steps - Sequential steps to execute (can include SQL snippets or descriptions)\n * @param input.triggers - Optional phrases that should activate this workflow\n * @param input.notes - Optional additional context, warnings, or guidance\n *\n * @example\n * // Insurance dataset\n * workflow({\n * task: \"Claims Loss Ratio Analysis\",\n * triggers: [\"loss ratio\", \"claims ratio\", \"underwriting performance\"],\n * steps: [\n * \"Calculate total claims paid for each policy period\",\n * \"Calculate total premiums earned for same period\",\n * \"Compute loss ratio as (claims_paid / premiums_earned) * 100\",\n * \"Segment by policy type, geography, and underwriter\",\n * \"Identify policies with loss ratio > 100% (losing money)\",\n * \"Calculate trend over time using rolling 12-month windows\"\n * ],\n * notes: \"Use incurred date for claims, not paid date. Exclude reinsurance recoveries from claims total.\"\n * })\n *\n * @example\n * // Media/Publishing dataset\n * workflow({\n * task: \"Content Performance Funnel\",\n * triggers: [\"content funnel\", \"engagement funnel\", \"content performance\"],\n * steps: [\n * \"Count total impressions (articles shown) per content piece\",\n * \"Count click-throughs (articles opened)\",\n * \"Count scroll depth > 50% (meaningful engagement)\",\n * \"Count shares, comments, or saves (viral actions)\",\n * \"Calculate conversion rate at each funnel stage\",\n * \"Identify top-performing content by final conversion rate\"\n * ],\n * notes: \"Requires multiple event types. Join events table multiple times or use conditional aggregation.\"\n * })\n *\n * @example\n * // Sports Analytics dataset\n * workflow({\n * task: \"Player Performance Rating Calculation\",\n * triggers: [\"player rating\", \"performance score\", \"player analytics\"],\n * steps: [\n * \"Aggregate per-game stats: points, assists, rebounds, turnovers\",\n * \"Calculate efficiency metrics: shooting percentage, plus/minus\",\n * \"Normalize each metric using z-scores vs league average\",\n * \"Apply position-specific weights to each metric\",\n * \"Combine weighted scores into overall performance rating (0-100)\",\n * \"Rank players within position group and overall\"\n * ],\n * notes: \"Requires league-wide statistics for normalization. Update weights each season based on game trends.\"\n * })\n */\nexport function workflow(input: {\n task: string;\n steps: string[];\n triggers?: string[];\n notes?: string;\n}): Teachables {\n const { task, steps, triggers, notes } = input;\n return {\n type: 'workflow',\n format: () =>\n wrapBlock('workflow', [\n leaf('task', task),\n triggers?.length ? list('triggers', triggers, 'trigger') : '',\n list('steps', steps, 'step'),\n notes ? leaf('notes', notes) : '',\n ]),\n };\n}\n\n/**\n * Teach the system about data quirks, edge cases, or database-specific issues and their workarounds.\n *\n * Use this to document weird data patterns, database limitations, or special handling\n * required for specific scenarios. Helps the system navigate real-world messiness.\n *\n * @param input.issue - Description of the quirk, edge case, or problem\n * @param input.workaround - How to handle or work around this issue\n *\n * @example\n * // Government/Public Services dataset\n * quirk({\n * issue: \"Citizen IDs contain leading zeros but are stored as integers, losing the zeros\",\n * workaround: \"Always cast to VARCHAR and use LPAD(citizen_id::VARCHAR, 10, '0') to restore leading zeros\"\n * })\n *\n * @example\n * // Aviation dataset\n * quirk({\n * issue: \"Flight times crossing midnight show as negative duration (landing before takeoff)\",\n * workaround: \"Add 24 hours when calculated duration < 0: CASE WHEN duration < 0 THEN duration + INTERVAL '24 hours' ELSE duration END\"\n * })\n *\n * @example\n * // Automotive/Dealership dataset\n * quirk({\n * issue: \"VIN numbers with letter 'O' were incorrectly entered as zero '0' in legacy data\",\n * workaround: \"When searching by VIN, use REPLACE(vin, '0', 'O') or fuzzy matching to handle both cases\"\n * })\n */\nexport function quirk(input: {\n issue: string;\n workaround: string;\n}): Teachables {\n const { issue, workaround } = input;\n return {\n type: 'quirk',\n format: () =>\n wrapBlock('quirk', [\n leaf('issue', issue),\n leaf('workaround', workaround),\n ]),\n };\n}\n\n/**\n * Teach the system SQL style preferences and coding standards for generated queries.\n *\n * Use this to enforce consistent SQL formatting, naming conventions, and best practices\n * specific to your team or organization. Improves readability and maintainability.\n *\n * @param input.prefer - Preferred SQL style or pattern\n * @param input.never - Optional anti-pattern to avoid\n * @param input.always - Optional rule that must always be followed\n *\n * @example\n * // Non-profit/Charity dataset\n * styleGuide({\n * prefer: \"Use donor-centric language in column aliases: 'donor_name' not 'customer_name'\",\n * never: \"Never expose internal donor IDs in external reports - use public gift IDs\",\n * always: \"Always include fiscal year in date-based aggregations (FY starts July 1)\"\n * })\n *\n * @example\n * // Legal/Law Firm dataset\n * styleGuide({\n * prefer: \"Use billable_hours with 2 decimal precision for accurate client billing\",\n * never: \"Never include attorney_rate in queries visible to paralegals - confidential data\",\n * always: \"Always filter by matter_status = 'open' unless specifically analyzing closed cases\"\n * })\n *\n * @example\n * // Inventory/Warehouse dataset\n * styleGuide({\n * prefer: \"Use location_id in joins rather than location_name (duplicates exist across warehouses)\",\n * never: \"Never aggregate inventory without grouping by warehouse_id first\",\n * always: \"Always use inventory_on_hand - inventory_reserved for available stock calculations\"\n * })\n */\nexport function styleGuide(input: {\n prefer: string;\n never?: string;\n always?: string;\n}): Teachables {\n const { prefer, never, always } = input;\n return {\n type: 'styleGuide',\n format: () =>\n wrapBlock('style_guide', [\n leaf('prefer', prefer),\n always ? leaf('always', always) : '',\n never ? leaf('never', never) : '',\n ]),\n };\n}\n\n/**\n * Teach the system by comparing related concepts through real-world analogies.\n *\n * Use this to teach relational understanding between two concepts by drawing comparisons\n * to familiar real-world scenarios. Helps the system understand WHY concepts differ and\n * when to use each one appropriately.\n *\n * @param input.concept - Array of two related concepts to compare\n * @param input.relationship - The comparison/analogy using real-world examples\n * @param input.insight - Optional key insight the analogy reveals\n * @param input.therefore - Optional actionable instruction based on this understanding\n * @param input.pitfall - Optional common mistake to avoid\n *\n * @example\n * // E-commerce dataset\n * analogy({\n * concept: [\"cart abandonment\", \"browse abandonment\"],\n * relationship: \"Cart abandonment is like leaving items at a checkout counter, browse abandonment is like window shopping without picking anything up\",\n * insight: \"Cart abandonment shows purchase intent (added to cart), browse abandonment shows only interest\",\n * therefore: \"Prioritize cart abandonment recovery campaigns - higher conversion potential than browse\",\n * pitfall: \"Don't combine both into generic 'abandonment rate' - they need different marketing strategies\"\n * })\n *\n * @example\n * // SaaS dataset\n * analogy({\n * concept: [\"logo churn\", \"revenue churn\"],\n * relationship: \"Logo churn is like counting how many customers left the store, revenue churn is how much money walked out\",\n * insight: \"Losing 10 small customers (high logo churn) might hurt less than losing 1 enterprise customer (high revenue churn)\",\n * therefore: \"Always report both metrics - logo churn for customer satisfaction, revenue churn for financial health\",\n * pitfall: \"Don't use logo churn to predict revenue impact - customer size distribution matters\"\n * })\n *\n * @example\n * // Healthcare dataset\n * analogy({\n * concept: [\"incident\", \"prevalence\"],\n * relationship: \"Incidence is like new house sales this month, prevalence is total houses currently occupied\",\n * insight: \"Incidence measures new cases over time, prevalence measures all existing cases at a point in time\",\n * therefore: \"For tracking disease outbreaks use incidence rate, for resource planning use prevalence\",\n * pitfall: \"Don't sum incidence rates across time periods - it's a rate not a count\"\n * })\n */\nexport function analogy(input: {\n concept: string[];\n relationship: string;\n insight?: string;\n therefore?: string;\n pitfall?: string;\n}): Teachables {\n const { concept, relationship, insight, therefore, pitfall } = input;\n return {\n type: 'analogy',\n format: () =>\n wrapBlock('analogy', [\n list('concepts', concept, 'concept'),\n leaf('relationship', relationship),\n insight ? leaf('insight', insight) : '',\n therefore ? leaf('therefore', therefore) : '',\n pitfall ? leaf('pitfall', pitfall) : '',\n ]),\n };\n}\n\n/**\n * Map business terms directly to SQL expressions or fragments.\n *\n * Use this to teach the system how to CALCULATE or QUERY specific business concepts.\n * The system will substitute these SQL patterns when users mention the term.\n *\n * **Glossary vs Alias:**\n * - `alias` = user vocabulary \u2192 table/column name (\"the big table\" \u2192 \"orders table\")\n * - `glossary` = business term \u2192 SQL expression (\"revenue\" \u2192 \"SUM(orders.total_amount)\")\n *\n * In short: alias renames, glossary computes.\n *\n * @param entries - Record mapping business terms to their SQL expressions\n *\n * @example\n * glossary({\n * \"revenue\": \"SUM(orders.total_amount)\",\n * \"average order value\": \"AVG(orders.total_amount)\",\n * \"active user\": \"last_login > NOW() - INTERVAL '30 days'\",\n * \"churned\": \"status = 'churned'\",\n * \"power user\": \"order_count > 10\",\n * \"net revenue\": \"SUM(orders.total_amount) - SUM(refunds.amount)\",\n * })\n */\nexport function glossary(entries: Record<string, string>): Teachables {\n return {\n type: 'glossary',\n format: () =>\n wrapBlock(\n 'glossary',\n Object.entries(entries).map(([term, sql]) =>\n wrapBlock('entry', [leaf('term', term), leaf('sql', sql)]),\n ),\n ),\n };\n}\n\n// =============================================================================\n// User-Specific Teachable Types\n// =============================================================================\n\n/**\n * Define the user's identity including name and/or role.\n *\n * Use this to capture who the user is and what lens they view data through.\n * Helps tailor explanations, terminology, and focus areas.\n *\n * @param input.name - The user's name (optional)\n * @param input.role - The user's role or position (optional)\n *\n * @example\n * identity({ name: \"John\", role: \"VP of Sales\" })\n * identity({ role: \"Data analyst in the marketing team\" })\n * identity({ name: \"Sarah\" })\n * identity({ role: \"Finance manager focused on cost optimization\" })\n */\nexport function identity(input: { name?: string; role?: string }): Teachables {\n const { name, role } = input;\n return {\n type: 'identity',\n format: () =>\n wrapBlock('identity', [\n name ? leaf('name', name) : '',\n role ? leaf('role', role) : '',\n ]),\n };\n}\n\n/**\n * Define an AI persona with a name, role, and communication tone.\n *\n * Use this to customize the assistant's personality and how it communicates.\n * The persona influences the style and approach of responses.\n *\n * @param input.name - The persona's name\n * @param input.role - The persona's role or expertise\n * @param input.tone - The communication style (e.g., friendly, professional, concise)\n *\n * @example\n * persona({ name: \"DataBot\", role: \"SQL Expert\", tone: \"friendly and encouraging\" })\n * persona({ name: \"QueryMaster\", role: \"Database Analyst\", tone: \"professional and concise\" })\n * persona({ name: \"SQLHelper\", role: \"Data Assistant\", tone: \"casual and approachable\" })\n */\nexport function persona(input: {\n name: string;\n role: string;\n tone: string;\n}): Teachables {\n const { name, role, tone } = input;\n return {\n type: 'persona',\n format: () =>\n wrapBlock('persona', [\n leaf('name', name),\n leaf('role', role),\n leaf('tone', tone),\n ]),\n };\n}\n\n/**\n * Define user-specific term meanings and vocabulary.\n *\n * Use this when the user has their own definitions for terms that might\n * differ from standard or domain definitions. Like `term()` but personal.\n *\n * @param termName - The term the user uses\n * @param meaning - What the user means by this term\n *\n * @example\n * alias(\"revenue\", \"gross revenue before deductions, not net\")\n * alias(\"active users\", \"users who logged in within the last 30 days\")\n * alias(\"the big table\", \"the orders table\")\n * alias(\"Q4\", \"October through December, not fiscal Q4\")\n */\nexport function alias(termName: string, meaning: string): Teachables {\n return {\n type: 'alias',\n format: () =>\n wrapBlock('alias', [leaf('term', termName), leaf('meaning', meaning)]),\n };\n}\n\n/**\n * Define how the user prefers results presented.\n *\n * Use this to capture output formatting, style, and behavioral preferences\n * that should apply to all interactions with this user.\n *\n * @param aspect - What aspect of output this preference applies to\n * @param value - The user's preference\n *\n * @example\n * preference(\"date format\", \"YYYY-MM-DD\")\n * preference(\"output style\", \"tables over charts unless trend data\")\n * preference(\"detail level\", \"always show the SQL query in responses\")\n * preference(\"row limit\", \"default to 50 rows unless I ask for more\")\n * preference(\"explanation style\", \"brief and to the point\")\n */\nexport function preference(aspect: string, value: string): Teachables {\n return {\n type: 'preference',\n format: () =>\n wrapBlock('preference', [leaf('aspect', aspect), leaf('value', value)]),\n };\n}\n\n/**\n * Define the user's current working focus or project.\n *\n * Use this to capture temporary context that helps inform defaults,\n * assumptions, and suggestions. Should be updated as focus changes.\n *\n * @param description - What the user is currently working on\n *\n * @example\n * context(\"Preparing Q4 board presentation\")\n * context(\"Investigating drop in signups last week\")\n * context(\"Working on EMEA regional analysis for strategy meeting\")\n * context(\"Debugging discrepancy in revenue numbers\")\n */\nexport function context(description: string): Teachables {\n return {\n type: 'context',\n format: () => leaf('context', description),\n };\n}\n\n/**\n * Record a correction the user made to previous understanding.\n *\n * Use this when the user corrects a misunderstanding about data, columns,\n * or business logic. Prevents repeating the same mistake.\n *\n * @param subject - What was misunderstood\n * @param clarification - The correct understanding\n *\n * @example\n * correction(\"status column\", \"1 = active, 0 = inactive, not boolean true/false\")\n * correction(\"orders table\", \"Use orders_v2, not the deprecated legacy_orders table\")\n * correction(\"date field\", \"order_date is when order was placed, ship_date is when shipped\")\n * correction(\"revenue calculation\", \"Must exclude refunds and chargebacks\")\n */\nexport function correction(subject: string, clarification: string): Teachables {\n return {\n type: 'correction',\n format: () =>\n wrapBlock('correction', [\n leaf('subject', subject),\n leaf('clarification', clarification),\n ]),\n };\n}\n\nexport function teachable(\n tag: string,\n ...teachables: Teachables[]\n): Teachables {\n return {\n type: 'user_profile',\n format: () => toInstructions(tag, ...teachables),\n };\n}\n\nexport function toInstructions(\n tag: string,\n ...teachables: Teachables[]\n): string {\n if (!teachables.length) {\n return '';\n }\n\n const grouped = new Map<Teachables['type'], Teachables[]>();\n for (const teachable of teachables) {\n const existing = grouped.get(teachable.type) ?? [];\n existing.push(teachable);\n grouped.set(teachable.type, existing);\n }\n\n const definedTypes = new Set(SECTION_ORDER.map((s) => s.type));\n\n const sections = SECTION_ORDER.map(({ type, tag }) => {\n const items = grouped.get(type);\n if (!items?.length) {\n return '';\n }\n const renderedItems = items\n .map((item) => item.format().trim())\n .filter(Boolean)\n .map((item) => indentBlock(item, 2))\n .join('\\n');\n if (!renderedItems.length) {\n return '';\n }\n return `<${tag}>\\n${renderedItems}\\n</${tag}>`;\n }).filter((section): section is string => Boolean(section));\n\n // Render types not defined in SECTION_ORDER at the end\n for (const [type, items] of grouped) {\n if (definedTypes.has(type)) {\n continue;\n }\n const renderedItems = items\n .map((item) => item.format().trim())\n .filter(Boolean)\n .map((item) => indentBlock(item, 2))\n .join('\\n');\n if (renderedItems.length) {\n sections.push(renderedItems);\n }\n }\n\n if (!sections.length) {\n return '';\n }\n\n const content = indentBlock(sections.join('\\n'), 2);\n return `<${tag}>\\n${content}\\n</${tag}>`;\n}\n\nconst SECTION_ORDER: Array<{ type: Teachables['type']; tag: string }> = [\n // User context (render first - most important for personalization)\n { type: 'identity', tag: 'identity' },\n { type: 'persona', tag: 'persona' },\n { type: 'context', tag: 'user_context' },\n { type: 'preference', tag: 'user_preferences' },\n { type: 'alias', tag: 'user_vocabulary' },\n { type: 'correction', tag: 'user_corrections' },\n // Domain knowledge\n { type: 'guardrail', tag: 'guardrails' },\n { type: 'styleGuide', tag: 'style_guides' },\n { type: 'hint', tag: 'hints' },\n { type: 'clarification', tag: 'clarifications' },\n { type: 'workflow', tag: 'workflows' },\n { type: 'quirk', tag: 'quirks' },\n { type: 'term', tag: 'terminology' },\n { type: 'explain', tag: 'explanations' },\n { type: 'analogy', tag: 'analogies' },\n { type: 'glossary', tag: 'glossary' },\n { type: 'example', tag: 'examples' },\n];\n\nexport function toTeachables(generated: GeneratedTeachable[]): Teachables[] {\n return generated.map((item) => {\n switch (item.type) {\n case 'persona':\n return persona({ name: item.name, role: item.role, tone: item.tone });\n case 'term':\n return term(item.name, item.definition);\n case 'hint':\n return hint(item.text);\n case 'guardrail':\n return guardrail({\n rule: item.rule,\n reason: item.reason,\n action: item.action,\n });\n case 'explain':\n return explain({\n concept: item.concept,\n explanation: item.explanation,\n therefore: item.therefore,\n });\n case 'example':\n return example({\n question: item.question,\n answer: item.answer,\n note: item.note,\n });\n case 'clarification':\n return clarification({\n when: item.when,\n ask: item.ask,\n reason: item.reason,\n });\n case 'workflow':\n return workflow({\n task: item.task,\n steps: item.steps,\n triggers: item.triggers,\n notes: item.notes,\n });\n case 'quirk':\n return quirk({\n issue: item.issue,\n workaround: item.workaround,\n });\n case 'styleGuide':\n return styleGuide({\n prefer: item.prefer,\n never: item.never,\n always: item.always,\n });\n case 'analogy':\n return analogy({\n concept: item.concept,\n relationship: item.relationship,\n insight: item.insight,\n therefore: item.therefore,\n pitfall: item.pitfall,\n });\n case 'glossary':\n return glossary(item.entries);\n // User-specific teachable types\n case 'identity':\n return identity({ name: item.name, role: item.role });\n case 'alias':\n return alias(item.term, item.meaning);\n case 'preference':\n return preference(item.aspect, item.value);\n case 'context':\n return context(item.description);\n case 'correction':\n return correction(item.subject, item.clarification);\n }\n });\n}\n\n/**\n * Default export containing all system teachable factory functions.\n * Excludes user-specific teachables (identity, alias, preference, context, correction).\n */\nexport default {\n persona,\n term,\n hint,\n guardrail,\n explain,\n example,\n clarification,\n workflow,\n quirk,\n styleGuide,\n analogy,\n glossary,\n teachable,\n};\n"],
5
+ "mappings": ";AAAO,SAAS,UAAU,KAAa,UAA4B;AACjE,QAAM,UAAU,SACb,OAAO,CAAC,UAA2B,QAAQ,KAAK,CAAC,EACjD,KAAK,IAAI;AACZ,MAAI,CAAC,SAAS;AACZ,WAAO;AAAA,EACT;AACA,SAAO,IAAI,GAAG;AAAA,EAAM,YAAY,SAAS,CAAC,CAAC;AAAA,IAAO,GAAG;AACvD;AAEO,SAAS,KAAK,KAAa,QAAkB,UAA0B;AAC5E,MAAI,CAAC,OAAO,QAAQ;AAClB,WAAO;AAAA,EACT;AACA,QAAM,WAAW,OAAO,IAAI,CAAC,UAAU,KAAK,UAAU,KAAK,CAAC,EAAE,KAAK,IAAI;AACvE,SAAO,IAAI,GAAG;AAAA,EAAM,YAAY,UAAU,CAAC,CAAC;AAAA,IAAO,GAAG;AACxD;AAEO,SAAS,KAAK,KAAa,OAAuB;AACvD,QAAM,OAAO,UAAU,KAAK;AAC5B,MAAI,KAAK,SAAS,IAAI,GAAG;AACvB,WAAO,IAAI,GAAG;AAAA,EAAM,YAAY,MAAM,CAAC,CAAC;AAAA,IAAO,GAAG;AAAA,EACpD;AACA,SAAO,IAA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AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;",
6
+ "names": ["term", "clarification", "teachable", "tag"]
7
+ }
@@ -0,0 +1,3 @@
1
+ declare const _default: string;
2
+ export default _default;
3
+ //# sourceMappingURL=memory.prompt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory.prompt.d.ts","sourceRoot":"","sources":["../../../src/lib/memory/memory.prompt.ts"],"names":[],"mappings":";AAUA,wBA4JE"}
@@ -0,0 +1,5 @@
1
+ import { SqliteTeachablesStore } from './sqlite.store.ts';
2
+ export declare class InMemoryTeachablesStore extends SqliteTeachablesStore {
3
+ constructor();
4
+ }
5
+ //# sourceMappingURL=memory.store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory.store.d.ts","sourceRoot":"","sources":["../../../src/lib/memory/memory.store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAE1D,qBAAa,uBAAwB,SAAQ,qBAAqB;;CAIjE"}
@@ -0,0 +1,14 @@
1
+ import { type GeneratedTeachable, type Teachables } from '../teach/teachables.ts';
2
+ import { type StoredTeachable, TeachablesStore } from './store.ts';
3
+ export declare class SqliteTeachablesStore extends TeachablesStore {
4
+ #private;
5
+ constructor(path: string);
6
+ remember(userId: string, data: GeneratedTeachable): Promise<StoredTeachable>;
7
+ recall(userId: string, type?: GeneratedTeachable['type']): Promise<StoredTeachable[]>;
8
+ get(id: string): Promise<StoredTeachable | null>;
9
+ update(id: string, data: GeneratedTeachable): Promise<StoredTeachable>;
10
+ forget(id: string): Promise<void>;
11
+ forgetAll(userId: string): Promise<void>;
12
+ toTeachables(userId: string): Promise<Teachables[]>;
13
+ }
14
+ //# sourceMappingURL=sqlite.store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sqlite.store.d.ts","sourceRoot":"","sources":["../../../src/lib/memory/sqlite.store.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,UAAU,EAEhB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,KAAK,eAAe,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAsBnE,qBAAa,qBAAsB,SAAQ,eAAe;;gBAG5C,IAAI,EAAE,MAAM;IAMlB,QAAQ,CACZ,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,kBAAkB,GACvB,OAAO,CAAC,eAAe,CAAC;IAarB,MAAM,CACV,MAAM,EAAE,MAAM,EACd,IAAI,CAAC,EAAE,kBAAkB,CAAC,MAAM,CAAC,GAChC,OAAO,CAAC,eAAe,EAAE,CAAC;IAkBvB,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC;IAShD,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,kBAAkB,GAAG,OAAO,CAAC,eAAe,CAAC;IAYtE,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIjC,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIxC,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;CAI1D"}
@@ -0,0 +1,40 @@
1
+ import type { GeneratedTeachable, Teachables } from '../teach/teachables.ts';
2
+ export interface StoredTeachable {
3
+ id: string;
4
+ userId: string;
5
+ type: GeneratedTeachable['type'];
6
+ data: GeneratedTeachable;
7
+ createdAt: string;
8
+ updatedAt: string;
9
+ }
10
+ export declare abstract class TeachablesStore {
11
+ /**
12
+ * Remember a teachable for a user.
13
+ */
14
+ abstract remember(userId: string, data: GeneratedTeachable): Promise<StoredTeachable>;
15
+ /**
16
+ * Recall teachables for a user, optionally filtered by type.
17
+ */
18
+ abstract recall(userId: string, type?: GeneratedTeachable['type']): Promise<StoredTeachable[]>;
19
+ /**
20
+ * Get a specific teachable by ID.
21
+ */
22
+ abstract get(id: string): Promise<StoredTeachable | null>;
23
+ /**
24
+ * Update an existing teachable.
25
+ */
26
+ abstract update(id: string, data: GeneratedTeachable): Promise<StoredTeachable>;
27
+ /**
28
+ * Forget (remove) a specific teachable by ID.
29
+ */
30
+ abstract forget(id: string): Promise<void>;
31
+ /**
32
+ * Forget all teachables for a user.
33
+ */
34
+ abstract forgetAll(userId: string): Promise<void>;
35
+ /**
36
+ * Convert stored teachables to Teachables array for use with toInstructions().
37
+ */
38
+ abstract toTeachables(userId: string): Promise<Teachables[]>;
39
+ }
40
+ //# sourceMappingURL=store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../../src/lib/memory/store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAE7E,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,kBAAkB,CAAC,MAAM,CAAC,CAAC;IACjC,IAAI,EAAE,kBAAkB,CAAC;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,8BAAsB,eAAe;IACnC;;OAEG;IACH,QAAQ,CAAC,QAAQ,CACf,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,kBAAkB,GACvB,OAAO,CAAC,eAAe,CAAC;IAE3B;;OAEG;IACH,QAAQ,CAAC,MAAM,CACb,MAAM,EAAE,MAAM,EACd,IAAI,CAAC,EAAE,kBAAkB,CAAC,MAAM,CAAC,GAChC,OAAO,CAAC,eAAe,EAAE,CAAC;IAE7B;;OAEG;IACH,QAAQ,CAAC,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC;IAEzD;;OAEG;IACH,QAAQ,CAAC,MAAM,CACb,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,kBAAkB,GACvB,OAAO,CAAC,eAAe,CAAC;IAE3B;;OAEG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAE1C;;OAEG;IACH,QAAQ,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAEjD;;OAEG;IACH,QAAQ,CAAC,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;CAC7D"}
@@ -1,7 +1,2 @@
1
- import type { Introspection } from './adapters/adapter.ts';
2
- export declare function databaseSchemaPrompt(options: {
3
- introspection: Introspection;
4
- context?: string;
5
- adapterInfo?: string;
6
- }): string;
1
+ export declare function databaseSchemaPrompt(): void;
7
2
  //# sourceMappingURL=prompt.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"prompt.d.ts","sourceRoot":"","sources":["../../src/lib/prompt.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AA0H3D,wBAAgB,oBAAoB,CAAC,OAAO,EAAE;IAC5C,aAAa,EAAE,aAAa,CAAC;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,UAYA"}
1
+ {"version":3,"file":"prompt.d.ts","sourceRoot":"","sources":["../../src/lib/prompt.ts"],"names":[],"mappings":"AAAA,wBAAgB,oBAAoB,SAYnC"}