@morphllm/morphsdk 0.2.171 → 0.2.172

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 (259) hide show
  1. package/dist/{chunk-3XRNC56L.js → chunk-2SNAXTUJ.js} +4 -4
  2. package/dist/chunk-453ZV2AX.js +120 -0
  3. package/dist/chunk-453ZV2AX.js.map +1 -0
  4. package/dist/chunk-53ZJMCWU.js +142 -0
  5. package/dist/chunk-53ZJMCWU.js.map +1 -0
  6. package/dist/{chunk-IW4TYYG6.js → chunk-5DA6SZQJ.js} +2 -2
  7. package/dist/chunk-66OHYI24.js +78 -0
  8. package/dist/chunk-66OHYI24.js.map +1 -0
  9. package/dist/chunk-6X6QMRQG.js +158 -0
  10. package/dist/chunk-6X6QMRQG.js.map +1 -0
  11. package/dist/{chunk-C37YAYBK.js → chunk-7PVVPLRL.js} +2 -2
  12. package/dist/{chunk-MZZMSL26.js → chunk-AE7M2I52.js} +2 -2
  13. package/dist/{chunk-JLLIVBKY.js → chunk-CQF76HJC.js} +30 -6
  14. package/dist/chunk-CQF76HJC.js.map +1 -0
  15. package/dist/{chunk-EFCDIESP.js → chunk-ESXCQBMU.js} +2 -2
  16. package/dist/{chunk-FQJCE2FX.js → chunk-FOIDGIY4.js} +29 -10
  17. package/dist/chunk-FOIDGIY4.js.map +1 -0
  18. package/dist/{chunk-JEDEBCZM.js → chunk-GJZXDRH5.js} +8 -3
  19. package/dist/{chunk-JEDEBCZM.js.map → chunk-GJZXDRH5.js.map} +1 -1
  20. package/dist/{chunk-2ALTBYMY.js → chunk-IJ33I7P5.js} +4 -4
  21. package/dist/{chunk-UK7TI7QY.js → chunk-IN2U7AAI.js} +99 -143
  22. package/dist/chunk-IN2U7AAI.js.map +1 -0
  23. package/dist/{chunk-LE66XCOI.js → chunk-JWZ5DLAS.js} +27 -10
  24. package/dist/chunk-JWZ5DLAS.js.map +1 -0
  25. package/dist/chunk-LKFZBBTD.js +12 -0
  26. package/dist/chunk-LKFZBBTD.js.map +1 -0
  27. package/dist/{chunk-TAS6S42A.js → chunk-MO6S2LRD.js} +2 -2
  28. package/dist/{chunk-2OAKX4SZ.js → chunk-NI7PWQ3B.js} +4 -4
  29. package/dist/{chunk-GLQWEINZ.js → chunk-QAXXE4AD.js} +2 -2
  30. package/dist/{chunk-3BCKZKNK.js → chunk-QFE5523Q.js} +2 -2
  31. package/dist/{chunk-LL3EWDKD.js → chunk-QQXNZIVK.js} +4 -4
  32. package/dist/{chunk-IGQYZ2KH.js → chunk-QZ3V2BP7.js} +2 -2
  33. package/dist/chunk-QZR7SJ5N.js +24 -0
  34. package/dist/chunk-QZR7SJ5N.js.map +1 -0
  35. package/dist/{chunk-SW527EQT.js → chunk-SJVLAGUL.js} +4 -4
  36. package/dist/{chunk-CMFY26F3.js → chunk-U4J3BVAQ.js} +4 -4
  37. package/dist/{chunk-5EUMJI3I.js → chunk-U4MRSZQQ.js} +2 -2
  38. package/dist/{chunk-ZJQTTOHO.js → chunk-UADW6FYD.js} +2 -2
  39. package/dist/{chunk-4324ZSCW.js → chunk-VBARKJWL.js} +2 -2
  40. package/dist/{chunk-OPNTDMHH.js → chunk-VLZ6PNAD.js} +4 -4
  41. package/dist/chunk-VZ7BOH2K.js +1 -0
  42. package/dist/chunk-VZ7BOH2K.js.map +1 -0
  43. package/dist/{chunk-Y6T4NA75.js → chunk-XJDXV5VX.js} +2 -2
  44. package/dist/{chunk-JTUB5ZCT.js → chunk-XYTYIAMQ.js} +2 -2
  45. package/dist/{chunk-4MTZUTNH.js → chunk-Z4GJVN52.js} +23 -8
  46. package/dist/chunk-Z4GJVN52.js.map +1 -0
  47. package/dist/chunk-ZLSNL6M2.js +97 -0
  48. package/dist/chunk-ZLSNL6M2.js.map +1 -0
  49. package/dist/{client-DsAAqupx.d.ts → client-Dh6yzCm4.d.ts} +14 -5
  50. package/dist/client.cjs +724 -523
  51. package/dist/client.cjs.map +1 -1
  52. package/dist/client.d.ts +5 -1
  53. package/dist/client.js +31 -27
  54. package/dist/core/client.cjs +540 -0
  55. package/dist/core/client.cjs.map +1 -0
  56. package/dist/core/client.d.ts +79 -0
  57. package/dist/core/client.js +12 -0
  58. package/dist/core/client.js.map +1 -0
  59. package/dist/core/error.cjs +309 -0
  60. package/dist/core/error.cjs.map +1 -0
  61. package/dist/core/error.d.ts +18 -0
  62. package/dist/core/error.js +10 -0
  63. package/dist/core/error.js.map +1 -0
  64. package/dist/core/index.cjs +552 -0
  65. package/dist/core/index.cjs.map +1 -0
  66. package/dist/core/index.d.ts +4 -0
  67. package/dist/core/index.js +20 -0
  68. package/dist/core/index.js.map +1 -0
  69. package/dist/core/resource.cjs +36 -0
  70. package/dist/core/resource.cjs.map +1 -0
  71. package/dist/core/resource.d.ts +18 -0
  72. package/dist/core/resource.js +8 -0
  73. package/dist/core/resource.js.map +1 -0
  74. package/dist/edge.cjs +236 -173
  75. package/dist/edge.cjs.map +1 -1
  76. package/dist/edge.d.ts +2 -0
  77. package/dist/edge.js +8 -5
  78. package/dist/git/client.cjs +529 -9
  79. package/dist/git/client.cjs.map +1 -1
  80. package/dist/git/client.d.ts +8 -2
  81. package/dist/git/client.js +7 -1
  82. package/dist/git/index.cjs +529 -9
  83. package/dist/git/index.cjs.map +1 -1
  84. package/dist/git/index.d.ts +2 -0
  85. package/dist/git/index.js +7 -1
  86. package/dist/index.cjs +672 -465
  87. package/dist/index.cjs.map +1 -1
  88. package/dist/index.d.ts +6 -2
  89. package/dist/index.js +49 -33
  90. package/dist/modelrouter/core.cjs +204 -125
  91. package/dist/modelrouter/core.cjs.map +1 -1
  92. package/dist/modelrouter/core.d.ts +36 -9
  93. package/dist/modelrouter/core.js +6 -3
  94. package/dist/modelrouter/index.cjs +204 -125
  95. package/dist/modelrouter/index.cjs.map +1 -1
  96. package/dist/modelrouter/index.d.ts +3 -0
  97. package/dist/modelrouter/index.js +6 -3
  98. package/dist/subagents/anthropic.cjs +268 -52
  99. package/dist/subagents/anthropic.cjs.map +1 -1
  100. package/dist/subagents/anthropic.js +10 -6
  101. package/dist/subagents/vercel.cjs +268 -52
  102. package/dist/subagents/vercel.cjs.map +1 -1
  103. package/dist/subagents/vercel.js +10 -6
  104. package/dist/tools/browser/anthropic.cjs +7 -2
  105. package/dist/tools/browser/anthropic.cjs.map +1 -1
  106. package/dist/tools/browser/anthropic.js +9 -6
  107. package/dist/tools/browser/core.cjs +162 -10
  108. package/dist/tools/browser/core.cjs.map +1 -1
  109. package/dist/tools/browser/core.d.ts +8 -2
  110. package/dist/tools/browser/core.js +8 -5
  111. package/dist/tools/browser/index.cjs +163 -11
  112. package/dist/tools/browser/index.cjs.map +1 -1
  113. package/dist/tools/browser/index.d.ts +2 -0
  114. package/dist/tools/browser/index.js +18 -15
  115. package/dist/tools/browser/index.js.map +1 -1
  116. package/dist/tools/browser/openai.cjs +7 -2
  117. package/dist/tools/browser/openai.cjs.map +1 -1
  118. package/dist/tools/browser/openai.js +9 -6
  119. package/dist/tools/browser/profiles/core.cjs +7 -2
  120. package/dist/tools/browser/profiles/core.cjs.map +1 -1
  121. package/dist/tools/browser/profiles/core.js +3 -3
  122. package/dist/tools/browser/profiles/index.cjs +7 -2
  123. package/dist/tools/browser/profiles/index.cjs.map +1 -1
  124. package/dist/tools/browser/profiles/index.js +3 -3
  125. package/dist/tools/browser/vercel.cjs +7 -2
  126. package/dist/tools/browser/vercel.cjs.map +1 -1
  127. package/dist/tools/browser/vercel.js +9 -6
  128. package/dist/tools/codebase_search/anthropic.cjs +162 -41
  129. package/dist/tools/codebase_search/anthropic.cjs.map +1 -1
  130. package/dist/tools/codebase_search/anthropic.js +7 -4
  131. package/dist/tools/codebase_search/core.cjs +195 -66
  132. package/dist/tools/codebase_search/core.cjs.map +1 -1
  133. package/dist/tools/codebase_search/core.d.ts +18 -7
  134. package/dist/tools/codebase_search/core.js +6 -3
  135. package/dist/tools/codebase_search/index.cjs +162 -41
  136. package/dist/tools/codebase_search/index.cjs.map +1 -1
  137. package/dist/tools/codebase_search/index.d.ts +2 -0
  138. package/dist/tools/codebase_search/index.js +13 -10
  139. package/dist/tools/codebase_search/openai.cjs +162 -41
  140. package/dist/tools/codebase_search/openai.cjs.map +1 -1
  141. package/dist/tools/codebase_search/openai.js +7 -4
  142. package/dist/tools/codebase_search/vercel.cjs +162 -41
  143. package/dist/tools/codebase_search/vercel.cjs.map +1 -1
  144. package/dist/tools/codebase_search/vercel.js +7 -4
  145. package/dist/tools/compact/core.cjs +551 -47
  146. package/dist/tools/compact/core.cjs.map +1 -1
  147. package/dist/tools/compact/core.d.ts +16 -3
  148. package/dist/tools/compact/core.js +7 -1
  149. package/dist/tools/compact/index.cjs +549 -47
  150. package/dist/tools/compact/index.cjs.map +1 -1
  151. package/dist/tools/compact/index.d.ts +2 -0
  152. package/dist/tools/compact/index.js +8 -2
  153. package/dist/tools/fastapply/anthropic.cjs +16 -2
  154. package/dist/tools/fastapply/anthropic.cjs.map +1 -1
  155. package/dist/tools/fastapply/anthropic.js +8 -4
  156. package/dist/tools/fastapply/apply.cjs +7 -2
  157. package/dist/tools/fastapply/apply.cjs.map +1 -1
  158. package/dist/tools/fastapply/apply.js +2 -2
  159. package/dist/tools/fastapply/core.cjs +242 -12
  160. package/dist/tools/fastapply/core.cjs.map +1 -1
  161. package/dist/tools/fastapply/core.d.ts +8 -2
  162. package/dist/tools/fastapply/core.js +7 -3
  163. package/dist/tools/fastapply/index.cjs +16 -2
  164. package/dist/tools/fastapply/index.cjs.map +1 -1
  165. package/dist/tools/fastapply/index.d.ts +2 -0
  166. package/dist/tools/fastapply/index.js +13 -9
  167. package/dist/tools/fastapply/openai.cjs +16 -2
  168. package/dist/tools/fastapply/openai.cjs.map +1 -1
  169. package/dist/tools/fastapply/openai.js +8 -4
  170. package/dist/tools/fastapply/vercel.cjs +16 -2
  171. package/dist/tools/fastapply/vercel.cjs.map +1 -1
  172. package/dist/tools/fastapply/vercel.js +8 -4
  173. package/dist/tools/index.cjs +16 -2
  174. package/dist/tools/index.cjs.map +1 -1
  175. package/dist/tools/index.d.ts +2 -0
  176. package/dist/tools/index.js +13 -9
  177. package/dist/tools/reflex/core.cjs +693 -0
  178. package/dist/tools/reflex/core.cjs.map +1 -0
  179. package/dist/tools/reflex/core.d.ts +53 -0
  180. package/dist/tools/reflex/core.js +16 -0
  181. package/dist/tools/reflex/core.js.map +1 -0
  182. package/dist/tools/reflex/index.cjs +693 -0
  183. package/dist/tools/reflex/index.cjs.map +1 -0
  184. package/dist/tools/reflex/index.d.ts +5 -0
  185. package/dist/tools/reflex/index.js +16 -0
  186. package/dist/tools/reflex/index.js.map +1 -0
  187. package/dist/tools/reflex/types.cjs +19 -0
  188. package/dist/tools/reflex/types.cjs.map +1 -0
  189. package/dist/tools/reflex/types.d.ts +113 -0
  190. package/dist/tools/reflex/types.js +1 -0
  191. package/dist/tools/reflex/types.js.map +1 -0
  192. package/dist/tools/utils/resilience.cjs +7 -2
  193. package/dist/tools/utils/resilience.cjs.map +1 -1
  194. package/dist/tools/utils/resilience.js +2 -2
  195. package/dist/tools/warp_grep/agent/runner.cjs +7 -2
  196. package/dist/tools/warp_grep/agent/runner.cjs.map +1 -1
  197. package/dist/tools/warp_grep/agent/runner.js +2 -2
  198. package/dist/tools/warp_grep/anthropic.cjs +268 -52
  199. package/dist/tools/warp_grep/anthropic.cjs.map +1 -1
  200. package/dist/tools/warp_grep/anthropic.d.ts +2 -0
  201. package/dist/tools/warp_grep/anthropic.js +10 -6
  202. package/dist/tools/warp_grep/client.cjs +268 -52
  203. package/dist/tools/warp_grep/client.cjs.map +1 -1
  204. package/dist/tools/warp_grep/client.d.ts +8 -2
  205. package/dist/tools/warp_grep/client.js +9 -5
  206. package/dist/tools/warp_grep/gemini.cjs +268 -52
  207. package/dist/tools/warp_grep/gemini.cjs.map +1 -1
  208. package/dist/tools/warp_grep/gemini.d.ts +2 -0
  209. package/dist/tools/warp_grep/gemini.js +9 -5
  210. package/dist/tools/warp_grep/gemini.js.map +1 -1
  211. package/dist/tools/warp_grep/harness.js +5 -5
  212. package/dist/tools/warp_grep/index.cjs +268 -52
  213. package/dist/tools/warp_grep/index.cjs.map +1 -1
  214. package/dist/tools/warp_grep/index.d.ts +2 -0
  215. package/dist/tools/warp_grep/index.js +12 -8
  216. package/dist/tools/warp_grep/openai.cjs +268 -52
  217. package/dist/tools/warp_grep/openai.cjs.map +1 -1
  218. package/dist/tools/warp_grep/openai.d.ts +2 -0
  219. package/dist/tools/warp_grep/openai.js +10 -6
  220. package/dist/tools/warp_grep/providers/local.js +2 -2
  221. package/dist/tools/warp_grep/vercel.cjs +268 -52
  222. package/dist/tools/warp_grep/vercel.cjs.map +1 -1
  223. package/dist/tools/warp_grep/vercel.d.ts +2 -0
  224. package/dist/tools/warp_grep/vercel.js +10 -6
  225. package/dist/version.cjs +7 -2
  226. package/dist/version.cjs.map +1 -1
  227. package/dist/version.js +1 -1
  228. package/package.json +7 -2
  229. package/dist/chunk-4MTZUTNH.js.map +0 -1
  230. package/dist/chunk-FQJCE2FX.js.map +0 -1
  231. package/dist/chunk-H5WNI6R5.js +0 -102
  232. package/dist/chunk-H5WNI6R5.js.map +0 -1
  233. package/dist/chunk-JLLIVBKY.js.map +0 -1
  234. package/dist/chunk-KCFMXLZ7.js +0 -197
  235. package/dist/chunk-KCFMXLZ7.js.map +0 -1
  236. package/dist/chunk-LE66XCOI.js.map +0 -1
  237. package/dist/chunk-SCVWDNQP.js +0 -84
  238. package/dist/chunk-SCVWDNQP.js.map +0 -1
  239. package/dist/chunk-UK7TI7QY.js.map +0 -1
  240. /package/dist/{chunk-3XRNC56L.js.map → chunk-2SNAXTUJ.js.map} +0 -0
  241. /package/dist/{chunk-IW4TYYG6.js.map → chunk-5DA6SZQJ.js.map} +0 -0
  242. /package/dist/{chunk-C37YAYBK.js.map → chunk-7PVVPLRL.js.map} +0 -0
  243. /package/dist/{chunk-MZZMSL26.js.map → chunk-AE7M2I52.js.map} +0 -0
  244. /package/dist/{chunk-EFCDIESP.js.map → chunk-ESXCQBMU.js.map} +0 -0
  245. /package/dist/{chunk-2ALTBYMY.js.map → chunk-IJ33I7P5.js.map} +0 -0
  246. /package/dist/{chunk-TAS6S42A.js.map → chunk-MO6S2LRD.js.map} +0 -0
  247. /package/dist/{chunk-2OAKX4SZ.js.map → chunk-NI7PWQ3B.js.map} +0 -0
  248. /package/dist/{chunk-GLQWEINZ.js.map → chunk-QAXXE4AD.js.map} +0 -0
  249. /package/dist/{chunk-3BCKZKNK.js.map → chunk-QFE5523Q.js.map} +0 -0
  250. /package/dist/{chunk-LL3EWDKD.js.map → chunk-QQXNZIVK.js.map} +0 -0
  251. /package/dist/{chunk-IGQYZ2KH.js.map → chunk-QZ3V2BP7.js.map} +0 -0
  252. /package/dist/{chunk-SW527EQT.js.map → chunk-SJVLAGUL.js.map} +0 -0
  253. /package/dist/{chunk-CMFY26F3.js.map → chunk-U4J3BVAQ.js.map} +0 -0
  254. /package/dist/{chunk-5EUMJI3I.js.map → chunk-U4MRSZQQ.js.map} +0 -0
  255. /package/dist/{chunk-ZJQTTOHO.js.map → chunk-UADW6FYD.js.map} +0 -0
  256. /package/dist/{chunk-4324ZSCW.js.map → chunk-VBARKJWL.js.map} +0 -0
  257. /package/dist/{chunk-OPNTDMHH.js.map → chunk-VLZ6PNAD.js.map} +0 -0
  258. /package/dist/{chunk-Y6T4NA75.js.map → chunk-XJDXV5VX.js.map} +0 -0
  259. /package/dist/{chunk-JTUB5ZCT.js.map → chunk-XYTYIAMQ.js.map} +0 -0
