@arizeai/phoenix-client 0.0.1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (516) hide show
  1. package/README.md +136 -7
  2. package/dist/esm/__generated__/api/v1.d.ts +743 -12
  3. package/dist/esm/__generated__/api/v1.d.ts.map +1 -1
  4. package/dist/esm/client.d.ts +9 -2
  5. package/dist/esm/client.d.ts.map +1 -1
  6. package/dist/esm/client.js +3 -2
  7. package/dist/esm/client.js.map +1 -1
  8. package/dist/esm/config.d.ts.map +1 -1
  9. package/dist/esm/config.js +11 -1
  10. package/dist/esm/config.js.map +1 -1
  11. package/dist/esm/experiments/runExperiment.d.ts +35 -8
  12. package/dist/esm/experiments/runExperiment.d.ts.map +1 -1
  13. package/dist/esm/experiments/runExperiment.js +29 -39
  14. package/dist/esm/experiments/runExperiment.js.map +1 -1
  15. package/dist/esm/index.d.ts +0 -1
  16. package/dist/esm/index.d.ts.map +1 -1
  17. package/dist/esm/index.js +0 -1
  18. package/dist/esm/index.js.map +1 -1
  19. package/dist/esm/prompts/constants.d.ts +6 -0
  20. package/dist/esm/prompts/constants.d.ts.map +1 -0
  21. package/dist/esm/prompts/constants.js +10 -0
  22. package/dist/esm/prompts/constants.js.map +1 -0
  23. package/dist/esm/prompts/createPrompt.d.ts +65 -0
  24. package/dist/esm/prompts/createPrompt.d.ts.map +1 -0
  25. package/dist/esm/prompts/createPrompt.js +95 -0
  26. package/dist/esm/prompts/createPrompt.js.map +1 -0
  27. package/dist/esm/prompts/getPrompt.d.ts +16 -0
  28. package/dist/esm/prompts/getPrompt.d.ts.map +1 -0
  29. package/dist/esm/prompts/getPrompt.js +11 -0
  30. package/dist/esm/prompts/getPrompt.js.map +1 -0
  31. package/dist/esm/prompts/index.d.ts +4 -0
  32. package/dist/esm/prompts/index.d.ts.map +1 -0
  33. package/dist/esm/prompts/index.js +4 -0
  34. package/dist/esm/prompts/index.js.map +1 -0
  35. package/dist/esm/prompts/sdks/constants.d.ts +6 -0
  36. package/dist/esm/prompts/sdks/constants.d.ts.map +1 -0
  37. package/dist/esm/prompts/sdks/constants.js +6 -0
  38. package/dist/esm/prompts/sdks/constants.js.map +1 -0
  39. package/dist/esm/prompts/sdks/index.d.ts +2 -0
  40. package/dist/esm/prompts/sdks/index.d.ts.map +1 -0
  41. package/dist/esm/prompts/sdks/index.js +2 -0
  42. package/dist/esm/prompts/sdks/index.js.map +1 -0
  43. package/dist/esm/prompts/sdks/toAI.d.ts +12 -0
  44. package/dist/esm/prompts/sdks/toAI.d.ts.map +1 -0
  45. package/dist/esm/prompts/sdks/toAI.js +70 -0
  46. package/dist/esm/prompts/sdks/toAI.js.map +1 -0
  47. package/dist/esm/prompts/sdks/toAnthropic.d.ts +9 -0
  48. package/dist/esm/prompts/sdks/toAnthropic.d.ts.map +1 -0
  49. package/dist/esm/prompts/sdks/toAnthropic.js +69 -0
  50. package/dist/esm/prompts/sdks/toAnthropic.js.map +1 -0
  51. package/dist/esm/prompts/sdks/toOpenAI.d.ts +11 -0
  52. package/dist/esm/prompts/sdks/toOpenAI.d.ts.map +1 -0
  53. package/dist/esm/prompts/sdks/toOpenAI.js +77 -0
  54. package/dist/esm/prompts/sdks/toOpenAI.js.map +1 -0
  55. package/dist/esm/prompts/sdks/toSDK.d.ts +47 -0
  56. package/dist/esm/prompts/sdks/toSDK.d.ts.map +1 -0
  57. package/dist/esm/prompts/sdks/toSDK.js +44 -0
  58. package/dist/esm/prompts/sdks/toSDK.js.map +1 -0
  59. package/dist/esm/prompts/sdks/types.d.ts +28 -0
  60. package/dist/esm/prompts/sdks/types.d.ts.map +1 -0
  61. package/dist/esm/prompts/sdks/types.js +2 -0
  62. package/dist/esm/prompts/sdks/types.js.map +1 -0
  63. package/dist/esm/schemas/jsonLiteralSchema.d.ts +17 -0
  64. package/dist/esm/schemas/jsonLiteralSchema.d.ts.map +1 -0
  65. package/dist/esm/schemas/jsonLiteralSchema.js +16 -0
  66. package/dist/esm/schemas/jsonLiteralSchema.js.map +1 -0
  67. package/dist/esm/schemas/jsonSchema.d.ts +132 -0
  68. package/dist/esm/schemas/jsonSchema.d.ts.map +1 -0
  69. package/dist/esm/schemas/jsonSchema.js +42 -0
  70. package/dist/esm/schemas/jsonSchema.js.map +1 -0
  71. package/dist/esm/schemas/llm/anthropic/converters.d.ts +1497 -0
  72. package/dist/esm/schemas/llm/anthropic/converters.d.ts.map +1 -0
  73. package/dist/esm/schemas/llm/anthropic/converters.js +123 -0
  74. package/dist/esm/schemas/llm/anthropic/converters.js.map +1 -0
  75. package/dist/esm/schemas/llm/anthropic/messagePartSchemas.d.ts +264 -0
  76. package/dist/esm/schemas/llm/anthropic/messagePartSchemas.d.ts.map +1 -0
  77. package/dist/esm/schemas/llm/anthropic/messagePartSchemas.js +36 -0
  78. package/dist/esm/schemas/llm/anthropic/messagePartSchemas.js.map +1 -0
  79. package/dist/esm/schemas/llm/anthropic/messageSchemas.d.ts +795 -0
  80. package/dist/esm/schemas/llm/anthropic/messageSchemas.d.ts.map +1 -0
  81. package/dist/esm/schemas/llm/anthropic/messageSchemas.js +23 -0
  82. package/dist/esm/schemas/llm/anthropic/messageSchemas.js.map +1 -0
  83. package/dist/esm/schemas/llm/anthropic/toolCallSchemas.d.ts +48 -0
  84. package/dist/esm/schemas/llm/anthropic/toolCallSchemas.d.ts.map +1 -0
  85. package/dist/esm/schemas/llm/anthropic/toolCallSchemas.js +27 -0
  86. package/dist/esm/schemas/llm/anthropic/toolCallSchemas.js.map +1 -0
  87. package/dist/esm/schemas/llm/anthropic/toolChoiceSchemas.d.ts +30 -0
  88. package/dist/esm/schemas/llm/anthropic/toolChoiceSchemas.d.ts.map +1 -0
  89. package/dist/esm/schemas/llm/anthropic/toolChoiceSchemas.js +19 -0
  90. package/dist/esm/schemas/llm/anthropic/toolChoiceSchemas.js.map +1 -0
  91. package/dist/esm/schemas/llm/anthropic/toolSchemas.d.ts +191 -0
  92. package/dist/esm/schemas/llm/anthropic/toolSchemas.d.ts.map +1 -0
  93. package/dist/esm/schemas/llm/anthropic/toolSchemas.js +31 -0
  94. package/dist/esm/schemas/llm/anthropic/toolSchemas.js.map +1 -0
  95. package/dist/esm/schemas/llm/constants.d.ts +7422 -0
  96. package/dist/esm/schemas/llm/constants.d.ts.map +1 -0
  97. package/dist/esm/schemas/llm/constants.js +128 -0
  98. package/dist/esm/schemas/llm/constants.js.map +1 -0
  99. package/dist/esm/schemas/llm/converters.d.ts +29720 -0
  100. package/dist/esm/schemas/llm/converters.d.ts.map +1 -0
  101. package/dist/esm/schemas/llm/converters.js +308 -0
  102. package/dist/esm/schemas/llm/converters.js.map +1 -0
  103. package/dist/esm/schemas/llm/openai/converters.d.ts +3507 -0
  104. package/dist/esm/schemas/llm/openai/converters.d.ts.map +1 -0
  105. package/dist/esm/schemas/llm/openai/converters.js +311 -0
  106. package/dist/esm/schemas/llm/openai/converters.js.map +1 -0
  107. package/dist/esm/schemas/llm/openai/messagePartSchemas.d.ts +64 -0
  108. package/dist/esm/schemas/llm/openai/messagePartSchemas.d.ts.map +1 -0
  109. package/dist/esm/schemas/llm/openai/messagePartSchemas.js +21 -0
  110. package/dist/esm/schemas/llm/openai/messagePartSchemas.js.map +1 -0
  111. package/dist/esm/schemas/llm/openai/messageSchemas.d.ts +733 -0
  112. package/dist/esm/schemas/llm/openai/messageSchemas.d.ts.map +1 -0
  113. package/dist/esm/schemas/llm/openai/messageSchemas.js +67 -0
  114. package/dist/esm/schemas/llm/openai/messageSchemas.js.map +1 -0
  115. package/dist/esm/schemas/llm/openai/responseFormatSchema.d.ts +233 -0
  116. package/dist/esm/schemas/llm/openai/responseFormatSchema.d.ts.map +1 -0
  117. package/dist/esm/schemas/llm/openai/responseFormatSchema.js +19 -0
  118. package/dist/esm/schemas/llm/openai/responseFormatSchema.js.map +1 -0
  119. package/dist/esm/schemas/llm/openai/toolCallSchemas.d.ts +95 -0
  120. package/dist/esm/schemas/llm/openai/toolCallSchemas.d.ts.map +1 -0
  121. package/dist/esm/schemas/llm/openai/toolCallSchemas.js +40 -0
  122. package/dist/esm/schemas/llm/openai/toolCallSchemas.js.map +1 -0
  123. package/dist/esm/schemas/llm/openai/toolChoiceSchemas.d.ts +28 -0
  124. package/dist/esm/schemas/llm/openai/toolChoiceSchemas.d.ts.map +1 -0
  125. package/dist/esm/schemas/llm/openai/toolChoiceSchemas.js +16 -0
  126. package/dist/esm/schemas/llm/openai/toolChoiceSchemas.js.map +1 -0
  127. package/dist/esm/schemas/llm/openai/toolSchemas.d.ts +1282 -0
  128. package/dist/esm/schemas/llm/openai/toolSchemas.d.ts.map +1 -0
  129. package/dist/esm/schemas/llm/openai/toolSchemas.js +62 -0
  130. package/dist/esm/schemas/llm/openai/toolSchemas.js.map +1 -0
  131. package/dist/esm/schemas/llm/phoenixPrompt/converters.d.ts +847 -0
  132. package/dist/esm/schemas/llm/phoenixPrompt/converters.d.ts.map +1 -0
  133. package/dist/esm/schemas/llm/phoenixPrompt/converters.js +130 -0
  134. package/dist/esm/schemas/llm/phoenixPrompt/converters.js.map +1 -0
  135. package/dist/esm/schemas/llm/phoenixPrompt/messagePartSchemas.d.ts +128 -0
  136. package/dist/esm/schemas/llm/phoenixPrompt/messagePartSchemas.d.ts.map +1 -0
  137. package/dist/esm/schemas/llm/phoenixPrompt/messagePartSchemas.js +60 -0
  138. package/dist/esm/schemas/llm/phoenixPrompt/messagePartSchemas.js.map +1 -0
  139. package/dist/esm/schemas/llm/phoenixPrompt/messageSchemas.d.ts +196 -0
  140. package/dist/esm/schemas/llm/phoenixPrompt/messageSchemas.d.ts.map +1 -0
  141. package/dist/esm/schemas/llm/phoenixPrompt/messageSchemas.js +23 -0
  142. package/dist/esm/schemas/llm/phoenixPrompt/messageSchemas.js.map +1 -0
  143. package/dist/esm/schemas/llm/phoenixPrompt/responseFormatSchema.d.ts +41 -0
  144. package/dist/esm/schemas/llm/phoenixPrompt/responseFormatSchema.d.ts.map +1 -0
  145. package/dist/esm/schemas/llm/phoenixPrompt/responseFormatSchema.js +15 -0
  146. package/dist/esm/schemas/llm/phoenixPrompt/responseFormatSchema.js.map +1 -0
  147. package/dist/esm/schemas/llm/phoenixPrompt/toolCallSchemas.d.ts +36 -0
  148. package/dist/esm/schemas/llm/phoenixPrompt/toolCallSchemas.d.ts.map +1 -0
  149. package/dist/esm/schemas/llm/phoenixPrompt/toolCallSchemas.js +3 -0
  150. package/dist/esm/schemas/llm/phoenixPrompt/toolCallSchemas.js.map +1 -0
  151. package/dist/esm/schemas/llm/phoenixPrompt/toolChoiceSchemas.d.ts +34 -0
  152. package/dist/esm/schemas/llm/phoenixPrompt/toolChoiceSchemas.d.ts.map +1 -0
  153. package/dist/esm/schemas/llm/phoenixPrompt/toolChoiceSchemas.js +21 -0
  154. package/dist/esm/schemas/llm/phoenixPrompt/toolChoiceSchemas.js.map +1 -0
  155. package/dist/esm/schemas/llm/phoenixPrompt/toolSchemas.d.ts +41 -0
  156. package/dist/esm/schemas/llm/phoenixPrompt/toolSchemas.d.ts.map +1 -0
  157. package/dist/esm/schemas/llm/phoenixPrompt/toolSchemas.js +15 -0
  158. package/dist/esm/schemas/llm/phoenixPrompt/toolSchemas.js.map +1 -0
  159. package/dist/esm/schemas/llm/schemas.d.ts +2777 -0
  160. package/dist/esm/schemas/llm/schemas.d.ts.map +1 -0
  161. package/dist/esm/schemas/llm/schemas.js +77 -0
  162. package/dist/esm/schemas/llm/schemas.js.map +1 -0
  163. package/dist/esm/schemas/llm/types.d.ts +129 -0
  164. package/dist/esm/schemas/llm/types.d.ts.map +1 -0
  165. package/dist/esm/schemas/llm/types.js +2 -0
  166. package/dist/esm/schemas/llm/types.js.map +1 -0
  167. package/dist/esm/schemas/llm/utils.d.ts +25 -0
  168. package/dist/esm/schemas/llm/utils.d.ts.map +1 -0
  169. package/dist/esm/schemas/llm/utils.js +176 -0
  170. package/dist/esm/schemas/llm/utils.js.map +1 -0
  171. package/dist/esm/schemas/llm/vercel/messagePartSchemas.d.ts +114 -0
  172. package/dist/esm/schemas/llm/vercel/messagePartSchemas.d.ts.map +1 -0
  173. package/dist/esm/schemas/llm/vercel/messagePartSchemas.js +35 -0
  174. package/dist/esm/schemas/llm/vercel/messagePartSchemas.js.map +1 -0
  175. package/dist/esm/schemas/llm/vercel/messageSchemas.d.ts +142 -0
  176. package/dist/esm/schemas/llm/vercel/messageSchemas.d.ts.map +1 -0
  177. package/dist/esm/schemas/llm/vercel/messageSchemas.js +42 -0
  178. package/dist/esm/schemas/llm/vercel/messageSchemas.js.map +1 -0
  179. package/dist/esm/schemas/llm/vercel/toolChoiceSchemas.d.ts +16 -0
  180. package/dist/esm/schemas/llm/vercel/toolChoiceSchemas.d.ts.map +1 -0
  181. package/dist/esm/schemas/llm/vercel/toolChoiceSchemas.js +14 -0
  182. package/dist/esm/schemas/llm/vercel/toolChoiceSchemas.js.map +1 -0
  183. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  184. package/dist/esm/types/core.d.ts +8 -0
  185. package/dist/esm/types/core.d.ts.map +1 -1
  186. package/dist/esm/types/logger.d.ts +6 -0
  187. package/dist/esm/types/logger.d.ts.map +1 -0
  188. package/dist/esm/types/logger.js +2 -0
  189. package/dist/esm/types/logger.js.map +1 -0
  190. package/dist/esm/types/prompts.d.ts +107 -0
  191. package/dist/esm/types/prompts.d.ts.map +1 -0
  192. package/dist/esm/types/prompts.js +2 -0
  193. package/dist/esm/types/prompts.js.map +1 -0
  194. package/dist/esm/utils/assertUnreachable.d.ts +8 -0
  195. package/dist/esm/utils/assertUnreachable.d.ts.map +1 -0
  196. package/dist/esm/utils/assertUnreachable.js +10 -0
  197. package/dist/esm/utils/assertUnreachable.js.map +1 -0
  198. package/dist/esm/utils/formatPromptMessages.d.ts +26 -0
  199. package/dist/esm/utils/formatPromptMessages.d.ts.map +1 -0
  200. package/dist/esm/utils/formatPromptMessages.js +64 -0
  201. package/dist/esm/utils/formatPromptMessages.js.map +1 -0
  202. package/dist/esm/utils/getDatasetLike.d.ts +22 -0
  203. package/dist/esm/utils/getDatasetLike.d.ts.map +1 -0
  204. package/dist/esm/utils/getDatasetLike.js +37 -0
  205. package/dist/esm/utils/getDatasetLike.js.map +1 -0
  206. package/dist/esm/utils/getPromptVersionLike.d.ts +29 -0
  207. package/dist/esm/utils/getPromptVersionLike.d.ts.map +1 -0
  208. package/dist/esm/utils/getPromptVersionLike.js +50 -0
  209. package/dist/esm/utils/getPromptVersionLike.js.map +1 -0
  210. package/dist/esm/utils/isObject.d.ts +5 -0
  211. package/dist/esm/utils/isObject.d.ts.map +1 -0
  212. package/dist/esm/utils/isObject.js +7 -0
  213. package/dist/esm/utils/isObject.js.map +1 -0
  214. package/dist/esm/utils/noopLogger.d.ts +9 -0
  215. package/dist/esm/utils/noopLogger.d.ts.map +1 -0
  216. package/dist/esm/utils/noopLogger.js +9 -0
  217. package/dist/esm/utils/noopLogger.js.map +1 -0
  218. package/dist/esm/utils/safelyParseJSON.d.ts +14 -0
  219. package/dist/esm/utils/safelyParseJSON.d.ts.map +1 -0
  220. package/dist/esm/utils/safelyParseJSON.js +15 -0
  221. package/dist/esm/utils/safelyParseJSON.js.map +1 -0
  222. package/dist/esm/utils/safelyStringifyJSON.d.ts +14 -0
  223. package/dist/esm/utils/safelyStringifyJSON.d.ts.map +1 -0
  224. package/dist/esm/utils/safelyStringifyJSON.js +15 -0
  225. package/dist/esm/utils/safelyStringifyJSON.js.map +1 -0
  226. package/dist/esm/utils/schemaMatches.d.ts +17 -0
  227. package/dist/esm/utils/schemaMatches.d.ts.map +1 -0
  228. package/dist/esm/utils/schemaMatches.js +9 -0
  229. package/dist/esm/utils/schemaMatches.js.map +1 -0
  230. package/dist/src/__generated__/api/v1.d.ts +743 -12
  231. package/dist/src/__generated__/api/v1.d.ts.map +1 -1
  232. package/dist/src/client.d.ts +9 -2
  233. package/dist/src/client.d.ts.map +1 -1
  234. package/dist/src/client.js +3 -2
  235. package/dist/src/client.js.map +1 -1
  236. package/dist/src/config.d.ts.map +1 -1
  237. package/dist/src/config.js +9 -1
  238. package/dist/src/config.js.map +1 -1
  239. package/dist/src/experiments/runExperiment.d.ts +35 -8
  240. package/dist/src/experiments/runExperiment.d.ts.map +1 -1
  241. package/dist/src/experiments/runExperiment.js +29 -34
  242. package/dist/src/experiments/runExperiment.js.map +1 -1
  243. package/dist/src/index.d.ts +0 -1
  244. package/dist/src/index.d.ts.map +1 -1
  245. package/dist/src/index.js +0 -1
  246. package/dist/src/index.js.map +1 -1
  247. package/dist/src/prompts/constants.d.ts +6 -0
  248. package/dist/src/prompts/constants.d.ts.map +1 -0
  249. package/dist/src/prompts/constants.js +13 -0
  250. package/dist/src/prompts/constants.js.map +1 -0
  251. package/dist/src/prompts/createPrompt.d.ts +65 -0
  252. package/dist/src/prompts/createPrompt.d.ts.map +1 -0
  253. package/dist/src/prompts/createPrompt.js +123 -0
  254. package/dist/src/prompts/createPrompt.js.map +1 -0
  255. package/dist/src/prompts/getPrompt.d.ts +16 -0
  256. package/dist/src/prompts/getPrompt.d.ts.map +1 -0
  257. package/dist/src/prompts/getPrompt.js +25 -0
  258. package/dist/src/prompts/getPrompt.js.map +1 -0
  259. package/dist/src/prompts/index.d.ts +4 -0
  260. package/dist/src/prompts/index.d.ts.map +1 -0
  261. package/dist/src/prompts/index.js +20 -0
  262. package/dist/src/prompts/index.js.map +1 -0
  263. package/dist/src/prompts/sdks/constants.d.ts +6 -0
  264. package/dist/src/prompts/sdks/constants.d.ts.map +1 -0
  265. package/dist/src/prompts/sdks/constants.js +9 -0
  266. package/dist/src/prompts/sdks/constants.js.map +1 -0
  267. package/dist/src/prompts/sdks/index.d.ts +2 -0
  268. package/dist/src/prompts/sdks/index.d.ts.map +1 -0
  269. package/dist/src/prompts/sdks/index.js +18 -0
  270. package/dist/src/prompts/sdks/index.js.map +1 -0
  271. package/dist/src/prompts/sdks/toAI.d.ts +12 -0
  272. package/dist/src/prompts/sdks/toAI.d.ts.map +1 -0
  273. package/dist/src/prompts/sdks/toAI.js +75 -0
  274. package/dist/src/prompts/sdks/toAI.js.map +1 -0
  275. package/dist/src/prompts/sdks/toAnthropic.d.ts +9 -0
  276. package/dist/src/prompts/sdks/toAnthropic.d.ts.map +1 -0
  277. package/dist/src/prompts/sdks/toAnthropic.js +71 -0
  278. package/dist/src/prompts/sdks/toAnthropic.js.map +1 -0
  279. package/dist/src/prompts/sdks/toOpenAI.d.ts +11 -0
  280. package/dist/src/prompts/sdks/toOpenAI.d.ts.map +1 -0
  281. package/dist/src/prompts/sdks/toOpenAI.js +78 -0
  282. package/dist/src/prompts/sdks/toOpenAI.js.map +1 -0
  283. package/dist/src/prompts/sdks/toSDK.d.ts +47 -0
  284. package/dist/src/prompts/sdks/toSDK.d.ts.map +1 -0
  285. package/dist/src/prompts/sdks/toSDK.js +63 -0
  286. package/dist/src/prompts/sdks/toSDK.js.map +1 -0
  287. package/dist/src/prompts/sdks/types.d.ts +28 -0
  288. package/dist/src/prompts/sdks/types.d.ts.map +1 -0
  289. package/dist/src/prompts/sdks/types.js +3 -0
  290. package/dist/src/prompts/sdks/types.js.map +1 -0
  291. package/dist/src/schemas/jsonLiteralSchema.d.ts +17 -0
  292. package/dist/src/schemas/jsonLiteralSchema.d.ts.map +1 -0
  293. package/dist/src/schemas/jsonLiteralSchema.js +22 -0
  294. package/dist/src/schemas/jsonLiteralSchema.js.map +1 -0
  295. package/dist/src/schemas/jsonSchema.d.ts +132 -0
  296. package/dist/src/schemas/jsonSchema.d.ts.map +1 -0
  297. package/dist/src/schemas/jsonSchema.js +48 -0
  298. package/dist/src/schemas/jsonSchema.js.map +1 -0
  299. package/dist/src/schemas/llm/anthropic/converters.d.ts +1497 -0
  300. package/dist/src/schemas/llm/anthropic/converters.d.ts.map +1 -0
  301. package/dist/src/schemas/llm/anthropic/converters.js +132 -0
  302. package/dist/src/schemas/llm/anthropic/converters.js.map +1 -0
  303. package/dist/src/schemas/llm/anthropic/messagePartSchemas.d.ts +264 -0
  304. package/dist/src/schemas/llm/anthropic/messagePartSchemas.d.ts.map +1 -0
  305. package/dist/src/schemas/llm/anthropic/messagePartSchemas.js +42 -0
  306. package/dist/src/schemas/llm/anthropic/messagePartSchemas.js.map +1 -0
  307. package/dist/src/schemas/llm/anthropic/messageSchemas.d.ts +795 -0
  308. package/dist/src/schemas/llm/anthropic/messageSchemas.d.ts.map +1 -0
  309. package/dist/src/schemas/llm/anthropic/messageSchemas.js +29 -0
  310. package/dist/src/schemas/llm/anthropic/messageSchemas.js.map +1 -0
  311. package/dist/src/schemas/llm/anthropic/toolCallSchemas.d.ts +48 -0
  312. package/dist/src/schemas/llm/anthropic/toolCallSchemas.d.ts.map +1 -0
  313. package/dist/src/schemas/llm/anthropic/toolCallSchemas.js +34 -0
  314. package/dist/src/schemas/llm/anthropic/toolCallSchemas.js.map +1 -0
  315. package/dist/src/schemas/llm/anthropic/toolChoiceSchemas.d.ts +30 -0
  316. package/dist/src/schemas/llm/anthropic/toolChoiceSchemas.d.ts.map +1 -0
  317. package/dist/src/schemas/llm/anthropic/toolChoiceSchemas.js +25 -0
  318. package/dist/src/schemas/llm/anthropic/toolChoiceSchemas.js.map +1 -0
  319. package/dist/src/schemas/llm/anthropic/toolSchemas.d.ts +191 -0
  320. package/dist/src/schemas/llm/anthropic/toolSchemas.d.ts.map +1 -0
  321. package/dist/src/schemas/llm/anthropic/toolSchemas.js +38 -0
  322. package/dist/src/schemas/llm/anthropic/toolSchemas.js.map +1 -0
  323. package/dist/src/schemas/llm/constants.d.ts +7422 -0
  324. package/dist/src/schemas/llm/constants.d.ts.map +1 -0
  325. package/dist/src/schemas/llm/constants.js +131 -0
  326. package/dist/src/schemas/llm/constants.js.map +1 -0
  327. package/dist/src/schemas/llm/converters.d.ts +29720 -0
  328. package/dist/src/schemas/llm/converters.d.ts.map +1 -0
  329. package/dist/src/schemas/llm/converters.js +330 -0
  330. package/dist/src/schemas/llm/converters.js.map +1 -0
  331. package/dist/src/schemas/llm/openai/converters.d.ts +3507 -0
  332. package/dist/src/schemas/llm/openai/converters.d.ts.map +1 -0
  333. package/dist/src/schemas/llm/openai/converters.js +321 -0
  334. package/dist/src/schemas/llm/openai/converters.js.map +1 -0
  335. package/dist/src/schemas/llm/openai/messagePartSchemas.d.ts +64 -0
  336. package/dist/src/schemas/llm/openai/messagePartSchemas.d.ts.map +1 -0
  337. package/dist/src/schemas/llm/openai/messagePartSchemas.js +27 -0
  338. package/dist/src/schemas/llm/openai/messagePartSchemas.js.map +1 -0
  339. package/dist/src/schemas/llm/openai/messageSchemas.d.ts +733 -0
  340. package/dist/src/schemas/llm/openai/messageSchemas.d.ts.map +1 -0
  341. package/dist/src/schemas/llm/openai/messageSchemas.js +73 -0
  342. package/dist/src/schemas/llm/openai/messageSchemas.js.map +1 -0
  343. package/dist/src/schemas/llm/openai/responseFormatSchema.d.ts +233 -0
  344. package/dist/src/schemas/llm/openai/responseFormatSchema.d.ts.map +1 -0
  345. package/dist/src/schemas/llm/openai/responseFormatSchema.js +25 -0
  346. package/dist/src/schemas/llm/openai/responseFormatSchema.js.map +1 -0
  347. package/dist/src/schemas/llm/openai/toolCallSchemas.d.ts +95 -0
  348. package/dist/src/schemas/llm/openai/toolCallSchemas.d.ts.map +1 -0
  349. package/dist/src/schemas/llm/openai/toolCallSchemas.js +47 -0
  350. package/dist/src/schemas/llm/openai/toolCallSchemas.js.map +1 -0
  351. package/dist/src/schemas/llm/openai/toolChoiceSchemas.d.ts +28 -0
  352. package/dist/src/schemas/llm/openai/toolChoiceSchemas.d.ts.map +1 -0
  353. package/dist/src/schemas/llm/openai/toolChoiceSchemas.js +22 -0
  354. package/dist/src/schemas/llm/openai/toolChoiceSchemas.js.map +1 -0
  355. package/dist/src/schemas/llm/openai/toolSchemas.d.ts +1282 -0
  356. package/dist/src/schemas/llm/openai/toolSchemas.d.ts.map +1 -0
  357. package/dist/src/schemas/llm/openai/toolSchemas.js +69 -0
  358. package/dist/src/schemas/llm/openai/toolSchemas.js.map +1 -0
  359. package/dist/src/schemas/llm/phoenixPrompt/converters.d.ts +847 -0
  360. package/dist/src/schemas/llm/phoenixPrompt/converters.d.ts.map +1 -0
  361. package/dist/src/schemas/llm/phoenixPrompt/converters.js +133 -0
  362. package/dist/src/schemas/llm/phoenixPrompt/converters.js.map +1 -0
  363. package/dist/src/schemas/llm/phoenixPrompt/messagePartSchemas.d.ts +128 -0
  364. package/dist/src/schemas/llm/phoenixPrompt/messagePartSchemas.d.ts.map +1 -0
  365. package/dist/src/schemas/llm/phoenixPrompt/messagePartSchemas.js +71 -0
  366. package/dist/src/schemas/llm/phoenixPrompt/messagePartSchemas.js.map +1 -0
  367. package/dist/src/schemas/llm/phoenixPrompt/messageSchemas.d.ts +196 -0
  368. package/dist/src/schemas/llm/phoenixPrompt/messageSchemas.d.ts.map +1 -0
  369. package/dist/src/schemas/llm/phoenixPrompt/messageSchemas.js +29 -0
  370. package/dist/src/schemas/llm/phoenixPrompt/messageSchemas.js.map +1 -0
  371. package/dist/src/schemas/llm/phoenixPrompt/responseFormatSchema.d.ts +41 -0
  372. package/dist/src/schemas/llm/phoenixPrompt/responseFormatSchema.d.ts.map +1 -0
  373. package/dist/src/schemas/llm/phoenixPrompt/responseFormatSchema.js +21 -0
  374. package/dist/src/schemas/llm/phoenixPrompt/responseFormatSchema.js.map +1 -0
  375. package/dist/src/schemas/llm/phoenixPrompt/toolCallSchemas.d.ts +36 -0
  376. package/dist/src/schemas/llm/phoenixPrompt/toolCallSchemas.d.ts.map +1 -0
  377. package/dist/src/schemas/llm/phoenixPrompt/toolCallSchemas.js +6 -0
  378. package/dist/src/schemas/llm/phoenixPrompt/toolCallSchemas.js.map +1 -0
  379. package/dist/src/schemas/llm/phoenixPrompt/toolChoiceSchemas.d.ts +34 -0
  380. package/dist/src/schemas/llm/phoenixPrompt/toolChoiceSchemas.d.ts.map +1 -0
  381. package/dist/src/schemas/llm/phoenixPrompt/toolChoiceSchemas.js +27 -0
  382. package/dist/src/schemas/llm/phoenixPrompt/toolChoiceSchemas.js.map +1 -0
  383. package/dist/src/schemas/llm/phoenixPrompt/toolSchemas.d.ts +41 -0
  384. package/dist/src/schemas/llm/phoenixPrompt/toolSchemas.d.ts.map +1 -0
  385. package/dist/src/schemas/llm/phoenixPrompt/toolSchemas.js +21 -0
  386. package/dist/src/schemas/llm/phoenixPrompt/toolSchemas.js.map +1 -0
  387. package/dist/src/schemas/llm/schemas.d.ts +2777 -0
  388. package/dist/src/schemas/llm/schemas.d.ts.map +1 -0
  389. package/dist/src/schemas/llm/schemas.js +83 -0
  390. package/dist/src/schemas/llm/schemas.js.map +1 -0
  391. package/dist/src/schemas/llm/types.d.ts +129 -0
  392. package/dist/src/schemas/llm/types.d.ts.map +1 -0
  393. package/dist/src/schemas/llm/types.js +3 -0
  394. package/dist/src/schemas/llm/types.js.map +1 -0
  395. package/dist/src/schemas/llm/utils.d.ts +25 -0
  396. package/dist/src/schemas/llm/utils.d.ts.map +1 -0
  397. package/dist/src/schemas/llm/utils.js +187 -0
  398. package/dist/src/schemas/llm/utils.js.map +1 -0
  399. package/dist/src/schemas/llm/vercel/messagePartSchemas.d.ts +114 -0
  400. package/dist/src/schemas/llm/vercel/messagePartSchemas.d.ts.map +1 -0
  401. package/dist/src/schemas/llm/vercel/messagePartSchemas.js +41 -0
  402. package/dist/src/schemas/llm/vercel/messagePartSchemas.js.map +1 -0
  403. package/dist/src/schemas/llm/vercel/messageSchemas.d.ts +142 -0
  404. package/dist/src/schemas/llm/vercel/messageSchemas.d.ts.map +1 -0
  405. package/dist/src/schemas/llm/vercel/messageSchemas.js +48 -0
  406. package/dist/src/schemas/llm/vercel/messageSchemas.js.map +1 -0
  407. package/dist/src/schemas/llm/vercel/toolChoiceSchemas.d.ts +16 -0
  408. package/dist/src/schemas/llm/vercel/toolChoiceSchemas.d.ts.map +1 -0
  409. package/dist/src/schemas/llm/vercel/toolChoiceSchemas.js +20 -0
  410. package/dist/src/schemas/llm/vercel/toolChoiceSchemas.js.map +1 -0
  411. package/dist/src/types/core.d.ts +8 -0
  412. package/dist/src/types/core.d.ts.map +1 -1
  413. package/dist/src/types/logger.d.ts +6 -0
  414. package/dist/src/types/logger.d.ts.map +1 -0
  415. package/dist/src/types/logger.js +3 -0
  416. package/dist/src/types/logger.js.map +1 -0
  417. package/dist/src/types/prompts.d.ts +107 -0
  418. package/dist/src/types/prompts.d.ts.map +1 -0
  419. package/dist/src/types/prompts.js +3 -0
  420. package/dist/src/types/prompts.js.map +1 -0
  421. package/dist/src/utils/assertUnreachable.d.ts +8 -0
  422. package/dist/src/utils/assertUnreachable.d.ts.map +1 -0
  423. package/dist/src/utils/assertUnreachable.js +13 -0
  424. package/dist/src/utils/assertUnreachable.js.map +1 -0
  425. package/dist/src/utils/formatPromptMessages.d.ts +26 -0
  426. package/dist/src/utils/formatPromptMessages.d.ts.map +1 -0
  427. package/dist/src/utils/formatPromptMessages.js +61 -0
  428. package/dist/src/utils/formatPromptMessages.js.map +1 -0
  429. package/dist/src/utils/getDatasetLike.d.ts +22 -0
  430. package/dist/src/utils/getDatasetLike.d.ts.map +1 -0
  431. package/dist/src/utils/getDatasetLike.js +47 -0
  432. package/dist/src/utils/getDatasetLike.js.map +1 -0
  433. package/dist/src/utils/getPromptVersionLike.d.ts +29 -0
  434. package/dist/src/utils/getPromptVersionLike.d.ts.map +1 -0
  435. package/dist/src/utils/getPromptVersionLike.js +68 -0
  436. package/dist/src/utils/getPromptVersionLike.js.map +1 -0
  437. package/dist/src/utils/isObject.d.ts +5 -0
  438. package/dist/src/utils/isObject.d.ts.map +1 -0
  439. package/dist/src/utils/isObject.js +10 -0
  440. package/dist/src/utils/isObject.js.map +1 -0
  441. package/dist/src/utils/noopLogger.d.ts +9 -0
  442. package/dist/src/utils/noopLogger.d.ts.map +1 -0
  443. package/dist/src/utils/noopLogger.js +12 -0
  444. package/dist/src/utils/noopLogger.js.map +1 -0
  445. package/dist/src/utils/safelyParseJSON.d.ts +14 -0
  446. package/dist/src/utils/safelyParseJSON.d.ts.map +1 -0
  447. package/dist/src/utils/safelyParseJSON.js +18 -0
  448. package/dist/src/utils/safelyParseJSON.js.map +1 -0
  449. package/dist/src/utils/safelyStringifyJSON.d.ts +14 -0
  450. package/dist/src/utils/safelyStringifyJSON.d.ts.map +1 -0
  451. package/dist/src/utils/safelyStringifyJSON.js +18 -0
  452. package/dist/src/utils/safelyStringifyJSON.js.map +1 -0
  453. package/dist/src/utils/schemaMatches.d.ts +17 -0
  454. package/dist/src/utils/schemaMatches.d.ts.map +1 -0
  455. package/dist/src/utils/schemaMatches.js +13 -0
  456. package/dist/src/utils/schemaMatches.js.map +1 -0
  457. package/dist/tsconfig.tsbuildinfo +1 -1
  458. package/package.json +32 -5
  459. package/src/__generated__/api/v1.ts +743 -12
  460. package/src/client.ts +9 -2
  461. package/src/config.ts +12 -1
  462. package/src/experiments/runExperiment.ts +54 -53
  463. package/src/index.ts +0 -2
  464. package/src/prompts/constants.ts +11 -0
  465. package/src/prompts/createPrompt.ts +181 -0
  466. package/src/prompts/getPrompt.ts +26 -0
  467. package/src/prompts/index.ts +3 -0
  468. package/src/prompts/sdks/constants.ts +10 -0
  469. package/src/prompts/sdks/index.ts +1 -0
  470. package/src/prompts/sdks/toAI.ts +105 -0
  471. package/src/prompts/sdks/toAnthropic.ts +98 -0
  472. package/src/prompts/sdks/toOpenAI.ts +115 -0
  473. package/src/prompts/sdks/toSDK.ts +81 -0
  474. package/src/prompts/sdks/types.ts +28 -0
  475. package/src/schemas/jsonLiteralSchema.ts +24 -0
  476. package/src/schemas/jsonSchema.ts +47 -0
  477. package/src/schemas/llm/anthropic/converters.ts +172 -0
  478. package/src/schemas/llm/anthropic/messagePartSchemas.ts +53 -0
  479. package/src/schemas/llm/anthropic/messageSchemas.ts +34 -0
  480. package/src/schemas/llm/anthropic/toolCallSchemas.ts +34 -0
  481. package/src/schemas/llm/anthropic/toolChoiceSchemas.ts +21 -0
  482. package/src/schemas/llm/anthropic/toolSchemas.ts +41 -0
  483. package/src/schemas/llm/constants.ts +156 -0
  484. package/src/schemas/llm/converters.ts +499 -0
  485. package/src/schemas/llm/openai/converters.ts +383 -0
  486. package/src/schemas/llm/openai/messagePartSchemas.ts +30 -0
  487. package/src/schemas/llm/openai/messageSchemas.ts +78 -0
  488. package/src/schemas/llm/openai/responseFormatSchema.ts +22 -0
  489. package/src/schemas/llm/openai/toolCallSchemas.ts +58 -0
  490. package/src/schemas/llm/openai/toolChoiceSchemas.ts +18 -0
  491. package/src/schemas/llm/openai/toolSchemas.ts +74 -0
  492. package/src/schemas/llm/phoenixPrompt/converters.ts +178 -0
  493. package/src/schemas/llm/phoenixPrompt/messagePartSchemas.ts +95 -0
  494. package/src/schemas/llm/phoenixPrompt/messageSchemas.ts +34 -0
  495. package/src/schemas/llm/phoenixPrompt/responseFormatSchema.ts +21 -0
  496. package/src/schemas/llm/phoenixPrompt/toolCallSchemas.ts +7 -0
  497. package/src/schemas/llm/phoenixPrompt/toolChoiceSchemas.ts +26 -0
  498. package/src/schemas/llm/phoenixPrompt/toolSchemas.ts +20 -0
  499. package/src/schemas/llm/schemas.ts +94 -0
  500. package/src/schemas/llm/types.ts +161 -0
  501. package/src/schemas/llm/utils.ts +259 -0
  502. package/src/schemas/llm/vercel/messagePartSchemas.ts +54 -0
  503. package/src/schemas/llm/vercel/messageSchemas.ts +54 -0
  504. package/src/schemas/llm/vercel/toolChoiceSchemas.ts +16 -0
  505. package/src/types/core.ts +9 -0
  506. package/src/types/logger.ts +5 -0
  507. package/src/types/prompts.ts +151 -0
  508. package/src/utils/assertUnreachable.ts +9 -0
  509. package/src/utils/formatPromptMessages.ts +79 -0
  510. package/src/utils/getDatasetLike.ts +52 -0
  511. package/src/utils/getPromptVersionLike.ts +73 -0
  512. package/src/utils/isObject.ts +6 -0
  513. package/src/utils/noopLogger.ts +10 -0
  514. package/src/utils/safelyParseJSON.ts +13 -0
  515. package/src/utils/safelyStringifyJSON.ts +15 -0
  516. package/src/utils/schemaMatches.ts +29 -0
