liminal 0.4.1 → 0.5.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 (562) hide show
  1. package/Action.ts +29 -0
  2. package/Actor.ts +20 -0
  3. package/CHANGELOG.md +14 -0
  4. package/Exec.ts +63 -0
  5. package/L.ts +27 -0
  6. package/LiminalAssertionError.ts +3 -0
  7. package/LiminalConfig.ts +7 -0
  8. package/Message.ts +94 -0
  9. package/Model.ts +20 -0
  10. package/PathLike.ts +19 -0
  11. package/Scope.ts +133 -0
  12. package/Spec.ts +29 -0
  13. package/Tool.ts +58 -0
  14. package/_.ts +11 -0
  15. package/actions/abort.ts +23 -0
  16. package/actions/actions_common/updateModels.ts +23 -0
  17. package/actions/actions_derived/__snapshots__/declareModel.test.ts.snap +89 -0
  18. package/actions/actions_derived/clear.ts +6 -0
  19. package/actions/actions_derived/declareModel.test.ts +33 -0
  20. package/actions/actions_derived/declareModel.ts +9 -0
  21. package/actions/actions_derived/declareModel.type-test.ts +70 -0
  22. package/actions/actions_derived/getMessages.ts +9 -0
  23. package/actions/actions_derived/messages.test.ts +88 -0
  24. package/actions/actions_derived/messages.ts +19 -0
  25. package/actions/actions_derived/metatype.ts +9 -0
  26. package/actions/appendMessage.ts +30 -0
  27. package/actions/await.ts +13 -0
  28. package/actions/branch.ts +108 -0
  29. package/actions/catch.ts +42 -0
  30. package/actions/declareArg.ts +14 -0
  31. package/actions/disableTool.ts +26 -0
  32. package/actions/embed.ts +28 -0
  33. package/actions/emit.ts +21 -0
  34. package/actions/enableTool.ts +75 -0
  35. package/actions/enableTool.type-test.ts +118 -0
  36. package/actions/getScope.ts +11 -0
  37. package/actions/getSignal.ts +10 -0
  38. package/actions/getTools.ts +11 -0
  39. package/actions/infer.ts +37 -0
  40. package/actions/pushModel.ts +32 -0
  41. package/actions/removeMessage.ts +22 -0
  42. package/actions/removeModel.ts +31 -0
  43. package/actions/setMessages.ts +66 -0
  44. package/actions/throw.ts +18 -0
  45. package/cli/WriteHandler.ts +35 -0
  46. package/cli/cli_common.ts +3 -0
  47. package/cli/main.ts +19 -0
  48. package/cli/runExec.ts +68 -0
  49. package/dist/Action.d.ts +15 -0
  50. package/dist/Action.js +13 -0
  51. package/dist/Action.js.map +1 -0
  52. package/dist/Actor.d.ts +14 -0
  53. package/dist/Actor.js +2 -0
  54. package/dist/Actor.js.map +1 -0
  55. package/dist/Exec.d.ts +27 -0
  56. package/dist/Exec.js +22 -0
  57. package/dist/Exec.js.map +1 -0
  58. package/dist/L.d.ts +26 -0
  59. package/dist/L.js +27 -0
  60. package/dist/L.js.map +1 -0
  61. package/dist/LiminalAssertionError.d.ts +3 -0
  62. package/dist/LiminalAssertionError.js +4 -0
  63. package/dist/LiminalAssertionError.js.map +1 -0
  64. package/dist/LiminalConfig.d.ts +6 -0
  65. package/dist/LiminalConfig.js +2 -0
  66. package/dist/LiminalConfig.js.map +1 -0
  67. package/dist/Message.d.ts +82 -0
  68. package/dist/Message.js +2 -0
  69. package/dist/Message.js.map +1 -0
  70. package/dist/Model.d.ts +16 -0
  71. package/dist/Model.js +2 -0
  72. package/dist/Model.js.map +1 -0
  73. package/dist/PathLike.d.ts +14 -0
  74. package/dist/PathLike.js +2 -0
  75. package/dist/PathLike.js.map +1 -0
  76. package/dist/Scope.d.ts +36 -0
  77. package/dist/Scope.js +90 -0
  78. package/dist/Scope.js.map +1 -0
  79. package/dist/Spec.d.ts +20 -0
  80. package/dist/Spec.js +2 -0
  81. package/dist/Spec.js.map +1 -0
  82. package/dist/Tool.d.ts +21 -0
  83. package/dist/Tool.js +32 -0
  84. package/dist/Tool.js.map +1 -0
  85. package/dist/_.d.ts +5 -0
  86. package/dist/_.js +7 -0
  87. package/dist/_.js.map +1 -0
  88. package/dist/actions/abort.d.ts +9 -0
  89. package/dist/actions/abort.js +15 -0
  90. package/dist/actions/abort.js.map +1 -0
  91. package/dist/actions/actions_common/updateModels.d.ts +3 -0
  92. package/dist/actions/actions_common/updateModels.js +17 -0
  93. package/dist/actions/actions_common/updateModels.js.map +1 -0
  94. package/dist/actions/actions_derived/clear.d.ts +8 -0
  95. package/dist/actions/actions_derived/clear.js +5 -0
  96. package/dist/actions/actions_derived/clear.js.map +1 -0
  97. package/dist/actions/actions_derived/declareModel.d.ts +5 -0
  98. package/dist/actions/actions_derived/declareModel.js +7 -0
  99. package/dist/actions/actions_derived/declareModel.js.map +1 -0
  100. package/dist/actions/actions_derived/declareModel.test.d.ts +1 -0
  101. package/dist/actions/actions_derived/declareModel.test.js +32 -0
  102. package/dist/actions/actions_derived/declareModel.test.js.map +1 -0
  103. package/dist/actions/actions_derived/declareModel.type-test.d.ts +1 -0
  104. package/dist/actions/actions_derived/declareModel.type-test.js +66 -0
  105. package/dist/actions/actions_derived/declareModel.type-test.js.map +1 -0
  106. package/dist/actions/actions_derived/getMessages.d.ts +3 -0
  107. package/dist/actions/actions_derived/getMessages.js +8 -0
  108. package/dist/actions/actions_derived/getMessages.js.map +1 -0
  109. package/dist/actions/actions_derived/messages.d.ts +6 -0
  110. package/dist/actions/actions_derived/messages.js +15 -0
  111. package/dist/actions/actions_derived/messages.js.map +1 -0
  112. package/dist/actions/actions_derived/messages.test.d.ts +1 -0
  113. package/dist/actions/actions_derived/messages.test.js +72 -0
  114. package/dist/actions/actions_derived/messages.test.js.map +1 -0
  115. package/dist/actions/actions_derived/metatype.d.ts +9 -0
  116. package/dist/actions/actions_derived/metatype.js +7 -0
  117. package/dist/actions/actions_derived/metatype.js.map +1 -0
  118. package/dist/actions/appendMessage.d.ts +10 -0
  119. package/dist/actions/appendMessage.js +20 -0
  120. package/dist/actions/appendMessage.js.map +1 -0
  121. package/dist/actions/await.d.ts +5 -0
  122. package/dist/actions/await.js +10 -0
  123. package/dist/actions/await.js.map +1 -0
  124. package/dist/actions/branch.d.ts +35 -0
  125. package/dist/actions/branch.js +40 -0
  126. package/dist/actions/branch.js.map +1 -0
  127. package/dist/actions/catch.d.ts +10 -0
  128. package/dist/actions/catch.js +27 -0
  129. package/dist/actions/catch.js.map +1 -0
  130. package/dist/actions/declareArg.d.ts +8 -0
  131. package/dist/actions/declareArg.js +10 -0
  132. package/dist/actions/declareArg.js.map +1 -0
  133. package/dist/actions/disableTool.d.ts +10 -0
  134. package/dist/actions/disableTool.js +17 -0
  135. package/dist/actions/disableTool.js.map +1 -0
  136. package/dist/actions/embed.d.ts +9 -0
  137. package/dist/actions/embed.js +23 -0
  138. package/dist/actions/embed.js.map +1 -0
  139. package/dist/actions/emit.d.ts +9 -0
  140. package/dist/actions/emit.js +14 -0
  141. package/dist/actions/emit.js.map +1 -0
  142. package/dist/actions/enableTool.d.ts +20 -0
  143. package/dist/actions/enableTool.js +26 -0
  144. package/dist/actions/enableTool.js.map +1 -0
  145. package/dist/actions/enableTool.type-test.d.ts +1 -0
  146. package/dist/actions/enableTool.type-test.js +30 -0
  147. package/dist/actions/enableTool.type-test.js.map +1 -0
  148. package/dist/actions/getScope.d.ts +5 -0
  149. package/dist/actions/getScope.js +8 -0
  150. package/dist/actions/getScope.js.map +1 -0
  151. package/dist/actions/getSignal.d.ts +4 -0
  152. package/dist/actions/getSignal.js +8 -0
  153. package/dist/actions/getSignal.js.map +1 -0
  154. package/dist/actions/getTools.d.ts +5 -0
  155. package/dist/actions/getTools.js +8 -0
  156. package/dist/actions/getTools.js.map +1 -0
  157. package/dist/actions/infer.d.ts +13 -0
  158. package/dist/actions/infer.js +21 -0
  159. package/dist/actions/infer.js.map +1 -0
  160. package/dist/actions/pushModel.d.ts +11 -0
  161. package/dist/actions/pushModel.js +21 -0
  162. package/dist/actions/pushModel.js.map +1 -0
  163. package/dist/actions/removeMessage.d.ts +9 -0
  164. package/dist/actions/removeMessage.js +17 -0
  165. package/dist/actions/removeMessage.js.map +1 -0
  166. package/dist/actions/removeModel.d.ts +10 -0
  167. package/dist/actions/removeModel.js +20 -0
  168. package/dist/actions/removeModel.js.map +1 -0
  169. package/dist/actions/setMessages.d.ts +16 -0
  170. package/dist/actions/setMessages.js +31 -0
  171. package/dist/actions/setMessages.js.map +1 -0
  172. package/dist/actions/throw.d.ts +9 -0
  173. package/dist/actions/throw.js +13 -0
  174. package/dist/actions/throw.js.map +1 -0
  175. package/dist/cli/WriteHandler.d.ts +9 -0
  176. package/dist/cli/WriteHandler.js +24 -0
  177. package/dist/cli/WriteHandler.js.map +1 -0
  178. package/dist/cli/cli_common.d.ts +3 -0
  179. package/dist/cli/cli_common.js +2 -0
  180. package/dist/cli/cli_common.js.map +1 -0
  181. package/dist/cli/main.d.ts +2 -0
  182. package/dist/cli/main.js +15 -0
  183. package/dist/cli/main.js.map +1 -0
  184. package/dist/cli/runExec.d.ts +2 -0
  185. package/dist/cli/runExec.js +69 -0
  186. package/dist/cli/runExec.js.map +1 -0
  187. package/dist/events/Aborted.d.ts +4 -0
  188. package/dist/events/Aborted.js +2 -0
  189. package/dist/events/Aborted.js.map +1 -0
  190. package/dist/events/Embedded.d.ts +5 -0
  191. package/dist/events/Embedded.js +2 -0
  192. package/dist/events/Embedded.js.map +1 -0
  193. package/dist/events/EmbeddingRequested.d.ts +4 -0
  194. package/dist/events/EmbeddingRequested.js +2 -0
  195. package/dist/events/EmbeddingRequested.js.map +1 -0
  196. package/dist/events/Emitted.d.ts +4 -0
  197. package/dist/events/Emitted.js +2 -0
  198. package/dist/events/Emitted.js.map +1 -0
  199. package/dist/events/EventBase.d.ts +3 -0
  200. package/dist/events/EventBase.js +2 -0
  201. package/dist/events/EventBase.js.map +1 -0
  202. package/dist/events/EventHandler.d.ts +2 -0
  203. package/dist/events/EventHandler.js +2 -0
  204. package/dist/events/EventHandler.js.map +1 -0
  205. package/dist/events/EventResolved.d.ts +19 -0
  206. package/dist/events/EventResolved.js +2 -0
  207. package/dist/events/EventResolved.js.map +1 -0
  208. package/dist/events/Forked.d.ts +3 -0
  209. package/dist/events/Forked.js +2 -0
  210. package/dist/events/Forked.js.map +1 -0
  211. package/dist/events/InferenceRequested.d.ts +3 -0
  212. package/dist/events/InferenceRequested.js +2 -0
  213. package/dist/events/InferenceRequested.js.map +1 -0
  214. package/dist/events/Inferred.d.ts +5 -0
  215. package/dist/events/Inferred.js +2 -0
  216. package/dist/events/Inferred.js.map +1 -0
  217. package/dist/events/LEvent.d.ts +18 -0
  218. package/dist/events/LEvent.js +2 -0
  219. package/dist/events/LEvent.js.map +1 -0
  220. package/dist/events/MessageAppended.d.ts +5 -0
  221. package/dist/events/MessageAppended.js +2 -0
  222. package/dist/events/MessageAppended.js.map +1 -0
  223. package/dist/events/MessageRemoved.d.ts +5 -0
  224. package/dist/events/MessageRemoved.js +2 -0
  225. package/dist/events/MessageRemoved.js.map +1 -0
  226. package/dist/events/MessagesSet.d.ts +5 -0
  227. package/dist/events/MessagesSet.js +2 -0
  228. package/dist/events/MessagesSet.js.map +1 -0
  229. package/dist/events/ModelPushed.d.ts +7 -0
  230. package/dist/events/ModelPushed.js +2 -0
  231. package/dist/events/ModelPushed.js.map +1 -0
  232. package/dist/events/ModelRemoved.d.ts +7 -0
  233. package/dist/events/ModelRemoved.js +2 -0
  234. package/dist/events/ModelRemoved.js.map +1 -0
  235. package/dist/events/Returned.d.ts +4 -0
  236. package/dist/events/Returned.js +2 -0
  237. package/dist/events/Returned.js.map +1 -0
  238. package/dist/events/Threw.d.ts +4 -0
  239. package/dist/events/Threw.js +2 -0
  240. package/dist/events/Threw.js.map +1 -0
  241. package/dist/events/ToolCalled.d.ts +6 -0
  242. package/dist/events/ToolCalled.js +2 -0
  243. package/dist/events/ToolCalled.js.map +1 -0
  244. package/dist/events/ToolDisabled.d.ts +5 -0
  245. package/dist/events/ToolDisabled.js +2 -0
  246. package/dist/events/ToolDisabled.js.map +1 -0
  247. package/dist/events/ToolEnabled.d.ts +7 -0
  248. package/dist/events/ToolEnabled.js +2 -0
  249. package/dist/events/ToolEnabled.js.map +1 -0
  250. package/dist/events/isScopeChildEvent.d.ts +6 -0
  251. package/dist/events/isScopeChildEvent.js +9 -0
  252. package/dist/events/isScopeChildEvent.js.map +1 -0
  253. package/dist/events/isScopeDescendantEvent.d.ts +14 -0
  254. package/dist/events/isScopeDescendantEvent.js +12 -0
  255. package/dist/events/isScopeDescendantEvent.js.map +1 -0
  256. package/dist/index.d.ts +41 -0
  257. package/dist/index.js +42 -0
  258. package/dist/index.js.map +1 -0
  259. package/dist/testing/ActorAssertions.d.ts +9 -0
  260. package/dist/testing/ActorAssertions.js +6 -0
  261. package/dist/testing/ActorAssertions.js.map +1 -0
  262. package/dist/testing/TestEmbeddingModel.d.ts +6 -0
  263. package/dist/testing/TestEmbeddingModel.js +10 -0
  264. package/dist/testing/TestEmbeddingModel.js.map +1 -0
  265. package/dist/testing/TestLanguageModel.d.ts +8 -0
  266. package/dist/testing/TestLanguageModel.js +21 -0
  267. package/dist/testing/TestLanguageModel.js.map +1 -0
  268. package/dist/testing/index.d.ts +4 -0
  269. package/dist/testing/index.js +5 -0
  270. package/dist/testing/index.js.map +1 -0
  271. package/dist/testing/takeFirstAction.d.ts +3 -0
  272. package/dist/testing/takeFirstAction.js +6 -0
  273. package/dist/testing/takeFirstAction.js.map +1 -0
  274. package/dist/tsconfig.tsbuildinfo +1 -0
  275. package/dist/types/AssertDiagnostics.d.ts +18 -0
  276. package/dist/types/AssertDiagnostics.js +152 -0
  277. package/dist/types/AssertDiagnostics.js.map +1 -0
  278. package/dist/types/JSONRootType.d.ts +6 -0
  279. package/dist/types/JSONRootType.js +2 -0
  280. package/dist/types/JSONRootType.js.map +1 -0
  281. package/dist/types/JSONType.d.ts +16 -0
  282. package/dist/types/JSONType.js +2 -0
  283. package/dist/types/JSONType.js.map +1 -0
  284. package/dist/types/JSONTypeBase.d.ts +3 -0
  285. package/dist/types/JSONTypeBase.js +2 -0
  286. package/dist/types/JSONTypeBase.js.map +1 -0
  287. package/dist/types/Metatype/MetatypeDescriptor.d.ts +41 -0
  288. package/dist/types/Metatype/MetatypeDescriptor.js +38 -0
  289. package/dist/types/Metatype/MetatypeDescriptor.js.map +1 -0
  290. package/dist/types/Metatype/fromMetatypeDescriptor.d.ts +6 -0
  291. package/dist/types/Metatype/fromMetatypeDescriptor.js +43 -0
  292. package/dist/types/Metatype/fromMetatypeDescriptor.js.map +1 -0
  293. package/dist/types/Type.d.ts +30 -0
  294. package/dist/types/Type.js +5 -0
  295. package/dist/types/Type.js.map +1 -0
  296. package/dist/types/TypeContext.d.ts +7 -0
  297. package/dist/types/TypeContext.js +17 -0
  298. package/dist/types/TypeContext.js.map +1 -0
  299. package/dist/types/TypeLike.d.ts +23 -0
  300. package/dist/types/TypeLike.js +23 -0
  301. package/dist/types/TypeLike.js.map +1 -0
  302. package/dist/types/TypeVisitor.d.ts +14 -0
  303. package/dist/types/TypeVisitor.js +12 -0
  304. package/dist/types/TypeVisitor.js.map +1 -0
  305. package/dist/types/array.d.ts +10 -0
  306. package/dist/types/array.js +9 -0
  307. package/dist/types/array.js.map +1 -0
  308. package/dist/types/boolean.d.ts +6 -0
  309. package/dist/types/boolean.js +3 -0
  310. package/dist/types/boolean.js.map +1 -0
  311. package/dist/types/const.d.ts +8 -0
  312. package/dist/types/const.js +7 -0
  313. package/dist/types/const.js.map +1 -0
  314. package/dist/types/declareType.d.ts +2 -0
  315. package/dist/types/declareType.js +57 -0
  316. package/dist/types/declareType.js.map +1 -0
  317. package/dist/types/enum.d.ts +8 -0
  318. package/dist/types/enum.js +7 -0
  319. package/dist/types/enum.js.map +1 -0
  320. package/dist/types/factories.d.ts +8 -0
  321. package/dist/types/factories.js +9 -0
  322. package/dist/types/factories.js.map +1 -0
  323. package/dist/types/index.d.ts +2 -0
  324. package/dist/types/index.js +3 -0
  325. package/dist/types/index.js.map +1 -0
  326. package/dist/types/integer.d.ts +6 -0
  327. package/dist/types/integer.js +3 -0
  328. package/dist/types/integer.js.map +1 -0
  329. package/dist/types/intrinsics.d.ts +11 -0
  330. package/dist/types/intrinsics.js +12 -0
  331. package/dist/types/intrinsics.js.map +1 -0
  332. package/dist/types/match.d.ts +3 -0
  333. package/dist/types/match.js +11 -0
  334. package/dist/types/match.js.map +1 -0
  335. package/dist/types/non_factories.d.ts +21 -0
  336. package/dist/types/non_factories.js +9 -0
  337. package/dist/types/non_factories.js.map +1 -0
  338. package/dist/types/null.d.ts +7 -0
  339. package/dist/types/null.js +4 -0
  340. package/dist/types/null.js.map +1 -0
  341. package/dist/types/number.d.ts +6 -0
  342. package/dist/types/number.js +3 -0
  343. package/dist/types/number.js.map +1 -0
  344. package/dist/types/object.d.ts +16 -0
  345. package/dist/types/object.js +10 -0
  346. package/dist/types/object.js.map +1 -0
  347. package/dist/types/ref.d.ts +7 -0
  348. package/dist/types/ref.js +5 -0
  349. package/dist/types/ref.js.map +1 -0
  350. package/dist/types/string.d.ts +6 -0
  351. package/dist/types/string.js +3 -0
  352. package/dist/types/string.js.map +1 -0
  353. package/dist/types/toJSON.d.ts +5 -0
  354. package/dist/types/toJSON.js +97 -0
  355. package/dist/types/toJSON.js.map +1 -0
  356. package/dist/types/type_common.d.ts +10 -0
  357. package/dist/types/type_common.js +12 -0
  358. package/dist/types/type_common.js.map +1 -0
  359. package/dist/types/types_derived/option.d.ts +5 -0
  360. package/dist/types/types_derived/option.js +6 -0
  361. package/dist/types/types_derived/option.js.map +1 -0
  362. package/dist/types/types_derived/taggedUnion.d.ts +19 -0
  363. package/dist/types/types_derived/taggedUnion.js +8 -0
  364. package/dist/types/types_derived/taggedUnion.js.map +1 -0
  365. package/dist/types/types_derived/wrapper.d.ts +8 -0
  366. package/dist/types/types_derived/wrapper.js +5 -0
  367. package/dist/types/types_derived/wrapper.js.map +1 -0
  368. package/dist/types/union.d.ts +9 -0
  369. package/dist/types/union.js +9 -0
  370. package/dist/types/union.js.map +1 -0
  371. package/dist/util/ArrayOfLength.d.ts +1 -0
  372. package/dist/util/ArrayOfLength.js +2 -0
  373. package/dist/util/ArrayOfLength.js.map +1 -0
  374. package/dist/util/DeferredOr.d.ts +1 -0
  375. package/dist/util/DeferredOr.js +2 -0
  376. package/dist/util/DeferredOr.js.map +1 -0
  377. package/dist/util/EnsureNarrow.d.ts +2 -0
  378. package/dist/util/EnsureNarrow.js +2 -0
  379. package/dist/util/EnsureNarrow.js.map +1 -0
  380. package/dist/util/EnsureRecord.d.ts +2 -0
  381. package/dist/util/EnsureRecord.js +2 -0
  382. package/dist/util/EnsureRecord.js.map +1 -0
  383. package/dist/util/Expand.d.ts +3 -0
  384. package/dist/util/Expand.js +2 -0
  385. package/dist/util/Expand.js.map +1 -0
  386. package/dist/util/Falsy.d.ts +1 -0
  387. package/dist/util/Falsy.js +2 -0
  388. package/dist/util/Falsy.js.map +1 -0
  389. package/dist/util/FromEntries.d.ts +3 -0
  390. package/dist/util/FromEntries.js +2 -0
  391. package/dist/util/FromEntries.js.map +1 -0
  392. package/dist/util/IteratorLike.d.ts +1 -0
  393. package/dist/util/IteratorLike.js +2 -0
  394. package/dist/util/IteratorLike.js.map +1 -0
  395. package/dist/util/JSONEntry.d.ts +2 -0
  396. package/dist/util/JSONEntry.js +2 -0
  397. package/dist/util/JSONEntry.js.map +1 -0
  398. package/dist/util/JSONKey.d.ts +1 -0
  399. package/dist/util/JSONKey.js +2 -0
  400. package/dist/util/JSONKey.js.map +1 -0
  401. package/dist/util/JSONObject.d.ts +5 -0
  402. package/dist/util/JSONObject.js +2 -0
  403. package/dist/util/JSONObject.js.map +1 -0
  404. package/dist/util/JSONSchemaMemo.d.ts +2 -0
  405. package/dist/util/JSONSchemaMemo.js +13 -0
  406. package/dist/util/JSONSchemaMemo.js.map +1 -0
  407. package/dist/util/JSONValue.d.ts +2 -0
  408. package/dist/util/JSONValue.js +2 -0
  409. package/dist/util/JSONValue.js.map +1 -0
  410. package/dist/util/PromiseOr.d.ts +1 -0
  411. package/dist/util/PromiseOr.js +2 -0
  412. package/dist/util/PromiseOr.js.map +1 -0
  413. package/dist/util/Result.d.ts +7 -0
  414. package/dist/util/Result.js +2 -0
  415. package/dist/util/Result.js.map +1 -0
  416. package/dist/util/Taggable.d.ts +9 -0
  417. package/dist/util/Taggable.js +8 -0
  418. package/dist/util/Taggable.js.map +1 -0
  419. package/dist/util/TupleToRecord.d.ts +5 -0
  420. package/dist/util/TupleToRecord.js +2 -0
  421. package/dist/util/TupleToRecord.js.map +1 -0
  422. package/dist/util/assert.d.ts +1 -0
  423. package/dist/util/assert.js +7 -0
  424. package/dist/util/assert.js.map +1 -0
  425. package/dist/util/dedent.d.ts +1 -0
  426. package/dist/util/dedent.js +5 -0
  427. package/dist/util/dedent.js.map +1 -0
  428. package/dist/util/fixTemplateStrings.d.ts +11 -0
  429. package/dist/util/fixTemplateStrings.js +83 -0
  430. package/dist/util/fixTemplateStrings.js.map +1 -0
  431. package/dist/util/fixTemplateStrings.test.d.ts +1 -0
  432. package/dist/util/fixTemplateStrings.test.js +221 -0
  433. package/dist/util/fixTemplateStrings.test.js.map +1 -0
  434. package/dist/util/isAsyncIterator.d.ts +1 -0
  435. package/dist/util/isAsyncIterator.js +7 -0
  436. package/dist/util/isAsyncIterator.js.map +1 -0
  437. package/dist/util/isIterator.d.ts +1 -0
  438. package/dist/util/isIterator.js +7 -0
  439. package/dist/util/isIterator.js.map +1 -0
  440. package/dist/util/isJSONValue.d.ts +2 -0
  441. package/dist/util/isJSONValue.js +16 -0
  442. package/dist/util/isJSONValue.js.map +1 -0
  443. package/dist/util/isPropertyKey.d.ts +1 -0
  444. package/dist/util/isPropertyKey.js +4 -0
  445. package/dist/util/isPropertyKey.js.map +1 -0
  446. package/dist/util/isTemplateStringsArray.d.ts +1 -0
  447. package/dist/util/isTemplateStringsArray.js +4 -0
  448. package/dist/util/isTemplateStringsArray.js.map +1 -0
  449. package/dist/util/jsonEquals.d.ts +2 -0
  450. package/dist/util/jsonEquals.js +33 -0
  451. package/dist/util/jsonEquals.js.map +1 -0
  452. package/dist/util/nullaryMemo.d.ts +1 -0
  453. package/dist/util/nullaryMemo.js +12 -0
  454. package/dist/util/nullaryMemo.js.map +1 -0
  455. package/dist/util/unimplemented.d.ts +1 -0
  456. package/dist/util/unimplemented.js +5 -0
  457. package/dist/util/unimplemented.js.map +1 -0
  458. package/dist/util/unreachable.d.ts +1 -0
  459. package/dist/util/unreachable.js +5 -0
  460. package/dist/util/unreachable.js.map +1 -0
  461. package/dist/util/unwrapDeferred.d.ts +2 -0
  462. package/dist/util/unwrapDeferred.js +4 -0
  463. package/dist/util/unwrapDeferred.js.map +1 -0
  464. package/dist/util/util.d.ts +10 -0
  465. package/dist/util/util.js +11 -0
  466. package/dist/util/util.js.map +1 -0
  467. package/events/Aborted.ts +5 -0
  468. package/events/Embedded.ts +6 -0
  469. package/events/EmbeddingRequested.ts +5 -0
  470. package/events/Emitted.ts +5 -0
  471. package/events/EventBase.ts +3 -0
  472. package/events/EventHandler.ts +3 -0
  473. package/events/EventResolved.ts +30 -0
  474. package/events/Forked.ts +3 -0
  475. package/events/InferenceRequested.ts +3 -0
  476. package/events/Inferred.ts +6 -0
  477. package/events/LEvent.ts +36 -0
  478. package/events/MessageAppended.ts +6 -0
  479. package/events/MessageRemoved.ts +6 -0
  480. package/events/MessagesSet.ts +6 -0
  481. package/events/ModelPushed.ts +10 -0
  482. package/events/ModelRemoved.ts +10 -0
  483. package/events/Returned.ts +5 -0
  484. package/events/Threw.ts +5 -0
  485. package/events/ToolCalled.ts +7 -0
  486. package/events/ToolDisabled.ts +6 -0
  487. package/events/ToolEnabled.ts +8 -0
  488. package/events/isScopeChildEvent.ts +15 -0
  489. package/events/isScopeDescendantEvent.ts +30 -0
  490. package/index.ts +41 -0
  491. package/package.json +32 -9
  492. package/testing/ActorAssertions.ts +19 -0
  493. package/testing/TestEmbeddingModel.ts +18 -0
  494. package/testing/TestLanguageModel.ts +32 -0
  495. package/testing/index.ts +4 -0
  496. package/testing/takeFirstAction.ts +8 -0
  497. package/tsconfig.json +8 -0
  498. package/types/AssertDiagnostics.ts +183 -0
  499. package/types/JSONRootType.ts +8 -0
  500. package/types/JSONType.ts +27 -0
  501. package/types/JSONTypeBase.ts +3 -0
  502. package/types/Metatype/MetatypeDescriptor.ts +80 -0
  503. package/types/Metatype/fromMetatypeDescriptor.ts +52 -0
  504. package/types/Type.ts +46 -0
  505. package/types/TypeContext.ts +19 -0
  506. package/types/TypeLike.ts +60 -0
  507. package/types/TypeVisitor.ts +49 -0
  508. package/types/array.ts +20 -0
  509. package/types/boolean.ts +9 -0
  510. package/types/const.ts +17 -0
  511. package/types/declareType.ts +71 -0
  512. package/types/enum.ts +14 -0
  513. package/types/factories.ts +8 -0
  514. package/types/index.ts +2 -0
  515. package/types/integer.ts +9 -0
  516. package/types/intrinsics.ts +11 -0
  517. package/types/match.ts +13 -0
  518. package/types/non_factories.ts +26 -0
  519. package/types/null.ts +10 -0
  520. package/types/number.ts +9 -0
  521. package/types/object.ts +27 -0
  522. package/types/ref.ts +12 -0
  523. package/types/string.ts +9 -0
  524. package/types/toJSON.ts +111 -0
  525. package/types/type_common.ts +21 -0
  526. package/types/types_derived/option.ts +10 -0
  527. package/types/types_derived/taggedUnion.ts +30 -0
  528. package/types/types_derived/wrapper.ts +10 -0
  529. package/types/union.ts +19 -0
  530. package/util/ArrayOfLength.ts +5 -0
  531. package/util/DeferredOr.ts +1 -0
  532. package/util/EnsureNarrow.ts +5 -0
  533. package/util/EnsureRecord.ts +3 -0
  534. package/util/Expand.ts +1 -0
  535. package/util/Falsy.ts +1 -0
  536. package/util/FromEntries.ts +3 -0
  537. package/util/IteratorLike.ts +1 -0
  538. package/util/JSONEntry.ts +3 -0
  539. package/util/JSONKey.ts +1 -0
  540. package/util/JSONObject.ts +6 -0
  541. package/util/JSONSchemaMemo.ts +15 -0
  542. package/util/JSONValue.ts +3 -0
  543. package/util/PromiseOr.ts +1 -0
  544. package/util/Result.ts +7 -0
  545. package/util/Taggable.ts +18 -0
  546. package/util/TupleToRecord.ts +5 -0
  547. package/util/assert.ts +7 -0
  548. package/util/dedent.ts +5 -0
  549. package/util/fixTemplateStrings.test.ts +250 -0
  550. package/util/fixTemplateStrings.ts +99 -0
  551. package/util/isAsyncIterator.ts +6 -0
  552. package/util/isIterator.ts +6 -0
  553. package/util/isJSONValue.ts +20 -0
  554. package/util/isPropertyKey.ts +3 -0
  555. package/util/isTemplateStringsArray.ts +3 -0
  556. package/util/jsonEquals.ts +41 -0
  557. package/util/nullaryMemo.ts +11 -0
  558. package/util/unimplemented.ts +5 -0
  559. package/util/unreachable.ts +5 -0
  560. package/util/unwrapDeferred.ts +5 -0
  561. package/util/util.ts +10 -0
  562. package/lib/index.js +0 -1
