@stackfactor/agent-utils 1.13.4 → 1.32.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.
Files changed (252) hide show
  1. package/README.md +667 -23
  2. package/dist/cjs/agentProto.d.ts +13 -3
  3. package/dist/cjs/agentProto.d.ts.map +1 -1
  4. package/dist/cjs/agentProto.js +25 -4
  5. package/dist/cjs/backoff.d.ts +17 -0
  6. package/dist/cjs/backoff.d.ts.map +1 -0
  7. package/dist/cjs/backoff.js +26 -0
  8. package/dist/cjs/cancellation.d.ts +22 -0
  9. package/dist/cjs/cancellation.d.ts.map +1 -0
  10. package/dist/cjs/cancellation.js +36 -0
  11. package/dist/cjs/cli.d.ts +3 -0
  12. package/dist/cjs/cli.d.ts.map +1 -0
  13. package/dist/cjs/cli.js +85 -0
  14. package/dist/cjs/client.d.ts +11 -0
  15. package/dist/cjs/client.d.ts.map +1 -1
  16. package/dist/cjs/client.js +27 -0
  17. package/dist/cjs/const.d.ts +23 -0
  18. package/dist/cjs/const.d.ts.map +1 -1
  19. package/dist/cjs/const.js +23 -0
  20. package/dist/cjs/daemon.d.ts +94 -0
  21. package/dist/cjs/daemon.d.ts.map +1 -0
  22. package/dist/cjs/daemon.js +507 -0
  23. package/dist/cjs/daemonConfig.d.ts +45 -0
  24. package/dist/cjs/daemonConfig.d.ts.map +1 -0
  25. package/dist/cjs/daemonConfig.js +148 -0
  26. package/dist/cjs/daemonEnv.d.ts +10 -0
  27. package/dist/cjs/daemonEnv.d.ts.map +1 -0
  28. package/dist/cjs/daemonEnv.js +12 -0
  29. package/dist/cjs/durable/clientTool.d.ts +39 -0
  30. package/dist/cjs/durable/clientTool.d.ts.map +1 -0
  31. package/dist/cjs/durable/clientTool.js +90 -0
  32. package/dist/cjs/durable/index.d.ts +9 -0
  33. package/dist/cjs/durable/index.d.ts.map +1 -0
  34. package/dist/cjs/durable/index.js +16 -0
  35. package/dist/cjs/durable/journal.d.ts +218 -0
  36. package/dist/cjs/durable/journal.d.ts.map +1 -0
  37. package/dist/cjs/durable/journal.js +392 -0
  38. package/dist/cjs/durable/pause.d.ts +84 -0
  39. package/dist/cjs/durable/pause.d.ts.map +1 -0
  40. package/dist/cjs/durable/pause.js +241 -0
  41. package/dist/cjs/durable/resume.d.ts +27 -0
  42. package/dist/cjs/durable/resume.d.ts.map +1 -0
  43. package/dist/cjs/durable/resume.js +80 -0
  44. package/dist/cjs/durable/snapshotSaver.d.ts +38 -0
  45. package/dist/cjs/durable/snapshotSaver.d.ts.map +1 -0
  46. package/dist/cjs/durable/snapshotSaver.js +81 -0
  47. package/dist/cjs/durable/step.d.ts +28 -0
  48. package/dist/cjs/durable/step.d.ts.map +1 -0
  49. package/dist/cjs/durable/step.js +43 -0
  50. package/dist/cjs/index.d.ts +30 -7
  51. package/dist/cjs/index.d.ts.map +1 -1
  52. package/dist/cjs/index.js +28 -1
  53. package/dist/cjs/infrastructure.d.ts +50 -0
  54. package/dist/cjs/infrastructure.d.ts.map +1 -0
  55. package/dist/cjs/infrastructure.js +163 -0
  56. package/dist/cjs/langChain.d.ts +15 -3
  57. package/dist/cjs/langChain.d.ts.map +1 -1
  58. package/dist/cjs/langChain.js +986 -180
  59. package/dist/cjs/learningActivityMedia.d.ts +196 -0
  60. package/dist/cjs/learningActivityMedia.d.ts.map +1 -0
  61. package/dist/cjs/learningActivityMedia.js +861 -0
  62. package/dist/cjs/learningContentPlan.d.ts +105 -0
  63. package/dist/cjs/learningContentPlan.d.ts.map +1 -0
  64. package/dist/cjs/learningContentPlan.js +305 -0
  65. package/dist/cjs/learningContentThread.d.ts +184 -0
  66. package/dist/cjs/learningContentThread.d.ts.map +1 -0
  67. package/dist/cjs/learningContentThread.js +407 -0
  68. package/dist/cjs/logger.d.ts +1 -0
  69. package/dist/cjs/logger.d.ts.map +1 -1
  70. package/dist/cjs/logger.js +17 -3
  71. package/dist/cjs/modelRates.d.ts +40 -0
  72. package/dist/cjs/modelRates.d.ts.map +1 -0
  73. package/dist/cjs/modelRates.js +76 -0
  74. package/dist/cjs/referenceContext.d.ts +4 -145
  75. package/dist/cjs/referenceContext.d.ts.map +1 -1
  76. package/dist/cjs/referenceContext.js +16 -251
  77. package/dist/cjs/retry.d.ts +64 -0
  78. package/dist/cjs/retry.d.ts.map +1 -0
  79. package/dist/cjs/retry.js +138 -0
  80. package/dist/cjs/runtimeContext.d.ts +8 -1
  81. package/dist/cjs/runtimeContext.d.ts.map +1 -1
  82. package/dist/cjs/runtimeContext.js +3 -1
  83. package/dist/cjs/serve.d.ts +3 -2
  84. package/dist/cjs/serve.d.ts.map +1 -1
  85. package/dist/cjs/serve.js +32 -2
  86. package/dist/cjs/sourceStore.d.ts +378 -0
  87. package/dist/cjs/sourceStore.d.ts.map +1 -0
  88. package/dist/cjs/sourceStore.js +872 -0
  89. package/dist/cjs/stackfactorKnowledge.d.ts +91 -7
  90. package/dist/cjs/stackfactorKnowledge.d.ts.map +1 -1
  91. package/dist/cjs/stackfactorKnowledge.js +108 -44
  92. package/dist/cjs/tavily.d.ts +108 -4
  93. package/dist/cjs/tavily.d.ts.map +1 -1
  94. package/dist/cjs/tavily.js +242 -21
  95. package/dist/cjs/usage.d.ts.map +1 -1
  96. package/dist/cjs/usage.js +9 -15
  97. package/dist/cjs/version.d.ts +3 -0
  98. package/dist/cjs/version.d.ts.map +1 -0
  99. package/dist/cjs/version.js +5 -0
  100. package/dist/cjs/workflow/bookkeeping.d.ts +78 -0
  101. package/dist/cjs/workflow/bookkeeping.d.ts.map +1 -0
  102. package/dist/cjs/workflow/bookkeeping.js +75 -0
  103. package/dist/cjs/workflow/index.d.ts +13 -0
  104. package/dist/cjs/workflow/index.d.ts.map +1 -0
  105. package/dist/cjs/workflow/index.js +51 -0
  106. package/dist/cjs/workflow/limits.d.ts +52 -0
  107. package/dist/cjs/workflow/limits.d.ts.map +1 -0
  108. package/dist/cjs/workflow/limits.js +62 -0
  109. package/dist/cjs/workflow/platformTransport.d.ts +39 -0
  110. package/dist/cjs/workflow/platformTransport.d.ts.map +1 -0
  111. package/dist/cjs/workflow/platformTransport.js +115 -0
  112. package/dist/cjs/workflow/retrying.d.ts +44 -0
  113. package/dist/cjs/workflow/retrying.d.ts.map +1 -0
  114. package/dist/cjs/workflow/retrying.js +82 -0
  115. package/dist/cjs/workflow/run.d.ts +195 -0
  116. package/dist/cjs/workflow/run.d.ts.map +1 -0
  117. package/dist/cjs/workflow/run.js +858 -0
  118. package/dist/cjs/workflow/testing/index.d.ts +3 -0
  119. package/dist/cjs/workflow/testing/index.d.ts.map +1 -0
  120. package/dist/cjs/workflow/testing/index.js +6 -0
  121. package/dist/cjs/workflow/testing/memoryTransport.d.ts +203 -0
  122. package/dist/cjs/workflow/testing/memoryTransport.d.ts.map +1 -0
  123. package/dist/cjs/workflow/testing/memoryTransport.js +1171 -0
  124. package/dist/cjs/workflow/transport.d.ts +219 -0
  125. package/dist/cjs/workflow/transport.d.ts.map +1 -0
  126. package/dist/cjs/workflow/transport.js +19 -0
  127. package/dist/esm/agentProto.d.ts +13 -3
  128. package/dist/esm/agentProto.d.ts.map +1 -1
  129. package/dist/esm/agentProto.js +23 -3
  130. package/dist/esm/backoff.d.ts +17 -0
  131. package/dist/esm/backoff.d.ts.map +1 -0
  132. package/dist/esm/backoff.js +22 -0
  133. package/dist/esm/cancellation.d.ts +22 -0
  134. package/dist/esm/cancellation.d.ts.map +1 -0
  135. package/dist/esm/cancellation.js +27 -0
  136. package/dist/esm/cli.d.ts +3 -0
  137. package/dist/esm/cli.d.ts.map +1 -0
  138. package/dist/esm/cli.js +80 -0
  139. package/dist/esm/client.d.ts +11 -0
  140. package/dist/esm/client.d.ts.map +1 -1
  141. package/dist/esm/client.js +25 -1
  142. package/dist/esm/const.d.ts +23 -0
  143. package/dist/esm/const.d.ts.map +1 -1
  144. package/dist/esm/const.js +23 -0
  145. package/dist/esm/daemon.d.ts +94 -0
  146. package/dist/esm/daemon.d.ts.map +1 -0
  147. package/dist/esm/daemon.js +499 -0
  148. package/dist/esm/daemonConfig.d.ts +45 -0
  149. package/dist/esm/daemonConfig.d.ts.map +1 -0
  150. package/dist/esm/daemonConfig.js +142 -0
  151. package/dist/esm/daemonEnv.d.ts +10 -0
  152. package/dist/esm/daemonEnv.d.ts.map +1 -0
  153. package/dist/esm/daemonEnv.js +9 -0
  154. package/dist/esm/durable/clientTool.d.ts +39 -0
  155. package/dist/esm/durable/clientTool.d.ts.map +1 -0
  156. package/dist/esm/durable/clientTool.js +82 -0
  157. package/dist/esm/durable/index.d.ts +9 -0
  158. package/dist/esm/durable/index.d.ts.map +1 -0
  159. package/dist/esm/durable/index.js +8 -0
  160. package/dist/esm/durable/journal.d.ts +218 -0
  161. package/dist/esm/durable/journal.d.ts.map +1 -0
  162. package/dist/esm/durable/journal.js +374 -0
  163. package/dist/esm/durable/pause.d.ts +84 -0
  164. package/dist/esm/durable/pause.d.ts.map +1 -0
  165. package/dist/esm/durable/pause.js +226 -0
  166. package/dist/esm/durable/resume.d.ts +27 -0
  167. package/dist/esm/durable/resume.d.ts.map +1 -0
  168. package/dist/esm/durable/resume.js +72 -0
  169. package/dist/esm/durable/snapshotSaver.d.ts +38 -0
  170. package/dist/esm/durable/snapshotSaver.d.ts.map +1 -0
  171. package/dist/esm/durable/snapshotSaver.js +77 -0
  172. package/dist/esm/durable/step.d.ts +28 -0
  173. package/dist/esm/durable/step.d.ts.map +1 -0
  174. package/dist/esm/durable/step.js +36 -0
  175. package/dist/esm/index.d.ts +30 -7
  176. package/dist/esm/index.d.ts.map +1 -1
  177. package/dist/esm/index.js +20 -4
  178. package/dist/esm/infrastructure.d.ts +50 -0
  179. package/dist/esm/infrastructure.d.ts.map +1 -0
  180. package/dist/esm/infrastructure.js +156 -0
  181. package/dist/esm/langChain.d.ts +15 -3
  182. package/dist/esm/langChain.d.ts.map +1 -1
  183. package/dist/esm/langChain.js +984 -179
  184. package/dist/esm/learningActivityMedia.d.ts +196 -0
  185. package/dist/esm/learningActivityMedia.d.ts.map +1 -0
  186. package/dist/esm/learningActivityMedia.js +807 -0
  187. package/dist/esm/learningContentPlan.d.ts +105 -0
  188. package/dist/esm/learningContentPlan.d.ts.map +1 -0
  189. package/dist/esm/learningContentPlan.js +299 -0
  190. package/dist/esm/learningContentThread.d.ts +184 -0
  191. package/dist/esm/learningContentThread.d.ts.map +1 -0
  192. package/dist/esm/learningContentThread.js +364 -0
  193. package/dist/esm/logger.d.ts +1 -0
  194. package/dist/esm/logger.d.ts.map +1 -1
  195. package/dist/esm/logger.js +17 -3
  196. package/dist/esm/modelRates.d.ts +40 -0
  197. package/dist/esm/modelRates.d.ts.map +1 -0
  198. package/dist/esm/modelRates.js +68 -0
  199. package/dist/esm/referenceContext.d.ts +4 -145
  200. package/dist/esm/referenceContext.d.ts.map +1 -1
  201. package/dist/esm/referenceContext.js +16 -243
  202. package/dist/esm/retry.d.ts +64 -0
  203. package/dist/esm/retry.d.ts.map +1 -0
  204. package/dist/esm/retry.js +127 -0
  205. package/dist/esm/runtimeContext.d.ts +8 -1
  206. package/dist/esm/runtimeContext.d.ts.map +1 -1
  207. package/dist/esm/runtimeContext.js +3 -1
  208. package/dist/esm/serve.d.ts +3 -2
  209. package/dist/esm/serve.d.ts.map +1 -1
  210. package/dist/esm/serve.js +33 -3
  211. package/dist/esm/sourceStore.d.ts +378 -0
  212. package/dist/esm/sourceStore.d.ts.map +1 -0
  213. package/dist/esm/sourceStore.js +855 -0
  214. package/dist/esm/stackfactorKnowledge.d.ts +91 -7
  215. package/dist/esm/stackfactorKnowledge.d.ts.map +1 -1
  216. package/dist/esm/stackfactorKnowledge.js +101 -41
  217. package/dist/esm/tavily.d.ts +108 -4
  218. package/dist/esm/tavily.d.ts.map +1 -1
  219. package/dist/esm/tavily.js +237 -20
  220. package/dist/esm/usage.d.ts.map +1 -1
  221. package/dist/esm/usage.js +9 -15
  222. package/dist/esm/version.d.ts +3 -0
  223. package/dist/esm/version.d.ts.map +1 -0
  224. package/dist/esm/version.js +2 -0
  225. package/dist/esm/workflow/bookkeeping.d.ts +78 -0
  226. package/dist/esm/workflow/bookkeeping.d.ts.map +1 -0
  227. package/dist/esm/workflow/bookkeeping.js +67 -0
  228. package/dist/esm/workflow/index.d.ts +13 -0
  229. package/dist/esm/workflow/index.d.ts.map +1 -0
  230. package/dist/esm/workflow/index.js +10 -0
  231. package/dist/esm/workflow/limits.d.ts +52 -0
  232. package/dist/esm/workflow/limits.d.ts.map +1 -0
  233. package/dist/esm/workflow/limits.js +59 -0
  234. package/dist/esm/workflow/platformTransport.d.ts +39 -0
  235. package/dist/esm/workflow/platformTransport.d.ts.map +1 -0
  236. package/dist/esm/workflow/platformTransport.js +110 -0
  237. package/dist/esm/workflow/retrying.d.ts +44 -0
  238. package/dist/esm/workflow/retrying.d.ts.map +1 -0
  239. package/dist/esm/workflow/retrying.js +73 -0
  240. package/dist/esm/workflow/run.d.ts +195 -0
  241. package/dist/esm/workflow/run.d.ts.map +1 -0
  242. package/dist/esm/workflow/run.js +850 -0
  243. package/dist/esm/workflow/testing/index.d.ts +3 -0
  244. package/dist/esm/workflow/testing/index.d.ts.map +1 -0
  245. package/dist/esm/workflow/testing/index.js +2 -0
  246. package/dist/esm/workflow/testing/memoryTransport.d.ts +203 -0
  247. package/dist/esm/workflow/testing/memoryTransport.d.ts.map +1 -0
  248. package/dist/esm/workflow/testing/memoryTransport.js +1167 -0
  249. package/dist/esm/workflow/transport.d.ts +219 -0
  250. package/dist/esm/workflow/transport.d.ts.map +1 -0
  251. package/dist/esm/workflow/transport.js +16 -0
  252. package/package.json +8 -7
