@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,364 @@
1
+ //
2
+ // learningContentThread — the rules of a lesson's two thread lines: the
3
+ // opening that ties the lesson to what it builds on, and the closing that
4
+ // hands over to what follows. Pure functions; nothing here calls a model.
5
+ //
6
+ import { z } from "zod";
7
+ import langChain, { isRateLimitError } from "./langChain.js";
8
+ import { isRequestCancelled } from "./cancellation.js";
9
+ import { planContextSchema } from "./learningContentPlan.js";
10
+ /** The limits of the two lines. Opening: at most 60 words and 3 sentences. Closing: at most 30 words and 2 sentences. */
11
+ export const THREAD_LIMITS = Object.freeze({ OPENING_WORDS: 60, OPENING_SENTENCES: 3, CLOSING_WORDS: 30, CLOSING_SENTENCES: 2 });
12
+ const HAS_WORD = /[\p{L}\p{N}]/u;
13
+ // Text is compared in Unicode NFC form throughout.
14
+ const nfc = (text) => String(text ?? "").normalize("NFC");
15
+ /**
16
+ * The number of runs of non-whitespace that hold a letter or a digit.
17
+ * "" and " — " are 0. A line is blank when this is 0.
18
+ */
19
+ export const countWords = (text) => nfc(text)
20
+ .split(/\s+/)
21
+ .filter((run) => HAS_WORD.test(run)).length;
22
+ const ABBREVIATIONS = new Set(["e.g", "i.e", "etc", "vs", "mr", "mrs", "ms", "dr", "prof", "st"]);
23
+ const CLOSERS = new Set(['"', "'", ")", "]", "”", "’", "»"]);
24
+ // A period after one of these is not an end when a digit follows ("No. 4", "Art. 6").
25
+ const NUMBERED = new Set(["no", "art", "sec", "fig", "approx"]);
26
+ const LOOK_BACK = 12;
27
+ const isMark = (c) => c === "." || c === "!" || c === "?";
28
+ const isSpace = (c) => /\s/.test(c);
29
+ // Whether the lone period at `periodAt` (its own index) is not the end of a
30
+ // sentence: after an abbreviation, after "No", "Art", "Sec", "Fig" or "approx" before a digit (`afterSpaceAt`
31
+ // is where the text goes on after the whitespace), or after an initial. It
32
+ // looks back at most LOOK_BACK characters, so a scan of a long text stays linear.
33
+ const periodIsNotAnEnd = (text, periodAt, afterSpaceAt) => {
34
+ const token = text
35
+ .slice(Math.max(0, periodAt - LOOK_BACK), periodAt)
36
+ .match(/\S*$/)[0]
37
+ .replace(/^[^\p{L}\p{N}]+/u, "");
38
+ const lower = token.toLowerCase();
39
+ if (NUMBERED.has(lower))
40
+ return afterSpaceAt < text.length && /\d/.test(text[afterSpaceAt]);
41
+ if (ABBREVIATIONS.has(lower))
42
+ return true;
43
+ // A single capital letter that stands alone or follows a period (J. Smith, U.S.), not one glued to a digit or a hyphen.
44
+ return /^\p{Lu}$/u.test(token) || /\.\p{Lu}$/u.test(token);
45
+ };
46
+ /**
47
+ * The number of sentences. A sentence ends at one or more of . ! ? (with any
48
+ * closing " ' ) ] ” ’ » after them) followed by whitespace or the end of the
49
+ * text. Not an end: a mark followed by whitespace and then a lower-case letter;
50
+ * a period after e.g, i.e, etc, vs, Mr, Mrs, Ms, Dr, Prof or St (any case), or
51
+ * after No, Art, Sec, Fig or approx (any case) when a digit follows; a period after a single capital letter that
52
+ * stands alone or follows a period (not one glued to a digit or a hyphen). A
53
+ * piece with no letter or digit is not a sentence. Text with no end mark is one
54
+ * sentence when it has a word, else 0. The scan is linear.
55
+ */
56
+ export const countSentences = (text) => {
57
+ const source = nfc(text);
58
+ const length = source.length;
59
+ let count = 0;
60
+ let from = 0;
61
+ let at = 0;
62
+ while (at < length) {
63
+ if (!isMark(source[at])) {
64
+ at += 1;
65
+ continue;
66
+ }
67
+ const start = at;
68
+ let marksEnd = at;
69
+ while (marksEnd < length && isMark(source[marksEnd]))
70
+ marksEnd += 1;
71
+ let end = marksEnd;
72
+ while (end < length && CLOSERS.has(source[end]))
73
+ end += 1;
74
+ at = end;
75
+ if (end < length && !isSpace(source[end]))
76
+ continue;
77
+ let next = end;
78
+ while (next < length && isSpace(source[next]))
79
+ next += 1;
80
+ if (next < length && /\p{Ll}/u.test(source[next]))
81
+ continue;
82
+ if (marksEnd - start === 1 && source[start] === "." && periodIsNotAnEnd(source, start, next))
83
+ continue;
84
+ if (HAS_WORD.test(source.slice(from, end)))
85
+ count += 1;
86
+ from = end;
87
+ }
88
+ if (HAS_WORD.test(source.slice(from)))
89
+ count += 1;
90
+ return count;
91
+ };
92
+ const B = "(?<![\\p{L}\\p{N}])";
93
+ const E = "(?![\\p{L}\\p{N}])";
94
+ const RELATIVE = "last|previous|prior|earlier|preceding|next|following|upcoming|later|subsequent";
95
+ const ORDINAL = "first|second|third|fourth|fifth|final";
96
+ const NUMBER_WORD = "one|two|three|four|five|six|seven|eight|nine|ten";
97
+ const VERB = "saw|seen|learned|learnt|met|covered|discussed|explored|defined|introduced|studied|mentioned|noted|looked";
98
+ // A lesson word, singular or plural, but not "lesson(s) learned" or "video call" and its kin.
99
+ const LESSON_WORD = `lessons?(?!\\s+(?:learned|learnt)${E})`;
100
+ const OTHER_LESSON = `videos?(?!\\s+(?:calls?|conferences?|meetings?|chats?)${E})|lectures?`;
101
+ const OTHER_UNIT = `(?:${OTHER_LESSON}|modules?|chapters?|episodes?|sections?)`;
102
+ // A unit followed by "of" and something other than a part of the course is content, not position.
103
+ const COURSE_PART = `(?:(?:this|the|our)\\s+)?(?:course|series|module|level|programme|program|path)${E}`;
104
+ const NOT_OF_CONTENT = `(?!\\s+of\\s+(?!${COURSE_PART})\\S)`;
105
+ // Not a position phrase when the word right before it is one of these ("your first video", "a later section").
106
+ // A lesson is always one: "in a later lesson" and "your next lesson" are about the course.
107
+ const NOT_AFTER_OWNER = "(?<!(?:^|[^\\p{L}\\p{N}])(?:your|my|their|his|her|its|a|an|each|every|any)\\s+)";
108
+ const NOT_AFTER_THE = "(?<!(?:^|[^\\p{L}\\p{N}])the\\s+)";
109
+ const NOT_COURSE_OF = `(?!\\s+of${E})`;
110
+ const VERB_AHEAD = "learn|see|meet|explore|cover|look|study|discover";
111
+ const VERB_DONE = "learned|learnt|mastered|covered|seen|met|studied|explored";
112
+ const POSITION_PATTERNS = [
113
+ `(?:${RELATIVE}|${ORDINAL})\\s+${LESSON_WORD}${E}${NOT_OF_CONTENT}`,
114
+ `${NOT_AFTER_OWNER}(?:${RELATIVE})\\s+${OTHER_UNIT}${E}${NOT_OF_CONTENT}`,
115
+ `${NOT_AFTER_OWNER}(?:${ORDINAL})\\s+(?:${OTHER_LESSON})${E}${NOT_OF_CONTENT}`,
116
+ `(?:lessons?|videos?|lectures?)\\s+(?:\\d+|${NUMBER_WORD})${E}`,
117
+ `as\\s+(?:we|you)(?:\\s+have|['’]ve)?\\s+(?:${VERB})`,
118
+ `as\\s+(?:discussed|mentioned|covered|shown|noted|explained|seen)\\s+(?:earlier|before|previously|above)`,
119
+ `(?:earlier|later|previously|so\\s+far)\\s+in\\s+(?:this|the)\\s+course${NOT_COURSE_OF}`,
120
+ `previously,?\\s+(?:we|you)`,
121
+ `(?:we|you)\\s+previously\\s+(?:${VERB})`,
122
+ `earlier,?\\s+(?:we|you)\\s+(?:${VERB})`,
123
+ `${NOT_AFTER_THE}last\\s+time,?\\s+(?:we|you)`,
124
+ `in\\s+(?:the|our)\\s+(?:previous|last|next|following|earlier)\\s+(?:unit(?!\\s+tests?${E})|topic|part|class)${E}${NOT_OF_CONTENT}`,
125
+ `next,?\\s+(?:we|you)(?:\\s+will|['’]ll)\\s+(?:${VERB_AHEAD})`,
126
+ `before\\s+this,?\\s+(?:we|you)`,
127
+ `now\\s+that\\s+(?:we|you)(?:\\s+have|['’]ve)\\s+(?:${VERB_DONE})`,
128
+ `as\\s+(?:we|you)\\s+will\\s+see`,
129
+ `coming\\s+up\\s+next`,
130
+ `up\\s+next`,
131
+ ].map((body) => new RegExp(`${B}(?:${body})${E}`, "giu"));
132
+ /**
133
+ * Every phrase of the text that depends on the order of lessons, as written in
134
+ * the text (each run of whitespace as one space), in the order the phrases
135
+ * start. [] when none. Case-insensitive, on word boundaries. The families:
136
+ * a relative word (last, previous, prior, earlier, preceding, next, following,
137
+ * upcoming, later, subsequent) then a unit (lesson, video, lecture, module,
138
+ * chapter, episode, section); an ordinal (first ... fifth, final) then
139
+ * lesson, video or lecture; lesson, video or lecture with a number ("lessons 4",
140
+ * "lesson one"); "as we saw" and its kin ("as you have learned", "as we've
141
+ * seen"); "as discussed earlier" and its kin; "earlier in this course" and its
142
+ * kin ("so far in the course"); "previously we"; "we previously saw"; "earlier,
143
+ * you met"; "last time, we"; "in" + the or our + previous, last, next, following
144
+ * or earlier + unit, topic, part or class ("in the previous unit"); "next, you
145
+ * will learn" and its kin (next, optional comma, we or you, will or 'll, then
146
+ * learn, see, meet, explore, cover, look, study or discover); "before this, you"
147
+ * (or we); "now that you have learned" and its kin (have or 've, then learned,
148
+ * learnt, mastered, covered, seen, met, studied or explored); "as you will
149
+ * see" (or we); "up next" and "coming up next". Not a position phrase: a unit
150
+ * (or a part, topic or class of the "in the next ..." family) followed by "of"
151
+ * and something other than a part of the course (course, series, module, level,
152
+ * programme, program, path, with or without this, the or our); a unit followed
153
+ * by "test" or "tests" in the "in the next unit" form; "lesson learned"; "video
154
+ * call", "video meetings" and their kin; a module, chapter, episode, section
155
+ * or session with a number; "session" as a unit; a relative word then a unit
156
+ * other than lesson, or an ordinal then video or lecture, when the word right
157
+ * before it is your, my, their, his, her, its, a, an, each, every or any ("your
158
+ * first video" is content; "a later lesson" and "your next lesson" are always
159
+ * about the course); "last time, we"
160
+ * when the word right before it is "the"; "earlier in this course" and its kin
161
+ * when "of" follows. Where two overlap, the one that starts first is kept, and
162
+ * of two that start together the longer.
163
+ */
164
+ export const findPositionPhrases = (text) => {
165
+ const source = nfc(text);
166
+ const found = [];
167
+ for (const pattern of POSITION_PATTERNS) {
168
+ pattern.lastIndex = 0;
169
+ let match;
170
+ while ((match = pattern.exec(source)))
171
+ found.push({ start: match.index, end: match.index + match[0].length });
172
+ }
173
+ found.sort((a, b) => a.start - b.start || b.end - a.end);
174
+ const kept = [];
175
+ let reached = -1;
176
+ for (const hit of found) {
177
+ if (hit.start < reached)
178
+ continue;
179
+ kept.push(hit);
180
+ reached = hit.end;
181
+ }
182
+ return kept.map((hit) => source.slice(hit.start, hit.end).replace(/\s+/g, " "));
183
+ };
184
+ const wordsOf = (text) => nfc(text).match(/[\p{L}\p{N}]+/gu) ?? [];
185
+ const isPluralOf = (plural, word) => plural === `${word}s` ||
186
+ plural === `${word}es` ||
187
+ (word.endsWith("y") && plural === `${word.slice(0, -1)}ies`) ||
188
+ (word.endsWith("is") && plural === `${word.slice(0, -2)}es`);
189
+ const wordsMatch = (a, b) => {
190
+ const x = a.toLowerCase();
191
+ const y = b.toLowerCase();
192
+ return x === y || isPluralOf(x, y) || isPluralOf(y, x);
193
+ };
194
+ const escapeRegExp = (text) => text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
195
+ /**
196
+ * Whether the text names the term, in the form given or its plural. A word is a
197
+ * run of letters and digits; two words match when they are equal ignoring case,
198
+ * or one is the other's plural (plus "s", plus "es", "y" replaced by "ies", or "is" replaced by "es").
199
+ * A term with a word of 3 or more characters is named when every such word of it
200
+ * matches some word of the text, and every shorter word of it that is in capitals
201
+ * or holds a digit ("AI", "1") is in the text as a whole word, written the same,
202
+ * with an optional "s" after it.
203
+ * A term with no word of 3 or more characters ("AI", "P x I") is named when the
204
+ * text holds the whole term as written (any run of whitespace in it matching any run of whitespace), bounded by characters that are not
205
+ * letters or digits, with an optional "s" after it; ignoring case, unless the
206
+ * term is all in capitals, which is matched as written. Compared in NFC form.
207
+ * A term that ends in one part in round brackets holding a word of two letters
208
+ * or more, such as "Personal protective equipment (PPE)", is named when the
209
+ * text names the part before the brackets or the part inside them, each judged
210
+ * by the rules above. Any other brackets ("Article 6(1)(f)", "Regulation (EU)
211
+ * 2016/679") are read as spaces, and the whole term is judged.
212
+ */
213
+ export const namesTerm = (text, term) => {
214
+ const whole = nfc(term);
215
+ const trailing = /^([^()]*[^()\s])\s*\(([^()]*)\)\s*$/u.exec(whole);
216
+ if (trailing && /\p{L}{2}/u.test(trailing[2]))
217
+ return namesPart(text, trailing[1]) || namesPart(text, trailing[2]);
218
+ return namesPart(text, whole.replace(/[()]/g, " "));
219
+ };
220
+ const namesPart = (text, term) => {
221
+ const wanted = nfc(term).trim();
222
+ if (wanted === "")
223
+ return true;
224
+ const termWords = wordsOf(wanted);
225
+ const longWords = termWords.filter((word) => word.length >= 3);
226
+ if (longWords.length === 0) {
227
+ const allCapitals = wanted === wanted.toUpperCase() && wanted !== wanted.toLowerCase();
228
+ const pattern = wanted.split(/\s+/).map(escapeRegExp).join("\\s+");
229
+ return new RegExp(`${B}${pattern}s?${E}`, allCapitals ? "u" : "iu").test(nfc(text));
230
+ }
231
+ const textWords = wordsOf(text);
232
+ const shortRequired = termWords.filter((word) => word.length < 3 && (/\d/.test(word) || (word === word.toUpperCase() && word !== word.toLowerCase())));
233
+ return longWords.every((word) => textWords.some((candidate) => wordsMatch(word, candidate))) && shortRequired.every((word) => textWords.some((candidate) => candidate === word || candidate === `${word}s`));
234
+ };
235
+ /**
236
+ * What is wrong with the two lines, one sentence each, written for the model
237
+ * that must fix them. [] when nothing is. A line is blank when it has no word.
238
+ * In order: the opening is blank; the closing is blank; the opening's words,
239
+ * then its sentences; the closing's words, then its sentences; each position
240
+ * phrase (opening first, with advice that depends on the line); each built-on
241
+ * term the opening does not name (an entry without a term is passed over). A
242
+ * blank line gets only its "blank" problem.
243
+ */
244
+ export const threadProblems = (lines, planContext) => {
245
+ const opening = nfc(lines?.opening);
246
+ const closing = nfc(lines?.closing);
247
+ const openingBlank = countWords(opening) === 0;
248
+ const closingBlank = countWords(closing) === 0;
249
+ const problems = [];
250
+ if (openingBlank)
251
+ problems.push("The opening is blank; write it.");
252
+ if (closingBlank)
253
+ problems.push("The closing is blank; write it.");
254
+ if (!openingBlank) {
255
+ const words = countWords(opening);
256
+ if (words > THREAD_LIMITS.OPENING_WORDS)
257
+ problems.push(`The opening has ${words} words; the limit is ${THREAD_LIMITS.OPENING_WORDS}.`);
258
+ const sentences = countSentences(opening);
259
+ if (sentences > THREAD_LIMITS.OPENING_SENTENCES)
260
+ problems.push(`The opening has ${sentences} sentences; the limit is ${THREAD_LIMITS.OPENING_SENTENCES}.`);
261
+ }
262
+ if (!closingBlank) {
263
+ const words = countWords(closing);
264
+ if (words > THREAD_LIMITS.CLOSING_WORDS)
265
+ problems.push(`The closing has ${words} words; the limit is ${THREAD_LIMITS.CLOSING_WORDS}.`);
266
+ const sentences = countSentences(closing);
267
+ if (sentences > THREAD_LIMITS.CLOSING_SENTENCES)
268
+ problems.push(`The closing has ${sentences} sentences; the limit is ${THREAD_LIMITS.CLOSING_SENTENCES}.`);
269
+ }
270
+ const advice = { opening: "name the idea itself instead", closing: "say the idea the course turns to instead" };
271
+ for (const [name, line, blank] of [["opening", opening, openingBlank], ["closing", closing, closingBlank]]) {
272
+ if (blank)
273
+ continue;
274
+ for (const phrase of findPositionPhrases(line)) {
275
+ problems.push(`The ${name} says "${phrase}", which depends on the order of lessons; ${advice[name]}.`);
276
+ }
277
+ }
278
+ if (!openingBlank) {
279
+ for (const entry of planContext?.buildsOn ?? []) {
280
+ const term = entry && typeof entry.term === "string" ? entry.term : "";
281
+ if (term.trim() === "")
282
+ continue;
283
+ if (!namesTerm(opening, term))
284
+ problems.push(`The opening does not name the term "${term}", which this lesson builds on; name it.`);
285
+ }
286
+ }
287
+ return problems;
288
+ };
289
+ /** The rules as data, for the user message of the model that writes the lines. The example phrases are each found by findPositionPhrases. */
290
+ export const threadRulesForPrompt = () => ({
291
+ opening: { maxWords: THREAD_LIMITS.OPENING_WORDS, maxSentences: THREAD_LIMITS.OPENING_SENTENCES, namesEachTermItBuildsOn: true },
292
+ closing: { maxWords: THREAD_LIMITS.CLOSING_WORDS, maxSentences: THREAD_LIMITS.CLOSING_SENTENCES },
293
+ neverRefersToLessonOrder: ["the last video", "lesson 4", "the next lesson", "as we saw", "earlier in this course", "last time, we", "in the previous unit", "next, you will learn", "now that you have learned", "up next"],
294
+ });
295
+ // Structure only: the rules are checked in code, so a broken rule is never a schema failure.
296
+ const threadAnswerSchema = z.object({ opening: z.string(), closing: z.string() });
297
+ /**
298
+ * Asks a model for a lesson's two thread lines, checks them with
299
+ * {@link threadProblems} and, when they break a rule, asks once more with
300
+ * the problems. At most two model calls. A model call that throws is a failed
301
+ * attempt and is retried once, with these exceptions: a cancelled request and an
302
+ * error with code 402 are thrown on, untouched, with no further call; an error
303
+ * that is a rate limit (as the library itself recognises one: a status or code of
304
+ * 429, in whichever field the provider puts it) is a failed attempt with no second call (the library has already
305
+ * waited and retried a rate limit itself). A 503 is an ordinary failed attempt.
306
+ * The result carries `error` (the same error object) when `lines` is null and the
307
+ * last attempt's model call threw. The model is called with 10 arguments, or 11
308
+ * (the usage tracker last) when `input.usageTracker` is given.
309
+ * @throws The error of a plan context that does not parse, or of a cancelled request or a 402
310
+ */
311
+ export const writeThread = async (input) => {
312
+ const planContext = planContextSchema.parse(input.planContext);
313
+ const base = [
314
+ { role: "system", content: input.instructions },
315
+ { role: "user", content: JSON.stringify({ planContext, learningTargets: input.learningTargets ?? [], takeaways: input.takeaways ?? [], rules: threadRulesForPrompt() }) },
316
+ ];
317
+ const attempt = async (messages) => {
318
+ let answer;
319
+ try {
320
+ answer = await langChain.runPromptWithModel(input.modelName, { ...input.config, agentic: false, tavily: undefined }, messages, null, 0, 100, true, threadAnswerSchema, input.agentName ?? "Thread writer", [], ...(input.usageTracker != null ? [input.usageTracker] : []));
321
+ }
322
+ catch (error) {
323
+ if (isRequestCancelled() || error?.code === 402)
324
+ throw error;
325
+ return { answer: null, lines: null, problems: [`The model call failed: ${error?.message ?? String(error)}`], error, rateLimited: isRateLimitError(error) };
326
+ }
327
+ let parsed;
328
+ try {
329
+ parsed = threadAnswerSchema.parse(JSON.parse(answer));
330
+ }
331
+ catch {
332
+ return { answer, lines: null, problems: ["The answer was not a JSON object with an opening and a closing."] };
333
+ }
334
+ const lines = { opening: parsed.opening.trim(), closing: parsed.closing.trim() };
335
+ const problems = threadProblems(lines, planContext);
336
+ return problems.length === 0 ? { answer, lines, problems: [] } : { answer, lines: null, problems };
337
+ };
338
+ const first = await attempt(base);
339
+ if (first.lines)
340
+ return { lines: first.lines, problems: [], attempts: 1 };
341
+ if (first.rateLimited)
342
+ return { lines: null, problems: first.problems, attempts: 1, error: first.error };
343
+ const retryMessages = first.answer === null
344
+ ? base
345
+ : [
346
+ ...base,
347
+ { role: "assistant", content: first.answer },
348
+ { role: "user", content: `Your two lines were rejected:\n${first.problems.map((p) => `- ${p}`).join("\n")}\n\nReturn both lines again, corrected.` },
349
+ ];
350
+ const second = await attempt(retryMessages);
351
+ if (second.lines)
352
+ return { lines: second.lines, problems: [], attempts: 2 };
353
+ return { lines: null, problems: second.problems, attempts: 2, ...("error" in second ? { error: second.error } : {}) };
354
+ };
355
+ export default {
356
+ THREAD_LIMITS,
357
+ countSentences,
358
+ countWords,
359
+ findPositionPhrases,
360
+ namesTerm,
361
+ threadProblems,
362
+ threadRulesForPrompt,
363
+ writeThread,
364
+ };
@@ -24,6 +24,7 @@ declare const _default: {
24
24
  readonly debug: "debug";
25
25
  readonly silly: "silly";
26
26
  };