@@ -0,0 +1,111 @@
1
+ import type { JSONValue } from "../util/JSONValue.ts"
2
+ import type { JSONArrayType } from "./array.ts"
3
+ import type { JSONBooleanType } from "./boolean.ts"
4
+ import { type JSONConstType } from "./const.ts"
5
+ import type { JSONEnumType } from "./enum.ts"
6
+ import type { JSONIntegerType } from "./integer.ts"
7
+ import type { JSONRootType } from "./JSONRootType.ts"
8
+ import { JSONSchema$schema } from "./JSONRootType.ts"
9
+ import type { JSONRootableType, JSONType } from "./JSONType"
10
+ import type { JSONNullType } from "./null.ts"
11
+ import type { JSONNumberType } from "./number.ts"
12
+ import { _object, type JSONObjectType } from "./object.ts"
13
+ import { type JSONStringType } from "./string.ts"
14
+ import { type Type } from "./Type.ts"
15
+ import { PARENT_TYPE_NAMES, typeName } from "./type_common.ts"
16
+ import { TypeContext } from "./TypeContext.ts"
17
+ import { TypeVisitor } from "./TypeVisitor.ts"
18
+ import type { JSONUnionType } from "./union.ts"
19
+
20
+ export function toJSON<T extends JSONValue, J extends JSONRootableType>(this: Type<T, J>): JSONRootType<J> {
21
+ const { $defs: { 0: root, ...$defs } } = new ToJSONState(this)
22
+ return {
23
+ $schema: JSONSchema$schema,
24
+ ...root,
25
+ $defs,
26
+ } as never
27
+ }
28
+
29
+ class ToJSONState extends TypeContext {
30
+ readonly $defs: Record<string, JSONType | undefined> = {}
31
+ constructor(root: Type) {
32
+ super(root)
33
+ visit(this, root)
34
+ }
35
+ }
36
+
37
+ const visit: TypeVisitor<ToJSONState, JSONType> = TypeVisitor({
38
+ hook(next, state, type) {
39
+ const which = typeName(type)
40
+ if (PARENT_TYPE_NAMES[which]) {
41
+ const id = state.id(type)
42
+ if (!(id in state.$defs)) {
43
+ state.$defs[id] = undefined
44
+ state.$defs[id] = next(state, type)
45
+ }
46
+ return type === state.root ? { $ref: "$" } : { $ref: `#/$defs/${id}` }
47
+ }
48
+ if (which === "ref") {
49
+ if (state.ids.has(type)) {
50
+ const getType = type.args?.[0] as () => Type
51
+ return { $ref: `#/$defs/${state.id(getType())}` }
52
+ }
53
+ state.id(type)
54
+ return next(state, type)
55
+ }
56
+ return next(state, type)
57
+ },
58
+ null(): JSONNullType {
59
+ return { type: "null" }
60
+ },
61
+ boolean(): JSONBooleanType {
62
+ return { type: "boolean" }
63
+ },
64
+ integer(): JSONIntegerType {
65
+ return { type: "integer" }
66
+ },
67
+ number(): JSONNumberType {
68
+ return { type: "number" }
69
+ },
70
+ string(): JSONStringType {
71
+ return { type: "string" }
72
+ },
73
+ const(state, _type, valueType, value): JSONConstType {
74
+ return {
75
+ ...visit(state, valueType),
76
+ const: value,
77
+ } as never
78
+ },
79
+ _array(state, _type, element): JSONArrayType {
80
+ return {
81
+ type: "array",
82
+ items: visit(state, element),
83
+ }
84
+ },
85
+ enum(_state, _type, ...values): JSONEnumType {
86
+ return {
87
+ type: "string",
88
+ enum: values,
89
+ }
90
+ },
91
+ _union(state, _type, ...members): JSONUnionType {
92
+ return {
93
+ anyOf: members.map((m) => visit(state, m)),
94
+ }
95
+ },
96
+ _object(state, _type, fields): JSONObjectType {
97
+ return {
98
+ type: "object",
99
+ properties: Object.fromEntries(
100
+ Array.isArray(fields)
101
+ ? fields.map((v, i) => [i, visit(state, v)])
102
+ : Object.entries(fields).map(([k, v]) => [k, visit(state, v)]),
103
+ ),
104
+ required: Object.keys(fields),
105
+ additionalProperties: false,
106
+ }
107
+ },
108
+ ref(state, _type, getType) {
109
+ return visit(state, getType())
110
+ },
111
+ })
@@ -0,0 +1,21 @@
1
+ import { nullaryMemo } from "../util/nullaryMemo.ts"
2
+ import * as I from "./intrinsics.ts"
3
+ import type { Type } from "./Type.ts"
4
+
5
+ export type IntrinsicTypes = typeof I
6
+ export type IntrinsicTypeName = keyof IntrinsicTypes
7
+ export type IntrinsicType = IntrinsicTypes[IntrinsicTypeName]
8
+
9
+ export const getIntrinsicNameLookup = nullaryMemo(() =>
10
+ new Map(Object.entries(I).map((entry) => entry.reverse() as [IntrinsicType, keyof IntrinsicTypes]))
11
+ )
12
+
13
+ export function typeName(type: Type): IntrinsicTypeName {
14
+ return getIntrinsicNameLookup().get(type.declaration() as IntrinsicType)!
15
+ }
16
+
17
+ export const PARENT_TYPE_NAMES: { [K in IntrinsicTypeName]?: true } = {
18
+ _object: true,
19
+ _array: true,
20
+ _union: true,
21
+ }
@@ -0,0 +1,10 @@
1
+ import { type JSONNullType, null as null_ } from "../null.ts"
2
+ import type { Type } from "../Type.ts"
3
+ import type { NormalizeTypeLikeJ, NormalizeTypeLikeT, TypeLike } from "../TypeLike.ts"
4
+ import { _union, type JSONUnionType, union } from "../union.ts"
5
+
6
+ export function option<const X extends TypeLike>(
7
+ of: X,
8
+ ): Type<null | NormalizeTypeLikeT<X>, JSONUnionType<JSONNullType | NormalizeTypeLikeJ<X>>> {
9
+ return union(null_, of)
10
+ }
@@ -0,0 +1,30 @@
1
+ import type { JSONKey } from "../../util/JSONKey.ts"
2
+ import type { JSONConstType } from "../const.ts"
3
+ import { type JSONObjectType, object } from "../object.ts"
4
+ import type { JSONStringType } from "../string.ts"
5
+ import { type Type } from "../Type.ts"
6
+ import { type NormalizeTypeLikeJ, type NormalizeTypeLikeT, type TypeLike } from "../TypeLike.ts"
7
+ import { _union, type JSONUnionType, union } from "../union.ts"
8
+
9
+ export function taggedUnion<const M extends TaggedUnionMembers, K extends Extract<keyof M, string>>(members: M): Type<
10
+ {
11
+ [L in K]: {
12
+ type: L
13
+ value: NormalizeTypeLikeT<M[L]>
14
+ }
15
+ }[K],
16
+ JSONUnionType<
17
+ {
18
+ [L in K]: JSONObjectType<{
19
+ type: JSONConstType<JSONStringType, L>
20
+ value: NormalizeTypeLikeJ<M[L]>
21
+ }>
22
+ }[K]
23
+ >
24
+ > {
25
+ return union(
26
+ ...Object.entries(members).map(([type, value]) => object({ type, value })),
27
+ ) as never
28
+ }
29
+
30
+ export type TaggedUnionMembers = Record<JSONKey, TypeLike>
@@ -0,0 +1,10 @@
1
+ import { type JSONObjectType, object } from "../object.ts"
2
+ import type { Type } from "../Type.ts"
3
+ import type { NormalizeTypeLikeJ, NormalizeTypeLikeT, TypeLike } from "../TypeLike.ts"
4
+
5
+ export function wrapper<X extends TypeLike>(value: X): Type<
6
+ { value: NormalizeTypeLikeT<X> },
7
+ JSONObjectType<{ value: NormalizeTypeLikeJ<X> }>
8
+ > {
9
+ return object({ value }) as never
10
+ }
package/types/union.ts ADDED
@@ -0,0 +1,19 @@
1
+ import { declareType } from "./declareType.ts"
2
+ import type { JSONType } from "./JSONType.ts"
3
+ import type { JSONTypeBase } from "./JSONTypeBase.ts"
4
+ import type { Type } from "./Type.ts"
5
+ import { normalizeTypeLike, type NormalizeTypeLikeJ, type NormalizeTypeLikeT, type TypeLike } from "./TypeLike.ts"
6
+
7
+ export function union<const M extends Array<TypeLike>>(
8
+ ...members: M
9
+ ): Type<NormalizeTypeLikeT<M[number]>, JSONUnionType<NormalizeTypeLikeJ<M[number]>>> {
10
+ return _union(...members.map(normalizeTypeLike)) as never
11
+ }
12
+
13
+ export function _union(...members: Array<Type>): Type {
14
+ return declareType(() => _union, members)
15
+ }
16
+
17
+ export interface JSONUnionType<M extends JSONType = any> extends JSONTypeBase {
18
+ anyOf: Array<M>
19
+ }
@@ -0,0 +1,5 @@
1
+ export type ArrayOfLength<
2
+ T,
3
+ L extends number,
4
+ A extends Array<T> = [],
5
+ > = number extends L ? Array<T> : L extends A["length"] ? A : ArrayOfLength<T, L, [...A, T]>
@@ -0,0 +1 @@
1
+ export type DeferredOr<T> = T | (() => T)
@@ -0,0 +1,5 @@
1
+ export type EnsureNarrow<V> = unknown extends V ? [error: typeof WIDENING_TYPE_DISALLOWED]
2
+ : [V] extends [never] ? [error: typeof WIDENING_TYPE_DISALLOWED]
3
+ : []
4
+
5
+ export declare const WIDENING_TYPE_DISALLOWED: unique symbol
@@ -0,0 +1,3 @@
1
+ import type { TupleToRecord } from "./TupleToRecord.ts"
2
+
3
+ export type EnsureRecord<T> = T extends Array<any> ? TupleToRecord<T> : T
package/util/Expand.ts ADDED
@@ -0,0 +1 @@
1
+ export type Expand<T> = T extends T ? { [K in keyof T]: T[K] } : never
package/util/Falsy.ts ADDED
@@ -0,0 +1 @@
1
+ export type Falsy = false | 0 | 0n | "" | null | undefined
@@ -0,0 +1,3 @@
1
+ export type FromEntries<E extends [keyof any, any]> = {
2
+ [K in E[0]]: Extract<E, [K, any]> extends [K, infer V] ? V : never
3
+ }
@@ -0,0 +1 @@
1
+ export type IteratorLike<Y = any, O = any> = Iterator<Y, O> | AsyncIterator<Y, O>
@@ -0,0 +1,3 @@
1
+ import type { JSONKey } from "./JSONKey.ts"
2
+
3
+ export type JSONEntry<V = any> = [JSONKey, V]
@@ -0,0 +1 @@
1
+ export type JSONKey = number | string
@@ -0,0 +1,6 @@
1
+ import type { JSONKey } from "./JSONKey.ts"
2
+ import type { JSONValue } from "./JSONValue.ts"
3
+
4
+ export type JSONObject = {
5
+ [value: JSONKey]: JSONValue
6
+ }
@@ -0,0 +1,15 @@
1
+ import type { StandardSchemaV1 } from "@standard-schema/spec"
2
+ import { toJSONSchema } from "standard-json-schema"
3
+ import { isType } from "../types/Type.ts"
4
+
5
+ const memo = new WeakMap<StandardSchemaV1, Promise<object>>()
6
+
7
+ export function JSONSchemaMemo(type: StandardSchemaV1): Promise<object> {
8
+ let pending = memo.get(type)
9
+ if (pending) {
10
+ return pending
11
+ }
12
+ pending = isType(type) ? Promise.resolve(type.toJSON()) : toJSONSchema(type)
13
+ memo.set(type, pending)
14
+ return pending
15
+ }
@@ -0,0 +1,3 @@
1
+ import type { JSONObject } from "./JSONObject.ts"
2
+
3
+ export type JSONValue = null | boolean | number | string | Array<JSONValue> | JSONObject
@@ -0,0 +1 @@
1
+ export type PromiseOr<T> = T | Promise<T>
package/util/Result.ts ADDED
@@ -0,0 +1,7 @@
1
+ export type Result<T, E> = {
2
+ value: T
3
+ thrown?: never
4
+ } | {
5
+ value?: never
6
+ thrown: E
7
+ }
@@ -0,0 +1,18 @@
1
+ import { applyTemplateWithIndentation } from "./fixTemplateStrings.ts"
2
+ import { isTemplateStringsArray } from "./isTemplateStringsArray.ts"
3
+
4
+ export interface Taggable<A extends Array<any>> {
5
+ (template: TemplateStringsArray, ...substitutions: Array<string>): this
6
+ (...values: A): this
7
+ }
8
+
9
+ export type TaggableArgs<A extends Array<any>> = A | [
10
+ raw: TemplateStringsArray,
11
+ ...substitutions: Array<string>,
12
+ ]
13
+
14
+ export function normalizeTaggableArgs<A extends Array<unknown>>(...[e0, ...eRest]: TaggableArgs<A>) {
15
+ return isTemplateStringsArray(e0)
16
+ ? [applyTemplateWithIndentation(e0, ...eRest)] as [string]
17
+ : [e0, ...eRest] as A
18
+ }
@@ -0,0 +1,5 @@
1
+ export type TupleToRecord<T extends Array<any>> = [
2
+ {
3
+ [K in keyof T as K extends `${number}` ? K : never]: T[K]
4
+ },
5
+ ][0]
package/util/assert.ts ADDED
@@ -0,0 +1,7 @@
1
+ import { LiminalAssertionError } from "../LiminalAssertionError.ts"
2
+
3
+ export function assert(expr: unknown, msg = ""): asserts expr {
4
+ if (!expr) {
5
+ throw new LiminalAssertionError(msg)
6
+ }
7
+ }
package/util/dedent.ts ADDED
@@ -0,0 +1,5 @@
1
+ import { fixTemplateStrings } from "./fixTemplateStrings.ts"
2
+
3
+ export function dedent(input: TemplateStringsArray, ...values: Array<unknown>): string {
4
+ return String.raw(fixTemplateStrings(input), ...values)
5
+ }
@@ -0,0 +1,250 @@
1
+ import { describe, expect, test } from "bun:test"
2
+ import { applyTemplateWithIndentation, fixTemplateStrings } from "./fixTemplateStrings"
3
+
4
+ // Helper to create a mock TemplateStringsArray
5
+ function createTemplateArray(strings: string[]): TemplateStringsArray {
6
+ const arr = [...strings] as unknown as TemplateStringsArray
7
+ Object.defineProperty(arr, "raw", { value: strings })
8
+ return arr
9
+ }
10
+
11
+ // A template tag function that applies indentation to substitutions
12
+ function templateTag(strings: TemplateStringsArray, ...values: any[]): string {
13
+ return applyTemplateWithIndentation(strings, ...values)
14
+ }
15
+
16
+ describe("fixTemplateStrings", () => {
17
+ test("handles basic template strings without indentation", () => {
18
+ const template = createTemplateArray(["hello", "world", "!"])
19
+ const result = fixTemplateStrings(template)
20
+ expect(result.raw).toEqual(["hello", "world", "!"])
21
+ })
22
+
23
+ test("removes common indentation from multiline strings", () => {
24
+ const template = createTemplateArray([`
25
+ first line
26
+ second line
27
+ third line`])
28
+
29
+ const result = fixTemplateStrings(template)
30
+ // Leading newline should be removed
31
+ expect(result.raw[0]).toBe("first line\nsecond line\nthird line")
32
+ })
33
+
34
+ test("handles escaped characters", () => {
35
+ const template = createTemplateArray(["\\`template\\$\\{with\\}escaped\\nchars"])
36
+ const result = fixTemplateStrings(template)
37
+ // The function only unescapes backticks, dollar signs, and opening braces
38
+ expect(result.raw[0]).toBe("`template${with\\}escaped\\nchars")
39
+ })
40
+
41
+ test("preserves intended backticks and dollar signs", () => {
42
+ const template = createTemplateArray(["const code = `const value = ${'test'}`"])
43
+ const result = fixTemplateStrings(template)
44
+ expect(result.raw[0]).toBe("const code = `const value = ${'test'}`")
45
+ })
46
+
47
+ test("removes trailing spaces in last segment", () => {
48
+ const template = createTemplateArray([`
49
+ some text
50
+ with trailing spaces
51
+ `])
52
+
53
+ const result = fixTemplateStrings(template)
54
+ // The function only removes trailing spaces after a newline at the end
55
+ // And only if indentation is detected
56
+ // Leading newline should be removed
57
+ expect(result.raw[0]).toBe("some text\nwith trailing spaces \n")
58
+ })
59
+
60
+ test("handles mixed indentation", () => {
61
+ const template = createTemplateArray([`
62
+ spaces here
63
+ more spaces
64
+ less spaces
65
+ most spaces`])
66
+
67
+ const result = fixTemplateStrings(template)
68
+ // The function uses the indentation of the first line as the baseline
69
+ // Leading newline should be removed
70
+ expect(result.raw[0]).toBe("spaces here\n more spaces\n less spaces\n most spaces")
71
+ })
72
+
73
+ test("removes escaped newlines", () => {
74
+ const template = createTemplateArray(["first line\\\nsecond line\\\nthird line"])
75
+ const result = fixTemplateStrings(template)
76
+ expect(result.raw[0]).toBe("first linesecond linethird line")
77
+ })
78
+
79
+ test("handles multiple segments with indentation", () => {
80
+ const template = createTemplateArray([
81
+ `
82
+ first \${`,
83
+ `}
84
+ second \${`,
85
+ `}
86
+ third
87
+ `,
88
+ ])
89
+
90
+ const result = fixTemplateStrings(template)
91
+ // Leading newline should be removed in first segment only
92
+ expect(result.raw).toEqual([
93
+ "first ${",
94
+ "}\nsecond ${",
95
+ "}\nthird",
96
+ ])
97
+ })
98
+ })
99
+
100
+ describe("templateTag with indentation", () => {
101
+ test("basic template with substitution", () => {
102
+ const result = templateTag`Hello ${"world"}!`
103
+ expect(result).toBe("Hello world!")
104
+ })
105
+
106
+ test("multiline template with indentation", () => {
107
+ const result = templateTag`
108
+ This is a multiline
109
+ string with proper indentation
110
+ `
111
+ // Leading newline should be removed
112
+ expect(result).toBe("This is a multiline\nstring with proper indentation")
113
+ })
114
+
115
+ test("template with multiline substitution without indentation", () => {
116
+ const multilineValue = "line1\nline2\nline3"
117
+ const result = templateTag`Value: ${multilineValue}`
118
+ // The substitution doesn't get indentation because there's no preceding newline
119
+ expect(result).toBe("Value: line1\nline2\nline3")
120
+ })
121
+
122
+ test("template with multiline substitution with indentation", () => {
123
+ const multilineValue = "line1\nline2\nline3"
124
+ const result = templateTag`
125
+ Values:
126
+ ${multilineValue}
127
+ End of values
128
+ `
129
+ // The substitution should get the indentation from before the ${}
130
+ // Leading newline should be removed
131
+ expect(result).toBe("Values:\n line1\n line2\n line3\nEnd of values")
132
+ })
133
+
134
+ test("nested indentation with multiline values", () => {
135
+ const codeBlock = "function example() {\n console.log('test');\n}"
136
+ const result = templateTag`
137
+ Here is some code:
138
+ ${codeBlock}
139
+ End of code
140
+ `
141
+ // The function should preserve the internal indentation of the code block
142
+ // Leading newline should be removed
143
+ expect(result).toBe("Here is some code:\n function example() {\n console.log('test');\n }\nEnd of code")
144
+ })
145
+
146
+ test("mixed indentation with tabs and spaces", () => {
147
+ const tabIndentedValue = "line1\n\tline2\n\t\tline3"
148
+ const result = templateTag`
149
+ Tab indented:
150
+ ${tabIndentedValue}
151
+ End
152
+ `
153
+ // Space indentation should be applied to all lines including those with tabs
154
+ // Leading newline should be removed
155
+ expect(result).toBe("Tab indented:\n line1\n \tline2\n \t\tline3\nEnd")
156
+ })
157
+
158
+ test("numbered list with indented content", () => {
159
+ const listItems = "1\n2\n3"
160
+ const result = templateTag`
161
+ 1. Part one:
162
+ ${listItems}
163
+ 2. Part two
164
+ `
165
+ // This is specifically testing the case mentioned by the user
166
+ // Leading newline should be removed
167
+ expect(result).toBe("1. Part one:\n 1\n 2\n 3\n2. Part two")
168
+ })
169
+
170
+ test("complex nested structures", () => {
171
+ const jsonData = `{
172
+ "name": "example",
173
+ "values": [1, 2, 3]
174
+ }`
175
+ const code = `function test() {
176
+ if (condition) {
177
+ return true;
178
+ }
179
+ return false;
180
+ }`
181
+
182
+ const result = templateTag`
183
+ JSON data:
184
+ ${jsonData}
185
+
186
+ Code:
187
+ ${code}
188
+
189
+ End of examples
190
+ `
191
+
192
+ // The code gets additional indentation due to the spacing before the interpolation
193
+ // Leading newline should be removed
194
+ expect(result).toBe(`JSON data:
195
+ {
196
+ "name": "example",
197
+ "values": [1, 2, 3]
198
+ }
199
+
200
+ Code:
201
+ function test() {
202
+ if (condition) {
203
+ return true;
204
+ }
205
+ return false;
206
+ }
207
+
208
+ End of examples`)
209
+ })
210
+
211
+ test("preserves indentation within code blocks", () => {
212
+ const code = `if (true) {
213
+ console.log("indented");
214
+ console.log("double indented");
215
+ }`
216
+
217
+ const result = templateTag`
218
+ Code example:
219
+ ${code}
220
+ End
221
+ `
222
+
223
+ // The indentation is applied to each line based on the template's indentation
224
+ // Leading newline should be removed
225
+ expect(result).toBe(`Code example:
226
+ if (true) {
227
+ console.log("indented");
228
+ console.log("double indented");
229
+ }
230
+ End`)
231
+ })
232
+
233
+ test("handles empty lines in substitutions", () => {
234
+ const textWithEmptyLines = "line1\n\nline3"
235
+
236
+ const result = templateTag`
237
+ Text:
238
+ ${textWithEmptyLines}
239
+ End
240
+ `
241
+
242
+ // Empty lines also get indentation
243
+ // Leading newline should be removed
244
+ expect(result).toBe(`Text:
245
+ line1
246
+
247
+ line3
248
+ End`)
249
+ })
250
+ })