baml-py 0.1.7__tar.gz

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 (323) hide show
  1. baml_py-0.1.7/PKG-INFO +12 -0
  2. baml_py-0.1.7/README.md +1 -0
  3. baml_py-0.1.7/baml-lib/baml-core/Cargo.toml +39 -0
  4. baml_py-0.1.7/baml-lib/baml-core/README.md +0 -0
  5. baml_py-0.1.7/baml-lib/baml-core/askama.toml +6 -0
  6. baml_py-0.1.7/baml-lib/baml-core/src/common/preview_features.rs +88 -0
  7. baml_py-0.1.7/baml-lib/baml-core/src/common.rs +5 -0
  8. baml_py-0.1.7/baml-lib/baml-core/src/configuration/configuration_struct.rs +24 -0
  9. baml_py-0.1.7/baml-lib/baml-core/src/configuration/generator.rs +217 -0
  10. baml_py-0.1.7/baml-lib/baml-core/src/configuration.rs +5 -0
  11. baml_py-0.1.7/baml-lib/baml-core/src/generate/dir_writer.rs +242 -0
  12. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_pipeline.rs +24 -0
  13. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client/class.rs +105 -0
  14. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client/client.rs +79 -0
  15. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client/enum.rs +51 -0
  16. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client/expression.rs +66 -0
  17. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client/field_type.rs +295 -0
  18. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client/function.rs +99 -0
  19. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client/impl.rs +138 -0
  20. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client/intermediate_repr.rs +26 -0
  21. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client/mod.rs +37 -0
  22. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client/python_language_features.rs +96 -0
  23. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client/template.rs +136 -0
  24. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client/templates/configs/retry_policy.hbs +6 -0
  25. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client/templates/export/generated_baml_client.hbs +36 -0
  26. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client/templates/functions/arg_list.hbs +1 -0
  27. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client/templates/functions/arg_types_list.hbs +1 -0
  28. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client/templates/functions/arg_values.hbs +1 -0
  29. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client/templates/functions/func_def.hbs +5 -0
  30. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client/templates/functions/func_params.hbs +6 -0
  31. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client/templates/functions/function_py.hbs +28 -0
  32. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client/templates/functions/function_pyi.hbs +136 -0
  33. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client/templates/functions/impl.hbs +96 -0
  34. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client/templates/functions/interface.hbs +45 -0
  35. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client/templates/functions/method_def.hbs +5 -0
  36. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client/templates/tests/multi_arg_snippet.hbs +29 -0
  37. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client/templates/tests/single_arg_snippet.hbs +19 -0
  38. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client/templates/types/class.hbs +14 -0
  39. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client/templates/types/class_partial.hbs +8 -0
  40. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client/templates/types/client.hbs +11 -0
  41. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client/templates/types/enum.hbs +14 -0
  42. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client_old/class.rs +113 -0
  43. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client_old/client.rs +133 -0
  44. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client_old/configuration.rs +177 -0
  45. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client_old/enum.rs +93 -0
  46. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client_old/field.rs +63 -0
  47. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client_old/file.rs +301 -0
  48. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client_old/function.rs +229 -0
  49. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client_old/mod.rs +233 -0
  50. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client_old/template.rs +181 -0
  51. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client_old/templates/configs/retry_policy.hb +6 -0
  52. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client_old/templates/export/generated_baml_client.hb +36 -0
  53. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client_old/templates/functions/arg_list.hb +1 -0
  54. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client_old/templates/functions/arg_types_list.hb +1 -0
  55. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client_old/templates/functions/arg_values.hb +1 -0
  56. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client_old/templates/functions/default_variant.hb +56 -0
  57. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client_old/templates/functions/func_def.hb +5 -0
  58. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client_old/templates/functions/func_params.hb +5 -0
  59. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client_old/templates/functions/function_py.hb +28 -0
  60. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client_old/templates/functions/function_pyi.hb +136 -0
  61. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client_old/templates/functions/interface.hb +45 -0
  62. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client_old/templates/functions/method_def.hb +5 -0
  63. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client_old/templates/functions/variant.hb +96 -0
  64. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client_old/templates/tests/multi_arg_snippet.hb +29 -0
  65. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client_old/templates/tests/single_arg_snippet.hb +20 -0
  66. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client_old/templates/types/class.hb +14 -0
  67. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client_old/templates/types/class_partial.hb +8 -0
  68. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client_old/templates/types/client.hb +11 -0
  69. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client_old/templates/types/enum.hb +12 -0
  70. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client_old/traits.rs +21 -0
  71. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client_old/types.rs +101 -0
  72. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client_old/types_partial.rs +116 -0
  73. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client_old/value.rs +67 -0
  74. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_python_client_old/variants.rs +175 -0
  75. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_ts_client/class.rs +68 -0
  76. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_ts_client/client.rs +54 -0
  77. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_ts_client/default_config.rs +84 -0
  78. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_ts_client/enum.rs +34 -0
  79. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_ts_client/expression.rs +54 -0
  80. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_ts_client/field_type.rs +277 -0
  81. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_ts_client/function.rs +94 -0
  82. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_ts_client/impl.rs +106 -0
  83. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_ts_client/intermediate_repr.rs +26 -0
  84. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_ts_client/mod.rs +168 -0
  85. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_ts_client/retry_policy.rs +63 -0
  86. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_ts_client/template.rs +89 -0
  87. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_ts_client/templates/exports/baml_client.hbs +15 -0
  88. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_ts_client/templates/functions/default_impl.hbs +46 -0
  89. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_ts_client/templates/functions/function.hbs +107 -0
  90. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_ts_client/templates/functions/impl.hbs +61 -0
  91. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_ts_client/templates/functions/test_case.hbs +22 -0
  92. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_ts_client/templates/types/class.hbs +5 -0
  93. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_ts_client/templates/types/class_internal.hbs +44 -0
  94. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_ts_client/templates/types/client.hbs +5 -0
  95. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_ts_client/templates/types/enum.hbs +5 -0
  96. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_ts_client/templates/types/enum_internal.hbs +4 -0
  97. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_ts_client/test_case.rs +59 -0
  98. baml_py-0.1.7/baml-lib/baml-core/src/generate/generate_ts_client/ts_language_features.rs +93 -0
  99. baml_py-0.1.7/baml-lib/baml-core/src/generate/ir/generate.rs +26 -0
  100. baml_py-0.1.7/baml-lib/baml-core/src/generate/ir/ir_helpers/error_utils.rs +89 -0
  101. baml_py-0.1.7/baml-lib/baml-core/src/generate/ir/ir_helpers/mod.rs +175 -0
  102. baml_py-0.1.7/baml-lib/baml-core/src/generate/ir/ir_helpers/parse_response.rs +1 -0
  103. baml_py-0.1.7/baml-lib/baml-core/src/generate/ir/ir_helpers/scope_diagnostics.rs +136 -0
  104. baml_py-0.1.7/baml-lib/baml-core/src/generate/ir/ir_helpers/to_baml_arg.rs +188 -0
  105. baml_py-0.1.7/baml-lib/baml-core/src/generate/ir/json_schema.rs +295 -0
  106. baml_py-0.1.7/baml-lib/baml-core/src/generate/ir/mod.rs +39 -0
  107. baml_py-0.1.7/baml-lib/baml-core/src/generate/ir/repr.rs +1089 -0
  108. baml_py-0.1.7/baml-lib/baml-core/src/generate/ir/walker.rs +324 -0
  109. baml_py-0.1.7/baml-lib/baml-core/src/generate/mod.rs +7 -0
  110. baml_py-0.1.7/baml-lib/baml-core/src/lib.rs +168 -0
  111. baml_py-0.1.7/baml-lib/baml-core/src/lockfile.rs +236 -0
  112. baml_py-0.1.7/baml-lib/baml-core/src/validate/generator_loader/mod.rs +67 -0
  113. baml_py-0.1.7/baml-lib/baml-core/src/validate/generator_loader/v0.rs +227 -0
  114. baml_py-0.1.7/baml-lib/baml-core/src/validate/generator_loader/v1.rs +187 -0
  115. baml_py-0.1.7/baml-lib/baml-core/src/validate/validation_pipeline/context.rs +25 -0
  116. baml_py-0.1.7/baml-lib/baml-core/src/validate/validation_pipeline/validations/classes.rs +18 -0
  117. baml_py-0.1.7/baml-lib/baml-core/src/validate/validation_pipeline/validations/clients.rs +26 -0
  118. baml_py-0.1.7/baml-lib/baml-core/src/validate/validation_pipeline/validations/common.rs +26 -0
  119. baml_py-0.1.7/baml-lib/baml-core/src/validate/validation_pipeline/validations/configurations.rs +23 -0
  120. baml_py-0.1.7/baml-lib/baml-core/src/validate/validation_pipeline/validations/cycle.rs +89 -0
  121. baml_py-0.1.7/baml-lib/baml-core/src/validate/validation_pipeline/validations/enums.rs +7 -0
  122. baml_py-0.1.7/baml-lib/baml-core/src/validate/validation_pipeline/validations/functions.rs +170 -0
  123. baml_py-0.1.7/baml-lib/baml-core/src/validate/validation_pipeline/validations/variants.rs +116 -0
  124. baml_py-0.1.7/baml-lib/baml-core/src/validate/validation_pipeline/validations.rs +23 -0
  125. baml_py-0.1.7/baml-lib/baml-core/src/validate/validation_pipeline.rs +23 -0
  126. baml_py-0.1.7/baml-lib/baml-core/src/validate.rs +5 -0
  127. baml_py-0.1.7/baml-lib/diagnostics/Cargo.toml +16 -0
  128. baml_py-0.1.7/baml-lib/diagnostics/src/collection.rs +152 -0
  129. baml_py-0.1.7/baml-lib/diagnostics/src/error.rs +615 -0
  130. baml_py-0.1.7/baml-lib/diagnostics/src/lib.rs +12 -0
  131. baml_py-0.1.7/baml-lib/diagnostics/src/pretty_print.rs +111 -0
  132. baml_py-0.1.7/baml-lib/diagnostics/src/source_file.rs +91 -0
  133. baml_py-0.1.7/baml-lib/diagnostics/src/span.rs +76 -0
  134. baml_py-0.1.7/baml-lib/diagnostics/src/warning.rs +181 -0
  135. baml_py-0.1.7/baml-lib/jinja/Cargo.toml +39 -0
  136. baml_py-0.1.7/baml-lib/jinja/src/baml_image.rs +1 -0
  137. baml_py-0.1.7/baml-lib/jinja/src/callable_jinja.rs +45 -0
  138. baml_py-0.1.7/baml-lib/jinja/src/evaluate_type/expr.rs +242 -0
  139. baml_py-0.1.7/baml-lib/jinja/src/evaluate_type/mod.rs +218 -0
  140. baml_py-0.1.7/baml-lib/jinja/src/evaluate_type/pretty_print.rs +163 -0
  141. baml_py-0.1.7/baml-lib/jinja/src/evaluate_type/stmt.rs +134 -0
  142. baml_py-0.1.7/baml-lib/jinja/src/evaluate_type/test_expr.rs +198 -0
  143. baml_py-0.1.7/baml-lib/jinja/src/evaluate_type/test_stmt.rs +269 -0
  144. baml_py-0.1.7/baml-lib/jinja/src/evaluate_type/types.rs +432 -0
  145. baml_py-0.1.7/baml-lib/jinja/src/get_vars.rs +484 -0
  146. baml_py-0.1.7/baml-lib/jinja/src/lib.rs +1171 -0
  147. baml_py-0.1.7/baml-lib/jinja/src/output_format.rs +83 -0
  148. baml_py-0.1.7/baml-lib/jinja/src/render_context.rs +106 -0
  149. baml_py-0.1.7/baml-lib/jsonish/Cargo.toml +21 -0
  150. baml_py-0.1.7/baml-lib/jsonish/README.md +19 -0
  151. baml_py-0.1.7/baml-lib/jsonish/src/deserializer/iterative_parser.rs +771 -0
  152. baml_py-0.1.7/baml-lib/jsonish/src/deserializer/mod.rs +6 -0
  153. baml_py-0.1.7/baml-lib/jsonish/src/deserializer/old_mod.rs +347 -0
  154. baml_py-0.1.7/baml-lib/jsonish/src/deserializer/parse_state.rs +201 -0
  155. baml_py-0.1.7/baml-lib/jsonish/src/deserializer/raw_value.rs +580 -0
  156. baml_py-0.1.7/baml-lib/jsonish/src/deserializer/test_iterative_parser.rs +419 -0
  157. baml_py-0.1.7/baml-lib/jsonish/src/deserializer/test_raw_value.rs +240 -0
  158. baml_py-0.1.7/baml-lib/jsonish/src/json_schema/deserialize_flags.rs +206 -0
  159. baml_py-0.1.7/baml-lib/jsonish/src/json_schema/mod.rs +820 -0
  160. baml_py-0.1.7/baml-lib/jsonish/src/lib.rs +42 -0
  161. baml_py-0.1.7/baml-lib/jsonish/src/tests/mod.rs +113 -0
  162. baml_py-0.1.7/baml-lib/parser-database/Cargo.toml +29 -0
  163. baml_py-0.1.7/baml-lib/parser-database/build.rs +5 -0
  164. baml_py-0.1.7/baml-lib/parser-database/src/attributes/alias.rs +15 -0
  165. baml_py-0.1.7/baml-lib/parser-database/src/attributes/description.rs +22 -0
  166. baml_py-0.1.7/baml-lib/parser-database/src/attributes/get.rs +38 -0
  167. baml_py-0.1.7/baml-lib/parser-database/src/attributes/meta.rs +38 -0
  168. baml_py-0.1.7/baml-lib/parser-database/src/attributes/mod.rs +122 -0
  169. baml_py-0.1.7/baml-lib/parser-database/src/attributes/to_string_attribute.rs +55 -0
  170. baml_py-0.1.7/baml-lib/parser-database/src/coerce_expression.rs +156 -0
  171. baml_py-0.1.7/baml-lib/parser-database/src/context/attributes.rs +29 -0
  172. baml_py-0.1.7/baml-lib/parser-database/src/context/mod.rs +273 -0
  173. baml_py-0.1.7/baml-lib/parser-database/src/interner.rs +36 -0
  174. baml_py-0.1.7/baml-lib/parser-database/src/lib.rs +403 -0
  175. baml_py-0.1.7/baml-lib/parser-database/src/names/mod.rs +242 -0
  176. baml_py-0.1.7/baml-lib/parser-database/src/names/validate_reserved_names.rs +145 -0
  177. baml_py-0.1.7/baml-lib/parser-database/src/printer/enum_printer.rs +14 -0
  178. baml_py-0.1.7/baml-lib/parser-database/src/printer/mod.rs +155 -0
  179. baml_py-0.1.7/baml-lib/parser-database/src/printer/print_enum_default.rs +57 -0
  180. baml_py-0.1.7/baml-lib/parser-database/src/printer/print_type_default.rs +257 -0
  181. baml_py-0.1.7/baml-lib/parser-database/src/printer/templates/print_enum_default.py +55 -0
  182. baml_py-0.1.7/baml-lib/parser-database/src/printer/templates/print_type_default.py +125 -0
  183. baml_py-0.1.7/baml-lib/parser-database/src/printer/type_printer.rs +19 -0
  184. baml_py-0.1.7/baml-lib/parser-database/src/types/configurations.rs +319 -0
  185. baml_py-0.1.7/baml-lib/parser-database/src/types/mod.rs +995 -0
  186. baml_py-0.1.7/baml-lib/parser-database/src/types/post_prompt.rs +269 -0
  187. baml_py-0.1.7/baml-lib/parser-database/src/types/prompt.rs +187 -0
  188. baml_py-0.1.7/baml-lib/parser-database/src/types/to_string_attributes.rs +74 -0
  189. baml_py-0.1.7/baml-lib/parser-database/src/types/types.rs +31 -0
  190. baml_py-0.1.7/baml-lib/parser-database/src/walkers/class.rs +214 -0
  191. baml_py-0.1.7/baml-lib/parser-database/src/walkers/client.rs +96 -0
  192. baml_py-0.1.7/baml-lib/parser-database/src/walkers/configuration.rs +59 -0
  193. baml_py-0.1.7/baml-lib/parser-database/src/walkers/enum.rs +157 -0
  194. baml_py-0.1.7/baml-lib/parser-database/src/walkers/field.rs +169 -0
  195. baml_py-0.1.7/baml-lib/parser-database/src/walkers/function.rs +346 -0
  196. baml_py-0.1.7/baml-lib/parser-database/src/walkers/mod.rs +362 -0
  197. baml_py-0.1.7/baml-lib/parser-database/src/walkers/template_string.rs +55 -0
  198. baml_py-0.1.7/baml-lib/parser-database/src/walkers/variants.rs +143 -0
  199. baml_py-0.1.7/baml-lib/prompt-parser/Cargo.toml +21 -0
  200. baml_py-0.1.7/baml-lib/prompt-parser/src/ast/code_block.rs +95 -0
  201. baml_py-0.1.7/baml-lib/prompt-parser/src/ast/comment_block.rs +28 -0
  202. baml_py-0.1.7/baml-lib/prompt-parser/src/ast/prompt_text.rs +23 -0
  203. baml_py-0.1.7/baml-lib/prompt-parser/src/ast/top.rs +72 -0
  204. baml_py-0.1.7/baml-lib/prompt-parser/src/ast/traits.rs +19 -0
  205. baml_py-0.1.7/baml-lib/prompt-parser/src/ast/variable.rs +41 -0
  206. baml_py-0.1.7/baml-lib/prompt-parser/src/ast/white_space_text.rs +23 -0
  207. baml_py-0.1.7/baml-lib/prompt-parser/src/ast.rs +111 -0
  208. baml_py-0.1.7/baml-lib/prompt-parser/src/lib.rs +8 -0
  209. baml_py-0.1.7/baml-lib/prompt-parser/src/parser/datamodel.pest +37 -0
  210. baml_py-0.1.7/baml-lib/prompt-parser/src/parser/helpers.rs +32 -0
  211. baml_py-0.1.7/baml-lib/prompt-parser/src/parser/parse_prompt.rs +504 -0
  212. baml_py-0.1.7/baml-lib/prompt-parser/src/parser.rs +10 -0
  213. baml_py-0.1.7/baml-lib/schema-ast/Cargo.toml +23 -0
  214. baml_py-0.1.7/baml-lib/schema-ast/src/ast/adapter.rs +18 -0
  215. baml_py-0.1.7/baml-lib/schema-ast/src/ast/argument.rs +69 -0
  216. baml_py-0.1.7/baml-lib/schema-ast/src/ast/attribute.rs +170 -0
  217. baml_py-0.1.7/baml-lib/schema-ast/src/ast/class.rs +111 -0
  218. baml_py-0.1.7/baml-lib/schema-ast/src/ast/client.rs +111 -0
  219. baml_py-0.1.7/baml-lib/schema-ast/src/ast/comment.rs +4 -0
  220. baml_py-0.1.7/baml-lib/schema-ast/src/ast/config.rs +59 -0
  221. baml_py-0.1.7/baml-lib/schema-ast/src/ast/configurations.rs +49 -0
  222. baml_py-0.1.7/baml-lib/schema-ast/src/ast/enum.rs +146 -0
  223. baml_py-0.1.7/baml-lib/schema-ast/src/ast/expression.rs +339 -0
  224. baml_py-0.1.7/baml-lib/schema-ast/src/ast/field.rs +252 -0
  225. baml_py-0.1.7/baml-lib/schema-ast/src/ast/find_at_position.rs +124 -0
  226. baml_py-0.1.7/baml-lib/schema-ast/src/ast/function.rs +232 -0
  227. baml_py-0.1.7/baml-lib/schema-ast/src/ast/generator_config.rs +99 -0
  228. baml_py-0.1.7/baml-lib/schema-ast/src/ast/identifier.rs +148 -0
  229. baml_py-0.1.7/baml-lib/schema-ast/src/ast/indentation_type.rs +32 -0
  230. baml_py-0.1.7/baml-lib/schema-ast/src/ast/newline_type.rs +26 -0
  231. baml_py-0.1.7/baml-lib/schema-ast/src/ast/printer_config.rs +101 -0
  232. baml_py-0.1.7/baml-lib/schema-ast/src/ast/retry_policy_config.rs +99 -0
  233. baml_py-0.1.7/baml-lib/schema-ast/src/ast/serializer.rs +116 -0
  234. baml_py-0.1.7/baml-lib/schema-ast/src/ast/template_string.rs +80 -0
  235. baml_py-0.1.7/baml-lib/schema-ast/src/ast/top.rs +146 -0
  236. baml_py-0.1.7/baml-lib/schema-ast/src/ast/traits.rs +42 -0
  237. baml_py-0.1.7/baml-lib/schema-ast/src/ast/variant.rs +171 -0
  238. baml_py-0.1.7/baml-lib/schema-ast/src/ast.rs +337 -0
  239. baml_py-0.1.7/baml-lib/schema-ast/src/lib.rs +98 -0
  240. baml_py-0.1.7/baml-lib/schema-ast/src/parser/datamodel.pest +258 -0
  241. baml_py-0.1.7/baml-lib/schema-ast/src/parser/helpers.rs +53 -0
  242. baml_py-0.1.7/baml-lib/schema-ast/src/parser/parse_adapter.rs +114 -0
  243. baml_py-0.1.7/baml-lib/schema-ast/src/parser/parse_arguments.rs +28 -0
  244. baml_py-0.1.7/baml-lib/schema-ast/src/parser/parse_attribute.rs +36 -0
  245. baml_py-0.1.7/baml-lib/schema-ast/src/parser/parse_class.rs +71 -0
  246. baml_py-0.1.7/baml-lib/schema-ast/src/parser/parse_comments.rs +58 -0
  247. baml_py-0.1.7/baml-lib/schema-ast/src/parser/parse_config.rs +184 -0
  248. baml_py-0.1.7/baml-lib/schema-ast/src/parser/parse_enum.rs +107 -0
  249. baml_py-0.1.7/baml-lib/schema-ast/src/parser/parse_expression.rs +164 -0
  250. baml_py-0.1.7/baml-lib/schema-ast/src/parser/parse_field.rs +59 -0
  251. baml_py-0.1.7/baml-lib/schema-ast/src/parser/parse_function.rs +199 -0
  252. baml_py-0.1.7/baml-lib/schema-ast/src/parser/parse_identifier.rs +65 -0
  253. baml_py-0.1.7/baml-lib/schema-ast/src/parser/parse_old_function.rs +243 -0
  254. baml_py-0.1.7/baml-lib/schema-ast/src/parser/parse_schema.rs +182 -0
  255. baml_py-0.1.7/baml-lib/schema-ast/src/parser/parse_serializer.rs +111 -0
  256. baml_py-0.1.7/baml-lib/schema-ast/src/parser/parse_template_args.rs +31 -0
  257. baml_py-0.1.7/baml-lib/schema-ast/src/parser/parse_template_string.rs +156 -0
  258. baml_py-0.1.7/baml-lib/schema-ast/src/parser/parse_test.rs +202 -0
  259. baml_py-0.1.7/baml-lib/schema-ast/src/parser/parse_types.rs +167 -0
  260. baml_py-0.1.7/baml-lib/schema-ast/src/parser/parse_variant.rs +115 -0
  261. baml_py-0.1.7/baml-lib/schema-ast/src/parser.rs +28 -0
  262. baml_py-0.1.7/baml-runtime/Cargo.toml +75 -0
  263. baml_py-0.1.7/baml-runtime/README.md +5 -0
  264. baml_py-0.1.7/baml-runtime/src/internal/ir_features.rs +60 -0
  265. baml_py-0.1.7/baml-runtime/src/internal/llm_client/anthropic/anthropic_client.rs +134 -0
  266. baml_py-0.1.7/baml-runtime/src/internal/llm_client/anthropic/mod.rs +3 -0
  267. baml_py-0.1.7/baml-runtime/src/internal/llm_client/expression_helper.rs +44 -0
  268. baml_py-0.1.7/baml-runtime/src/internal/llm_client/llm_provider.rs +73 -0
  269. baml_py-0.1.7/baml-runtime/src/internal/llm_client/mod.rs +151 -0
  270. baml_py-0.1.7/baml-runtime/src/internal/llm_client/openai/mod.rs +4 -0
  271. baml_py-0.1.7/baml-runtime/src/internal/llm_client/openai/openai_client.rs +347 -0
  272. baml_py-0.1.7/baml-runtime/src/internal/llm_client/openai/types.rs +127 -0
  273. baml_py-0.1.7/baml-runtime/src/internal/llm_client/retry_policy.rs +51 -0
  274. baml_py-0.1.7/baml-runtime/src/internal/llm_client/state.rs +9 -0
  275. baml_py-0.1.7/baml-runtime/src/internal/llm_client/traits/chat.rs +47 -0
  276. baml_py-0.1.7/baml-runtime/src/internal/llm_client/traits/completion.rs +43 -0
  277. baml_py-0.1.7/baml-runtime/src/internal/llm_client/traits/mod.rs +202 -0
  278. baml_py-0.1.7/baml-runtime/src/internal/mod.rs +3 -0
  279. baml_py-0.1.7/baml-runtime/src/internal/prompt_renderer.rs +94 -0
  280. baml_py-0.1.7/baml-runtime/src/lib.rs +91 -0
  281. baml_py-0.1.7/baml-runtime/src/macros.rs +9 -0
  282. baml_py-0.1.7/baml-runtime/src/runtime/ir_features.rs +43 -0
  283. baml_py-0.1.7/baml-runtime/src/runtime/mod.rs +72 -0
  284. baml_py-0.1.7/baml-runtime/src/runtime/runtime_interface.rs +345 -0
  285. baml_py-0.1.7/baml-runtime/src/runtime/tests.rs +58 -0
  286. baml_py-0.1.7/baml-runtime/src/runtime_interface.rs +88 -0
  287. baml_py-0.1.7/baml-runtime/src/types/mod.rs +5 -0
  288. baml_py-0.1.7/baml-runtime/src/types/response.rs +137 -0
  289. baml_py-0.1.7/baml-runtime/src/types/runtime_context.rs +33 -0
  290. baml_py-0.1.7/language-client-codegen/Cargo.toml +18 -0
  291. baml_py-0.1.7/language-client-codegen/README.md +5 -0
  292. baml_py-0.1.7/language-client-codegen/askama.toml +6 -0
  293. baml_py-0.1.7/language-client-codegen/src/dir_writer.rs +100 -0
  294. baml_py-0.1.7/language-client-codegen/src/lib.rs +35 -0
  295. baml_py-0.1.7/language-client-codegen/src/python/generate_types.rs +103 -0
  296. baml_py-0.1.7/language-client-codegen/src/python/mod.rs +157 -0
  297. baml_py-0.1.7/language-client-codegen/src/python/python_language_features.rs +51 -0
  298. baml_py-0.1.7/language-client-codegen/src/python/templates/__init__.py.j2 +15 -0
  299. baml_py-0.1.7/language-client-codegen/src/python/templates/client.py.j2 +82 -0
  300. baml_py-0.1.7/language-client-codegen/src/python/templates/types.py.j2 +18 -0
  301. baml_py-0.1.7/language-client-codegen/src/ruby/expression.rs +54 -0
  302. baml_py-0.1.7/language-client-codegen/src/ruby/field_type.rs +47 -0
  303. baml_py-0.1.7/language-client-codegen/src/ruby/generate_types.rs +99 -0
  304. baml_py-0.1.7/language-client-codegen/src/ruby/mod.rs +104 -0
  305. baml_py-0.1.7/language-client-codegen/src/ruby/ruby_language_features.rs +35 -0
  306. baml_py-0.1.7/language-client-codegen/src/ruby/templates/class.rb.j2 +24 -0
  307. baml_py-0.1.7/language-client-codegen/src/ruby/templates/class_forward_decl.rb.j2 +6 -0
  308. baml_py-0.1.7/language-client-codegen/src/ruby/templates/client.rb.j2 +91 -0
  309. baml_py-0.1.7/language-client-codegen/src/ruby/templates/enum.rb.j2 +12 -0
  310. baml_py-0.1.7/language-client-codegen/src/ruby/templates/types.rb.j2 +38 -0
  311. baml_py-0.1.7/language_client_python/.bumpversion.cfg +15 -0
  312. baml_py-0.1.7/language_client_python/.gitignore +14 -0
  313. baml_py-0.1.7/language_client_python/Cargo.lock +535 -0
  314. baml_py-0.1.7/language_client_python/Cargo.toml +45 -0
  315. baml_py-0.1.7/language_client_python/LICENSE +201 -0
  316. baml_py-0.1.7/language_client_python/README.md +1 -0
  317. baml_py-0.1.7/language_client_python/baml_py.pyi +50 -0
  318. baml_py-0.1.7/language_client_python/build.rs +3 -0
  319. baml_py-0.1.7/language_client_python/py.typed +0 -0
  320. baml_py-0.1.7/language_client_python/src/lib.rs +207 -0
  321. baml_py-0.1.7/language_client_python/src/parse_py_type.rs +340 -0
  322. baml_py-0.1.7/language_client_python/src/python_types.rs +67 -0
  323. baml_py-0.1.7/pyproject.toml +15 -0