27
+ messageOf: (request: any, level: string, message: string) => string;
27
28
  };
28
29
  export default _default;
29
30
  //# sourceMappingURL=logger.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/logger.ts"],"names":[],"mappings":"AAiEA;;;;;;;;;;;;;GAaG;AACH,KAAK,QAAQ,GACT,OAAO,GACP,MAAM,GACN,MAAM,GACN,MAAM,GACN,SAAS,GACT,OAAO,GACP,OAAO,CAAC;;mBAGD,GAAG,SACL,QAAQ,WACN,MAAM,YACN,GAAG,KACX,IAAI;;;;;;;;;;;AA0BP,wBAGE"}
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/logger.ts"],"names":[],"mappings":"AAiEA;;;;;;;;;;;;;GAaG;AACH,KAAK,QAAQ,GACT,OAAO,GACP,MAAM,GACN,MAAM,GACN,MAAM,GACN,SAAS,GACT,OAAO,GACP,OAAO,CAAC;;mBAGD,GAAG,SACL,QAAQ,WACN,MAAM,YACN,GAAG,KACX,IAAI;;;;;;;;;;yBA8BqB,GAAG,SAAS,MAAM,WAAW,MAAM,KAAG,MAAM;;AAOxE,wBAIE"}
@@ -54,11 +54,9 @@ const log = (request, level, message, options = {}) => {
54
54
  traceId = spanContext.traceId;
55
55
  spanId = spanContext.spanId;
56
56
  }