package/dist/index.cjs CHANGED
@@ -36,7 +36,7 @@ var init_package = __esm({
36
36
  "package.json"() {
37
37
  package_default = {
38
38
  name: "@morphllm/morphsdk",
39
- version: "0.2.171",
39
+ version: "0.2.172",
40
40
  description: "TypeScript SDK and CLI for Morph Fast Apply integration",
41
41
  type: "module",
42
42
  main: "./dist/index.cjs",
@@ -173,6 +173,11 @@ var init_package = __esm({
173
173
  import: "./dist/tools/compact/index.js",
174
174
  require: "./dist/tools/compact/index.cjs"
175
175
  },
176
+ "./tools/reflex": {
177
+ types: "./dist/tools/reflex/index.d.ts",
178
+ import: "./dist/tools/reflex/index.js",
179
+ require: "./dist/tools/reflex/index.cjs"
180
+ },
176
181
  "./subagents": {
177
182
  types: "./dist/subagents/index.d.ts",
178
183
  import: "./dist/subagents/index.js",
@@ -198,7 +203,7 @@ var init_package = __esm({
198
203
  "!dist/**/*.test.*"
199
204
  ],
200
205
  scripts: {
201
- build: "tsup version.ts index.ts edge.ts client.ts tools/index.ts tools/fastapply/index.ts tools/fastapply/core.ts tools/fastapply/apply.ts tools/fastapply/types.ts tools/fastapply/prompts.ts tools/fastapply/anthropic.ts tools/fastapply/openai.ts tools/fastapply/vercel.ts tools/codebase_search/index.ts tools/codebase_search/core.ts tools/codebase_search/types.ts tools/codebase_search/prompts.ts tools/codebase_search/anthropic.ts tools/codebase_search/openai.ts tools/codebase_search/vercel.ts tools/warp_grep/index.ts tools/warp_grep/client.ts tools/warp_grep/openai.ts tools/warp_grep/anthropic.ts tools/warp_grep/vercel.ts tools/warp_grep/gemini.ts tools/warp_grep/harness.ts tools/warp_grep/agent/config.ts tools/warp_grep/agent/parser.ts tools/warp_grep/agent/runner.ts tools/warp_grep/agent/types.ts tools/warp_grep/agent/formatter.ts tools/warp_grep/providers/types.ts tools/warp_grep/providers/local.ts tools/warp_grep/providers/remote.ts tools/warp_grep/providers/code_storage_http.ts tools/warp_grep/tools/grep.ts tools/warp_grep/tools/analyse.ts tools/warp_grep/tools/read.ts tools/warp_grep/tools/finish.ts tools/warp_grep/utils/paths.ts tools/warp_grep/utils/github.ts tools/warp_grep/utils/ripgrep.ts tools/warp_grep/utils/format.ts tools/warp_grep/utils/files.ts git/index.ts git/client.ts git/config.ts git/types.ts tools/browser/index.ts tools/browser/core.ts tools/browser/types.ts tools/browser/prompts.ts tools/browser/anthropic.ts tools/browser/openai.ts tools/browser/vercel.ts tools/browser/live.ts tools/browser/errors.ts tools/browser/profiles/index.ts tools/browser/profiles/core.ts tools/browser/profiles/types.ts modelrouter/index.ts modelrouter/core.ts modelrouter/types.ts tools/compact/index.ts tools/compact/core.ts tools/compact/types.ts tools/utils/resilience.ts subagents/index.ts subagents/types.ts subagents/prompts.ts subagents/vercel.ts subagents/anthropic.ts --format esm,cjs --sourcemap --clean --dts --dts-resolve",
206
+ build: "tsup version.ts index.ts edge.ts client.ts core/index.ts core/client.ts core/resource.ts core/error.ts tools/index.ts tools/fastapply/index.ts tools/fastapply/core.ts tools/fastapply/apply.ts tools/fastapply/types.ts tools/fastapply/prompts.ts tools/fastapply/anthropic.ts tools/fastapply/openai.ts tools/fastapply/vercel.ts tools/codebase_search/index.ts tools/codebase_search/core.ts tools/codebase_search/types.ts tools/codebase_search/prompts.ts tools/codebase_search/anthropic.ts tools/codebase_search/openai.ts tools/codebase_search/vercel.ts tools/warp_grep/index.ts tools/warp_grep/client.ts tools/warp_grep/openai.ts tools/warp_grep/anthropic.ts tools/warp_grep/vercel.ts tools/warp_grep/gemini.ts tools/warp_grep/harness.ts tools/warp_grep/agent/config.ts tools/warp_grep/agent/parser.ts tools/warp_grep/agent/runner.ts tools/warp_grep/agent/types.ts tools/warp_grep/agent/formatter.ts tools/warp_grep/providers/types.ts tools/warp_grep/providers/local.ts tools/warp_grep/providers/remote.ts tools/warp_grep/providers/code_storage_http.ts tools/warp_grep/tools/grep.ts tools/warp_grep/tools/analyse.ts tools/warp_grep/tools/read.ts tools/warp_grep/tools/finish.ts tools/warp_grep/utils/paths.ts tools/warp_grep/utils/github.ts tools/warp_grep/utils/ripgrep.ts tools/warp_grep/utils/format.ts tools/warp_grep/utils/files.ts git/index.ts git/client.ts git/config.ts git/types.ts tools/browser/index.ts tools/browser/core.ts tools/browser/types.ts tools/browser/prompts.ts tools/browser/anthropic.ts tools/browser/openai.ts tools/browser/vercel.ts tools/browser/live.ts tools/browser/errors.ts tools/browser/profiles/index.ts tools/browser/profiles/core.ts tools/browser/profiles/types.ts modelrouter/index.ts modelrouter/core.ts modelrouter/types.ts tools/compact/index.ts tools/compact/core.ts tools/compact/types.ts tools/reflex/index.ts tools/reflex/core.ts tools/reflex/types.ts tools/utils/resilience.ts subagents/index.ts subagents/types.ts subagents/prompts.ts subagents/vercel.ts subagents/anthropic.ts --format esm,cjs --sourcemap --clean --dts --dts-resolve",
202
207
  prepare: "npm run build",
203
208
  typecheck: "tsc --noEmit",
204
209
  lint: "eslint .",
@@ -384,7 +389,7 @@ async function callMorphAPI(originalCode, codeEdit, instructions, filepath, conf
384
389
  const apiUrl = config.morphApiUrl || DEFAULT_API_URL;
385
390
  const useLarge = config.large ?? (typeof process !== "undefined" ? process.env?.MORPH_LARGE_APPLY !== "false" : true);
386
391
  const model = useLarge ? "morph-v3-large" : "morph-v3-fast";
387
- const timeout = config.timeout || DEFAULT_TIMEOUT;
392
+ const timeout = config.timeout || DEFAULT_TIMEOUT2;
388
393
  const debug = config.debug || false;
389
394
  if (!apiKey) {
390
395
  throw new Error(
@@ -478,7 +483,7 @@ async function applyEdit(input, config = {}) {
478
483
  };
479
484
  }
480
485
  }
481
- var import_diff, import_openai, DEFAULT_API_URL, DEFAULT_TIMEOUT;
486
+ var import_diff, import_openai, DEFAULT_API_URL, DEFAULT_TIMEOUT2;
482
487
  var init_apply = __esm({
483
488
  "tools/fastapply/apply.ts"() {
484
489
  "use strict";
@@ -487,7 +492,7 @@ var init_apply = __esm({
487
492
  init_version();
488
493
  init_logger();
489
494
  DEFAULT_API_URL = "https://api.morphllm.com";
490
- DEFAULT_TIMEOUT = 9e4;
495
+ DEFAULT_TIMEOUT2 = 9e4;
491
496
  }
492
497
  });
493
498
 
@@ -1081,6 +1086,7 @@ Details: ${res.stderr}` : ""}`
1081
1086
  // index.ts
1082
1087
  var index_exports = {};
1083
1088
  __export(index_exports, {
1089
+ APIResource: () => APIResource,
1084
1090
  AnthropicRouter: () => AnthropicRouter,
1085
1091
  AnthropicToolFactory: () => AnthropicToolFactory,
1086
1092
  BrowserClient: () => BrowserClient,
@@ -1091,6 +1097,7 @@ __export(index_exports, {
1091
1097
  GitHubClient: () => GitHubClient,
1092
1098
  GitHubError: () => GitHubError,
1093
1099
  LocalRipgrepProvider: () => LocalRipgrepProvider,
1100
+ MorphAPIClient: () => MorphAPIClient,
1094
1101
  MorphClient: () => MorphClient,
1095
1102
  MorphGit: () => MorphGit,
1096
1103
  NoInstallationError: () => NoInstallationError,
@@ -1099,6 +1106,8 @@ __export(index_exports, {
1099
1106
  OpenAIToolFactory: () => OpenAIToolFactory,
1100
1107
  PermissionError: () => PermissionError,
1101
1108
  RawRouter: () => RawRouter,
1109
+ ReflexClient: () => ReflexClient,
1110
+ ReflexJobsResource: () => ReflexJobsResource,
1102
1111
  SDK_VERSION: () => SDK_VERSION,
1103
1112
  VercelToolFactory: () => VercelToolFactory,
1104
1113
  WarpGrepClient: () => WarpGrepClient,
@@ -1107,12 +1116,228 @@ __export(index_exports, {
1107
1116
  module.exports = __toCommonJS(index_exports);
1108
1117
  init_version();
1109
1118
 
1119
+ // tools/utils/resilience.ts
1120
+ init_version();
1121
+ var DEFAULT_RETRY_CONFIG = {
1122
+ maxRetries: 3,
1123
+ initialDelay: 1e3,
1124
+ maxDelay: 3e4,
1125
+ backoffMultiplier: 2,
1126
+ retryableErrors: ["ECONNREFUSED", "ETIMEDOUT", "ENOTFOUND"]
1127
+ };
1128
+ async function fetchWithRetry(url, options, retryConfig = {}) {
1129
+ const {
1130
+ maxRetries = DEFAULT_RETRY_CONFIG.maxRetries,
1131
+ initialDelay = DEFAULT_RETRY_CONFIG.initialDelay,
1132
+ maxDelay = DEFAULT_RETRY_CONFIG.maxDelay,
1133
+ backoffMultiplier = DEFAULT_RETRY_CONFIG.backoffMultiplier,
1134
+ retryableErrors = DEFAULT_RETRY_CONFIG.retryableErrors,
1135
+ onRetry
1136
+ } = retryConfig;
1137
+ let lastError = null;
1138
+ let delay = initialDelay;
1139
+ options = { ...options, headers: { "X-Morph-SDK-Version": SDK_VERSION, ...options.headers } };
1140
+ for (let attempt = 0; attempt <= maxRetries; attempt++) {
1141
+ try {
1142
+ const response = await fetch(url, options);
1143
+ if (response.status === 429 || response.status === 503) {
1144
+ if (attempt < maxRetries) {
1145
+ const retryAfter = response.headers.get("Retry-After");
1146
+ const waitTime = retryAfter ? parseInt(retryAfter) * 1e3 : Math.min(delay, maxDelay);
1147
+ const error = new Error(`HTTP ${response.status}: Retrying after ${waitTime}ms`);
1148
+ if (onRetry) {
1149
+ onRetry(attempt + 1, error);
1150
+ }
1151
+ await sleep(waitTime);
1152
+ delay *= backoffMultiplier;
1153
+ continue;
1154
+ }
1155
+ }
1156
+ return response;
1157
+ } catch (error) {
1158
+ lastError = error;
1159
+ const isRetryable = retryableErrors.some(
1160
+ (errType) => lastError?.message?.includes(errType)
1161
+ );
1162
+ if (!isRetryable || attempt === maxRetries) {
1163
+ throw lastError;
1164
+ }
1165
+ const waitTime = Math.min(delay, maxDelay);
1166
+ if (onRetry) {
1167
+ onRetry(attempt + 1, lastError);
1168
+ }
1169
+ await sleep(waitTime);
1170
+ delay *= backoffMultiplier;
1171
+ }
1172
+ }
1173
+ throw lastError || new Error("Max retries exceeded");
1174
+ }
1175
+ async function withTimeout(promise, timeoutMs, errorMessage) {
1176
+ let timeoutId;
1177
+ const timeoutPromise = new Promise((_, reject) => {
1178
+ timeoutId = setTimeout(() => {
1179
+ reject(new Error(errorMessage || `Operation timed out after ${timeoutMs}ms`));
1180
+ }, timeoutMs);
1181
+ });
1182
+ try {
1183
+ const result = await Promise.race([promise, timeoutPromise]);
1184
+ clearTimeout(timeoutId);
1185
+ return result;
1186
+ } catch (error) {
1187
+ clearTimeout(timeoutId);
1188
+ throw error;
1189
+ }
1190
+ }
1191
+ function sleep(ms) {
1192
+ return new Promise((resolve2) => setTimeout(resolve2, ms));
1193
+ }
1194
+ var MorphError = class extends Error {
1195
+ constructor(message, code, statusCode, retryable = false) {
1196
+ super(message);
1197
+ this.code = code;
1198
+ this.statusCode = statusCode;
1199
+ this.retryable = retryable;
1200
+ this.name = "MorphError";
1201
+ }
1202
+ };
1203
+
1204
+ // core/client.ts
1205
+ init_logger();
1206
+ init_version();
1207
+
1208
+ // core/error.ts
1209
+ async function toMorphError(response) {
1210
+ let message = `Morph API request failed (${response.status})`;
1211
+ let code = "api_error";
1212
+ try {
1213
+ const body = await response.json();
1214
+ message = body.error?.message ?? body.message ?? message;
1215
+ code = body.error?.code ?? body.error?.type ?? code;
1216
+ } catch {
1217
+ }
1218
+ if (response.status === 401) code = "authentication_error";
1219
+ if (response.status === 429) code = "rate_limit_exceeded";
1220
+ const retryable = response.status === 429 || response.status === 503;
1221
+ return new MorphError(message, code, response.status, retryable);
1222
+ }
1223
+
1224
+ // core/client.ts
1225
+ var DEFAULT_BASE_URL = "https://api.morphllm.com";
1226
+ var DEFAULT_REPOS_URL = "https://repos.morphllm.com";
1227
+ var DEFAULT_BROWSER_URL = "https://browser.morphllm.com";
1228
+ var DEFAULT_TIMEOUT = 6e4;
1229
+ var env = (name) => typeof process !== "undefined" ? process.env?.[name] : void 0;
1230
+ var stripTrailingSlash = (url) => url.replace(/\/+$/, "");
1231
+ var MorphAPIClient = class {
1232
+ /** Explicit key as provided; resolved against env at request time. */
1233
+ apiKey;
1234
+ baseURL;
1235
+ reposURL;
1236
+ browserURL;
1237
+ /** Explicit default timeout (ms), if set. The request default is applied lazily so
1238
+ * resources can read an undefined value and supply their own fallback. */
1239
+ timeout;
1240
+ retryConfig;
1241
+ debug;
1242
+ constructor(options = {}) {
1243
+ this.apiKey = options.apiKey;
1244
+ this.baseURL = stripTrailingSlash(options.baseURL ?? DEFAULT_BASE_URL);
1245
+ this.reposURL = stripTrailingSlash(options.reposURL ?? env("MORPH_SEARCH_URL") ?? DEFAULT_REPOS_URL);
1246
+ this.browserURL = stripTrailingSlash(
1247
+ options.browserURL ?? (env("MORPH_ENVIRONMENT") === "DEV" ? "http://localhost:8000" : DEFAULT_BROWSER_URL)
1248
+ );
1249
+ this.timeout = options.timeout;
1250
+ this.retryConfig = options.retryConfig;
1251
+ this.debug = options.debug ?? false;
1252
+ if (this.debug) logger.enable();
1253
+ }
1254
+ /** The key actually used for requests: explicit, else `MORPH_API_KEY`. */
1255
+ resolveApiKey() {
1256
+ return this.apiKey ?? env("MORPH_API_KEY");
1257
+ }
1258
+ /** Headers shared with tools that bring their own HTTP client (FastApply/WarpGrep via the `openai` package). */
1259
+ defaultHeaders() {
1260
+ return { "X-Morph-SDK-Version": SDK_VERSION };
1261
+ }
1262
+ buildURL(path6, baseURL) {
1263
+ if (/^https?:\/\//i.test(path6)) return path6;
1264
+ const base = stripTrailingSlash(baseURL ?? this.baseURL);
1265
+ return `${base}${path6.startsWith("/") ? "" : "/"}${path6}`;
1266
+ }
1267
+ buildHeaders(apiKey, extra) {
1268
+ return {
1269
+ "Content-Type": "application/json",
1270
+ "X-Morph-SDK-Version": SDK_VERSION,
1271
+ Authorization: `Bearer ${apiKey}`,
1272
+ ...extra
1273
+ };
1274
+ }
1275
+ applyQuery(url, query) {
1276
+ if (!query) return url;
1277
+ const params = new URLSearchParams();
1278
+ for (const [key, value] of Object.entries(query)) {
1279
+ if (value !== void 0 && value !== null) params.set(key, String(value));
1280
+ }
1281
+ const qs = params.toString();
1282
+ return qs ? `${url}${url.includes("?") ? "&" : "?"}${qs}` : url;
1283
+ }
1284
+ async request(method, path6, opts = {}) {
1285
+ const apiKey = this.resolveApiKey();
1286
+ if (!apiKey) {
1287
+ throw new MorphError(
1288
+ "Morph API key not found. Set the MORPH_API_KEY environment variable or pass apiKey in config.",
1289
+ "missing_api_key",
1290
+ 401
1291
+ );
1292
+ }
1293
+ const url = this.applyQuery(this.buildURL(path6, opts.baseURL), opts.query);
1294
+ const timeout = opts.timeout ?? this.timeout ?? DEFAULT_TIMEOUT;
1295
+ const init = {
1296
+ method,
1297
+ headers: this.buildHeaders(apiKey, opts.headers),
1298
+ ...opts.body !== void 0 ? { body: JSON.stringify(opts.body) } : {},
1299
+ ...opts.signal ? { signal: opts.signal } : {}
1300
+ };
1301
+ logger.debug("MorphAPIClient", "request", { method, url });
1302
+ const response = await withTimeout(
1303
+ fetchWithRetry(url, init, this.retryConfig ?? {}),
1304
+ timeout,
1305
+ `Morph request to ${url} timed out after ${timeout}ms`
1306
+ );
1307
+ if (opts.raw) return response;
1308
+ if (!response.ok) throw await toMorphError(response);
1309
+ if (opts.stream) return response;
1310
+ if (response.status === 204) return void 0;
1311
+ const text = await response.text();
1312
+ return text ? JSON.parse(text) : void 0;
1313
+ }
1314
+ get(path6, opts) {
1315
+ return this.request("GET", path6, opts);
1316
+ }
1317
+ post(path6, opts) {
1318
+ return this.request("POST", path6, opts);
1319
+ }
1320
+ delete(path6, opts) {
1321
+ return this.request("DELETE", path6, opts);
1322
+ }
1323
+ };
1324
+
1110
1325
  // client.ts
1111
1326
  init_logger();
1112
1327
 
1113
1328
  // tools/fastapply/core.ts
1114
1329
  var import_path = require("path");
1115
1330
  init_logger();
1331
+
1332
+ // core/resource.ts
1333
+ var APIResource = class {
1334
+ _client;
1335
+ constructor(client) {
1336
+ this._client = client;
1337
+ }
1338
+ };
1339
+
1340
+ // tools/fastapply/core.ts
1116
1341
  init_apply();
1117
1342
  var DEFAULT_CONFIG = {
1118
1343
  morphApiUrl: "https://api.morphllm.com",
@@ -1122,15 +1347,24 @@ var DEFAULT_CONFIG = {
1122
1347
  timeout: 9e4,
1123
1348
  debug: false
1124
1349
  };
1125
- var FastApplyClient = class {
1350
+ var FastApplyClient = class extends APIResource {
1126
1351
  config;
1127
- constructor(config = {}) {
1352
+ constructor(clientOrConfig = {}) {
1353
+ const isClient = clientOrConfig instanceof MorphAPIClient;
1354
+ super(
1355
+ isClient ? clientOrConfig : new MorphAPIClient({
1356
+ apiKey: clientOrConfig.apiKey,
1357
+ timeout: clientOrConfig.timeout ?? DEFAULT_CONFIG.timeout,
1358
+ retryConfig: clientOrConfig.retryConfig,
1359
+ debug: clientOrConfig.debug
1360
+ })
1361
+ );
1128
1362
  this.config = {
1129
- morphApiKey: config.apiKey,
1130
- morphApiUrl: DEFAULT_CONFIG.morphApiUrl,
1131
- debug: config.debug,
1132
- timeout: config.timeout || DEFAULT_CONFIG.timeout,
1133
- retryConfig: config.retryConfig,
1363
+ morphApiKey: this._client.resolveApiKey(),
1364
+ morphApiUrl: this._client.baseURL,
1365
+ debug: this._client.debug,
1366
+ timeout: (isClient ? void 0 : clientOrConfig.timeout) ?? DEFAULT_CONFIG.timeout,
1367
+ retryConfig: this._client.retryConfig,
1134
1368
  generateUdiff: DEFAULT_CONFIG.generateUdiff,
1135
1369
  autoWrite: DEFAULT_CONFIG.autoWrite
1136
1370
  };
@@ -1230,111 +1464,68 @@ async function executeEditFile(input, config = {}) {
1230
1464
  }
1231
1465
  }
1232
1466
 
1233
- // tools/utils/resilience.ts
1234
- init_version();
1235
- var DEFAULT_RETRY_CONFIG = {
1236
- maxRetries: 3,
1237
- initialDelay: 1e3,
1238
- maxDelay: 3e4,
1239
- backoffMultiplier: 2,
1240
- retryableErrors: ["ECONNREFUSED", "ETIMEDOUT", "ENOTFOUND"]
1241
- };
1242
- async function fetchWithRetry(url, options, retryConfig = {}) {
1243
- const {
1244
- maxRetries = DEFAULT_RETRY_CONFIG.maxRetries,
1245
- initialDelay = DEFAULT_RETRY_CONFIG.initialDelay,
1246
- maxDelay = DEFAULT_RETRY_CONFIG.maxDelay,
1247
- backoffMultiplier = DEFAULT_RETRY_CONFIG.backoffMultiplier,
1248
- retryableErrors = DEFAULT_RETRY_CONFIG.retryableErrors,
1249
- onRetry
1250
- } = retryConfig;
1251
- let lastError = null;
1252
- let delay = initialDelay;
1253
- options = { ...options, headers: { "X-Morph-SDK-Version": SDK_VERSION, ...options.headers } };
1254
- for (let attempt = 0; attempt <= maxRetries; attempt++) {
1255
- try {
1256
- const response = await fetch(url, options);
1257
- if (response.status === 429 || response.status === 503) {
1258
- if (attempt < maxRetries) {
1259
- const retryAfter = response.headers.get("Retry-After");
1260
- const waitTime = retryAfter ? parseInt(retryAfter) * 1e3 : Math.min(delay, maxDelay);
1261
- const error = new Error(`HTTP ${response.status}: Retrying after ${waitTime}ms`);
1262
- if (onRetry) {
1263
- onRetry(attempt + 1, error);
1264
- }
1265
- await sleep(waitTime);
1266
- delay *= backoffMultiplier;
1267
- continue;
1467
+ // tools/codebase_search/core.ts
1468
+ init_logger();
1469
+ var DEFAULT_TIMEOUT3 = 3e4;
1470
+ var emptyStats = { totalResults: 0, candidatesRetrieved: 0, searchTimeMs: 0 };
1471
+ async function runSearch(client, input, repoId, timeout, baseURL) {
1472
+ const startTime = Date.now();
1473
+ logger.debug("CodebaseSearch", "request", { query: input.query.slice(0, 100), repo_id: repoId });
1474
+ try {
1475
+ const data = await client.post(
1476
+ "/v1/codebase_search",
1477
+ {
1478
+ baseURL: baseURL ?? client.reposURL,
1479
+ timeout,
1480
+ body: {
1481
+ query: input.query,
1482
+ repoId,
1483
+ targetDirectories: input.target_directories || [],
1484
+ limit: input.limit || 10,
1485
+ candidateLimit: 50
1268
1486
  }
1269
1487
  }
1270
- return response;
1271
- } catch (error) {
1272
- lastError = error;
1273
- const isRetryable = retryableErrors.some(
1274
- (errType) => lastError?.message?.includes(errType)
1275
- );
1276
- if (!isRetryable || attempt === maxRetries) {
1277
- throw lastError;
1278
- }
1279
- const waitTime = Math.min(delay, maxDelay);
1280
- if (onRetry) {
1281
- onRetry(attempt + 1, lastError);
1282
- }
1283
- await sleep(waitTime);
1284
- delay *= backoffMultiplier;
1285
- }
1286
- }
1287
- throw lastError || new Error("Max retries exceeded");
1288
- }
1289
- async function withTimeout(promise, timeoutMs, errorMessage) {
1290
- let timeoutId;
1291
- const timeoutPromise = new Promise((_, reject) => {
1292
- timeoutId = setTimeout(() => {
1293
- reject(new Error(errorMessage || `Operation timed out after ${timeoutMs}ms`));
1294
- }, timeoutMs);
1295
- });
1296
- try {
1297
- const result = await Promise.race([promise, timeoutPromise]);
1298
- clearTimeout(timeoutId);
1299
- return result;
1488
+ );
1489
+ const elapsed = Date.now() - startTime;
1490
+ logger.debug("CodebaseSearch", "response", { results_count: data.results?.length || 0, latency_ms: elapsed });
1491
+ return {
1492
+ success: true,
1493
+ results: data.results || [],
1494
+ stats: data.stats || { totalResults: 0, candidatesRetrieved: 0, searchTimeMs: elapsed }
1495
+ };
1300
1496
  } catch (error) {
1301
- clearTimeout(timeoutId);
1302
- throw error;
1497
+ const message = error instanceof MorphError && error.statusCode ? `Search failed (${error.statusCode}): ${error.message}` : error instanceof Error ? error.message : "Unknown error";
1498
+ logger.error("CodebaseSearch", "error", { error: message, latency_ms: Date.now() - startTime });
1499
+ return { success: false, results: [], stats: { ...emptyStats }, error: message };
1303
1500
  }
1304
1501
  }
1305
- function sleep(ms) {
1306
- return new Promise((resolve2) => setTimeout(resolve2, ms));
1307
- }
1308
-
1309
- // tools/codebase_search/core.ts
1310
- init_logger();
1311
- var CodebaseSearchClient = class {
1312
- config;
1313
- constructor(config = {}) {
1314
- this.config = {
1315
- apiKey: config.apiKey,
1316
- searchUrl: process.env.MORPH_SEARCH_URL || "https://repos.morphllm.com",
1317
- debug: config.debug,
1318
- timeout: config.timeout || 3e4,
1319
- retryConfig: config.retryConfig
1320
- };
1502
+ var CodebaseSearchClient = class extends APIResource {
1503
+ timeout;
1504
+ constructor(clientOrConfig = {}) {
1505
+ super(
1506
+ clientOrConfig instanceof MorphAPIClient ? clientOrConfig : new MorphAPIClient({
1507
+ apiKey: clientOrConfig.apiKey,
1508
+ timeout: clientOrConfig.timeout ?? DEFAULT_TIMEOUT3,
1509
+ retryConfig: clientOrConfig.retryConfig,
1510
+ debug: clientOrConfig.debug
1511
+ })
1512
+ );
1513
+ this.timeout = (clientOrConfig instanceof MorphAPIClient ? void 0 : clientOrConfig.timeout) ?? DEFAULT_TIMEOUT3;
1321
1514
  }
1322
1515
  /**
1323
1516
  * Execute a semantic code search
1324
- *
1517
+ *
1325
1518
  * @param input - Search parameters including query, repoId, and target directories
1326
1519
  * @param overrides - Optional config overrides for this operation
1327
1520
  * @returns Search results with ranked code matches
1328
1521
  */
1329
1522
  async search(input, overrides) {
1330
- return executeCodebaseSearch(
1331
- {
1332
- query: input.query,
1333
- target_directories: input.target_directories,
1334
- explanation: input.explanation,
1335
- limit: input.limit
1336
- },
1337
- { ...this.config, repoId: input.repoId, ...overrides }
1523
+ return runSearch(
1524
+ this._client,
1525
+ { query: input.query, target_directories: input.target_directories, explanation: input.explanation, limit: input.limit },
1526
+ input.repoId,
1527
+ overrides?.timeout ?? this.timeout,
1528
+ overrides?.searchUrl
1338
1529
  );
1339
1530
  }
1340
1531
  };
@@ -1343,57 +1534,14 @@ async function executeCodebaseSearch(input, config) {
1343
1534
  if (!apiKey) {
1344
1535
  throw new Error("MORPH_API_KEY not found. Set environment variable or pass in config");
1345
1536
  }
1346
- const searchUrl = config.searchUrl || process.env.MORPH_SEARCH_URL || "https://repos.morphllm.com";
1347
- const timeout = config.timeout || 3e4;
1348
- logger.debug("CodebaseSearch", "request", { query: input.query.slice(0, 100), repo_id: config.repoId, url: `${searchUrl}/v1/codebase_search` });
1349
- const startTime = Date.now();
1350
- try {
1351
- const fetchPromise = fetchWithRetry(
1352
- `${searchUrl}/v1/codebase_search`,
1353
- {
1354
- method: "POST",
1355
- headers: {
1356
- "Content-Type": "application/json",
1357
- "Authorization": `Bearer ${apiKey}`
1358
- },
1359
- body: JSON.stringify({
1360
- query: input.query,
1361
- repoId: config.repoId,
1362
- targetDirectories: input.target_directories || [],
1363
- limit: input.limit || 10,
1364
- candidateLimit: 50
1365
- })
1366
- },
1367
- config.retryConfig
1368
- );
1369
- const response = await withTimeout(fetchPromise, timeout, `Codebase search timed out after ${timeout}ms`);
1370
- if (!response.ok) {
1371
- const errorText = await response.text();
1372
- logger.error("CodebaseSearch", "response_error", { status: response.status, error: errorText, latency_ms: Date.now() - startTime });
1373
- return {
1374
- success: false,
1375
- results: [],
1376
- stats: { totalResults: 0, candidatesRetrieved: 0, searchTimeMs: 0 },
1377
- error: `Search failed (${response.status}): ${errorText}`
1378
- };
1379
- }
1380
- const data = await response.json();
1381
- const elapsed = Date.now() - startTime;
1382
- logger.debug("CodebaseSearch", "response", { results_count: data.results?.length || 0, latency_ms: elapsed });
1383
- return {
1384
- success: true,
1385
- results: data.results || [],
1386
- stats: data.stats || { totalResults: 0, candidatesRetrieved: 0, searchTimeMs: elapsed }
1387
- };
1388
- } catch (error) {
1389
- logger.error("CodebaseSearch", "exception", { error: error instanceof Error ? error.message : String(error), latency_ms: Date.now() - startTime });
1390
- return {
1391
- success: false,
1392
- results: [],
1393
- stats: { totalResults: 0, candidatesRetrieved: 0, searchTimeMs: 0 },
1394
- error: error instanceof Error ? error.message : "Unknown error"
1395
- };
1396
- }
1537
+ const client = new MorphAPIClient({
1538
+ apiKey,
1539
+ reposURL: config.searchUrl,
1540
+ timeout: config.timeout ?? DEFAULT_TIMEOUT3,
1541
+ retryConfig: config.retryConfig,
1542
+ debug: config.debug
1543
+ });
1544
+ return runSearch(client, input, config.repoId, config.timeout ?? DEFAULT_TIMEOUT3, config.searchUrl);
1397
1545
  }
1398
1546
 
1399
1547
  // tools/browser/core.ts
@@ -1498,7 +1646,7 @@ function resolvePreset(optionsOrPreset) {
1498
1646
  }
1499
1647
 
1500
1648
  // tools/browser/errors.ts
1501
- var MorphError = class extends Error {
1649
+ var MorphError2 = class extends Error {
1502
1650
  /** Error code for programmatic handling */
1503
1651
  code;
1504
1652
  /** Original cause of the error, if any */
@@ -1524,7 +1672,7 @@ var MorphError = class extends Error {
1524
1672
  };
1525
1673
  }
1526
1674
  };
1527
- var MorphValidationError = class extends MorphError {
1675
+ var MorphValidationError = class extends MorphError2 {
1528
1676
  /** The field that failed validation */
1529
1677
  field;
1530
1678
  constructor(message, field) {
@@ -1539,7 +1687,7 @@ var MorphValidationError = class extends MorphError {
1539
1687
  };
1540
1688
  }
1541
1689
  };
1542
- var MorphAPIError = class extends MorphError {
1690
+ var MorphAPIError = class extends MorphError2 {
1543
1691
  /** HTTP status code */
1544
1692
  statusCode;
1545
1693
  /** Request ID for debugging (if available) */
@@ -2068,17 +2216,30 @@ var DEFAULT_CONFIG2 = {
2068
2216
  // 10 minutes for complex tasks
2069
2217
  debug: false
2070
2218
  };
2071
- var BrowserClient = class {
2219
+ var BrowserClient = class extends APIResource {
2072
2220
  config;
2073
2221
  /**
2074
2222
  * Profile management - create and manage browser profiles for storing login state.
2075
2223
  */
2076
2224
  profiles;
2077
- constructor(config = {}) {
2078
- this.config = {
2225
+ constructor(clientOrConfig = {}) {
2226
+ const isClient = clientOrConfig instanceof MorphAPIClient;
2227
+ super(
2228
+ isClient ? clientOrConfig : new MorphAPIClient({
2229
+ apiKey: clientOrConfig.apiKey,
2230
+ browserURL: clientOrConfig.apiUrl,
2231
+ timeout: clientOrConfig.timeout,
2232
+ retryConfig: clientOrConfig.retryConfig,
2233
+ debug: clientOrConfig.debug
2234
+ })
2235
+ );
2236
+ this.config = isClient ? {
2079
2237
  ...DEFAULT_CONFIG2,
2080
- ...config
2081
- };
2238
+ apiUrl: clientOrConfig.browserURL,
2239
+ apiKey: clientOrConfig.resolveApiKey(),
2240
+ retryConfig: clientOrConfig.retryConfig,
2241
+ debug: clientOrConfig.debug
2242
+ } : { ...DEFAULT_CONFIG2, ...clientOrConfig };
2082
2243
  this.profiles = new ProfilesClient(this.config);
2083
2244
  }
2084
2245
  /**
@@ -3600,14 +3761,27 @@ function parseGitHubUrl(input) {
3600
3761
 
3601
3762
  // tools/compact/core.ts
3602
3763
  var DEFAULT_API_URL4 = "https://api.morphllm.com";
3603
- var DEFAULT_TIMEOUT2 = 12e4;
3604
- var CompactClient = class {
3764
+ var DEFAULT_TIMEOUT4 = 12e4;
3765
+ function resolveClient(clientOrConfig) {
3766
+ if (clientOrConfig instanceof MorphAPIClient) return clientOrConfig;
3767
+ return new MorphAPIClient({
3768
+ apiKey: clientOrConfig.morphApiKey,
3769
+ baseURL: clientOrConfig.morphApiUrl ?? DEFAULT_API_URL4,
3770
+ timeout: clientOrConfig.timeout ?? DEFAULT_TIMEOUT4,
3771
+ retryConfig: clientOrConfig.retryConfig,
3772
+ debug: clientOrConfig.debug
3773
+ });
3774
+ }
3775
+ var CompactClient = class extends APIResource {
3776
+ /** Resolved URL/timeout, exposed for backwards-compatible introspection. */
3605
3777
  config;
3606
- constructor(config = {}) {
3778
+ constructor(clientOrConfig = {}) {
3779
+ super(resolveClient(clientOrConfig));
3780
+ const cfg = clientOrConfig instanceof MorphAPIClient ? {} : clientOrConfig;
3607
3781
  this.config = {
3608
- ...config,
3609
- morphApiUrl: config.morphApiUrl ?? DEFAULT_API_URL4,
3610
- timeout: config.timeout ?? DEFAULT_TIMEOUT2
3782
+ morphApiUrl: this._client.baseURL,
3783
+ timeout: cfg.timeout ?? DEFAULT_TIMEOUT4,
3784
+ debug: cfg.debug ?? false
3611
3785
  };
3612
3786
  }
3613
3787
  /**
@@ -3626,17 +3800,6 @@ var CompactClient = class {
3626
3800
  * ```
3627
3801
  */
3628
3802
  async compact(input) {
3629
- const apiKey = this.config.morphApiKey || (typeof process !== "undefined" ? process.env?.MORPH_API_KEY : void 0);
3630
- const debug = this.config.debug || false;
3631
- if (!apiKey) {
3632
- throw new Error(
3633
- "Morph API key not found. Set MORPH_API_KEY environment variable or pass morphApiKey in config."
3634
- );
3635
- }
3636
- const url = `${this.config.morphApiUrl}/v1/compact`;
3637
- if (debug) {
3638
- console.log(`[Compact] Calling ${url}`);
3639
- }
3640
3803
  const body = {
3641
3804
  compression_ratio: input.compressionRatio ?? 0.5,
3642
3805
  preserve_recent: input.preserveRecent ?? 2,
@@ -3644,37 +3807,19 @@ var CompactClient = class {
3644
3807
  include_line_ranges: input.includeLineRanges ?? true,
3645
3808
  include_markers: input.includeMarkers ?? true
3646
3809
  };
3647
- if (input.query !== void 0) {
3648
- body.query = input.query;
3649
- }
3650
- if (input.messages) {
3651
- body.messages = input.messages;
3652
- } else if (typeof input.input === "string") {
3653
- body.input = input.input;
3654
- } else if (Array.isArray(input.input)) {
3655
- body.messages = input.input;
3656
- } else {
3657
- throw new Error("Either 'input' or 'messages' must be provided");
3658
- }
3659
- const startTime = Date.now();
3660
- const response = await fetch(url, {
3661
- method: "POST",
3662
- headers: {
3663
- "Authorization": `Bearer ${apiKey}`,
3664
- "Content-Type": "application/json"
3665
- },
3666
- body: JSON.stringify(body),
3667
- signal: AbortSignal.timeout(this.config.timeout)
3668
- });
3669
- if (!response.ok) {
3670
- const text = await response.text();
3671
- throw new Error(`Compact API error ${response.status}: ${text}`);
3672
- }
3673
- const data = await response.json();
3674
- if (debug) {
3675
- console.log(`[Compact] compact() done in ${Date.now() - startTime}ms`);
3810
+ if (input.query !== void 0) body.query = input.query;
3811
+ if (input.messages) body.messages = input.messages;
3812
+ else if (typeof input.input === "string") body.input = input.input;
3813
+ else if (Array.isArray(input.input)) body.messages = input.input;
3814
+ else throw new Error("Either 'input' or 'messages' must be provided");
3815
+ try {
3816
+ return await this._client.post("/v1/compact", { body, timeout: this.config.timeout });
3817
+ } catch (err) {
3818
+ if (err instanceof MorphError) {
3819
+ throw new Error(`Compact API error ${err.statusCode}: ${err.message}`);
3820
+ }
3821
+ throw err;
3676
3822
  }
3677
- return data;
3678
3823
  }
3679
3824
  };
3680
3825
 
@@ -3730,10 +3875,28 @@ async function getLocalProvider(repoRoot, excludes, allowNames) {
3730
3875
  const opts = allowNames?.length ? { allowNames } : void 0;
3731
3876
  return new LocalRipgrepProvider2(repoRoot, excludes, opts);
3732
3877
  }
3733
- var WarpGrepClient = class {
3878
+ var WarpGrepClient = class extends APIResource {
3734
3879
  config;
3735
- constructor(config = {}) {
3736
- this.config = { ...config };
3880
+ constructor(clientOrConfig = {}) {
3881
+ const isClient = clientOrConfig instanceof MorphAPIClient;
3882
+ super(
3883
+ isClient ? clientOrConfig : new MorphAPIClient({
3884
+ apiKey: clientOrConfig.morphApiKey,
3885
+ baseURL: clientOrConfig.morphApiUrl,
3886
+ timeout: clientOrConfig.timeout,
3887
+ retryConfig: clientOrConfig.retryConfig,
3888
+ debug: clientOrConfig.debug
3889
+ })
3890
+ );
3891
+ const cfg = isClient ? {} : clientOrConfig;
3892
+ this.config = {
3893
+ ...cfg,
3894
+ morphApiKey: this._client.resolveApiKey(),
3895
+ morphApiUrl: this._client.baseURL,
3896
+ timeout: this._client.timeout,
3897
+ retryConfig: this._client.retryConfig,
3898
+ debug: this._client.debug
3899
+ };
3737
3900
  }
3738
3901
  execute(input) {
3739
3902
  const toolConfig = {
@@ -4007,11 +4170,9 @@ var PermissionError = class extends GitHubError {
4007
4170
  };
4008
4171
 
4009
4172
  // tools/github/core.ts
4010
- var DEFAULT_BASE_URL = "https://api.morphllm.com";
4011
- var DEFAULT_TIMEOUT3 = 3e4;
4012
- var GitHubClient = class {
4013
- apiKey;
4014
- baseUrl;
4173
+ var DEFAULT_BASE_URL2 = "https://api.morphllm.com";
4174
+ var DEFAULT_TIMEOUT5 = 3e4;
4175
+ var GitHubClient = class extends APIResource {
4015
4176
  timeout;
4016
4177
  debug;
4017
4178
  defaultInstallationId;
@@ -4036,13 +4197,21 @@ var GitHubClient = class {
4036
4197
  getInstallUrl() {
4037
4198
  return "https://github.com/apps/morph-subagents/installations/new";
4038
4199
  }
4039
- constructor(config = {}) {
4040
- this.apiKey = config.apiKey || process.env.MORPH_API_KEY || "";
4041
- this.baseUrl = config.baseUrl || DEFAULT_BASE_URL;
4042
- this.timeout = config.timeout || DEFAULT_TIMEOUT3;
4200
+ constructor(clientOrConfig = {}, options = {}) {
4201
+ const isClient = clientOrConfig instanceof MorphAPIClient;
4202
+ const config = isClient ? {} : clientOrConfig;
4203
+ super(
4204
+ isClient ? clientOrConfig : new MorphAPIClient({
4205
+ apiKey: config.apiKey,
4206
+ baseURL: config.baseUrl ?? DEFAULT_BASE_URL2,
4207
+ timeout: config.timeout ?? DEFAULT_TIMEOUT5,
4208
+ debug: config.debug
4209
+ })
4210
+ );
4211
+ this.timeout = config.timeout || DEFAULT_TIMEOUT5;
4043
4212
  this.debug = config.debug || false;
4044
- this.defaultInstallationId = config.installationId;
4045
- if (!this.apiKey) {
4213
+ this.defaultInstallationId = isClient ? options.installationId : config.installationId;
4214
+ if (!this._client.resolveApiKey()) {
4046
4215
  throw new Error("API key required. Set MORPH_API_KEY or pass apiKey in config.");
4047
4216
  }
4048
4217
  this.installations = {
@@ -4086,59 +4255,44 @@ var GitHubClient = class {
4086
4255
  * Make an authenticated API request
4087
4256
  */
4088
4257
  async request(method, path6, body) {
4089
- const url = `${this.baseUrl}${path6}`;
4090
4258
  if (this.debug) {
4091
4259
  console.log(`[GitHub SDK] ${method} ${path6}`, body || "");
4092
4260
  }
4093
- const controller = new AbortController();
4094
- const timeoutId = setTimeout(() => controller.abort(), this.timeout);
4261
+ let response;
4095
4262
  try {
4096
- const response = await fetch(url, {
4097
- method,
4098
- headers: {
4099
- "Content-Type": "application/json",
4100
- Authorization: `Bearer ${this.apiKey}`
4101
- },
4102
- body: body ? JSON.stringify(body) : void 0,
4103
- signal: controller.signal
4263
+ response = await this._client.request(method, path6, {
4264
+ body,
4265
+ timeout: this.timeout,
4266
+ raw: true
4104
4267
  });
4105
- clearTimeout(timeoutId);
4106
- if (!response.ok) {
4107
- const errorData = await response.json().catch(() => ({}));
4108
- const message = errorData.error || errorData.detail || errorData.message || response.statusText;
4109
- if (this.debug) {
4110
- console.error(`[GitHub SDK] Error ${response.status}:`, message);
4111
- }
4112
- if (response.status === 404) {
4113
- if (message.includes("installation")) {
4114
- throw new NoInstallationError(message);
4115
- }
4116
- throw new NotFoundError(message);
4117
- }
4118
- if (response.status === 403) {
4119
- throw new PermissionError(message);
4120
- }
4121
- throw new GitHubError(message, response.status, errorData.code);
4268
+ } catch (error) {
4269
+ if (error instanceof Error && /timed out/i.test(error.message)) {
4270
+ throw new GitHubError("Request timeout", 408, "TIMEOUT");
4122
4271
  }
4123
- const data = await response.json();
4272
+ throw new GitHubError(error instanceof Error ? error.message : "Unknown error", 500, "UNKNOWN");
4273
+ }
4274
+ if (!response.ok) {
4275
+ const errorData = await response.json().catch(() => ({}));
4276
+ const message = errorData.error || errorData.detail || errorData.message || response.statusText;
4124
4277
  if (this.debug) {
4125
- console.log(`[GitHub SDK] Response:`, JSON.stringify(data).slice(0, 200));
4278
+ console.error(`[GitHub SDK] Error ${response.status}:`, message);
4126
4279
  }
4127
- return data;
4128
- } catch (error) {
4129
- clearTimeout(timeoutId);
4130
- if (error instanceof GitHubError) {
4131
- throw error;
4280
+ if (response.status === 404) {
4281
+ if (message.includes("installation")) {
4282
+ throw new NoInstallationError(message);
4283
+ }
4284
+ throw new NotFoundError(message);
4132
4285
  }
4133
- if (error instanceof Error && error.name === "AbortError") {
4134
- throw new GitHubError("Request timeout", 408, "TIMEOUT");
4286
+ if (response.status === 403) {
4287
+ throw new PermissionError(message);
4135
4288
  }
4136
- throw new GitHubError(
4137
- error instanceof Error ? error.message : "Unknown error",
4138
- 500,
4139
- "UNKNOWN"
4140
- );
4289
+ throw new GitHubError(message, response.status, errorData.code);
4141
4290
  }
4291
+ const data = await response.json();
4292
+ if (this.debug) {
4293
+ console.log(`[GitHub SDK] Response:`, JSON.stringify(data).slice(0, 200));
4294
+ }
4295
+ return data;
4142
4296
  }
4143
4297
  /**
4144
4298
  * Get the installation ID to use for a request
@@ -4332,18 +4486,28 @@ var import_isomorphic_git = __toESM(require("isomorphic-git"), 1);
4332
4486
  var import_node = __toESM(require("isomorphic-git/http/node"), 1);
4333
4487
  var import_fs2 = __toESM(require("fs"), 1);
4334
4488
  var DEFAULT_PROXY_URL = "https://repos.morphllm.com";
4335
- var MorphGit = class {
4489
+ var MorphGit = class extends APIResource {
4336
4490
  apiKey;
4337
4491
  proxyUrl;
4338
- constructor(config) {
4339
- if (!config.apiKey) {
4340
- throw new Error("API key is required. Get one at https://morphllm.com/dashboard");
4341
- }
4342
- if (!config.apiKey.startsWith("sk-") && !config.apiKey.startsWith("morph-")) {
4343
- throw new Error("Invalid API key format. Expected: sk-... or morph-...");
4492
+ constructor(clientOrConfig) {
4493
+ const isClient = clientOrConfig instanceof MorphAPIClient;
4494
+ if (!isClient) {
4495
+ if (!clientOrConfig.apiKey) {
4496
+ throw new Error("API key is required. Get one at https://morphllm.com/dashboard");
4497
+ }
4498
+ if (!clientOrConfig.apiKey.startsWith("sk-") && !clientOrConfig.apiKey.startsWith("morph-")) {
4499
+ throw new Error("Invalid API key format. Expected: sk-... or morph-...");
4500
+ }
4344
4501
  }
4345
- this.apiKey = config.apiKey;
4346
- this.proxyUrl = config.proxyUrl || DEFAULT_PROXY_URL;
4502
+ super(
4503
+ isClient ? clientOrConfig : new MorphAPIClient({
4504
+ apiKey: clientOrConfig.apiKey,
4505
+ reposURL: clientOrConfig.proxyUrl,
4506
+ retryConfig: clientOrConfig.retryConfig
4507
+ })
4508
+ );
4509
+ this.apiKey = this._client.resolveApiKey() ?? "";
4510
+ this.proxyUrl = isClient ? this._client.reposURL : clientOrConfig.proxyUrl || DEFAULT_PROXY_URL;
4347
4511
  }
4348
4512
  /**
4349
4513
  * Get auth callback for isomorphic-git operations
@@ -4871,87 +5035,212 @@ var MorphGit = class {
4871
5035
  var import_isomorphic_git2 = __toESM(require("isomorphic-git"), 1);
4872
5036
  var import_node2 = __toESM(require("isomorphic-git/http/node"), 1);
4873
5037
 
5038
+ // tools/reflex/core.ts
5039
+ var BASE_MODEL = "morph-reflex-v1";
5040
+ function resolveClient2(clientOrConfig) {
5041
+ if (clientOrConfig instanceof MorphAPIClient) return clientOrConfig;
5042
+ return new MorphAPIClient({
5043
+ apiKey: clientOrConfig.apiKey,
5044
+ baseURL: clientOrConfig.baseUrl,
5045
+ timeout: clientOrConfig.timeout,
5046
+ retryConfig: clientOrConfig.retryConfig,
5047
+ debug: clientOrConfig.debug
5048
+ });
5049
+ }
5050
+ var ReflexClient = class extends APIResource {
5051
+ /** Train, retrieve, and manage classifier jobs. */
5052
+ jobs;
5053
+ constructor(clientOrConfig = {}) {
5054
+ super(resolveClient2(clientOrConfig));
5055
+ this.jobs = new ReflexJobsResource(this._client);
5056
+ }
5057
+ /** Classify text against a trained model. The model must be `succeeded`. */
5058
+ async predict(input) {
5059
+ const raw = await this._client.post("/v1/reflex/predict", {
5060
+ body: { model: input.model, text: input.text }
5061
+ });
5062
+ return {
5063
+ model: raw.model,
5064
+ label: raw.label,
5065
+ confidence: raw.confidence,
5066
+ allScores: raw.all_scores ?? {},
5067
+ inferenceTimeMs: raw.inference_time_ms
5068
+ };
5069
+ }
5070
+ };
5071
+ var ReflexJobsResource = class extends APIResource {
5072
+ /** Start a training job from labeled data, a description, or unlabeled text. */
5073
+ async create(input) {
5074
+ return toReflexJob(await this._client.post("/v1/fine_tuning/jobs", { body: createBody(input) }));
5075
+ }
5076
+ /** Fetch a job by id. */
5077
+ async retrieve(id) {
5078
+ return toReflexJob(await this._client.get(`/v1/fine_tuning/jobs/${encodeURIComponent(id)}`));
5079
+ }
5080
+ /** List the caller's jobs, newest first. */
5081
+ async list(input = {}) {
5082
+ const raw = await this._client.get("/v1/fine_tuning/jobs", {
5083
+ query: { limit: input.limit, after: input.after }
5084
+ });
5085
+ return { data: (raw.data ?? []).map(toReflexJob), hasMore: Boolean(raw.has_more) };
5086
+ }
5087
+ /** Stop a queued or running job. */
5088
+ async cancel(id) {
5089
+ return toReflexJob(await this._client.post(`/v1/fine_tuning/jobs/${encodeURIComponent(id)}/cancel`));
5090
+ }
5091
+ /** Delete a job and its trained model. */
5092
+ async delete(id) {
5093
+ const raw = await this._client.delete(
5094
+ `/v1/fine_tuning/jobs/${encodeURIComponent(id)}`
5095
+ );
5096
+ return { id: raw.id, deleted: Boolean(raw.deleted) };
5097
+ }
5098
+ /** The training loss curve as events, plus a terminal event. */
5099
+ async events(id) {
5100
+ const raw = await this._client.get(
5101
+ `/v1/fine_tuning/jobs/${encodeURIComponent(id)}/events`
5102
+ );
5103
+ return (raw.data ?? []).map(toReflexEvent);
5104
+ }
5105
+ /**
5106
+ * Poll until the job reaches a terminal status and return it on success.
5107
+ * Throws a `MorphError` if it fails, is cancelled, or exceeds `timeoutMs`.
5108
+ */
5109
+ async waitForReady(id, opts = {}) {
5110
+ const pollMs = opts.pollMs ?? 3e3;
5111
+ const deadline = Date.now() + (opts.timeoutMs ?? 15 * 6e4);
5112
+ for (; ; ) {
5113
+ const job = await this.retrieve(id);
5114
+ if (job.status === "succeeded") return job;
5115
+ if (job.status === "failed" || job.status === "cancelled") {
5116
+ throw new MorphError(job.error?.message ?? `Reflex job ${job.status}`, `reflex_job_${job.status}`);
5117
+ }
5118
+ if (Date.now() >= deadline) {
5119
+ throw new MorphError(`Reflex job ${id} did not finish in time`, "reflex_timeout");
5120
+ }
5121
+ await sleep2(pollMs);
5122
+ }
5123
+ }
5124
+ };
5125
+ function createBody(input) {
5126
+ const base = { model: BASE_MODEL };
5127
+ if (input.suffix) base.suffix = input.suffix;
5128
+ if ("trainingData" in input) {
5129
+ if (input.labels) base.labels = input.labels;
5130
+ return { ...base, training_data: input.trainingData };
5131
+ }
5132
+ if ("generate" in input) {
5133
+ return {
5134
+ ...base,
5135
+ labels: input.labels,
5136
+ generate: {
5137
+ description: input.generate.description,
5138
+ ...input.generate.examplesPerLabel != null ? { examples_per_label: input.generate.examplesPerLabel } : {}
5139
+ }
5140
+ };
5141
+ }
5142
+ return {
5143
+ ...base,
5144
+ labels: input.labels,
5145
+ label_data: {
5146
+ texts: input.labelData.texts,
5147
+ ...input.labelData.description ? { description: input.labelData.description } : {}
5148
+ }
5149
+ };
5150
+ }
5151
+ function toReflexJob(raw) {
5152
+ return {
5153
+ id: raw.id,
5154
+ object: "fine_tuning.job",
5155
+ model: raw.model,
5156
+ createdAt: raw.created_at,
5157
+ finishedAt: raw.finished_at ?? null,
5158
+ fineTunedModel: raw.fine_tuned_model ?? null,
5159
+ status: raw.status,
5160
+ labels: raw.labels ?? [],
5161
+ trainedExamples: raw.trained_examples ?? 0,
5162
+ result: raw.result ? { accuracy: raw.result.accuracy ?? null, f1Score: raw.result.f1_score ?? null } : null,
5163
+ error: raw.error ? { message: raw.error.message } : null,
5164
+ suffix: raw.suffix ?? null
5165
+ };
5166
+ }
5167
+ function toReflexEvent(raw) {
5168
+ return {
5169
+ id: raw.id,
5170
+ createdAt: raw.created_at,
5171
+ level: raw.level,
5172
+ message: raw.message,
5173
+ type: raw.type,
5174
+ data: { epoch: raw.data?.epoch ?? 0, step: raw.data?.step ?? 0, trainLoss: raw.data?.train_loss ?? 0 }
5175
+ };
5176
+ }
5177
+ function sleep2(ms) {
5178
+ return new Promise((resolve2) => setTimeout(resolve2, ms));
5179
+ }
5180
+
4874
5181
  // modelrouter/core.ts
4875
5182
  init_logger();
4876
- var DEFAULT_CONFIG3 = {
4877
- apiUrl: "https://api.morphllm.com",
4878
- timeout: 5e3,
4879
- // 5 seconds (responses typically <500ms)
4880
- debug: false
4881
- };
4882
- var BaseRouter = class {
4883
- config;
5183
+ var DEFAULT_API_URL5 = "https://api.morphllm.com";
5184
+ var DEFAULT_TIMEOUT6 = 5e3;
5185
+ function resolveClient3(clientOrConfig) {
5186
+ if (clientOrConfig instanceof MorphAPIClient) return clientOrConfig;
5187
+ return new MorphAPIClient({
5188
+ apiKey: clientOrConfig.apiKey,
5189
+ baseURL: clientOrConfig.apiUrl ?? DEFAULT_API_URL5,
5190
+ timeout: clientOrConfig.timeout ?? DEFAULT_TIMEOUT6,
5191
+ retryConfig: clientOrConfig.retryConfig,
5192
+ debug: clientOrConfig.debug
5193
+ });
5194
+ }
5195
+ var BaseRouter = class extends APIResource {
4884
5196
  provider;
4885
- constructor(provider, config = {}) {
5197
+ timeout;
5198
+ constructor(provider, clientOrConfig = {}) {
5199
+ super(resolveClient3(clientOrConfig));
4886
5200
  this.provider = provider;
4887
- this.config = {
4888
- apiKey: config.apiKey,
4889
- apiUrl: config.apiUrl || DEFAULT_CONFIG3.apiUrl,
4890
- timeout: config.timeout || DEFAULT_CONFIG3.timeout,
4891
- debug: config.debug || DEFAULT_CONFIG3.debug,
4892
- retryConfig: config.retryConfig
4893
- };
5201
+ const cfg = clientOrConfig instanceof MorphAPIClient ? {} : clientOrConfig;
5202
+ this.timeout = cfg.timeout ?? DEFAULT_TIMEOUT6;
4894
5203
  }
4895
- /**
4896
- * Select the optimal model for a given input and mode
4897
- */
4898
- async selectModel(input) {
4899
- const mode = input.mode || "balanced";
4900
- const apiKey = this.config.apiKey || (typeof process !== "undefined" ? process.env?.MORPH_API_KEY : void 0);
4901
- if (!apiKey) {
5204
+ /** Throw the historical "API key is required" message when no key is resolvable. */
5205
+ requireApiKey() {
5206
+ if (!this._client.resolveApiKey()) {
4902
5207
  throw new Error(
4903
5208
  "Morph API key is required. Set MORPH_API_KEY environment variable or pass apiKey in config."
4904
5209
  );
4905
5210
  }
4906
- const url = `${this.config.apiUrl}/v1/router/${this.provider}`;
4907
- const payload = {
4908
- input: input.input,
4909
- mode
4910
- };
4911
- logger.debug("ModelRouter", "request", { provider: this.provider, mode, input_len: input.input.length, url });
5211
+ }
5212
+ /** POST to the router and surface failures as `Router API error (<status>): ...`. */
5213
+ async route(provider, input) {
4912
5214
  try {
4913
- const fetchPromise = fetchWithRetry(
4914
- url,
4915
- {
4916
- method: "POST",
4917
- headers: {
4918
- "Content-Type": "application/json",
4919
- Authorization: `Bearer ${apiKey}`
4920
- },
4921
- body: JSON.stringify(payload)
4922
- },
4923
- this.config.retryConfig
4924
- );
4925
- const response = await withTimeout(
4926
- fetchPromise,
4927
- this.config.timeout,
4928
- `Router API request timed out after ${this.config.timeout}ms`
4929
- );
4930
- if (!response.ok) {
4931
- const errorText = await response.text();
4932
- throw new Error(
4933
- `Router API error (${response.status}): ${errorText || response.statusText}`
4934
- );
4935
- }
4936
- const apiResult = await response.json();
4937
- const result = {
4938
- model: apiResult.model
4939
- };
4940
- logger.debug("ModelRouter", "selected", { provider: this.provider, model: apiResult.model, confidence: apiResult.confidence });
4941
- return result;
5215
+ return await this._client.post(`/v1/router/${provider}`, {
5216
+ body: { input: input.input, mode: input.mode || "balanced" },
5217
+ timeout: this.timeout
5218
+ });
4942
5219
  } catch (error) {
4943
- logger.error("ModelRouter", "error", { provider: this.provider, error: error instanceof Error ? error.message : String(error) });
5220
+ if (error instanceof MorphError) {
5221
+ throw new Error(`Router API error (${error.statusCode}): ${error.message}`);
5222
+ }
4944
5223
  throw error;
4945
5224
  }
4946
5225
  }
5226
+ /**
5227
+ * Select the optimal model for a given input and mode
5228
+ */
5229
+ async selectModel(input) {
5230
+ this.requireApiKey();
5231
+ logger.debug("ModelRouter", "request", { provider: this.provider, mode: input.mode || "balanced" });
5232
+ const apiResult = await this.route(this.provider, input);
5233
+ logger.debug("ModelRouter", "selected", { provider: this.provider, model: apiResult.model });
5234
+ return { model: apiResult.model };
5235
+ }
4947
5236
  };
4948
5237
  var OpenAIRouter = class extends BaseRouter {
4949
- constructor(config = {}) {
4950
- super("openai", config);
5238
+ constructor(clientOrConfig = {}) {
5239
+ super("openai", clientOrConfig);
4951
5240
  }
4952
5241
  /**
4953
5242
  * Select optimal GPT-5 model
4954
- *
5243
+ *
4955
5244
  * @param input - User input and mode
4956
5245
  * @returns Selected model name (gpt-5-mini | gpt-5-low | gpt-5-medium | gpt-5-high)
4957
5246
  */
@@ -4960,12 +5249,12 @@ var OpenAIRouter = class extends BaseRouter {
4960
5249
  }
4961
5250
  };
4962
5251
  var AnthropicRouter = class extends BaseRouter {
4963
- constructor(config = {}) {
4964
- super("anthropic", config);
5252
+ constructor(clientOrConfig = {}) {
5253
+ super("anthropic", clientOrConfig);
4965
5254
  }
4966
5255
  /**
4967
5256
  * Select optimal Claude model
4968
- *
5257
+ *
4969
5258
  * @param input - User input and mode
4970
5259
  * @returns Selected model name (claude-4.5-haiku | claude-4.5-sonnet)
4971
5260
  */
@@ -4974,12 +5263,12 @@ var AnthropicRouter = class extends BaseRouter {
4974
5263
  }
4975
5264
  };
4976
5265
  var GeminiRouter = class extends BaseRouter {
4977
- constructor(config = {}) {
4978
- super("gemini", config);
5266
+ constructor(clientOrConfig = {}) {
5267
+ super("gemini", clientOrConfig);
4979
5268
  }
4980
5269
  /**
4981
5270
  * Select optimal Gemini model
4982
- *
5271
+ *
4983
5272
  * @param input - User input and mode
4984
5273
  * @returns Selected model name (gemini-2.5-flash | gemini-2.5-pro)
4985
5274
  */
@@ -4988,69 +5277,27 @@ var GeminiRouter = class extends BaseRouter {
4988
5277
  }
4989
5278
  };
4990
5279
  var RawRouter = class extends BaseRouter {
4991
- constructor(config = {}) {
4992
- super("raw", config);
5280
+ constructor(clientOrConfig = {}) {
5281
+ super("raw", clientOrConfig);
4993
5282
  }
4994
5283
  /**
4995
5284
  * Get raw difficulty classification
4996
- *
5285
+ *
4997
5286
  * @param input - User input and mode
4998
5287
  * @returns Raw difficulty (easy | medium | hard | needs_info)
4999
5288
  */
5000
5289
  async classify(input) {
5001
- const mode = input.mode || "balanced";
5002
- const apiKey = this.config.apiKey || (typeof process !== "undefined" ? process.env?.MORPH_API_KEY : void 0);
5003
- if (!apiKey) {
5004
- throw new Error(
5005
- "Morph API key is required. Set MORPH_API_KEY environment variable or pass apiKey in config."
5006
- );
5007
- }
5008
- const url = `${this.config.apiUrl}/v1/router/raw`;
5009
- const payload = {
5010
- input: input.input,
5011
- mode
5012
- };
5013
- logger.debug("RawRouter", "request", { mode, input_len: input.input.length, url });
5014
- try {
5015
- const fetchPromise = fetchWithRetry(
5016
- url,
5017
- {
5018
- method: "POST",
5019
- headers: {
5020
- "Content-Type": "application/json",
5021
- Authorization: `Bearer ${apiKey}`
5022
- },
5023
- body: JSON.stringify(payload)
5024
- },
5025
- this.config.retryConfig
5026
- );
5027
- const response = await withTimeout(
5028
- fetchPromise,
5029
- this.config.timeout,
5030
- `Router API request timed out after ${this.config.timeout}ms`
5031
- );
5032
- if (!response.ok) {
5033
- const errorText = await response.text();
5034
- throw new Error(
5035
- `Router API error (${response.status}): ${errorText || response.statusText}`
5036
- );
5037
- }
5038
- const apiResult = await response.json();
5039
- let difficulty;
5040
- if (apiResult.difficulty === "") {
5041
- difficulty = "medium";
5042
- } else {
5043
- difficulty = apiResult.difficulty || apiResult.model;
5044
- }
5045
- const result = {
5046
- difficulty
5047
- };
5048
- logger.debug("RawRouter", "classified", { difficulty });
5049
- return result;
5050
- } catch (error) {
5051
- logger.error("RawRouter", "error", { error: error instanceof Error ? error.message : String(error) });
5052
- throw error;
5290
+ this.requireApiKey();
5291
+ logger.debug("RawRouter", "request", { mode: input.mode || "balanced" });
5292
+ const apiResult = await this.route("raw", input);
5293
+ let difficulty;
5294
+ if (apiResult.difficulty === "") {
5295
+ difficulty = "medium";
5296
+ } else {
5297
+ difficulty = apiResult.difficulty || apiResult.model;
5053
5298
  }
5299
+ logger.debug("RawRouter", "classified", { difficulty });
5300
+ return { difficulty };
5054
5301
  }
5055
5302
  };
5056
5303
 
@@ -6433,7 +6680,7 @@ var VercelToolFactory = class {
6433
6680
  };
6434
6681
 
6435
6682
  // client.ts
6436
- var MorphClient = class {
6683
+ var MorphClient = class extends MorphAPIClient {
6437
6684
  /** Client configuration */
6438
6685
  config;
6439
6686
  /** FastApply tool for editing files with AI-powered merge */
@@ -6458,6 +6705,8 @@ var MorphClient = class {
6458
6705
  vercel;
6459
6706
  /** Compact context with line ranges */
6460
6707
  compact;
6708
+ /** Reflex: train and serve small text classifiers */
6709
+ reflex;
6461
6710
  /**
6462
6711
  * Create a new Morph SDK client
6463
6712
  *
@@ -6473,78 +6722,32 @@ var MorphClient = class {
6473
6722
  * ```
6474
6723
  */
6475
6724
  constructor(config = {}) {
6476
- this.config = config;
6477
- if (config.debug) {
6478
- logger.enable();
6479
- }
6480
- logger.debug("MorphClient", "initialized", { debug: !!config.debug, timeout: config.timeout });
6481
- this.fastApply = new FastApplyClient({
6482
- apiKey: config.apiKey,
6483
- debug: config.debug,
6484
- timeout: config.timeout,
6485
- retryConfig: config.retryConfig
6486
- });
6487
- this.codebaseSearch = new CodebaseSearchClient({
6725
+ super({
6488
6726
  apiKey: config.apiKey,
6489
- debug: config.debug,
6490
- timeout: config.timeout,
6491
- retryConfig: config.retryConfig
6492
- });
6493
- this.warpGrep = new WarpGrepClient({
6494
- morphApiKey: config.apiKey,
6495
- debug: config.debug,
6496
- timeout: config.timeout,
6497
- retryConfig: config.retryConfig
6498
- });
6499
- this.browser = new BrowserClient({
6500
- apiKey: config.apiKey,
6501
- debug: config.debug,
6502
- timeout: config.timeout,
6503
- retryConfig: config.retryConfig
6504
- });
6505
- this.github = new GitHubClient({
6506
- apiKey: config.apiKey,
6507
- debug: config.debug,
6508
- timeout: config.timeout,
6509
- installationId: config.github?.installationId
6510
- });
6511
- this.git = new MorphGit({
6512
- apiKey: config.apiKey,
6513
- retryConfig: config.retryConfig
6514
- });
6515
- this.routers = {
6516
- openai: new OpenAIRouter({
6517
- apiKey: config.apiKey,
6518
- debug: config.debug,
6519
- timeout: config.timeout,
6520
- retryConfig: config.retryConfig
6521
- }),
6522
- anthropic: new AnthropicRouter({
6523
- apiKey: config.apiKey,
6524
- debug: config.debug,
6525
- timeout: config.timeout,
6526
- retryConfig: config.retryConfig
6527
- }),
6528
- gemini: new GeminiRouter({
6529
- apiKey: config.apiKey,
6530
- debug: config.debug,
6531
- timeout: config.timeout,
6532
- retryConfig: config.retryConfig
6533
- }),
6534
- raw: new RawRouter({
6535
- apiKey: config.apiKey,
6536
- debug: config.debug,
6537
- timeout: config.timeout,
6538
- retryConfig: config.retryConfig
6539
- })
6540
- };
6541
- const compactClient = new CompactClient({
6542
- morphApiKey: config.apiKey,
6543
6727
  timeout: config.timeout,
6544
6728
  retryConfig: config.retryConfig,
6545
6729
  debug: config.debug
6546
6730
  });
6731
+ if (!config.apiKey) {
6732
+ throw new Error("Morph API key is required. Pass it as { apiKey } when constructing MorphClient.");
6733
+ }
6734
+ this.config = config;
6735
+ logger.debug("MorphClient", "initialized", { debug: !!config.debug, timeout: config.timeout });
6736
+ this.fastApply = new FastApplyClient(this);
6737
+ this.codebaseSearch = new CodebaseSearchClient(this);
6738
+ this.warpGrep = new WarpGrepClient(this);
6739
+ this.browser = new BrowserClient(this);
6740
+ this.github = new GitHubClient(this, { installationId: config.github?.installationId });
6741
+ this.git = new MorphGit(this);
6742
+ this.routers = {
6743
+ openai: new OpenAIRouter(this),
6744
+ anthropic: new AnthropicRouter(this),
6745
+ gemini: new GeminiRouter(this),
6746
+ raw: new RawRouter(this)
6747
+ };
6748
+ const compactClient = new CompactClient(this);
6547
6749
  this.compact = compactClient.compact.bind(compactClient);
6750
+ this.reflex = new ReflexClient(this);
6548
6751
  this.openai = new OpenAIToolFactory(config);
6549
6752
  this.anthropic = new AnthropicToolFactory(config);
6550
6753
  this.vercel = new VercelToolFactory(config);
@@ -6588,6 +6791,7 @@ var warpGrepInputSchema = import_zod5.z.object({
6588
6791
  });
6589
6792
  // Annotate the CommonJS export names for ESM import in node:
6590
6793
  0 && (module.exports = {
6794
+ APIResource,
6591
6795
  AnthropicRouter,
6592
6796
  AnthropicToolFactory,
6593
6797
  BrowserClient,
@@ -6598,6 +6802,7 @@ var warpGrepInputSchema = import_zod5.z.object({
6598
6802
  GitHubClient,
6599
6803
  GitHubError,
6600
6804
  LocalRipgrepProvider,
6805
+ MorphAPIClient,
6601
6806
  MorphClient,
6602
6807
  MorphGit,
6603
6808
  NoInstallationError,
@@ -6606,6 +6811,8 @@ var warpGrepInputSchema = import_zod5.z.object({
6606
6811
  OpenAIToolFactory,
6607
6812
  PermissionError,
6608
6813
  RawRouter,
6814
+ ReflexClient,
6815
+ ReflexJobsResource,
6609
6816
  SDK_VERSION,
6610
6817
  VercelToolFactory,
6611
6818
  WarpGrepClient,