@@ -0,0 +1,259 @@
1
+ import { anthropicMessagePartSchema } from "./anthropic/messagePartSchemas";
2
+ import { anthropicMessageSchema } from "./anthropic/messageSchemas";
3
+ import { openAIToolCallSchema } from "./openai/toolCallSchemas";
4
+ import { openaiChatPartSchema } from "./openai/messagePartSchemas";
5
+ import { openAIMessageSchema } from "./openai/messageSchemas";
6
+ import { openAIToolChoiceSchema } from "./openai/toolChoiceSchemas";
7
+ import { anthropicToolChoiceSchema } from "./anthropic/toolChoiceSchemas";
8
+ import { openAIToolDefinitionSchema } from "./openai/toolSchemas";
9
+ import { anthropicToolDefinitionSchema } from "./anthropic/toolSchemas";
10
+ import { anthropicToolCallSchema } from "./anthropic/toolCallSchemas";
11
+ import { llmProviderToolDefinitionSchema } from "./schemas";
12
+ import type {
13
+ LLMMessagePart,
14
+ MessagePartWithProvider,
15
+ MessageWithProvider,
16
+ SDKConverters,
17
+ ToolCallWithProvider,
18
+ ToolChoiceWithProvider,
19
+ ToolDefinitionWithProvider,
20
+ } from "./types";
21
+ import { isObject } from "../../utils/isObject";
22
+ import type { ZodTypeAny } from "zod";
23
+ import { vercelAIMessageSchema } from "./vercel/messageSchemas";
24
+ import { phoenixMessageSchema } from "./phoenixPrompt/messageSchemas";
25
+ import { phoenixToolCallSchema } from "./phoenixPrompt/toolCallSchemas";
26
+ import { phoenixToolChoiceSchema } from "./phoenixPrompt/toolChoiceSchemas";
27
+ import { phoenixToolDefinitionSchema } from "./phoenixPrompt/toolSchemas";
28
+ import { phoenixContentPartSchema } from "./phoenixPrompt/messagePartSchemas";
29
+
30
+ export const makeSDKConverters = <
31
+ MessageSchema extends ZodTypeAny,
32
+ MessagePartSchema extends ZodTypeAny,
33
+ ToolChoiceSchema extends ZodTypeAny,
34
+ ToolCallSchema extends ZodTypeAny,
35
+ ToolDefinitionSchema extends ZodTypeAny,
36
+ ResponseFormatSchema extends ZodTypeAny,
37
+ >({
38
+ messages,
39
+ messageParts,
40
+ toolChoices,
41
+ toolCalls,
42
+ toolDefinitions,
43
+ responseFormat,
44
+ }: SDKConverters<
45
+ MessageSchema,
46
+ MessagePartSchema,
47
+ ToolChoiceSchema,
48
+ ToolCallSchema,
49
+ ToolDefinitionSchema,
50
+ ResponseFormatSchema
51
+ >): SDKConverters<
52
+ MessageSchema,
53
+ MessagePartSchema,
54
+ ToolChoiceSchema,
55
+ ToolCallSchema,
56
+ ToolDefinitionSchema,
57
+ ResponseFormatSchema
58
+ > => {
59
+ return {
60
+ messages,
61
+ messageParts,
62
+ toolChoices,
63
+ toolCalls,
64
+ toolDefinitions,
65
+ responseFormat,
66
+ };
67
+ };
68
+
69
+ /**
70
+ * Detect the provider of a message object
71
+ */
72
+ export const detectMessageProvider = (
73
+ message: unknown
74
+ ): MessageWithProvider => {
75
+ const { success: openaiSuccess, data: openaiData } =
76
+ openAIMessageSchema.safeParse(message);
77
+ if (openaiSuccess) {
78
+ return {
79
+ // we cannot disambiguate between azure openai and openai here
80
+ provider: "OPENAI",
81
+ validatedMessage: openaiData,
82
+ };
83
+ }
84
+ const { success: anthropicSuccess, data: anthropicData } =
85
+ anthropicMessageSchema.safeParse(message);
86
+ if (anthropicSuccess) {
87
+ return {
88
+ provider: "ANTHROPIC",
89
+ validatedMessage: anthropicData,
90
+ };
91
+ }
92
+ const { success: vercelSuccess, data: vercelData } =
93
+ vercelAIMessageSchema.safeParse(message);
94
+ if (vercelSuccess) {
95
+ return { provider: "VERCEL_AI", validatedMessage: vercelData };
96
+ }
97
+ const { success: phoenixSuccess, data: phoenixData } =
98
+ phoenixMessageSchema.safeParse(message);
99
+ if (phoenixSuccess) {
100
+ return { provider: "PHOENIX", validatedMessage: phoenixData };
101
+ }
102
+ return { provider: null, validatedMessage: null };
103
+ };
104
+
105
+ export const detectMessagePartProvider = (
106
+ part: LLMMessagePart
107
+ ): MessagePartWithProvider => {
108
+ const { success: openaiSuccess, data: openaiData } =
109
+ openaiChatPartSchema.safeParse(part);
110
+ if (openaiSuccess) {
111
+ return {
112
+ provider: "OPENAI",
113
+ validatedMessage: openaiData,
114
+ };
115
+ }
116
+ const { success: anthropicSuccess, data: anthropicData } =
117
+ anthropicMessagePartSchema.safeParse(part);
118
+ if (anthropicSuccess) {
119
+ return {
120
+ provider: "ANTHROPIC",
121
+ validatedMessage: anthropicData,
122
+ };
123
+ }
124
+ const { success: phoenixSuccess, data: phoenixData } =
125
+ phoenixContentPartSchema.safeParse(part);
126
+ if (phoenixSuccess) {
127
+ return { provider: "PHOENIX", validatedMessage: phoenixData };
128
+ }
129
+ return { provider: null, validatedMessage: null };
130
+ };
131
+
132
+ /**
133
+ * Detect the provider of a tool call object
134
+ */
135
+ export const detectToolCallProvider = (
136
+ toolCall: unknown
137
+ ): ToolCallWithProvider => {
138
+ const { success: openaiSuccess, data: openaiData } =
139
+ openAIToolCallSchema.safeParse(toolCall);
140
+ if (openaiSuccess) {
141
+ // we cannot disambiguate between azure openai and openai here
142
+ return { provider: "OPENAI", validatedToolCall: openaiData };
143
+ }
144
+ const { success: anthropicSuccess, data: anthropicData } =
145
+ anthropicToolCallSchema.safeParse(toolCall);
146
+ if (anthropicSuccess) {
147
+ return { provider: "ANTHROPIC", validatedToolCall: anthropicData };
148
+ }
149
+ const { success: phoenixSuccess, data: phoenixData } =
150
+ phoenixToolCallSchema.safeParse(toolCall);
151
+ if (phoenixSuccess) {
152
+ return { provider: "PHOENIX", validatedToolCall: phoenixData };
153
+ }
154
+ return { provider: null, validatedToolCall: null };
155
+ };
156
+
157
+ /**
158
+ * Detects the provider of a tool choice
159
+ * @param toolChoice the tool choice to detect the provider of
160
+ * @returns the provider of the tool choice
161
+ */
162
+ export const detectToolChoiceProvider = (
163
+ toolChoice: unknown
164
+ ): ToolChoiceWithProvider => {
165
+ const { success: openAISuccess, data: openAIData } =
166
+ openAIToolChoiceSchema.safeParse(toolChoice);
167
+ if (openAISuccess) {
168
+ return { provider: "OPENAI", toolChoice: openAIData };
169
+ }
170
+ const { success: anthropicSuccess, data: anthropicData } =
171
+ anthropicToolChoiceSchema.safeParse(toolChoice);
172
+ if (anthropicSuccess) {
173
+ return { provider: "ANTHROPIC", toolChoice: anthropicData };
174
+ }
175
+ const { success: phoenixSuccess, data: phoenixData } =
176
+ phoenixToolChoiceSchema.safeParse(toolChoice);
177
+ if (phoenixSuccess) {
178
+ return { provider: "PHOENIX", toolChoice: phoenixData };
179
+ }
180
+ return { provider: null, toolChoice: null };
181
+ };
182
+
183
+ /**
184
+ * Detect the provider of a tool call object
185
+ */
186
+ export const detectToolDefinitionProvider = (
187
+ toolDefinition: unknown
188
+ ): ToolDefinitionWithProvider => {
189
+ const { success: openaiSuccess, data: openaiData } =
190
+ openAIToolDefinitionSchema.safeParse(toolDefinition);
191
+ if (openaiSuccess) {
192
+ return {
193
+ // we cannot disambiguate between azure openai and openai here
194
+ provider: "OPENAI",
195
+ validatedToolDefinition: openaiData,
196
+ };
197
+ }
198
+ const { success: anthropicSuccess, data: anthropicData } =
199
+ anthropicToolDefinitionSchema.safeParse(toolDefinition);
200
+ if (anthropicSuccess) {
201
+ return {
202
+ provider: "ANTHROPIC",
203
+ validatedToolDefinition: anthropicData,
204
+ };
205
+ }
206
+ const { success: phoenixSuccess, data: phoenixData } =
207
+ phoenixToolDefinitionSchema.safeParse(toolDefinition);
208
+ if (phoenixSuccess) {
209
+ return { provider: "PHOENIX", validatedToolDefinition: phoenixData };
210
+ }
211
+ return { provider: null, validatedToolDefinition: null };
212
+ };
213
+
214
+ export const findToolDefinitionName = (toolDefinition: unknown) => {
215
+ const parsed = llmProviderToolDefinitionSchema.safeParse(toolDefinition);
216
+ if (!parsed.success || parsed.data === null || !isObject(parsed.data)) {
217
+ return null;
218
+ }
219
+
220
+ if (
221
+ "function" in parsed.data &&
222
+ isObject(parsed.data.function) &&
223
+ "name" in parsed.data.function &&
224
+ typeof parsed.data.function.name === "string"
225
+ ) {
226
+ return parsed.data.function.name;
227
+ }
228
+
229
+ if ("name" in parsed.data && typeof parsed.data.name === "string") {
230
+ return parsed.data.name;
231
+ }
232
+
233
+ return null;
234
+ };
235
+
236
+ export const findToolDefinitionDescription = (toolDefinition: unknown) => {
237
+ const parsed = llmProviderToolDefinitionSchema.safeParse(toolDefinition);
238
+ if (!parsed.success || parsed.data === null || !isObject(parsed.data)) {
239
+ return null;
240
+ }
241
+
242
+ if (
243
+ "function" in parsed.data &&
244
+ isObject(parsed.data.function) &&
245
+ "description" in parsed.data.function &&
246
+ typeof parsed.data.function.description === "string"
247
+ ) {
248
+ return parsed.data.function.description;
249
+ }
250
+
251
+ if (
252
+ "description" in parsed.data &&
253
+ typeof parsed.data.description === "string"
254
+ ) {
255
+ return parsed.data.description;
256
+ }
257
+
258
+ return null;
259
+ };
@@ -0,0 +1,54 @@
1
+ import z from "zod";
2
+ import { jsonLiteralSchema } from "../../jsonLiteralSchema";
3
+
4
+ /*
5
+ *
6
+ * Vercel AI SDK Message Part Schemas
7
+ *
8
+ */
9
+
10
+ export const vercelAIChatPartTextSchema = z.object({
11
+ type: z.literal("text"),
12
+ text: z.string(),
13
+ });
14
+
15
+ export type VercelAIChatPartText = z.infer<typeof vercelAIChatPartTextSchema>;
16
+
17
+ export const vercelAIChatPartImageSchema = z.object({
18
+ type: z.literal("image"),
19
+ image: z.string(), // ai supports more, but we will just support base64 for now
20
+ mimeType: z.string().optional(),
21
+ });
22
+
23
+ export type VercelAIChatPartImage = z.infer<typeof vercelAIChatPartImageSchema>;
24
+
25
+ export const vercelAIChatPartToolCallSchema = z.object({
26
+ type: z.literal("tool-call"),
27
+ toolCallId: z.string(),
28
+ toolName: z.string(),
29
+ args: jsonLiteralSchema, // json serializable parameters
30
+ });
31
+
32
+ export type VercelAIChatPartToolCall = z.infer<
33
+ typeof vercelAIChatPartToolCallSchema
34
+ >;
35
+
36
+ export const vercelAIChatPartToolResultSchema = z.object({
37
+ type: z.literal("tool-result"),
38
+ toolCallId: z.string(),
39
+ toolName: z.string(),
40
+ result: jsonLiteralSchema, // json serializable result
41
+ });
42
+
43
+ export type VercelAIChatPartToolResult = z.infer<
44
+ typeof vercelAIChatPartToolResultSchema
45
+ >;
46
+
47
+ export const vercelAIChatPartSchema = z.discriminatedUnion("type", [
48
+ vercelAIChatPartTextSchema,
49
+ vercelAIChatPartImageSchema,
50
+ vercelAIChatPartToolCallSchema,
51
+ vercelAIChatPartToolResultSchema,
52
+ ]);
53
+
54
+ export type VercelAIChatPart = z.infer<typeof vercelAIChatPartSchema>;
@@ -0,0 +1,54 @@
1
+ import z from "zod";
2
+
3
+ import {
4
+ vercelAIChatPartImageSchema,
5
+ vercelAIChatPartTextSchema,
6
+ vercelAIChatPartToolCallSchema,
7
+ vercelAIChatPartToolResultSchema,
8
+ } from "./messagePartSchemas";
9
+
10
+ /*
11
+ *
12
+ * Vercel AI SDK Message Schemas
13
+ *
14
+ */
15
+
16
+ export const vercelAIMessageRoleSchema = z.enum([
17
+ "system",
18
+ "user",
19
+ "assistant",
20
+ "tool",
21
+ ]);
22
+
23
+ export type VercelAIMessageRole = z.infer<typeof vercelAIMessageRoleSchema>;
24
+
25
+ export const vercelAIMessageSchema = z.discriminatedUnion("role", [
26
+ z.object({
27
+ role: z.literal("system"),
28
+ content: z.string(),
29
+ }),
30
+ z.object({
31
+ role: z.literal("user"),
32
+ content: z.union([
33
+ z
34
+ .union([vercelAIChatPartTextSchema, vercelAIChatPartImageSchema])
35
+ .array(),
36
+ z.string(),
37
+ ]),
38
+ }),
39
+ z.object({
40
+ role: z.literal("assistant"),
41
+ content: z.union([
42
+ z
43
+ .union([vercelAIChatPartTextSchema, vercelAIChatPartToolCallSchema])
44
+ .array(),
45
+ z.string(),
46
+ ]),
47
+ }),
48
+ z.object({
49
+ role: z.literal("tool"),
50
+ content: vercelAIChatPartToolResultSchema.array(),
51
+ }),
52
+ ]);
53
+
54
+ export type VercelAIMessage = z.infer<typeof vercelAIMessageSchema>;
@@ -0,0 +1,16 @@
1
+ import z from "zod";
2
+
3
+ /**
4
+ * Vercel AI SDK Tool Choice Schema
5
+ */
6
+ export const vercelAIToolChoiceSchema = z.union([
7
+ z.literal("auto"),
8
+ z.literal("none"),
9
+ z.literal("required"),
10
+ z.object({
11
+ type: z.literal("tool"),
12
+ toolName: z.string(),
13
+ }),
14
+ ]);
15
+
16
+ export type VercelAIToolChoice = z.infer<typeof vercelAIToolChoiceSchema>;
package/src/types/core.ts CHANGED
@@ -1,6 +1,15 @@
1
+ import { PhoenixClient } from "../client";
1
2
  /**
2
3
  * A uniquely identifiable node in Phoenix
3
4
  */