baml_py-0.1.7/PKG-INFO ADDED
@@ -0,0 +1,12 @@
1
+ Metadata-Version: 2.3
2
+ Name: baml-py
3
+ Version: 0.1.7
4
+ License-File: LICENSE
5
+ License-File: LICENSE
6
+ Summary: BAML python bindings (pyproject.toml)
7
+ Author: Boundary <contact@boundaryml.com>
8
+ Author-email: Boundary <contact@boundaryml.com>
9
+ Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
10
+
11
+ BAML python bindings (readme.md)
12
+
@@ -0,0 +1 @@
1
+ BAML python bindings (readme.md)
@@ -0,0 +1,39 @@
1
+ [package]
2
+ edition = "2021"
3
+ name = "internal-baml-core"
4
+ version.workspace = true
5
+ authors.workspace = true
6
+ description.workspace = true
7
+ license-file.workspace = true
8
+
9
+ [dependencies]
10
+ internal-baml-jinja.workspace = true
11
+ internal-baml-diagnostics = { path = "../diagnostics" }
12
+ internal-baml-schema-ast = { path = "../schema-ast" }
13
+ internal-baml-parser-database = { path = "../parser-database" }
14
+ internal-baml-prompt-parser = { path = "../prompt-parser" }
15
+ anyhow.workspace = true
16
+ askama.workspace = true
17
+ indexmap.workspace = true
18
+ serde.workspace = true
19
+ serde_json.workspace = true
20
+ enumflags2 = "0.7"
21
+ rayon = "1.8.0"
22
+ handlebars = "4.4.0"
23
+ log = "0.4.20"
24
+ chrono = "0.4.31"
25
+ whoami = "1.4.1"
26
+ textwrap = "0.16.0"
27
+ either.workspace = true
28
+ strsim = "0.10.0"
29
+ semver = "1.0.20"
30
+ regex = "1.10.3"
31
+ shellwords = "1.1.0"
32
+
33
+
34
+ [dev-dependencies]
35
+ base64 = "0.13.0"
36
+ dissimilar = "1.0.4"
37
+ expect-test = "1.1.0"
38
+ indoc.workspace = true
39
+ either = "1.8.1"
File without changes
@@ -0,0 +1,6 @@
1
+ [general]
2
+ dirs = ["src/generate/generate_ruby_client/templates"]
3
+ # whitespace can be either preserve, suppress, or minimize
4
+ # suppress and minimize are both too aggressive for us
5
+ whitespace = "preserve"
6
+ escape = "none"
@@ -0,0 +1,88 @@
1
+ use serde::{Serialize, Serializer};
2
+ use std::fmt;
3
+
4
+ /// A set of preview features.
5
+ pub type PreviewFeatures = enumflags2::BitFlags<PreviewFeature>;
6
+
7
+ macro_rules! features {
8
+ ($( $variant:ident $(,)? ),*) => {
9
+ #[enumflags2::bitflags]
10
+ #[repr(u64)]
11
+ #[derive(Debug, Copy, Clone, PartialEq, Eq)]
12
+ pub enum PreviewFeature {
13
+ $( $variant,)*
14
+ }
15
+
16
+ impl PreviewFeature {
17
+ pub fn parse_opt(s: &str) -> Option<Self> {
18
+ $(
19
+ if s.eq_ignore_ascii_case(stringify!($variant)) { return Some(Self::$variant) }
20
+ )*
21
+
22
+ None
23
+ }
24
+ }
25
+
26
+ impl fmt::Display for PreviewFeature {
27
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
28
+ let variant = match self { $( Self::$variant => stringify!($variant),)* };
29
+ let mut first_char = variant.chars().next().unwrap();
30
+ first_char.make_ascii_lowercase();
31
+ f.write_fmt(format_args!("{first_char}{rest}", rest = &variant[1..]))
32
+ }
33
+ }
34
+ };
35
+ }
36
+
37
+ // (Usually) Append-only list of features.
38
+ features!(ScalarJson,);
39
+
40
+ /// Generator preview features
41
+ pub const ALL_PREVIEW_FEATURES: FeatureMap = FeatureMap {
42
+ active: enumflags2::BitFlags::EMPTY,
43
+ deprecated: enumflags2::BitFlags::EMPTY,
44
+ hidden: enumflags2::BitFlags::EMPTY,
45
+ };
46
+
47
+ #[derive(Debug)]
48
+ pub struct FeatureMap {
49
+ /// Valid, visible features.
50
+ active: PreviewFeatures,
51
+
52
+ /// Deprecated features.
53
+ #[allow(dead_code)]
54
+ deprecated: PreviewFeatures,
55
+
56
+ /// Hidden preview features are valid features, but are not propagated into the tooling
57
+ /// (as autocomplete or similar) or into error messages (eg. showing a list of valid features).
58
+ hidden: PreviewFeatures,
59
+ }
60
+
61
+ impl FeatureMap {
62
+ pub const fn active_features(&self) -> PreviewFeatures {
63
+ self.active
64
+ }
65
+
66
+ pub const fn hidden_features(&self) -> PreviewFeatures {
67
+ self.hidden
68
+ }
69
+
70
+ #[allow(dead_code)]
71
+ pub(crate) fn is_valid(&self, flag: PreviewFeature) -> bool {
72
+ (self.active | self.hidden).contains(flag)
73
+ }
74
+
75
+ #[allow(dead_code)]
76
+ pub(crate) fn is_deprecated(&self, flag: PreviewFeature) -> bool {
77
+ self.deprecated.contains(flag)
78
+ }
79
+ }
80
+
81
+ impl Serialize for PreviewFeature {
82
+ fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
83
+ where
84
+ S: Serializer,
85
+ {
86
+ serializer.serialize_str(&self.to_string())
87
+ }
88
+ }
@@ -0,0 +1,5 @@
1
+ //! This module contains shared constants and logic that can be used by engines.
2
+
3
+ mod preview_features;
4
+
5
+ pub use self::preview_features::{PreviewFeature, PreviewFeatures, ALL_PREVIEW_FEATURES};
@@ -0,0 +1,24 @@
1
+ use super::Generator;
2
+ use crate::{internal_baml_diagnostics::Diagnostics, lockfile::LockFileWrapper, PreviewFeature};
3
+ use enumflags2::BitFlags;
4
+
5
+ #[derive(Debug)]
6
+ pub struct Configuration {
7
+ pub generators: Vec<(Generator, LockFileWrapper)>,
8
+ }
9
+
10
+ impl Configuration {
11
+ pub fn validate_that_one_datasource_is_provided(&self) -> Result<(), Diagnostics> {
12
+ Ok(())
13
+ }
14
+
15
+ pub fn max_identifier_length(&self) -> usize {
16
+ 1024
17
+ }
18
+
19
+ pub fn preview_features(&self) -> BitFlags<PreviewFeature> {
20
+ self.generators
21
+ .iter()
22
+ .fold(BitFlags::empty(), |acc, _generator| acc)
23
+ }
24
+ }
@@ -0,0 +1,217 @@
1
+ use crate::ast::WithName;
2
+ use anyhow::Result;
3
+ use internal_baml_parser_database::ast::Expression;
4
+ use regex::Regex;
5
+ use serde::Serialize;
6
+ use std::{collections::HashMap, path::PathBuf, process::Command};
7
+
8
+ #[derive(Debug, Serialize, Clone)]
9
+ #[serde(untagged)]
10
+ pub enum GeneratorConfigValue {
11
+ String(String),
12
+ Array(Vec<GeneratorConfigValue>),
13
+ Map(HashMap<String, GeneratorConfigValue>),
14
+ }
15
+
16
+ impl From<String> for GeneratorConfigValue {
17
+ fn from(value: String) -> Self {
18
+ Self::String(value)
19
+ }
20
+ }
21
+
22
+ impl From<&Expression> for GeneratorConfigValue {
23
+ fn from(expr: &Expression) -> Self {
24
+ match expr {
25
+ Expression::BoolValue(val, _) => val.to_string().into(),
26
+ Expression::NumericValue(val, _) => val.clone().into(),
27
+ Expression::StringValue(val, _) => val.clone().into(),
28
+ Expression::Array(elements, _) => {
29
+ Self::Array(elements.iter().map(From::from).collect())
30
+ }
31
+ Expression::Map(elements, _) => Self::Map(
32
+ elements
33
+ .iter()
34
+ .map(|(k, v)| (k.to_string(), From::from(v)))
35
+ .collect(),
36
+ ),
37
+ Expression::Identifier(idn) => idn.name().to_string().into(),
38
+ Expression::RawStringValue(val) => val.value().to_string().into(),
39
+ }
40
+ }
41
+ }
42
+
43
+ #[derive(Debug, Serialize, Clone)]
44
+ pub enum GeneratorLanguage {
45
+ #[serde(rename = "python")]
46
+ Python,
47
+ #[serde(rename = "typescript")]
48
+ TypeScript,
49
+ #[serde(rename = "Ruby")]
50
+ Ruby,
51
+ }
52
+
53
+ impl GeneratorLanguage {
54
+ pub fn as_str(&self) -> &'static str {
55
+ match self {
56
+ Self::Python => "python",
57
+ Self::TypeScript => "typescript",
58
+ Self::Ruby => "ruby",
59
+ }
60
+ }
61
+
62
+ pub fn package_name(&self) -> &'static str {
63
+ match self {
64
+ Self::Python => "baml",
65
+ Self::TypeScript => "@boundaryml/baml-core",
66
+ Self::Ruby => "baml",
67
+ }
68
+ }
69
+
70
+ /// This is redundant with version_command::get_client_version
71
+ fn client_version(&self, command: &str) -> Option<String> {
72
+ let cmd = format!("{} {}", command, self.package_name());
73
+
74
+ // Run the command and get the version
75
+ Command::new(cmd)
76
+ .output()
77
+ .map(|output| {
78
+ // If the command fails, return None
79
+ if !output.status.success() {
80
+ return None;
81
+ }
82
+
83
+ // If the command succeeds, return the version
84
+ String::from_utf8(output.stdout)
85
+ .ok()
86
+ .map(|v| v.trim().to_string())
87
+ .map(|v| self.parse_version(v.as_str()).ok())
88
+ .flatten()
89
+ })
90
+ .ok()
91
+ .flatten()
92
+ }
93
+
94
+ /// This is redundant with version_command::extract_client_version
95
+ pub fn parse_version(&self, output: &str) -> Result<String> {
96
+ match self {
97
+ Self::Python => {
98
+ // Split the string by lines, and take the first line that has "version" in it
99
+ let version_line_re = Regex::new(r#"(?i)\b(?:version)\b"#)?;
100
+
101
+ let Some(version_line) = output
102
+ .trim()
103
+ .lines()
104
+ .find(|line| version_line_re.is_match(line))
105
+ else {
106
+ return Err(anyhow::format_err!(
107
+ "Could not infer the version of the client"
108
+ ));
109
+ };
110
+
111
+ let version_re = Regex::new("[0-9][^ ]*")?;
112
+
113
+ let Some(version) = version_re.find(version_line) else {
114
+ return Err(anyhow::format_err!(
115
+ "Could not parse the version of the client"
116
+ ));
117
+ };
118
+
119
+ Ok(version.as_str().to_string())
120
+ }
121
+ Self::TypeScript => {
122
+ // Look for "<package_name>@<version>"
123
+ let version_re = Regex::new(&format!(r#"{}@[^ ]+"#, self.package_name()))?;
124
+
125
+ let Some(version) = version_re.find(output.trim()) else {
126
+ return Err(anyhow::format_err!(
127
+ "Could not parse the version of the client:{}\n{}",
128
+ self.package_name(),
129
+ output
130
+ ));
131
+ };
132
+
133
+ Ok(version.as_str().split('@').last().unwrap().to_string())
134
+ }
135
+ Self::Ruby => {
136
+ // Look for "<package_name>@<version>"
137
+ let version_re = Regex::new(&format!(r#"{} ([^)]+)"#, self.package_name()))?;
138
+
139
+ let Some(version) = version_re.captures(output.trim()) else {
140
+ return Err(anyhow::format_err!(
141
+ "Could not find the version of the client: {}\n{}",
142
+ self.package_name(),
143
+ output
144
+ ));
145
+ };
146
+ let Some(version) = version.get(1) else {
147
+ return Err(anyhow::format_err!(
148
+ "Could not parse the version of the client: {}\n{}",
149
+ self.package_name(),
150
+ output
151
+ ));
152
+ };
153
+
154
+ Ok(version.as_str().into())
155
+ }
156
+ }
157
+ }
158
+ }
159
+
160
+ #[derive(Debug, Serialize, Clone)]
161
+ #[serde(rename_all = "camelCase")]
162
+ pub struct Generator {
163
+ pub name: String,
164
+ pub language: GeneratorLanguage,
165
+ pub test_command: String,
166
+ pub install_command: String,
167
+ pub package_version_command: String,
168
+
169
+ #[serde(skip)]
170
+ pub used_in_tests: bool,
171
+
172
+ // This is generated from the package_version_command
173
+ pub client_version: Option<String>,
174
+
175
+ /// Where the language source code is located (e.g. place where pyproject.toml is located or package.json is located)
176
+ pub project_root: PathBuf,
177
+
178
+ /// Where the generated code should be placed (usually a subdirectory of the project_root)
179
+ pub output_path: PathBuf,
180
+
181
+ #[serde(skip)]
182
+ pub(crate) span: crate::ast::Span,
183
+ }
184
+
185
+ impl Generator {
186
+ pub fn new(
187
+ name: String,
188
+ project_root: PathBuf,
189
+ language: GeneratorLanguage,
190
+ test_command: String,
191
+ install_command: String,
192
+ package_version_command: String,
193
+ output_path: Option<PathBuf>,
194
+ used_in_tests: Option<bool>,
195
+ span: crate::ast::Span,
196
+ ) -> Result<Self, std::io::Error> {
197
+ Ok(Self {
198
+ name,
199
+ output_path: output_path
200
+ .as_ref()
201
+ .unwrap_or(&project_root)
202
+ .join("baml_client"),
203
+ project_root,
204
+ client_version: language.client_version(&package_version_command),
205
+ language,
206
+ test_command,
207
+ install_command,
208
+ package_version_command,
209
+ span,
210
+ used_in_tests: used_in_tests.unwrap_or(false),
211
+ })
212
+ }
213
+
214
+ pub fn cli_version(&self) -> &'static str {
215
+ env!("CARGO_PKG_VERSION")
216
+ }
217
+ }
@@ -0,0 +1,5 @@
1
+ mod configuration_struct;
2
+ mod generator;
3
+
4
+ pub use configuration_struct::*;
5
+ pub use generator::*;
@@ -0,0 +1,242 @@
1
+ use std::io::{self, ErrorKind};
2
+ use std::thread::sleep;
3
+ use std::time::Duration;
4
+ use std::{
5
+ collections::{HashMap, HashSet},
6
+ path::PathBuf,
7
+ };
8
+
9
+ use log::info;
10
+
11
+ #[derive(PartialEq, Eq, Hash)]
12
+ pub(super) struct LibImport {
13
+ pub lib: String,
14
+ pub as_name: Option<String>,
15
+ }
16
+
17
+ #[derive(PartialEq, Eq, Hash)]
18
+ pub(super) struct Import {
19
+ pub lib: String,
20
+ pub name: String,
21
+ pub as_name: Option<String>,
22
+ }
23
+
24
+ pub(super) struct FileContent {
25
+ content: Vec<String>,
26
+ import_libs: HashSet<LibImport>,
27
+ imports: Vec<Import>,
28
+ exports: Vec<String>,
29
+ export_all: bool,
30
+ }
31
+
32
+ impl FileContent {
33
+ pub fn add_import_lib(&mut self, lib: impl Into<String>, as_name: Option<&str>) {
34
+ self.import_libs.insert(LibImport {
35
+ lib: lib.into(),
36
+ as_name: as_name.map(|s| s.to_string()),
37
+ });
38
+ }
39
+
40
+ pub fn add_import(
41
+ &mut self,
42
+ lib: impl Into<String>,
43
+ name: impl AsRef<str>,
44
+ as_name: Option<&str>,
45
+ is_export: bool,
46
+ ) {
47
+ self.imports.push(Import {
48
+ lib: lib.into(),
49
+ name: name.as_ref().to_string(),
50
+ as_name: as_name.map(|s| s.to_string()),
51
+ });
52
+ if is_export || self.export_all {
53
+ self.exports
54
+ .push(as_name.unwrap_or(name.as_ref()).to_string());
55
+ }
56
+ }
57
+
58
+ pub fn add_export(&mut self, name: impl Into<String>) {
59
+ self.exports.push(name.into());
60
+ }
61
+
62
+ pub fn trim_append(&mut self, content: String) {
63
+ let content = content.trim();
64
+ if content.len() > 0 {
65
+ self.content.push(content.to_string());
66
+ }
67
+ }
68
+
69
+ #[allow(dead_code)]
70
+ pub fn append(&mut self, content: String) {
71
+ if content.len() > 0 {
72
+ self.content.push(content.to_string());
73
+ }
74
+ }
75
+ }
76
+
77
+ pub(super) struct FileCollector<L: LanguageFeatures> {
78
+ // map of path to a an object that has the trail File
79
+ files: HashMap<PathBuf, FileContent>,
80
+ /// This is used to keep track of the last file that was written to
81
+ /// Useful for catching bugs to ensure that we don't write to the same file twice.
82
+ last_file: Option<PathBuf>,
83
+
84
+ lang: L,
85
+ }
86
+
87
+ impl<L: LanguageFeatures> FileCollector<L> {
88
+ pub(super) fn new(lang: L) -> Self {
89
+ Self {
90
+ files: HashMap::new(),
91
+ last_file: None,
92
+ lang,
93
+ }
94
+ }
95
+
96
+ pub(super) fn finish_file(&mut self) {
97
+ assert!(self.last_file.is_some(), "No file to finish!");
98
+ self.last_file = None;
99
+ }
100
+
101
+ pub(super) fn start_file<T: AsRef<str>>(
102
+ &mut self,
103
+ dir: &str,
104
+ name: T,
105
+ export_all: bool,
106
+ ) -> &mut FileContent {
107
+ assert!(
108
+ self.last_file.is_none(),
109
+ "Cannot start a new file before finishing the last one!"
110
+ );
111
+
112
+ let path = self.lang.to_file_path(dir, name.as_ref());
113
+ self.last_file = Some(path.clone());
114
+ self.files.entry(path).or_insert_with(|| FileContent {
115
+ content: vec![],
116
+ import_libs: HashSet::new(),
117
+ imports: vec![],
118
+ exports: vec![],
119
+ export_all,
120
+ })
121
+ }
122
+
123
+ pub(super) fn commit(&self, dir: &PathBuf) -> std::io::Result<()> {
124
+ let output_path = dir;
125
+ // info!("Writing files to {}", output_path.to_string_lossy());
126
+
127
+ let temp_path = PathBuf::from(format!("{}.tmp", output_path.to_string_lossy().to_string()));
128
+
129
+ // if the .tmp dir exists, delete it so we can get back to a working state without user intervention.
130
+ let delete_attempts = 3; // Number of attempts to delete the directory
131
+ let attempt_interval = Duration::from_millis(200); // Wait time between attempts
132
+
133
+ for attempt in 1..=delete_attempts {
134
+ if temp_path.exists() {
135
+ match std::fs::remove_dir_all(&temp_path) {
136
+ Ok(_) => {
137
+ println!("Temp directory successfully removed.");
138
+ break; // Exit loop after successful deletion
139
+ }
140
+ Err(e) if e.kind() == ErrorKind::Other && attempt < delete_attempts => {
141
+ info!(
142
+ "Attempt {}: Failed to delete temp directory: {}",
143
+ attempt, e
144
+ );
145
+ sleep(attempt_interval); // Wait before retrying
146
+ }
147
+ Err(e) => {
148
+ // For other errors or if it's the last attempt, fail with an error
149
+ return Err(io::Error::new(
150
+ e.kind(),
151
+ format!("Failed to delete temp directory: {}", e),
152
+ ));
153
+ }
154
+ }
155
+ } else {
156
+ break;
157
+ }
158
+ }
159
+
160
+ if temp_path.exists() {
161
+ // If the directory still exists after the loop, return an error
162
+ return Err(std::io::Error::new(
163
+ std::io::ErrorKind::Other,
164
+ "Failed to delete existing temp directory within the timeout",
165
+ ));
166
+ }
167
+
168
+ // Sort the files by path so that we always write to the same file
169
+ let mut files = self.files.iter().collect::<Vec<_>>();
170
+ files.sort_by(|(a, _), (b, _)| a.cmp(b));
171
+
172
+ for (relative_file_path, file) in &files {
173
+ let full_file_path = temp_path.join(relative_file_path);
174
+ std::fs::create_dir_all(full_file_path.parent().unwrap())?;
175
+ std::fs::write(&full_file_path, &self.format_file(file))?;
176
+ }
177
+
178
+ let _ = std::fs::remove_dir_all(dir);
179
+ let res = std::fs::rename(&temp_path, output_path);
180
+
181
+ info!("Wrote {} files to {}", files.len(), dir.display());
182
+ res
183
+ }
184
+
185
+ fn format_file(&self, content: &FileContent) -> String {
186
+ let mut result = vec![];
187
+
188
+ let content_prefix = self.lang.content_prefix();
189
+ if content_prefix.len() > 0 {
190
+ result.push(content_prefix.to_string());
191
+ }
192
+
193
+ if content.imports.len() + content.import_libs.len() > 0 {
194
+ result.push(
195
+ self.lang
196
+ .format_imports(&content.import_libs, &content.imports),
197
+ );
198
+ }
199
+
200
+ if content.content.len() > 0 {
201
+ result.push(content.content.join("\n\n") + "\n");
202
+ }
203
+
204
+ if content.exports.len() > 0 {
205
+ result.push(self.lang.format_exports(&content.exports));
206
+ }
207
+
208
+ // Ensure that the file ends with newlines.
209
+ result.push("".into());
210
+
211
+ result.join("\n\n")
212
+ }
213
+ }
214
+
215
+ // Add a trait per language that can be used to convert an Import into a string
216
+ pub(super) trait LanguageFeatures {
217
+ fn to_file_path(&self, path: &str, name: &str) -> PathBuf;
218
+ fn format_imports(&self, libs: &HashSet<LibImport>, import: &Vec<Import>) -> String;
219
+ fn format_exports(&self, exports: &Vec<String>) -> String;
220
+ fn content_prefix(&self) -> &'static str;
221
+ }
222
+
223
+ pub(super) trait WithFileContentTs<L: LanguageFeatures> {
224
+ fn file_dir(&self) -> &'static str;
225
+ fn file_name(&self) -> String;
226
+ fn write(&self, fc: &mut FileCollector<L>);
227
+ }
228
+
229
+ pub(super) trait WithFileContentRuby<L: LanguageFeatures> {
230
+ fn file_dir(&self) -> &'static str;
231
+ fn file_name(&self) -> String;
232
+ fn write(&self, fc: &mut FileCollector<L>);
233
+ }
234
+
235
+ // Until rust supports trait specialization, we can't implement a trait for the same type twice, even if it's generic and the generic type is different (e.g. a diff language).
236
+ // See https://users.rust-lang.org/t/multiple-trait-implementations-based-on-generic-type-bound/17064
237
+ // So to fix we have to hack around and actually have a *different* trait for Python
238
+ // pub(super) trait WithFileContentPy<L: LanguageFeatures> {
239
+ // fn file_dir(&self) -> &'static str;
240
+ // fn file_name(&self) -> String;
241
+ // fn write(&self, fc: &mut FileCollector<L>);
242
+ // }
@@ -0,0 +1,24 @@
1
+ use internal_baml_parser_database::ParserDatabase;
2
+
3
+ use crate::{
4
+ configuration::{Generator, GeneratorLanguage},
5
+ ir::IntermediateRepr,
6
+ lockfile::LockFileWrapper,
7
+ };
8
+
9
+ use super::generate_python_client_old::generate_py;
10
+ use super::generate_ts_client::generate_ts;
11
+
12
+
13
+ pub fn generate_pipeline(
14
+ db: &ParserDatabase,
15
+ gen: &Generator,
16
+ ir: &IntermediateRepr,
17
+ lock: &LockFileWrapper,
18
+ ) -> anyhow::Result<()> {
19
+ match gen.language {
20
+ GeneratorLanguage::Python => generate_py(db, gen, lock).map_err(anyhow::Error::new),
21
+ GeneratorLanguage::TypeScript => generate_ts(&ir, gen).map_err(anyhow::Error::new),
22
+ _ => anyhow::bail!("generator v1 only supports python and TS"),
23
+ }
24
+ }