57
- // eslint-disable-next-line security/detect-object-injection
58
- const icon = levelIcons[level] || "ℹ️";
59
57
  logger.log({
60
58
  level: level,
61
- message: `${icon} ${request && request.user ? request.user.email + " - " : ""}${message}`,
59
+ message: messageOf(request, level, message),
62
60
  trace: traceId
63
61
  ? `projects/${process.env.GOOGLE_CLOUD_PROJECT}/traces/${traceId}`
64
62
  : undefined,
@@ -66,7 +64,23 @@ const log = (request, level, message, options = {}) => {
66
64
  ...options,
67
65
  });
68
66
  };
67
+ /**
68
+ * The text a log line carries: the level's icon, then the user's email and a
69
+ * dash when the request has one (a person's request), then the message. An
70
+ * agent's run has a request with no user email, and gets no prefix — never
71
+ * "undefined - ".
72
+ * @param request - The request, or null
73
+ * @param level - The level, for its icon
74
+ * @param message - The message
75
+ */
76
+ const messageOf = (request, level, message) => {
77
+ // eslint-disable-next-line security/detect-object-injection
78
+ const icon = levelIcons[level] || "ℹ️";
79
+ const email = request?.user?.email;
80
+ return `${icon} ${typeof email === "string" && email ? `${email} - ` : ""}${message}`;
81
+ };
69
82
  export default {
70
83
  log,
71
84
  levels,
85
+ messageOf,
72
86
  };
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Whether a model may be called: only when the platform has a rate for it.
3
+ *
4
+ * What an agent uses is priced by the platform (see usage), and what a model
5
+ * without a rate uses is charged nothing: the tokens are counted, the tenant's
6
+ * AI credits are not touched. So before a model is called through this
7
+ * package, the platform is asked whether it has a rate, and a request whose
8
+ * model has none fails before anything is spent.
9
+ *
10
+ * An agent that calls a provider itself asks with {@link requirePricedModel}
11
+ * before the call, as it counts what the call used with `recordUsage` after.
12
+ */
13
+ /** How long a model the platform priced is taken to be priced, without asking again. */
14
+ export declare const PRICED_FOR_MS: number;
15
+ /** Asks the platform which of `models` have no rate. */
16
+ export type UnpricedLookup = (models: string[], token: string) => Promise<string[]>;
17
+ /**
18
+ * Fails unless the platform has a rate for `model`. Outside a request, or in
19
+ * one that carries no token, nothing is charged for what is used, so there is
20
+ * nothing to ask and the call goes ahead.
21
+ * @param model - The model's id, as its provider names it
22
+ * @throws 402 when the model has no rate; 503 when the platform cannot be asked.
23
+ * Either way, nothing has been called yet.
24
+ */
25
+ export declare const requirePricedModel: (model: string) => Promise<void>;
26
+ /** Forgets which models were priced, so each is asked about again. */
27
+ export declare const forget: () => void;
28
+ export declare const api: {
29
+ lookup: UnpricedLookup;
30
+ };
31
+ declare const _default: {
32
+ requirePricedModel: (model: string) => Promise<void>;
33
+ forget: () => void;
34
+ api: {
35
+ lookup: UnpricedLookup;
36
+ };
37
+ PRICED_FOR_MS: number;
38
+ };
39
+ export default _default;
40
+ //# sourceMappingURL=modelRates.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"modelRates.d.ts","sourceRoot":"","sources":["../../src/modelRates.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;GAWG;AAEH,wFAAwF;AACxF,eAAO,MAAM,aAAa,QAAa,CAAC;AAExC,wDAAwD;AACxD,MAAM,MAAM,cAAc,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;AAYpF;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB,GAAU,OAAO,MAAM,KAAG,OAAO,CAAC,IAAI,CA+BpE,CAAC;AAEF,sEAAsE;AACtE,eAAO,MAAM,MAAM,QAAO,IAEzB,CAAC;AAGF,eAAO,MAAM,GAAG,EAAE;IAAE,MAAM,EAAE,cAAc,CAAA;CAEzC,CAAC;;gCAzC8C,MAAM,KAAG,OAAO,CAAC,IAAI,CAAC;kBAkC5C,IAAI;;gBAKF,cAAc;;;;AAI1C,wBAAkE"}
@@ -0,0 +1,68 @@
1
+ import { integration as clientIntegration } from "@stackfactor/client-api";
2
+ import errorHandling from "./errorHandling.js";
3
+ import logger from "./logger.js";
4
+ import { getContext } from "./runtimeContext.js";
5
+ /**
6
+ * Whether a model may be called: only when the platform has a rate for it.
7
+ *
8
+ * What an agent uses is priced by the platform (see usage), and what a model
9
+ * without a rate uses is charged nothing: the tokens are counted, the tenant's
10
+ * AI credits are not touched. So before a model is called through this
11
+ * package, the platform is asked whether it has a rate, and a request whose
12
+ * model has none fails before anything is spent.
13
+ *
14
+ * An agent that calls a provider itself asks with {@link requirePricedModel}
15
+ * before the call, as it counts what the call used with `recordUsage` after.
16
+ */
17
+ /** How long a model the platform priced is taken to be priced, without asking again. */
18
+ export const PRICED_FOR_MS = 5 * 60_000;
19
+ /** HTTP 402: the request asks for work the platform cannot charge for. */
20
+ const UNPRICED = 402;
21
+ /** HTTP 503: the platform could not say. */
22
+ const UNKNOWN = 503;
23
+ // Rates are the platform's, one table for every tenant, so what one request
24
+ // learned holds for every other. Only a priced answer is kept: a model that
25
+ // is given a rate is callable at once, and one without is asked about again.
26
+ const pricedAt = new Map();
27
+ /**
28
+ * Fails unless the platform has a rate for `model`. Outside a request, or in
29
+ * one that carries no token, nothing is charged for what is used, so there is
30
+ * nothing to ask and the call goes ahead.
31
+ * @param model - The model's id, as its provider names it
32
+ * @throws 402 when the model has no rate; 503 when the platform cannot be asked.
33
+ * Either way, nothing has been called yet.
34
+ */
35
+ export const requirePricedModel = async (model) => {
36
+ const name = typeof model === "string" ? model.trim() : "";
37
+ if (!name)
38
+ return;
39
+ const context = getContext();
40
+ const token = context?.request?.authToken ?? context?.request?.authorization;
41
+ if (!context || !token)
42
+ return;
43
+ const at = pricedAt.get(name);
44
+ if (at !== undefined && Date.now() - at < PRICED_FOR_MS)
45
+ return;
46
+ let unpriced;
47
+ try {
48
+ unpriced = await api.lookup([name], token);
49
+ }
50
+ catch (error) {
51
+ // Not called, rather than called and possibly never charged.
52
+ logger.log(null, logger.levels.error, `could not ask whether "${name}" has a rate: ${error?.message ?? error}`);
53
+ throw errorHandling.create(UNKNOWN, `Could not confirm that "${name}" has a rate, so it was not called. Try again shortly.`);
54
+ }
55
+ if (Array.isArray(unpriced) && unpriced.includes(name)) {
56
+ throw errorHandling.create(UNPRICED, `The model "${name}" has no rate, so what it uses could not be charged to the tenant's AI credits. It was not called. Add a rate for it, or configure a model that has one.`);
57
+ }
58
+ pricedAt.set(name, Date.now());
59
+ };
60
+ /** Forgets which models were priced, so each is asked about again. */
61
+ export const forget = () => {
62
+ pricedAt.clear();
63
+ };
64
+ // Internal calls go through this object so tests can replace the lookup.
65
+ export const api = {
66
+ lookup: (models, token) => clientIntegration.getUnpricedModels(models, token),
67
+ };
68
+ export default { requirePricedModel, forget, api, PRICED_FOR_MS };