4
5
  export interface Node {
5
6
  id: string;
6
7
  }
8
+
9
+ export interface ClientFn {
10
+ /**
11
+ * An instance of the Phoenix client.
12
+ * If not provided, the client will be created using the default configuration.
13
+ */
14
+ client?: PhoenixClient;
15
+ }
@@ -0,0 +1,5 @@
1
+ export type Logger = {
2
+ info: (message: string) => void;
3
+ error: (message: string) => void;
4
+ log: (message: string) => void;
5
+ };
@@ -0,0 +1,151 @@
1
+ import { components } from "../__generated__/api/v1";
2
+
3
+ /**
4
+ * Supported prompt model providers
5
+ */
6
+ export type PromptModelProvider =
7
+ | "OPENAI"
8
+ | "AZURE_OPENAI"
9
+ | "ANTHROPIC"
10
+ | "GOOGLE";
11
+
12
+ /**
13
+ * Supported prompt provider SDKs
14
+ *
15
+ * These are possible sdk formats for prompt templates
16
+ */
17
+ export type PromptProviderSDKs =
18
+ | "PHOENIX"
19
+ | "AZURE_OPENAI"
20
+ | "OPENAI"
21
+ | "ANTHROPIC"
22
+ | "VERCEL_AI";
23
+
24
+ /**
25
+ * The role of a prompt chat message
26
+ */
27
+ export type PromptChatMessageRole = "user" | "system" | "ai" | "tool";
28
+
29
+ /**
30
+ * Selector for a prompt by id.
31
+ */
32
+ export interface GetPromptByIdSelector {
33
+ promptId: string;
34
+ }
35
+
36
+ /**
37
+ * Selector for a prompt by name.
38
+ */
39
+ export interface GetPromptByNameSelector {
40
+ name: string;
41
+ }
42
+
43
+ /**
44
+ * Selector for a prompt by version id.
45
+ */
46
+ export interface GetPromptByVersionSelector {
47
+ versionId: string;
48
+ }
49
+
50
+ /**
51
+ * Selector for a named prompt by tag.
52
+ */
53
+ export interface GetPromptByTagSelector {
54
+ tag: string;
55
+ name: string;
56
+ }
57
+
58
+ /**
59
+ * A prompt like object.
60
+ *
61
+ * Can be a prompt id, a prompt name, a prompt version id, or a prompt name + tag.
62
+ */
63
+ export type PromptSelector =
64
+ | GetPromptByIdSelector
65
+ | GetPromptByNameSelector
66
+ | GetPromptByVersionSelector
67
+ | GetPromptByTagSelector;
68
+
69
+ /**
70
+ * The prompt data needed to create a prompt.
71
+ */
72
+ export type PromptData = components["schemas"]["PromptData"];
73
+
74
+ /**
75
+ * The prompt version type from the API.
76
+ *
77
+ * aka the prompt at a specific point in time
78
+ */
79
+ export type PromptVersion = components["schemas"]["PromptVersion"];
80
+
81
+ /**
82
+ * The prompt version data needed to create a prompt version.
83
+ */
84
+ export type PromptVersionData = components["schemas"]["PromptVersionData"];
85
+
86
+ /**
87
+ * The invocation parameters for a prompt version for OpenAI.
88
+ */
89
+ export type OpenAIInvocationParameters =
90
+ components["schemas"]["PromptOpenAIInvocationParametersContent"];
91
+
92
+ /**
93
+ * The invocation parameters for a prompt version for Azure OpenAI.
94
+ */
95
+ export type AzureOpenAIInvocationParameters =
96
+ components["schemas"]["PromptAzureOpenAIInvocationParametersContent"];
97
+
98
+ /**
99
+ * The invocation parameters for a prompt version for Anthropic.
100
+ */
101
+ export type AnthropicInvocationParameters =
102
+ components["schemas"]["PromptAnthropicInvocationParametersContent"];
103
+
104
+ /**
105
+ * The invocation parameters for a prompt version for Google.
106
+ */
107
+ export type GoogleInvocationParameters =
108
+ components["schemas"]["PromptGoogleInvocationParametersContent"];
109
+
110
+ /**
111
+ * The format of the prompt template message(s).
112
+ */
113
+ export type PromptTemplateFormat = PromptVersion["template_format"];
114
+
115
+ /**
116
+ * Extracts the chat message type from the prompt template who may be a StringTemplate or ChatTemplate.
117
+ */
118
+ export type PromptChatMessage = Extract<
119
+ PromptVersion["template"],
120
+ { messages: unknown[] }
121
+ >["messages"][number];
122
+
123
+ /**
124
+ * Extracts the chat message part type from the prompt chat message.
125
+ */
126
+ export type PromptChatMessagePart =
127
+ | components["schemas"]["TextContentPart"]
128
+ | components["schemas"]["ToolCallContentPart"]
129
+ | components["schemas"]["ToolResultContentPart"];
130
+
131
+ /**
132
+ * The Phoenix prompt tool type from the API.
133
+ */
134
+ export type PromptTool = components["schemas"]["PromptTools"]["tools"][number];
135
+
136
+ /**
137
+ * The Phoenix prompt tool choice type from the API.
138
+ */
139
+ export type PromptToolChoice = NonNullable<
140
+ components["schemas"]["PromptTools"]["tool_choice"]
141
+ >;
142
+ /**
143
+ * The Phoenix prompt output schema type from the API.
144
+ */
145
+ export type PromptResponseFormat =
146
+ components["schemas"]["PromptResponseFormatJSONSchema"];
147
+
148
+ /**
149
+ * The prompt type from the API.
150
+ */
151
+ export type Prompt = components["schemas"]["Prompt"];
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Utility function that uses the type system to check if a switch statement is exhaustive.
3
+ * If the switch statement is not exhaustive, there will be a type error caught in typescript
4
+ *
5
+ * See https://stackoverflow.com/questions/39419170/how-do-i-check-that-a-switch-block-is-exhaustive-in-typescript for more details.
6
+ */
7
+ export function assertUnreachable(_: never): never {
8
+ throw new Error("Unreachable");
9
+ }
@@ -0,0 +1,79 @@
1
+ import { Variables } from "../prompts/sdks/types";
2
+ import { PromptChatMessage, PromptTemplateFormat } from "../types/prompts";
3
+ import { assertUnreachable } from "./assertUnreachable";
4
+ import {
5
+ TextPart,
6
+ asTextPart,
7
+ } from "../schemas/llm/phoenixPrompt/messagePartSchemas";
8
+
9
+ /**
10
+ * Format a list of prompt messages
11
+ *
12
+ * @param format - The format of the prompt message variables, e.g. MUSTACHE, F_STRING, NONE
13
+ * @param promptMessages - The prompt messages to format
14
+ * @param variables - The variables to use in the formatting
15
+ * @returns The formatted prompt messages
16
+ */
17
+ export function formatPromptMessages(
18
+ format: PromptTemplateFormat,
19
+ promptMessages: PromptChatMessage[],
20
+ variables: Variables = {}
21
+ ) {
22
+ const replacements: [RegExp, string][] = [];
23
+ switch (format) {
24
+ case "MUSTACHE": {
25
+ const asMustache = Object.entries(variables).map(([key, value]) => [
26
+ new RegExp(`\\{\\{\\s*${key}\\s*\\}\\}(?!\\})`, "g"),
27
+ value.toString(),
28
+ ]) satisfies [RegExp, string][];
29
+ replacements.push(...asMustache);
30
+ break;
31
+ }
32
+ case "F_STRING": {
33
+ const asF_STRING = Object.entries(variables).map(([key, value]) => [
34
+ new RegExp(`(?<!\\{)\\{\\s*${key}\\s*\\}(?!\\})`, "g"),
35
+ value.toString(),
36
+ ]) satisfies [RegExp, string][];
37
+ replacements.push(...asF_STRING);
38
+ break;
39
+ }
40
+ case "NONE":
41
+ break;
42
+ default:
43
+ assertUnreachable(format);
44
+ }
45
+
46
+ return promptMessages.map((message) => ({
47
+ ...message,
48
+ content:
49
+ typeof message.content == "string"
50
+ ? applyReplacements(message.content, replacements)
51
+ : message.content.map((content) => {
52
+ const textPart = asTextPart(content);
53
+ if (textPart) {
54
+ return {
55
+ ...textPart,
56
+ text: applyReplacements(textPart.text, replacements),
57
+ } satisfies TextPart;
58
+ }
59
+ return content;
60
+ }),
61
+ }));
62
+ }
63
+
64
+ /**
65
+ * Apply a list of replacements to a string
66
+ * @param text - The text to apply the replacements to
67
+ * @param replacements - The replacements to apply
68
+ * @returns The text with the replacements applied
69
+ */
70
+ function applyReplacements(
71
+ text: string,
72
+ replacements: [RegExp, string][]
73
+ ): string {
74
+ let newText = text;
75
+ for (const [key, value] of replacements) {
76
+ newText = newText.replaceAll(key, value);
77
+ }
78
+ return newText;
79
+ }
@@ -0,0 +1,52 @@
1
+ import invariant from "tiny-invariant";
2
+ import { PhoenixClient } from "../client";
3
+ import { Example } from "../types/datasets";
4
+
5
+ import { Dataset } from "../types/datasets";
6
+
7
+ /**
8
+ * Parameters for the getDatasetLike function
9
+ */
10
+ export type GetDatasetLikeParams = {
11
+ dataset: Dataset | string | Example[];
12
+ client: PhoenixClient;
13
+ };
14
+
15
+ /**
16
+ * Return a dataset object from the input.
17
+ *
18
+ * If the input is a string, assume it is a dataset id and fetch the dataset from the client.
19
+ * If the input is an array of examples, create a new dataset from the examples then return it.
20
+ * If the input is a dataset, return it as is.
21
+ *
22
+ * @param dataset - The dataset to get.
23
+ * @returns The dataset.
24
+ */
25
+ export async function getDatasetLike({
26
+ dataset,
27
+ client,
28
+ }: GetDatasetLikeParams): Promise<Dataset | null> {
29
+ if (typeof dataset === "string") {
30
+ const datasetResponse = await client
31
+ .GET(`/v1/datasets/{id}`, { params: { path: { id: dataset } } })
32
+ .then((d) => d.data?.data);
33
+ invariant(datasetResponse, `Dataset ${dataset} not found`);
34
+ const examples = await client
35
+ .GET(`/v1/datasets/{id}/examples`, { params: { path: { id: dataset } } })
36
+ .then((e) => e.data?.data);
37
+ invariant(examples, `Examples for dataset ${dataset} not found`);
38
+ const datasetWithExamples: Dataset = {
39
+ ...datasetResponse,
40
+ examples: examples.examples.map((example) => ({
41
+ ...example,
42
+ updatedAt: new Date(example.updated_at),
43
+ })),
44
+ versionId: examples.version_id,
45
+ };
46
+ return datasetWithExamples;
47
+ }
48
+ if (Array.isArray(dataset)) {
49
+ throw new Error("TODO: implement dataset creation from examples");
50
+ }
51
+ return dataset;
52
+ }