@@ -0,0 +1,105 @@
1
+ import { z } from "zod";
2
+ import { learningContentPlan } from "@stackfactor/client-api";
3
+ import type { LearningContentPlanContext } from "@stackfactor/client-api";
4
+ /** client-api's limits, frozen: THROUGH_LINE, ROLE, HANDS_TO, TERM, DEFINITION, BUILDS_ON, OWNED_TERMS. */
5
+ export declare const PLAN_LIMITS: Readonly<{
6
+ THROUGH_LINE: 200;
7
+ ROLE: 160;
8
+ HANDS_TO: 120;
9
+ TERM: 60;
10
+ DEFINITION: 200;
11
+ BUILDS_ON: 2;
12
+ OWNED_TERMS: 3;
13
+ }>;
14
+ export interface ContentPlanLesson {
15
+ microSkillId: string;
16
+ role: string;
17
+ buildsOn: string[];
18
+ handsTo: string;
19
+ }
20
+ export interface ContentPlanTerm {
21
+ key: string;
22
+ term: string;
23
+ definition: string;
24
+ ownerMicroSkillId: string;
25
+ }
26
+ export interface ContentPlan {
27
+ throughLine: string;
28
+ lessons: ContentPlanLesson[];
29
+ terms: ContentPlanTerm[];
30
+ }
31
+ /**
32
+ * A plan as a model answers it and as core takes it. The schema holds structure
33
+ * only (strings and arrays), so every provider's structured output can take it;
34
+ * each limit is a refinement, which a provider is never sent.
35
+ */
36
+ export declare const planSchema: z.ZodType<ContentPlan>;
37
+ /** What a model answers when it extends a plan: the new lessons and the new terms only. */
38
+ export interface ContentPlanExtension {
39
+ lessons: ContentPlanLesson[];
40
+ terms: ContentPlanTerm[];
41
+ }
42
+ /** Structure for the provider; every limit a refinement, as in planSchema. Limits are counted within the extension. */
43
+ export declare const planExtensionSchema: z.ZodType<ContentPlanExtension>;
44
+ /**
45
+ * What a lesson agent is given. Unknown keys are dropped; `handsTo` absent or
46
+ * null becomes "", the three booleans default to false, the lists to [].
47
+ */
48
+ export declare const planContextSchema: z.ZodType<LearningContentPlanContext>;
49
+ /**
50
+ * What does not fit between a plan and the skill it is for, one sentence each,
51
+ * each sentence once, in the order first met. `[]` when it fits. It never
52
+ * throws, whatever it is given: a `lessons` or `terms` that is missing or not a
53
+ * list counts as empty, an entry that is not an object is passed over, and a
54
+ * `buildsOn` that is not a list counts as empty.
55
+ * `microSkillIds` is every micro-skill of the skill in course order; it may hold
56
+ * strings or ids with a `toString()`, and ids are compared as strings.
57
+ */
58
+ export declare const planProblems: (plan: ContentPlan, microSkillIds: unknown[]) => string[];
59
+ /**
60
+ * What is wrong with an extension of a plan for a skill, one sentence each, each
61
+ * once. [] when nothing is. Never throws. `microSkillIds` is the skill's
62
+ * micro-skills in course order; ids are compared as strings. WRITTEN is the ids
63
+ * of the existing plan's lessons that are in the skill; an existing term counts
64
+ * only when its owner is in the skill. In order: a micro-skill that is not
65
+ * WRITTEN and has no lesson in the extension; an extension lesson for a WRITTEN
66
+ * micro-skill; an extension lesson for an id that is not in the skill; an
67
+ * extension term whose key is a key of the existing plan; an extension term
68
+ * owned by a WRITTEN micro-skill; an extension term whose owner has no lesson in
69
+ * the extension; a lesson building on a key that is no counted existing term and
70
+ * no extension term; a lesson building on a term it owns or on one owned by a
71
+ * micro-skill that is not earlier in course order. Existing lessons and terms
72
+ * are never reported, and an entry that already has a sentence is not judged by
73
+ * a later rule.
74
+ */
75
+ export declare const extensionProblems: (extension: ContentPlanExtension, existingPlan: unknown, microSkillIds: unknown[]) => string[];
76
+ /**
77
+ * The existing plan with the extension's lessons and terms after its own.
78
+ * Changes neither argument. Never throws: a missing or non-list `lessons` or
79
+ * `terms` counts as empty, an entry that is not an object is passed over, and an
80
+ * existing lesson's missing `buildsOn` or `handsTo` becomes [] or "".
81
+ */
82
+ export declare const mergePlanExtension: (existingPlan: unknown, extension: ContentPlanExtension) => ContentPlan;
83
+ /** The record a lesson answers and stores; the two lines as text are `ThreadLines`. */
84
+ export type { LearningContentThread } from "@stackfactor/client-api";
85
+ /** One of the two lines of `LearningContentThread`, with what it was written from. */
86
+ export type { LearningContentThreadSentence } from "@stackfactor/client-api";
87
+ declare const _default: {
88
+ PLAN_LIMITS: Readonly<{
89
+ THROUGH_LINE: 200;
90
+ ROLE: 160;
91
+ HANDS_TO: 120;
92
+ TERM: 60;
93
+ DEFINITION: 200;
94
+ BUILDS_ON: 2;
95
+ OWNED_TERMS: 3;
96
+ }>;
97
+ planSchema: z.ZodType<ContentPlan, unknown, z.core.$ZodTypeInternals<ContentPlan, unknown>>;
98
+ planContextSchema: z.ZodType<learningContentPlan.LearningContentPlanContext, unknown, z.core.$ZodTypeInternals<learningContentPlan.LearningContentPlanContext, unknown>>;
99
+ planProblems: (plan: ContentPlan, microSkillIds: unknown[]) => string[];
100
+ planExtensionSchema: z.ZodType<ContentPlanExtension, unknown, z.core.$ZodTypeInternals<ContentPlanExtension, unknown>>;
101
+ extensionProblems: (extension: ContentPlanExtension, existingPlan: unknown, microSkillIds: unknown[]) => string[];
102
+ mergePlanExtension: (existingPlan: unknown, extension: ContentPlanExtension) => ContentPlan;
103
+ };
104
+ export default _default;
105
+ //# sourceMappingURL=learningContentPlan.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"learningContentPlan.d.ts","sourceRoot":"","sources":["../../src/learningContentPlan.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,yBAAyB,CAAC;AAE1E,2GAA2G;AAC3G,eAAO,MAAM,WAAW;;;;;;;;EAAyE,CAAC;AAElG,MAAM,WAAW,iBAAiB;IAChC,YAAY,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,eAAe;IAC9B,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,iBAAiB,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,WAAW;IAC1B,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,iBAAiB,EAAE,CAAC;IAC7B,KAAK,EAAE,eAAe,EAAE,CAAC;CAC1B;AA2DD;;;;GAIG;AACH,eAAO,MAAM,UAAU,EAUJ,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;AAE1C,2FAA2F;AAC3F,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,iBAAiB,EAAE,CAAC;IAC7B,KAAK,EAAE,eAAe,EAAE,CAAC;CAC1B;AAED,uHAAuH;AACvH,eAAO,MAAM,mBAAmB,EAMb,CAAC,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAC;AAEnD;;;GAGG;AACH,eAAO,MAAM,iBAAiB,EAYb,CAAC,CAAC,OAAO,CAAC,0BAA0B,CAAC,CAAC;AAEvD;;;;;;;;GAQG;AACH,eAAO,MAAM,YAAY,GAAI,MAAM,WAAW,EAAE,eAAe,OAAO,EAAE,KAAG,MAAM,EA2ChF,CAAC;AAMF;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,iBAAiB,GAAI,WAAW,oBAAoB,EAAE,cAAc,OAAO,EAAE,eAAe,OAAO,EAAE,KAAG,MAAM,EAqE1H,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,GAAI,cAAc,OAAO,EAAE,WAAW,oBAAoB,KAAG,WAc3F,CAAC;AAEF,uFAAuF;AACvF,YAAY,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AACrE,sFAAsF;AACtF,YAAY,EAAE,6BAA6B,EAAE,MAAM,yBAAyB,CAAC;;;;;;;;;;;;;yBAjK1C,WAAW,iBAAiB,OAAO,EAAE,KAAG,MAAM,EAAE;;mCAiEtC,oBAAoB,gBAAgB,OAAO,iBAAiB,OAAO,EAAE,KAAG,MAAM,EAAE;uCA6E5E,OAAO,aAAa,oBAAoB,KAAG,WAAW;;AAqBvG,wBAQE"}
@@ -0,0 +1,305 @@
1
+ "use strict";
2
+ //
3
+ // learningContentPlan — the shape of a learning content plan and its fit with
4
+ // the skill it is for. Zod schemas and one pure function; nothing here calls a
5
+ // model. The limits are client-api's, which mirror core's.
6
+ //
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.mergePlanExtension = exports.extensionProblems = exports.planProblems = exports.planContextSchema = exports.planExtensionSchema = exports.planSchema = exports.PLAN_LIMITS = void 0;
9
+ const zod_1 = require("zod");
10
+ const client_api_1 = require("@stackfactor/client-api");
11
+ /** client-api's limits, frozen: THROUGH_LINE, ROLE, HANDS_TO, TERM, DEFINITION, BUILDS_ON, OWNED_TERMS. */
12
+ exports.PLAN_LIMITS = Object.freeze({ ...client_api_1.learningContentPlan.LEARNING_CONTENT_PLAN.LIMITS });
13
+ const blank = (text) => typeof text !== "string" || text.trim() === "";
14
+ const lessonShape = zod_1.z.object({
15
+ microSkillId: zod_1.z.string(),
16
+ role: zod_1.z.string(),
17
+ buildsOn: zod_1.z.array(zod_1.z.string()),
18
+ handsTo: zod_1.z.string(),
19
+ });
20
+ const termShape = zod_1.z.object({
21
+ key: zod_1.z.string(),
22
+ term: zod_1.z.string(),
23
+ definition: zod_1.z.string(),
24
+ ownerMicroSkillId: zod_1.z.string(),
25
+ });
26
+ // The refinements of a list of lessons.
27
+ const refineLessons = (lessons, add) => {
28
+ const seenLessons = new Set();
29
+ lessons.forEach((lesson, i) => {
30
+ const name = blank(lesson.microSkillId) ? `lesson ${i + 1}` : lesson.microSkillId;
31
+ if (blank(lesson.microSkillId))
32
+ add(`The lesson at position ${i + 1} has a blank microSkillId.`, ["lessons", i, "microSkillId"]);
33
+ else if (seenLessons.has(lesson.microSkillId))
34
+ add(`The plan has more than one lesson for ${lesson.microSkillId}.`, ["lessons", i, "microSkillId"]);
35
+ seenLessons.add(lesson.microSkillId);
36
+ if (blank(lesson.role))
37
+ add(`The lesson for ${name} has a blank role.`, ["lessons", i, "role"]);
38
+ else if (lesson.role.length > exports.PLAN_LIMITS.ROLE)
39
+ add(`The lesson for ${name} has a role over ${exports.PLAN_LIMITS.ROLE} characters.`, ["lessons", i, "role"]);
40
+ if (lesson.handsTo.length > exports.PLAN_LIMITS.HANDS_TO)
41
+ add(`The lesson for ${name} has a handsTo over ${exports.PLAN_LIMITS.HANDS_TO} characters.`, ["lessons", i, "handsTo"]);
42
+ if (lesson.buildsOn.length > exports.PLAN_LIMITS.BUILDS_ON)
43
+ add(`The lesson for ${name} builds on more than ${exports.PLAN_LIMITS.BUILDS_ON} terms.`, ["lessons", i, "buildsOn"]);
44
+ });
45
+ };
46
+ // The refinements of a list of terms.
47
+ const refineTerms = (terms, add) => {
48
+ const seenKeys = new Set();
49
+ const ownedBy = new Map();
50
+ terms.forEach((term, i) => {
51
+ const name = blank(term.key) ? `term ${i + 1}` : term.key;
52
+ if (blank(term.key))
53
+ add(`The term at position ${i + 1} has a blank key.`, ["terms", i, "key"]);
54
+ else if (seenKeys.has(term.key))
55
+ add(`The plan has more than one term with the key ${term.key}.`, ["terms", i, "key"]);
56
+ seenKeys.add(term.key);
57
+ if (blank(term.term))
58
+ add(`The term ${name} has a blank term.`, ["terms", i, "term"]);
59
+ else if (term.term.length > exports.PLAN_LIMITS.TERM)
60
+ add(`The term with the key ${name} is over ${exports.PLAN_LIMITS.TERM} characters.`, ["terms", i, "term"]);
61
+ if (blank(term.definition))
62
+ add(`The term ${name} has a blank definition.`, ["terms", i, "definition"]);
63
+ else if (term.definition.length > exports.PLAN_LIMITS.DEFINITION)
64
+ add(`The definition of the term with the key ${name} is over ${exports.PLAN_LIMITS.DEFINITION} characters.`, ["terms", i, "definition"]);
65
+ if (blank(term.ownerMicroSkillId))
66
+ add(`The term ${name} has a blank ownerMicroSkillId.`, ["terms", i, "ownerMicroSkillId"]);
67
+ else {
68
+ const count = (ownedBy.get(term.ownerMicroSkillId) ?? 0) + 1;
69
+ ownedBy.set(term.ownerMicroSkillId, count);
70
+ if (count === exports.PLAN_LIMITS.OWNED_TERMS + 1) {
71
+ add(`The lesson for ${term.ownerMicroSkillId} owns more than ${exports.PLAN_LIMITS.OWNED_TERMS} terms.`, ["terms", i, "ownerMicroSkillId"]);
72
+ }
73
+ }
74
+ });
75
+ };
76
+ /**
77
+ * A plan as a model answers it and as core takes it. The schema holds structure
78
+ * only (strings and arrays), so every provider's structured output can take it;
79
+ * each limit is a refinement, which a provider is never sent.
80
+ */
81
+ exports.planSchema = zod_1.z
82
+ .object({ throughLine: zod_1.z.string(), lessons: zod_1.z.array(lessonShape), terms: zod_1.z.array(termShape) })
83
+ .superRefine((plan, ctx) => {
84
+ const add = (message, path) => ctx.addIssue({ code: "custom", message, path });
85
+ if (blank(plan.throughLine))
86
+ add("The through-line is blank.", ["throughLine"]);
87
+ else if (plan.throughLine.length > exports.PLAN_LIMITS.THROUGH_LINE) {
88
+ add(`The through-line is over ${exports.PLAN_LIMITS.THROUGH_LINE} characters.`, ["throughLine"]);
89
+ }
90
+ refineLessons(plan.lessons, add);
91
+ refineTerms(plan.terms, add);
92
+ });
93
+ /** Structure for the provider; every limit a refinement, as in planSchema. Limits are counted within the extension. */
94
+ exports.planExtensionSchema = zod_1.z
95
+ .object({ lessons: zod_1.z.array(lessonShape), terms: zod_1.z.array(termShape) })
96
+ .superRefine((extension, ctx) => {
97
+ const add = (message, path) => ctx.addIssue({ code: "custom", message, path });
98
+ refineLessons(extension.lessons, add);
99
+ refineTerms(extension.terms, add);
100
+ });
101
+ /**
102
+ * What a lesson agent is given. Unknown keys are dropped; `handsTo` absent or
103
+ * null becomes "", the three booleans default to false, the lists to [].
104
+ */
105
+ exports.planContextSchema = zod_1.z.object({
106
+ throughLine: zod_1.z.string(),
107
+ role: zod_1.z.string(),
108
+ handsTo: zod_1.z
109
+ .string()
110
+ .nullish()
111
+ .transform((value) => value ?? ""),
112
+ opensContent: zod_1.z.boolean().default(false),
113
+ opensLevel: zod_1.z.boolean().default(false),
114
+ closesContent: zod_1.z.boolean().default(false),
115
+ buildsOn: zod_1.z.array(zod_1.z.object({ term: zod_1.z.string(), definition: zod_1.z.string() })).default([]),
116
+ ownedTerms: zod_1.z.array(zod_1.z.object({ term: zod_1.z.string(), definition: zod_1.z.string() })).default([]),
117
+ });
118
+ /**
119
+ * What does not fit between a plan and the skill it is for, one sentence each,
120
+ * each sentence once, in the order first met. `[]` when it fits. It never
121
+ * throws, whatever it is given: a `lessons` or `terms` that is missing or not a
122
+ * list counts as empty, an entry that is not an object is passed over, and a
123
+ * `buildsOn` that is not a list counts as empty.
124
+ * `microSkillIds` is every micro-skill of the skill in course order; it may hold
125
+ * strings or ids with a `toString()`, and ids are compared as strings.
126
+ */
127
+ const planProblems = (plan, microSkillIds) => {
128
+ const problems = new Set();
129
+ const entries = (value) => (Array.isArray(value) ? value.filter((e) => e && typeof e === "object") : []);
130
+ const lessons = entries(plan?.lessons);
131
+ const terms = entries(plan?.terms);
132
+ const position = new Map();
133
+ entries2(microSkillIds).forEach((id, i) => {
134
+ const key = String(id);
135
+ if (!position.has(key))
136
+ position.set(key, i);
137
+ });
138
+ const lessonIds = new Set(lessons.map((lesson) => String(lesson.microSkillId)));
139
+ for (const id of position.keys()) {
140
+ if (!lessonIds.has(id))
141
+ problems.add(`The plan has no lesson for ${id}.`);
142
+ }
143
+ for (const lesson of lessons) {
144
+ const id = String(lesson.microSkillId);
145
+ if (!position.has(id))
146
+ problems.add(`The plan has a lesson for ${id}, which is not a micro-skill of this skill.`);
147
+ }
148
+ const termByKey = new Map();
149
+ for (const term of terms) {
150
+ if (!termByKey.has(term.key))
151
+ termByKey.set(term.key, term);
152
+ const owner = String(term.ownerMicroSkillId);
153
+ if (!position.has(owner))
154
+ problems.add(`The term ${term.key} is owned by ${owner}, which is not a micro-skill of this skill.`);
155
+ }
156
+ for (const lesson of lessons) {
157
+ const id = String(lesson.microSkillId);
158
+ for (const key of Array.isArray(lesson.buildsOn) ? lesson.buildsOn : []) {
159
+ const term = termByKey.get(key);
160
+ if (!term) {
161
+ problems.add(`The lesson for ${id} builds on ${key}, which is not a term of the plan.`);
162
+ continue;
163
+ }
164
+ const owner = String(term.ownerMicroSkillId);
165
+ if (owner === id)
166
+ problems.add(`The lesson for ${id} builds on ${key}, a term it owns itself.`);
167
+ else if (position.has(owner) && position.has(id) && position.get(owner) > position.get(id)) {
168
+ problems.add(`The lesson for ${id} builds on ${key}, a term owned by ${owner}, which comes later in the course.`);
169
+ }
170
+ }
171
+ }
172
+ return [...problems];
173
+ };
174
+ exports.planProblems = planProblems;
175
+ const entries2 = (value) => (Array.isArray(value) ? value : []);
176
+ const objectsOf = (value) => (Array.isArray(value) ? value.filter((e) => e && typeof e === "object") : []);
177
+ /**
178
+ * What is wrong with an extension of a plan for a skill, one sentence each, each
179
+ * once. [] when nothing is. Never throws. `microSkillIds` is the skill's
180
+ * micro-skills in course order; ids are compared as strings. WRITTEN is the ids
181
+ * of the existing plan's lessons that are in the skill; an existing term counts
182
+ * only when its owner is in the skill. In order: a micro-skill that is not
183
+ * WRITTEN and has no lesson in the extension; an extension lesson for a WRITTEN
184
+ * micro-skill; an extension lesson for an id that is not in the skill; an
185
+ * extension term whose key is a key of the existing plan; an extension term
186
+ * owned by a WRITTEN micro-skill; an extension term whose owner has no lesson in
187
+ * the extension; a lesson building on a key that is no counted existing term and
188
+ * no extension term; a lesson building on a term it owns or on one owned by a
189
+ * micro-skill that is not earlier in course order. Existing lessons and terms
190
+ * are never reported, and an entry that already has a sentence is not judged by
191
+ * a later rule.
192
+ */
193
+ const extensionProblems = (extension, existingPlan, microSkillIds) => {
194
+ const problems = [];
195
+ const skill = [];
196
+ const position = new Map();
197
+ entries2(microSkillIds).forEach((id) => {
198
+ const key = String(id);
199
+ if (!position.has(key)) {
200
+ position.set(key, skill.length);
201
+ skill.push(key);
202
+ }
203
+ });
204
+ const existingLessons = objectsOf(existingPlan?.lessons);
205
+ const existingTerms = objectsOf(existingPlan?.terms);
206
+ const written = new Set(existingLessons.map((lesson) => String(lesson.microSkillId)).filter((id) => position.has(id)));
207
+ const existingKeys = new Set(existingTerms.map((term) => String(term.key)));
208
+ const counted = new Map();
209
+ for (const term of existingTerms) {
210
+ if (position.has(String(term.ownerMicroSkillId)) && !counted.has(String(term.key)))
211
+ counted.set(String(term.key), term);
212
+ }
213
+ const newLessons = objectsOf(extension?.lessons);
214
+ const newTerms = objectsOf(extension?.terms);
215
+ const newLessonIds = new Set(newLessons.map((lesson) => String(lesson.microSkillId)));
216
+ const say = (sentence) => {
217
+ if (!problems.includes(sentence))
218
+ problems.push(sentence);
219
+ };
220
+ for (const id of skill) {
221
+ if (!written.has(id) && !newLessonIds.has(id))
222
+ say(`The extension has no lesson for ${id}.`);
223
+ }
224
+ const badLessons = new Set();
225
+ for (const lesson of newLessons) {
226
+ const id = String(lesson.microSkillId);
227
+ if (written.has(id)) {
228
+ say(`The plan already has a lesson for ${id}; an extension leaves it as it is.`);
229
+ badLessons.add(lesson);
230
+ }
231
+ else if (!position.has(id)) {
232
+ say(`The extension has a lesson for ${id}, which is not a micro-skill of this skill.`);
233
+ badLessons.add(lesson);
234
+ }
235
+ }
236
+ const newByKey = new Map();
237
+ const goodTerms = new Set();
238
+ for (const term of newTerms) {
239
+ const key = String(term.key);
240
+ const owner = String(term.ownerMicroSkillId);
241
+ if (!newByKey.has(key))
242
+ newByKey.set(key, term);
243
+ if (existingKeys.has(key))
244
+ say(`The plan already has a term with the key ${key}.`);
245
+ else if (written.has(owner))
246
+ say(`The term ${key} is owned by ${owner}, whose lesson is already written; a new term is owned by a new lesson.`);
247
+ else if (!newLessonIds.has(owner) || !position.has(owner))
248
+ say(`The term ${key} is owned by ${owner}, which has no lesson in the extension.`);
249
+ else
250
+ goodTerms.add(term);
251
+ }
252
+ for (const lesson of newLessons) {
253
+ if (badLessons.has(lesson))
254
+ continue;
255
+ const id = String(lesson.microSkillId);
256
+ for (const key of Array.isArray(lesson.buildsOn) ? lesson.buildsOn : []) {
257
+ const term = newByKey.get(String(key)) ?? counted.get(String(key));
258
+ if (!term) {
259
+ say(`The lesson for ${id} builds on ${key}, which is not a term of the plan.`);
260
+ continue;
261
+ }
262
+ if (newByKey.get(String(key)) === term && !goodTerms.has(term))
263
+ continue;
264
+ const owner = String(term.ownerMicroSkillId);
265
+ if (owner === id)
266
+ say(`The lesson for ${id} builds on ${key}, a term it owns itself.`);
267
+ else if (position.has(owner) && position.has(id) && position.get(owner) > position.get(id)) {
268
+ say(`The lesson for ${id} builds on ${key}, a term owned by ${owner}, which comes later in the course.`);
269
+ }
270
+ }
271
+ }
272
+ return problems;
273
+ };
274
+ exports.extensionProblems = extensionProblems;
275
+ /**
276
+ * The existing plan with the extension's lessons and terms after its own.
277
+ * Changes neither argument. Never throws: a missing or non-list `lessons` or
278
+ * `terms` counts as empty, an entry that is not an object is passed over, and an
279
+ * existing lesson's missing `buildsOn` or `handsTo` becomes [] or "".
280
+ */
281
+ const mergePlanExtension = (existingPlan, extension) => {
282
+ const asLesson = (lesson) => ({
283
+ microSkillId: String(lesson.microSkillId),
284
+ role: lesson.role,
285
+ buildsOn: Array.isArray(lesson.buildsOn) ? [...lesson.buildsOn] : [],
286
+ handsTo: typeof lesson.handsTo === "string" ? lesson.handsTo : "",
287
+ });
288
+ const asTerm = (term) => ({ ...term, ownerMicroSkillId: String(term.ownerMicroSkillId) });
289
+ const throughLine = existingPlan?.throughLine;
290
+ return {
291
+ throughLine: typeof throughLine === "string" ? throughLine : "",
292
+ lessons: [...objectsOf(existingPlan?.lessons).map(asLesson), ...objectsOf(extension?.lessons).map(asLesson)],
293
+ terms: [...objectsOf(existingPlan?.terms).map(asTerm), ...objectsOf(extension?.terms).map(asTerm)],
294
+ };
295
+ };
296
+ exports.mergePlanExtension = mergePlanExtension;
297
+ exports.default = {
298
+ PLAN_LIMITS: exports.PLAN_LIMITS,
299
+ planSchema: exports.planSchema,
300
+ planContextSchema: exports.planContextSchema,
301
+ planProblems: exports.planProblems,
302
+ planExtensionSchema: exports.planExtensionSchema,
303
+ extensionProblems: exports.extensionProblems,
304
+ mergePlanExtension: exports.mergePlanExtension,
305
+ };
@@ -0,0 +1,184 @@
1
+ import type { UsageTracker } from "./langChain.js";
2
+ import type { LearningContentPlanContext } from "@stackfactor/client-api";
3
+ /** The limits of the two lines. Opening: at most 60 words and 3 sentences. Closing: at most 30 words and 2 sentences. */
4
+ export declare const THREAD_LIMITS: Readonly<{
5
+ OPENING_WORDS: 60;
6
+ OPENING_SENTENCES: 3;
7
+ CLOSING_WORDS: 30;
8
+ CLOSING_SENTENCES: 2;
9
+ }>;
10
+ /** The two lines as text; what a lesson stores of them is `LearningContentThread`. */
11
+ export interface ThreadLines {
12
+ opening: string;
13
+ closing: string;
14
+ }
15
+ /** What a lesson is given from the plan. Core builds it; one shape, client-api's. */
16
+ export type PlanContext = LearningContentPlanContext;
17
+ /**
18
+ * The number of runs of non-whitespace that hold a letter or a digit.
19
+ * "" and " — " are 0. A line is blank when this is 0.
20
+ */
21
+ export declare const countWords: (text: string) => number;
22
+ /**
23
+ * The number of sentences. A sentence ends at one or more of . ! ? (with any
24
+ * closing " ' ) ] ” ’ » after them) followed by whitespace or the end of the
25
+ * text. Not an end: a mark followed by whitespace and then a lower-case letter;
26
+ * a period after e.g, i.e, etc, vs, Mr, Mrs, Ms, Dr, Prof or St (any case), or
27
+ * after No, Art, Sec, Fig or approx (any case) when a digit follows; a period after a single capital letter that
28
+ * stands alone or follows a period (not one glued to a digit or a hyphen). A
29
+ * piece with no letter or digit is not a sentence. Text with no end mark is one
30
+ * sentence when it has a word, else 0. The scan is linear.
31
+ */
32
+ export declare const countSentences: (text: string) => number;
33
+ /**
34
+ * Every phrase of the text that depends on the order of lessons, as written in
35
+ * the text (each run of whitespace as one space), in the order the phrases
36
+ * start. [] when none. Case-insensitive, on word boundaries. The families:
37
+ * a relative word (last, previous, prior, earlier, preceding, next, following,
38
+ * upcoming, later, subsequent) then a unit (lesson, video, lecture, module,
39
+ * chapter, episode, section); an ordinal (first ... fifth, final) then
40
+ * lesson, video or lecture; lesson, video or lecture with a number ("lessons 4",
41
+ * "lesson one"); "as we saw" and its kin ("as you have learned", "as we've
42
+ * seen"); "as discussed earlier" and its kin; "earlier in this course" and its
43
+ * kin ("so far in the course"); "previously we"; "we previously saw"; "earlier,
44
+ * you met"; "last time, we"; "in" + the or our + previous, last, next, following
45
+ * or earlier + unit, topic, part or class ("in the previous unit"); "next, you
46
+ * will learn" and its kin (next, optional comma, we or you, will or 'll, then
47
+ * learn, see, meet, explore, cover, look, study or discover); "before this, you"
48
+ * (or we); "now that you have learned" and its kin (have or 've, then learned,
49
+ * learnt, mastered, covered, seen, met, studied or explored); "as you will
50
+ * see" (or we); "up next" and "coming up next". Not a position phrase: a unit
51
+ * (or a part, topic or class of the "in the next ..." family) followed by "of"
52
+ * and something other than a part of the course (course, series, module, level,
53
+ * programme, program, path, with or without this, the or our); a unit followed
54
+ * by "test" or "tests" in the "in the next unit" form; "lesson learned"; "video
55
+ * call", "video meetings" and their kin; a module, chapter, episode, section
56
+ * or session with a number; "session" as a unit; a relative word then a unit
57
+ * other than lesson, or an ordinal then video or lecture, when the word right
58
+ * before it is your, my, their, his, her, its, a, an, each, every or any ("your
59
+ * first video" is content; "a later lesson" and "your next lesson" are always
60
+ * about the course); "last time, we"
61
+ * when the word right before it is "the"; "earlier in this course" and its kin
62
+ * when "of" follows. Where two overlap, the one that starts first is kept, and
63
+ * of two that start together the longer.
64
+ */
65
+ export declare const findPositionPhrases: (text: string) => string[];
66
+ /**
67
+ * Whether the text names the term, in the form given or its plural. A word is a
68
+ * run of letters and digits; two words match when they are equal ignoring case,
69
+ * or one is the other's plural (plus "s", plus "es", "y" replaced by "ies", or "is" replaced by "es").
70
+ * A term with a word of 3 or more characters is named when every such word of it
71
+ * matches some word of the text, and every shorter word of it that is in capitals
72
+ * or holds a digit ("AI", "1") is in the text as a whole word, written the same,
73
+ * with an optional "s" after it.
74
+ * A term with no word of 3 or more characters ("AI", "P x I") is named when the
75
+ * text holds the whole term as written (any run of whitespace in it matching any run of whitespace), bounded by characters that are not
76
+ * letters or digits, with an optional "s" after it; ignoring case, unless the
77
+ * term is all in capitals, which is matched as written. Compared in NFC form.
78
+ * A term that ends in one part in round brackets holding a word of two letters
79
+ * or more, such as "Personal protective equipment (PPE)", is named when the
80
+ * text names the part before the brackets or the part inside them, each judged
81
+ * by the rules above. Any other brackets ("Article 6(1)(f)", "Regulation (EU)
82
+ * 2016/679") are read as spaces, and the whole term is judged.
83
+ */
84
+ export declare const namesTerm: (text: string, term: string) => boolean;
85
+ /**
86
+ * What is wrong with the two lines, one sentence each, written for the model
87
+ * that must fix them. [] when nothing is. A line is blank when it has no word.
88
+ * In order: the opening is blank; the closing is blank; the opening's words,
89
+ * then its sentences; the closing's words, then its sentences; each position
90
+ * phrase (opening first, with advice that depends on the line); each built-on
91
+ * term the opening does not name (an entry without a term is passed over). A
92
+ * blank line gets only its "blank" problem.
93
+ */
94
+ export declare const threadProblems: (lines: ThreadLines, planContext: PlanContext) => string[];
95
+ /** The rules as data, for the user message of the model that writes the lines. The example phrases are each found by findPositionPhrases. */
96
+ export declare const threadRulesForPrompt: () => {
97
+ opening: {
98
+ maxWords: number;
99
+ maxSentences: number;
100
+ namesEachTermItBuildsOn: boolean;
101
+ };
102
+ closing: {
103
+ maxWords: number;
104
+ maxSentences: number;
105
+ };
106
+ neverRefersToLessonOrder: string[];
107
+ };
108
+ export interface WriteThreadInput {
109
+ /** The model that writes the lines: the agent's choice, already checked against the models it supports. */
110
+ modelName: string;
111
+ /** The agent's config: the provider keys. `agentic` and `tavily` are switched off for this step. */
112
+ config: Record<string, any>;
113
+ /** The agent's own instructions for the step, from its config.yaml. */
114
+ instructions: string;
115
+ planContext: PlanContext;
116
+ learningTargets: {
117
+ title: string;
118
+ description?: string;
119
+ }[];
120
+ takeaways: {
121
+ title: string;
122
+ description?: string;
123
+ }[];
124
+ /** The name the model call runs under. Default "Thread writer". */
125
+ agentName?: string;
126
+ usageTracker?: UsageTracker | null;
127
+ }
128
+ export interface WriteThreadResult {
129
+ /** The two lines, trimmed, or null when no attempt gave lines that pass. */
130
+ lines: ThreadLines | null;
131
+ /** What was wrong with the last attempt. [] when `lines` is not null. */
132
+ problems: string[];
133
+ attempts: 1 | 2;
134
+ /**
135
+ * The error the model call threw, when the last attempt failed in the call
136
+ * itself and not on the rules. A caller whose only work is this step (a
137
+ * thread-only update) should throw it; a caller delivering a whole lesson
138
+ * can go on without the lines.
139
+ */
140
+ error?: unknown;
141
+ }
142
+ /**
143
+ * Asks a model for a lesson's two thread lines, checks them with
144
+ * {@link threadProblems} and, when they break a rule, asks once more with
145
+ * the problems. At most two model calls. A model call that throws is a failed
146
+ * attempt and is retried once, with these exceptions: a cancelled request and an
147
+ * error with code 402 are thrown on, untouched, with no further call; an error
148
+ * that is a rate limit (as the library itself recognises one: a status or code of
149
+ * 429, in whichever field the provider puts it) is a failed attempt with no second call (the library has already
150
+ * waited and retried a rate limit itself). A 503 is an ordinary failed attempt.
151
+ * The result carries `error` (the same error object) when `lines` is null and the
152
+ * last attempt's model call threw. The model is called with 10 arguments, or 11
153
+ * (the usage tracker last) when `input.usageTracker` is given.
154
+ * @throws The error of a plan context that does not parse, or of a cancelled request or a 402
155
+ */
156
+ export declare const writeThread: (input: WriteThreadInput) => Promise<WriteThreadResult>;
157
+ declare const _default: {
158
+ THREAD_LIMITS: Readonly<{
159
+ OPENING_WORDS: 60;
160
+ OPENING_SENTENCES: 3;
161
+ CLOSING_WORDS: 30;
162
+ CLOSING_SENTENCES: 2;
163
+ }>;
164
+ countSentences: (text: string) => number;
165
+ countWords: (text: string) => number;
166
+ findPositionPhrases: (text: string) => string[];
167
+ namesTerm: (text: string, term: string) => boolean;
168
+ threadProblems: (lines: ThreadLines, planContext: PlanContext) => string[];
169
+ threadRulesForPrompt: () => {
170
+ opening: {
171
+ maxWords: number;
172
+ maxSentences: number;
173
+ namesEachTermItBuildsOn: boolean;
174
+ };
175
+ closing: {
176
+ maxWords: number;
177
+ maxSentences: number;
178
+ };
179
+ neverRefersToLessonOrder: string[];
180
+ };
181
+ writeThread: (input: WriteThreadInput) => Promise<WriteThreadResult>;
182
+ };
183
+ export default _default;
184
+ //# sourceMappingURL=learningContentThread.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"learningContentThread.d.ts","sourceRoot":"","sources":["../../src/learningContentThread.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAEnD,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,yBAAyB,CAAC;AAG1E,yHAAyH;AACzH,eAAO,MAAM,aAAa;;;;;EAAsG,CAAC;AAEjI,sFAAsF;AACtF,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,qFAAqF;AACrF,MAAM,MAAM,WAAW,GAAG,0BAA0B,CAAC;AAOrD;;;GAGG;AACH,eAAO,MAAM,UAAU,GAAI,MAAM,MAAM,KAAG,MAGK,CAAC;AA0BhD;;;;;;;;;GASG;AACH,eAAO,MAAM,cAAc,GAAI,MAAM,MAAM,KAAG,MA2B7C,CAAC;AA2CF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,eAAO,MAAM,mBAAmB,GAAI,MAAM,MAAM,KAAG,MAAM,EAiBxD,CAAC;AAkBF;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,SAAS,GAAI,MAAM,MAAM,EAAE,MAAM,MAAM,KAAG,OAKtD,CAAC;AAiBF;;;;;;;;GAQG;AACH,eAAO,MAAM,cAAc,GAAI,OAAO,WAAW,EAAE,aAAa,WAAW,KAAG,MAAM,EAmCnF,CAAC;AAEF,6IAA6I;AAC7I,eAAO,MAAM,oBAAoB,QAAO;IACtC,OAAO,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,CAAC;QAAC,uBAAuB,EAAE,OAAO,CAAA;KAAE,CAAC;IACtF,OAAO,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,CAAA;KAAE,CAAC;IACpD,wBAAwB,EAAE,MAAM,EAAE,CAAC;CAKnC,CAAC;AAEH,MAAM,WAAW,gBAAgB;IAC/B,2GAA2G;IAC3G,SAAS,EAAE,MAAM,CAAC;IAClB,oGAAoG;IACpG,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC5B,uEAAuE;IACvE,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,WAAW,CAAC;IACzB,eAAe,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAC3D,SAAS,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IACrD,mEAAmE;IACnE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,YAAY,GAAG,IAAI,CAAC;CACpC;AAED,MAAM,WAAW,iBAAiB;IAChC,4EAA4E;IAC5E,KAAK,EAAE,WAAW,GAAG,IAAI,CAAC;IAC1B,yEAAyE;IACzE,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,QAAQ,EAAE,CAAC,GAAG,CAAC,CAAC;IAChB;;;;;OAKG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAKD;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,WAAW,GAAU,OAAO,gBAAgB,KAAG,OAAO,CAAC,iBAAiB,CAyCpF,CAAC;;;;;;;;2BAlUmC,MAAM,KAAG,MAAM;uBAvCnB,MAAM,KAAG,MAAM;gCA6IN,MAAM,KAAG,MAAM,EAAE;sBAqD3B,MAAM,QAAQ,MAAM,KAAG,OAAO;4BA+BxB,WAAW,eAAe,WAAW,KAAG,MAAM,EAAE;gCAsC9C;QACtC,OAAO,EAAE;YAAE,QAAQ,EAAE,MAAM,CAAC;YAAC,YAAY,EAAE,MAAM,CAAC;YAAC,uBAAuB,EAAE,OAAO,CAAA;SAAE,CAAC;QACtF,OAAO,EAAE;YAAE,QAAQ,EAAE,MAAM,CAAC;YAAC,YAAY,EAAE,MAAM,CAAA;SAAE,CAAC;QACpD,wBAAwB,EAAE,MAAM,EAAE,CAAC;KACpC;yBAqDwC,gBAAgB,KAAG,OAAO,CAAC,iBAAiB,CAAC;;AA2CtF,wBASE"}