@morphllm/morphsdk 0.2.170 → 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 (260) hide show
  1. package/dist/{chunk-IY7DESC3.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-5KFQBI4J.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-76XER44U.js → chunk-7PVVPLRL.js} +2 -2
  12. package/dist/{chunk-BCPZAPWY.js → chunk-AE7M2I52.js} +2 -2
  13. package/dist/{chunk-LNXIVRPY.js → chunk-CQF76HJC.js} +30 -6
  14. package/dist/chunk-CQF76HJC.js.map +1 -0
  15. package/dist/{chunk-OJQYBWHR.js → chunk-ESXCQBMU.js} +2 -2
  16. package/dist/{chunk-LAGN62H5.js → chunk-FOIDGIY4.js} +29 -10
  17. package/dist/chunk-FOIDGIY4.js.map +1 -0
  18. package/dist/{chunk-KUPSW5QN.js → chunk-GJZXDRH5.js} +8 -3
  19. package/dist/{chunk-KUPSW5QN.js.map → chunk-GJZXDRH5.js.map} +1 -1
  20. package/dist/{chunk-5IR3YE77.js → chunk-IJ33I7P5.js} +4 -4
  21. package/dist/{chunk-E5QWXVTF.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-6LPWEZ6H.js → chunk-MO6S2LRD.js} +2 -2
  28. package/dist/{chunk-S4IEM5EG.js → chunk-NI7PWQ3B.js} +4 -4
  29. package/dist/{chunk-GLQWEINZ.js → chunk-QAXXE4AD.js} +2 -2
  30. package/dist/{chunk-YG2I377B.js → chunk-QFE5523Q.js} +18 -3
  31. package/dist/chunk-QFE5523Q.js.map +1 -0
  32. package/dist/{chunk-G4FPDEUP.js → chunk-QQXNZIVK.js} +4 -4
  33. package/dist/{chunk-A3ZUWLYX.js → chunk-QZ3V2BP7.js} +2 -2
  34. package/dist/chunk-QZR7SJ5N.js +24 -0
  35. package/dist/chunk-QZR7SJ5N.js.map +1 -0
  36. package/dist/{chunk-SYD6BRQX.js → chunk-SJVLAGUL.js} +4 -4
  37. package/dist/{chunk-JMEQ6FLB.js → chunk-U4J3BVAQ.js} +4 -4
  38. package/dist/{chunk-QAWYDWDW.js → chunk-U4MRSZQQ.js} +2 -2
  39. package/dist/{chunk-WU3D46MH.js → chunk-UADW6FYD.js} +2 -2
  40. package/dist/{chunk-K7NY5SVR.js → chunk-VBARKJWL.js} +2 -2
  41. package/dist/{chunk-OPNTDMHH.js → chunk-VLZ6PNAD.js} +4 -4
  42. package/dist/chunk-VZ7BOH2K.js +1 -0
  43. package/dist/chunk-VZ7BOH2K.js.map +1 -0
  44. package/dist/{chunk-GUGHUAJU.js → chunk-XJDXV5VX.js} +2 -2
  45. package/dist/{chunk-GPNUS3H2.js → chunk-XYTYIAMQ.js} +2 -2
  46. package/dist/{chunk-MKBVWPU7.js → chunk-Z4GJVN52.js} +23 -8
  47. package/dist/chunk-Z4GJVN52.js.map +1 -0
  48. package/dist/chunk-ZLSNL6M2.js +97 -0
  49. package/dist/chunk-ZLSNL6M2.js.map +1 -0
  50. package/dist/{client-DsAAqupx.d.ts → client-Dh6yzCm4.d.ts} +14 -5
  51. package/dist/client.cjs +741 -525
  52. package/dist/client.cjs.map +1 -1
  53. package/dist/client.d.ts +5 -1
  54. package/dist/client.js +31 -27
  55. package/dist/core/client.cjs +540 -0
  56. package/dist/core/client.cjs.map +1 -0
  57. package/dist/core/client.d.ts +79 -0
  58. package/dist/core/client.js +12 -0
  59. package/dist/core/client.js.map +1 -0
  60. package/dist/core/error.cjs +309 -0
  61. package/dist/core/error.cjs.map +1 -0
  62. package/dist/core/error.d.ts +18 -0
  63. package/dist/core/error.js +10 -0
  64. package/dist/core/error.js.map +1 -0
  65. package/dist/core/index.cjs +552 -0
  66. package/dist/core/index.cjs.map +1 -0
  67. package/dist/core/index.d.ts +4 -0
  68. package/dist/core/index.js +20 -0
  69. package/dist/core/index.js.map +1 -0
  70. package/dist/core/resource.cjs +36 -0
  71. package/dist/core/resource.cjs.map +1 -0
  72. package/dist/core/resource.d.ts +18 -0
  73. package/dist/core/resource.js +8 -0
  74. package/dist/core/resource.js.map +1 -0
  75. package/dist/edge.cjs +252 -174
  76. package/dist/edge.cjs.map +1 -1
  77. package/dist/edge.d.ts +2 -0
  78. package/dist/edge.js +8 -5
  79. package/dist/git/client.cjs +529 -9
  80. package/dist/git/client.cjs.map +1 -1
  81. package/dist/git/client.d.ts +8 -2
  82. package/dist/git/client.js +7 -1
  83. package/dist/git/index.cjs +529 -9
  84. package/dist/git/index.cjs.map +1 -1
  85. package/dist/git/index.d.ts +2 -0
  86. package/dist/git/index.js +7 -1
  87. package/dist/index.cjs +688 -466
  88. package/dist/index.cjs.map +1 -1
  89. package/dist/index.d.ts +6 -2
  90. package/dist/index.js +49 -33
  91. package/dist/modelrouter/core.cjs +204 -125
  92. package/dist/modelrouter/core.cjs.map +1 -1
  93. package/dist/modelrouter/core.d.ts +36 -9
  94. package/dist/modelrouter/core.js +6 -3
  95. package/dist/modelrouter/index.cjs +204 -125
  96. package/dist/modelrouter/index.cjs.map +1 -1
  97. package/dist/modelrouter/index.d.ts +3 -0
  98. package/dist/modelrouter/index.js +6 -3
  99. package/dist/subagents/anthropic.cjs +268 -52
  100. package/dist/subagents/anthropic.cjs.map +1 -1
  101. package/dist/subagents/anthropic.js +10 -6
  102. package/dist/subagents/vercel.cjs +268 -52
  103. package/dist/subagents/vercel.cjs.map +1 -1
  104. package/dist/subagents/vercel.js +10 -6
  105. package/dist/tools/browser/anthropic.cjs +7 -2
  106. package/dist/tools/browser/anthropic.cjs.map +1 -1
  107. package/dist/tools/browser/anthropic.js +9 -6
  108. package/dist/tools/browser/core.cjs +162 -10
  109. package/dist/tools/browser/core.cjs.map +1 -1
  110. package/dist/tools/browser/core.d.ts +8 -2
  111. package/dist/tools/browser/core.js +8 -5
  112. package/dist/tools/browser/index.cjs +163 -11
  113. package/dist/tools/browser/index.cjs.map +1 -1
  114. package/dist/tools/browser/index.d.ts +2 -0
  115. package/dist/tools/browser/index.js +18 -15
  116. package/dist/tools/browser/index.js.map +1 -1
  117. package/dist/tools/browser/openai.cjs +7 -2
  118. package/dist/tools/browser/openai.cjs.map +1 -1
  119. package/dist/tools/browser/openai.js +9 -6
  120. package/dist/tools/browser/profiles/core.cjs +7 -2
  121. package/dist/tools/browser/profiles/core.cjs.map +1 -1
  122. package/dist/tools/browser/profiles/core.js +3 -3
  123. package/dist/tools/browser/profiles/index.cjs +7 -2
  124. package/dist/tools/browser/profiles/index.cjs.map +1 -1
  125. package/dist/tools/browser/profiles/index.js +3 -3
  126. package/dist/tools/browser/vercel.cjs +7 -2
  127. package/dist/tools/browser/vercel.cjs.map +1 -1
  128. package/dist/tools/browser/vercel.js +9 -6
  129. package/dist/tools/codebase_search/anthropic.cjs +162 -41
  130. package/dist/tools/codebase_search/anthropic.cjs.map +1 -1
  131. package/dist/tools/codebase_search/anthropic.js +7 -4
  132. package/dist/tools/codebase_search/core.cjs +195 -66
  133. package/dist/tools/codebase_search/core.cjs.map +1 -1
  134. package/dist/tools/codebase_search/core.d.ts +18 -7
  135. package/dist/tools/codebase_search/core.js +6 -3
  136. package/dist/tools/codebase_search/index.cjs +162 -41
  137. package/dist/tools/codebase_search/index.cjs.map +1 -1
  138. package/dist/tools/codebase_search/index.d.ts +2 -0
  139. package/dist/tools/codebase_search/index.js +13 -10
  140. package/dist/tools/codebase_search/openai.cjs +162 -41
  141. package/dist/tools/codebase_search/openai.cjs.map +1 -1
  142. package/dist/tools/codebase_search/openai.js +7 -4
  143. package/dist/tools/codebase_search/vercel.cjs +162 -41
  144. package/dist/tools/codebase_search/vercel.cjs.map +1 -1
  145. package/dist/tools/codebase_search/vercel.js +7 -4
  146. package/dist/tools/compact/core.cjs +551 -47
  147. package/dist/tools/compact/core.cjs.map +1 -1
  148. package/dist/tools/compact/core.d.ts +16 -3
  149. package/dist/tools/compact/core.js +7 -1
  150. package/dist/tools/compact/index.cjs +549 -47
  151. package/dist/tools/compact/index.cjs.map +1 -1
  152. package/dist/tools/compact/index.d.ts +2 -0
  153. package/dist/tools/compact/index.js +8 -2
  154. package/dist/tools/fastapply/anthropic.cjs +32 -3
  155. package/dist/tools/fastapply/anthropic.cjs.map +1 -1
  156. package/dist/tools/fastapply/anthropic.js +8 -4
  157. package/dist/tools/fastapply/apply.cjs +23 -3
  158. package/dist/tools/fastapply/apply.cjs.map +1 -1
  159. package/dist/tools/fastapply/apply.js +2 -2
  160. package/dist/tools/fastapply/core.cjs +258 -13
  161. package/dist/tools/fastapply/core.cjs.map +1 -1
  162. package/dist/tools/fastapply/core.d.ts +8 -2
  163. package/dist/tools/fastapply/core.js +7 -3
  164. package/dist/tools/fastapply/index.cjs +32 -3
  165. package/dist/tools/fastapply/index.cjs.map +1 -1
  166. package/dist/tools/fastapply/index.d.ts +2 -0
  167. package/dist/tools/fastapply/index.js +13 -9
  168. package/dist/tools/fastapply/openai.cjs +32 -3
  169. package/dist/tools/fastapply/openai.cjs.map +1 -1
  170. package/dist/tools/fastapply/openai.js +8 -4
  171. package/dist/tools/fastapply/vercel.cjs +32 -3
  172. package/dist/tools/fastapply/vercel.cjs.map +1 -1
  173. package/dist/tools/fastapply/vercel.js +8 -4
  174. package/dist/tools/index.cjs +32 -3
  175. package/dist/tools/index.cjs.map +1 -1
  176. package/dist/tools/index.d.ts +2 -0
  177. package/dist/tools/index.js +13 -9
  178. package/dist/tools/reflex/core.cjs +693 -0
  179. package/dist/tools/reflex/core.cjs.map +1 -0
  180. package/dist/tools/reflex/core.d.ts +53 -0
  181. package/dist/tools/reflex/core.js +16 -0
  182. package/dist/tools/reflex/core.js.map +1 -0
  183. package/dist/tools/reflex/index.cjs +693 -0
  184. package/dist/tools/reflex/index.cjs.map +1 -0
  185. package/dist/tools/reflex/index.d.ts +5 -0
  186. package/dist/tools/reflex/index.js +16 -0
  187. package/dist/tools/reflex/index.js.map +1 -0
  188. package/dist/tools/reflex/types.cjs +19 -0
  189. package/dist/tools/reflex/types.cjs.map +1 -0
  190. package/dist/tools/reflex/types.d.ts +113 -0
  191. package/dist/tools/reflex/types.js +1 -0
  192. package/dist/tools/reflex/types.js.map +1 -0
  193. package/dist/tools/utils/resilience.cjs +7 -2
  194. package/dist/tools/utils/resilience.cjs.map +1 -1
  195. package/dist/tools/utils/resilience.js +2 -2
  196. package/dist/tools/warp_grep/agent/runner.cjs +7 -2
  197. package/dist/tools/warp_grep/agent/runner.cjs.map +1 -1
  198. package/dist/tools/warp_grep/agent/runner.js +2 -2
  199. package/dist/tools/warp_grep/anthropic.cjs +268 -52
  200. package/dist/tools/warp_grep/anthropic.cjs.map +1 -1
  201. package/dist/tools/warp_grep/anthropic.d.ts +2 -0
  202. package/dist/tools/warp_grep/anthropic.js +10 -6
  203. package/dist/tools/warp_grep/client.cjs +268 -52
  204. package/dist/tools/warp_grep/client.cjs.map +1 -1
  205. package/dist/tools/warp_grep/client.d.ts +8 -2
  206. package/dist/tools/warp_grep/client.js +9 -5
  207. package/dist/tools/warp_grep/gemini.cjs +268 -52
  208. package/dist/tools/warp_grep/gemini.cjs.map +1 -1
  209. package/dist/tools/warp_grep/gemini.d.ts +2 -0
  210. package/dist/tools/warp_grep/gemini.js +9 -5
  211. package/dist/tools/warp_grep/gemini.js.map +1 -1
  212. package/dist/tools/warp_grep/harness.js +5 -5
  213. package/dist/tools/warp_grep/index.cjs +268 -52
  214. package/dist/tools/warp_grep/index.cjs.map +1 -1
  215. package/dist/tools/warp_grep/index.d.ts +2 -0
  216. package/dist/tools/warp_grep/index.js +12 -8
  217. package/dist/tools/warp_grep/openai.cjs +268 -52
  218. package/dist/tools/warp_grep/openai.cjs.map +1 -1
  219. package/dist/tools/warp_grep/openai.d.ts +2 -0
  220. package/dist/tools/warp_grep/openai.js +10 -6
  221. package/dist/tools/warp_grep/providers/local.js +2 -2
  222. package/dist/tools/warp_grep/vercel.cjs +268 -52
  223. package/dist/tools/warp_grep/vercel.cjs.map +1 -1
  224. package/dist/tools/warp_grep/vercel.d.ts +2 -0
  225. package/dist/tools/warp_grep/vercel.js +10 -6
  226. package/dist/version.cjs +7 -2
  227. package/dist/version.cjs.map +1 -1
  228. package/dist/version.js +1 -1
  229. package/package.json +7 -2
  230. package/dist/chunk-E5QWXVTF.js.map +0 -1
  231. package/dist/chunk-INBZD4EX.js +0 -197
  232. package/dist/chunk-INBZD4EX.js.map +0 -1
  233. package/dist/chunk-LAGN62H5.js.map +0 -1
  234. package/dist/chunk-LE66XCOI.js.map +0 -1
  235. package/dist/chunk-LNXIVRPY.js.map +0 -1
  236. package/dist/chunk-MKBVWPU7.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-VE7J6VYX.js +0 -102
  240. package/dist/chunk-VE7J6VYX.js.map +0 -1
  241. package/dist/chunk-YG2I377B.js.map +0 -1
  242. /package/dist/{chunk-IY7DESC3.js.map → chunk-2SNAXTUJ.js.map} +0 -0
  243. /package/dist/{chunk-5KFQBI4J.js.map → chunk-5DA6SZQJ.js.map} +0 -0
  244. /package/dist/{chunk-76XER44U.js.map → chunk-7PVVPLRL.js.map} +0 -0
  245. /package/dist/{chunk-BCPZAPWY.js.map → chunk-AE7M2I52.js.map} +0 -0
  246. /package/dist/{chunk-OJQYBWHR.js.map → chunk-ESXCQBMU.js.map} +0 -0
  247. /package/dist/{chunk-5IR3YE77.js.map → chunk-IJ33I7P5.js.map} +0 -0
  248. /package/dist/{chunk-6LPWEZ6H.js.map → chunk-MO6S2LRD.js.map} +0 -0
  249. /package/dist/{chunk-S4IEM5EG.js.map → chunk-NI7PWQ3B.js.map} +0 -0
  250. /package/dist/{chunk-GLQWEINZ.js.map → chunk-QAXXE4AD.js.map} +0 -0
  251. /package/dist/{chunk-G4FPDEUP.js.map → chunk-QQXNZIVK.js.map} +0 -0
  252. /package/dist/{chunk-A3ZUWLYX.js.map → chunk-QZ3V2BP7.js.map} +0 -0
  253. /package/dist/{chunk-SYD6BRQX.js.map → chunk-SJVLAGUL.js.map} +0 -0
  254. /package/dist/{chunk-JMEQ6FLB.js.map → chunk-U4J3BVAQ.js.map} +0 -0
  255. /package/dist/{chunk-QAWYDWDW.js.map → chunk-U4MRSZQQ.js.map} +0 -0
  256. /package/dist/{chunk-WU3D46MH.js.map → chunk-UADW6FYD.js.map} +0 -0
  257. /package/dist/{chunk-K7NY5SVR.js.map → chunk-VBARKJWL.js.map} +0 -0
  258. /package/dist/{chunk-OPNTDMHH.js.map → chunk-VLZ6PNAD.js.map} +0 -0
  259. /package/dist/{chunk-GUGHUAJU.js.map → chunk-XJDXV5VX.js.map} +0 -0
  260. /package/dist/{chunk-GPNUS3H2.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.170",
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(
@@ -424,11 +429,26 @@ async function callMorphAPI(originalCode, codeEdit, instructions, filepath, conf
424
429
  return { content, completionId: completion.id };
425
430
  } catch (error) {
426
431
  const elapsed = Date.now() - startTime;
432
+ const status = error?.status || error?.response?.status;
427
433
  logger.error("FastApply", "http_error", {
428
- status: error?.status || error?.response?.status,
434
+ status,
429
435
  error: error?.message,
430
436
  latency_ms: elapsed
431
437
  });
438
+ if (status === 401) {
439
+ const err = new Error(
440
+ "Authentication failed: Your Morph API key is invalid or has been revoked. Please visit https://morphllm.com to get a valid API key, then update your MCP configuration."
441
+ );
442
+ err.status = 401;
443
+ throw err;
444
+ }
445
+ if (status === 429) {
446
+ const err = new Error(
447
+ "Rate limited: You've exceeded your Morph API usage limits. Please visit https://morphllm.com to check your plan and purchase additional credits."
448
+ );
449
+ err.status = 429;
450
+ throw err;
451
+ }
432
452
  throw error;
433
453
  }
434
454
  }
@@ -463,7 +483,7 @@ async function applyEdit(input, config = {}) {
463
483
  };
464
484
  }
465
485
  }
466
- var import_diff, import_openai, DEFAULT_API_URL, DEFAULT_TIMEOUT;
486
+ var import_diff, import_openai, DEFAULT_API_URL, DEFAULT_TIMEOUT2;
467
487
  var init_apply = __esm({
468
488
  "tools/fastapply/apply.ts"() {
469
489
  "use strict";
@@ -472,7 +492,7 @@ var init_apply = __esm({
472
492
  init_version();
473
493
  init_logger();
474
494
  DEFAULT_API_URL = "https://api.morphllm.com";
475
- DEFAULT_TIMEOUT = 9e4;
495
+ DEFAULT_TIMEOUT2 = 9e4;
476
496
  }
477
497
  });
478
498
 
@@ -1066,6 +1086,7 @@ Details: ${res.stderr}` : ""}`
1066
1086
  // index.ts
1067
1087
  var index_exports = {};
1068
1088
  __export(index_exports, {
1089
+ APIResource: () => APIResource,
1069
1090
  AnthropicRouter: () => AnthropicRouter,
1070
1091
  AnthropicToolFactory: () => AnthropicToolFactory,
1071
1092
  BrowserClient: () => BrowserClient,
@@ -1076,6 +1097,7 @@ __export(index_exports, {
1076
1097
  GitHubClient: () => GitHubClient,
1077
1098
  GitHubError: () => GitHubError,
1078
1099
  LocalRipgrepProvider: () => LocalRipgrepProvider,
1100
+ MorphAPIClient: () => MorphAPIClient,
1079
1101
  MorphClient: () => MorphClient,
1080
1102
  MorphGit: () => MorphGit,
1081
1103
  NoInstallationError: () => NoInstallationError,
@@ -1084,6 +1106,8 @@ __export(index_exports, {
1084
1106
  OpenAIToolFactory: () => OpenAIToolFactory,
1085
1107
  PermissionError: () => PermissionError,
1086
1108
  RawRouter: () => RawRouter,
1109
+ ReflexClient: () => ReflexClient,
1110
+ ReflexJobsResource: () => ReflexJobsResource,
1087
1111
  SDK_VERSION: () => SDK_VERSION,
1088
1112
  VercelToolFactory: () => VercelToolFactory,
1089
1113
  WarpGrepClient: () => WarpGrepClient,
@@ -1092,12 +1116,228 @@ __export(index_exports, {
1092
1116
  module.exports = __toCommonJS(index_exports);
1093
1117
  init_version();
1094
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
+
1095
1325
  // client.ts
1096
1326
  init_logger();
1097
1327
 
1098
1328
  // tools/fastapply/core.ts
1099
1329
  var import_path = require("path");
1100
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
1101
1341
  init_apply();
1102
1342
  var DEFAULT_CONFIG = {
1103
1343
  morphApiUrl: "https://api.morphllm.com",
@@ -1107,15 +1347,24 @@ var DEFAULT_CONFIG = {
1107
1347
  timeout: 9e4,
1108
1348
  debug: false
1109
1349
  };
1110
- var FastApplyClient = class {
1350
+ var FastApplyClient = class extends APIResource {
1111
1351
  config;
1112
- 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
+ );
1113
1362
  this.config = {
1114
- morphApiKey: config.apiKey,
1115
- morphApiUrl: DEFAULT_CONFIG.morphApiUrl,
1116
- debug: config.debug,
1117
- timeout: config.timeout || DEFAULT_CONFIG.timeout,
1118
- 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,
1119
1368
  generateUdiff: DEFAULT_CONFIG.generateUdiff,
1120
1369
  autoWrite: DEFAULT_CONFIG.autoWrite
1121
1370
  };
@@ -1215,111 +1464,68 @@ async function executeEditFile(input, config = {}) {
1215
1464
  }
1216
1465
  }
1217
1466
 
1218
- // tools/utils/resilience.ts
1219
- init_version();
1220
- var DEFAULT_RETRY_CONFIG = {
1221
- maxRetries: 3,
1222
- initialDelay: 1e3,
1223
- maxDelay: 3e4,
1224
- backoffMultiplier: 2,
1225
- retryableErrors: ["ECONNREFUSED", "ETIMEDOUT", "ENOTFOUND"]
1226
- };
1227
- async function fetchWithRetry(url, options, retryConfig = {}) {
1228
- const {
1229
- maxRetries = DEFAULT_RETRY_CONFIG.maxRetries,
1230
- initialDelay = DEFAULT_RETRY_CONFIG.initialDelay,
1231
- maxDelay = DEFAULT_RETRY_CONFIG.maxDelay,
1232
- backoffMultiplier = DEFAULT_RETRY_CONFIG.backoffMultiplier,
1233
- retryableErrors = DEFAULT_RETRY_CONFIG.retryableErrors,
1234
- onRetry
1235
- } = retryConfig;
1236
- let lastError = null;
1237
- let delay = initialDelay;
1238
- options = { ...options, headers: { "X-Morph-SDK-Version": SDK_VERSION, ...options.headers } };
1239
- for (let attempt = 0; attempt <= maxRetries; attempt++) {
1240
- try {
1241
- const response = await fetch(url, options);
1242
- if (response.status === 429 || response.status === 503) {
1243
- if (attempt < maxRetries) {
1244
- const retryAfter = response.headers.get("Retry-After");
1245
- const waitTime = retryAfter ? parseInt(retryAfter) * 1e3 : Math.min(delay, maxDelay);
1246
- const error = new Error(`HTTP ${response.status}: Retrying after ${waitTime}ms`);
1247
- if (onRetry) {
1248
- onRetry(attempt + 1, error);
1249
- }
1250
- await sleep(waitTime);
1251
- delay *= backoffMultiplier;
1252
- 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
1253
1486
  }
1254
1487
  }
1255
- return response;
1256
- } catch (error) {
1257
- lastError = error;
1258
- const isRetryable = retryableErrors.some(
1259
- (errType) => lastError?.message?.includes(errType)
1260
- );
1261
- if (!isRetryable || attempt === maxRetries) {
1262
- throw lastError;
1263
- }
1264
- const waitTime = Math.min(delay, maxDelay);
1265
- if (onRetry) {
1266
- onRetry(attempt + 1, lastError);
1267
- }
1268
- await sleep(waitTime);
1269
- delay *= backoffMultiplier;
1270
- }
1271
- }
1272
- throw lastError || new Error("Max retries exceeded");
1273
- }
1274
- async function withTimeout(promise, timeoutMs, errorMessage) {
1275
- let timeoutId;
1276
- const timeoutPromise = new Promise((_, reject) => {
1277
- timeoutId = setTimeout(() => {
1278
- reject(new Error(errorMessage || `Operation timed out after ${timeoutMs}ms`));
1279
- }, timeoutMs);
1280
- });
1281
- try {
1282
- const result = await Promise.race([promise, timeoutPromise]);
1283
- clearTimeout(timeoutId);
1284
- 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
+ };
1285
1496
  } catch (error) {
1286
- clearTimeout(timeoutId);
1287
- 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 };
1288
1500
  }
1289
1501
  }
1290
- function sleep(ms) {
1291
- return new Promise((resolve2) => setTimeout(resolve2, ms));
1292
- }
1293
-
1294
- // tools/codebase_search/core.ts
1295
- init_logger();
1296
- var CodebaseSearchClient = class {
1297
- config;
1298
- constructor(config = {}) {
1299
- this.config = {
1300
- apiKey: config.apiKey,
1301
- searchUrl: process.env.MORPH_SEARCH_URL || "https://repos.morphllm.com",
1302
- debug: config.debug,
1303
- timeout: config.timeout || 3e4,
1304
- retryConfig: config.retryConfig
1305
- };
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;
1306
1514
  }
1307
1515
  /**
1308
1516
  * Execute a semantic code search
1309
- *
1517
+ *
1310
1518
  * @param input - Search parameters including query, repoId, and target directories
1311
1519
  * @param overrides - Optional config overrides for this operation
1312
1520
  * @returns Search results with ranked code matches
1313
1521
  */
1314
1522
  async search(input, overrides) {
1315
- return executeCodebaseSearch(
1316
- {
1317
- query: input.query,
1318
- target_directories: input.target_directories,
1319
- explanation: input.explanation,
1320
- limit: input.limit
1321
- },
1322
- { ...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
1323
1529
  );
1324
1530
  }
1325
1531
  };
@@ -1328,57 +1534,14 @@ async function executeCodebaseSearch(input, config) {
1328
1534
  if (!apiKey) {
1329
1535
  throw new Error("MORPH_API_KEY not found. Set environment variable or pass in config");
1330
1536
  }
1331
- const searchUrl = config.searchUrl || process.env.MORPH_SEARCH_URL || "https://repos.morphllm.com";
1332
- const timeout = config.timeout || 3e4;
1333
- logger.debug("CodebaseSearch", "request", { query: input.query.slice(0, 100), repo_id: config.repoId, url: `${searchUrl}/v1/codebase_search` });
1334
- const startTime = Date.now();
1335
- try {
1336
- const fetchPromise = fetchWithRetry(
1337
- `${searchUrl}/v1/codebase_search`,
1338
- {
1339
- method: "POST",
1340
- headers: {
1341
- "Content-Type": "application/json",
1342
- "Authorization": `Bearer ${apiKey}`
1343
- },
1344
- body: JSON.stringify({
1345
- query: input.query,
1346
- repoId: config.repoId,
1347
- targetDirectories: input.target_directories || [],
1348
- limit: input.limit || 10,
1349
- candidateLimit: 50
1350
- })
1351
- },
1352
- config.retryConfig
1353
- );
1354
- const response = await withTimeout(fetchPromise, timeout, `Codebase search timed out after ${timeout}ms`);
1355
- if (!response.ok) {
1356
- const errorText = await response.text();
1357
- logger.error("CodebaseSearch", "response_error", { status: response.status, error: errorText, latency_ms: Date.now() - startTime });
1358
- return {
1359
- success: false,
1360
- results: [],
1361
- stats: { totalResults: 0, candidatesRetrieved: 0, searchTimeMs: 0 },
1362
- error: `Search failed (${response.status}): ${errorText}`
1363
- };
1364
- }
1365
- const data = await response.json();
1366
- const elapsed = Date.now() - startTime;
1367
- logger.debug("CodebaseSearch", "response", { results_count: data.results?.length || 0, latency_ms: elapsed });
1368
- return {
1369
- success: true,
1370
- results: data.results || [],
1371
- stats: data.stats || { totalResults: 0, candidatesRetrieved: 0, searchTimeMs: elapsed }
1372
- };
1373
- } catch (error) {
1374
- logger.error("CodebaseSearch", "exception", { error: error instanceof Error ? error.message : String(error), latency_ms: Date.now() - startTime });
1375
- return {
1376
- success: false,
1377
- results: [],
1378
- stats: { totalResults: 0, candidatesRetrieved: 0, searchTimeMs: 0 },
1379
- error: error instanceof Error ? error.message : "Unknown error"
1380
- };
1381
- }
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);
1382
1545
  }
1383
1546
 
1384
1547
  // tools/browser/core.ts
@@ -1483,7 +1646,7 @@ function resolvePreset(optionsOrPreset) {
1483
1646
  }
1484
1647
 
1485
1648
  // tools/browser/errors.ts
1486
- var MorphError = class extends Error {
1649
+ var MorphError2 = class extends Error {
1487
1650
  /** Error code for programmatic handling */
1488
1651
  code;
1489
1652
  /** Original cause of the error, if any */
@@ -1509,7 +1672,7 @@ var MorphError = class extends Error {
1509
1672
  };
1510
1673
  }
1511
1674
  };
1512
- var MorphValidationError = class extends MorphError {
1675
+ var MorphValidationError = class extends MorphError2 {
1513
1676
  /** The field that failed validation */
1514
1677
  field;
1515
1678
  constructor(message, field) {
@@ -1524,7 +1687,7 @@ var MorphValidationError = class extends MorphError {
1524
1687
  };
1525
1688
  }
1526
1689
  };
1527
- var MorphAPIError = class extends MorphError {
1690
+ var MorphAPIError = class extends MorphError2 {
1528
1691
  /** HTTP status code */
1529
1692
  statusCode;
1530
1693
  /** Request ID for debugging (if available) */
@@ -2053,17 +2216,30 @@ var DEFAULT_CONFIG2 = {
2053
2216
  // 10 minutes for complex tasks
2054
2217
  debug: false
2055
2218
  };
2056
- var BrowserClient = class {
2219
+ var BrowserClient = class extends APIResource {
2057
2220
  config;
2058
2221
  /**
2059
2222
  * Profile management - create and manage browser profiles for storing login state.
2060
2223
  */
2061
2224
  profiles;
2062
- constructor(config = {}) {
2063
- 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 ? {
2064
2237
  ...DEFAULT_CONFIG2,
2065
- ...config
2066
- };
2238
+ apiUrl: clientOrConfig.browserURL,
2239
+ apiKey: clientOrConfig.resolveApiKey(),
2240
+ retryConfig: clientOrConfig.retryConfig,
2241
+ debug: clientOrConfig.debug
2242
+ } : { ...DEFAULT_CONFIG2, ...clientOrConfig };
2067
2243
  this.profiles = new ProfilesClient(this.config);
2068
2244
  }
2069
2245
  /**
@@ -3585,14 +3761,27 @@ function parseGitHubUrl(input) {
3585
3761
 
3586
3762
  // tools/compact/core.ts
3587
3763
  var DEFAULT_API_URL4 = "https://api.morphllm.com";
3588
- var DEFAULT_TIMEOUT2 = 12e4;
3589
- 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. */
3590
3777
  config;
3591
- constructor(config = {}) {
3778
+ constructor(clientOrConfig = {}) {
3779
+ super(resolveClient(clientOrConfig));
3780
+ const cfg = clientOrConfig instanceof MorphAPIClient ? {} : clientOrConfig;
3592
3781
  this.config = {
3593
- ...config,
3594
- morphApiUrl: config.morphApiUrl ?? DEFAULT_API_URL4,
3595
- timeout: config.timeout ?? DEFAULT_TIMEOUT2
3782
+ morphApiUrl: this._client.baseURL,
3783
+ timeout: cfg.timeout ?? DEFAULT_TIMEOUT4,
3784
+ debug: cfg.debug ?? false
3596
3785
  };
3597
3786
  }
3598
3787
  /**
@@ -3611,17 +3800,6 @@ var CompactClient = class {
3611
3800
  * ```
3612
3801
  */
3613
3802
  async compact(input) {
3614
- const apiKey = this.config.morphApiKey || (typeof process !== "undefined" ? process.env?.MORPH_API_KEY : void 0);
3615
- const debug = this.config.debug || false;
3616
- if (!apiKey) {
3617
- throw new Error(
3618
- "Morph API key not found. Set MORPH_API_KEY environment variable or pass morphApiKey in config."
3619
- );
3620
- }
3621
- const url = `${this.config.morphApiUrl}/v1/compact`;
3622
- if (debug) {
3623
- console.log(`[Compact] Calling ${url}`);
3624
- }
3625
3803
  const body = {
3626
3804
  compression_ratio: input.compressionRatio ?? 0.5,
3627
3805
  preserve_recent: input.preserveRecent ?? 2,
@@ -3629,37 +3807,19 @@ var CompactClient = class {
3629
3807
  include_line_ranges: input.includeLineRanges ?? true,
3630
3808
  include_markers: input.includeMarkers ?? true
3631
3809
  };
3632
- if (input.query !== void 0) {
3633
- body.query = input.query;
3634
- }
3635
- if (input.messages) {
3636
- body.messages = input.messages;
3637
- } else if (typeof input.input === "string") {
3638
- body.input = input.input;
3639
- } else if (Array.isArray(input.input)) {
3640
- body.messages = input.input;
3641
- } else {
3642
- throw new Error("Either 'input' or 'messages' must be provided");
3643
- }
3644
- const startTime = Date.now();
3645
- const response = await fetch(url, {
3646
- method: "POST",
3647
- headers: {
3648
- "Authorization": `Bearer ${apiKey}`,
3649
- "Content-Type": "application/json"
3650
- },
3651
- body: JSON.stringify(body),
3652
- signal: AbortSignal.timeout(this.config.timeout)
3653
- });
3654
- if (!response.ok) {
3655
- const text = await response.text();
3656
- throw new Error(`Compact API error ${response.status}: ${text}`);
3657
- }
3658
- const data = await response.json();
3659
- if (debug) {
3660
- 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;
3661
3822
  }
3662
- return data;
3663
3823
  }
3664
3824
  };
3665
3825
 
@@ -3715,10 +3875,28 @@ async function getLocalProvider(repoRoot, excludes, allowNames) {
3715
3875
  const opts = allowNames?.length ? { allowNames } : void 0;
3716
3876
  return new LocalRipgrepProvider2(repoRoot, excludes, opts);
3717
3877
  }
3718
- var WarpGrepClient = class {
3878
+ var WarpGrepClient = class extends APIResource {
3719
3879
  config;
3720
- constructor(config = {}) {
3721
- 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
+ };
3722
3900
  }
3723
3901
  execute(input) {
3724
3902
  const toolConfig = {
@@ -3992,11 +4170,9 @@ var PermissionError = class extends GitHubError {
3992
4170
  };
3993
4171
 
3994
4172
  // tools/github/core.ts
3995
- var DEFAULT_BASE_URL = "https://api.morphllm.com";
3996
- var DEFAULT_TIMEOUT3 = 3e4;
3997
- var GitHubClient = class {
3998
- apiKey;
3999
- baseUrl;
4173
+ var DEFAULT_BASE_URL2 = "https://api.morphllm.com";
4174
+ var DEFAULT_TIMEOUT5 = 3e4;
4175
+ var GitHubClient = class extends APIResource {
4000
4176
  timeout;
4001
4177
  debug;
4002
4178
  defaultInstallationId;
@@ -4021,13 +4197,21 @@ var GitHubClient = class {
4021
4197
  getInstallUrl() {
4022
4198
  return "https://github.com/apps/morph-subagents/installations/new";
4023
4199
  }
4024
- constructor(config = {}) {
4025
- this.apiKey = config.apiKey || process.env.MORPH_API_KEY || "";
4026
- this.baseUrl = config.baseUrl || DEFAULT_BASE_URL;
4027
- 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;
4028
4212
  this.debug = config.debug || false;
4029
- this.defaultInstallationId = config.installationId;
4030
- if (!this.apiKey) {
4213
+ this.defaultInstallationId = isClient ? options.installationId : config.installationId;
4214
+ if (!this._client.resolveApiKey()) {
4031
4215
  throw new Error("API key required. Set MORPH_API_KEY or pass apiKey in config.");
4032
4216
  }
4033
4217
  this.installations = {
@@ -4071,59 +4255,44 @@ var GitHubClient = class {
4071
4255
  * Make an authenticated API request
4072
4256
  */
4073
4257
  async request(method, path6, body) {
4074
- const url = `${this.baseUrl}${path6}`;
4075
4258
  if (this.debug) {
4076
4259
  console.log(`[GitHub SDK] ${method} ${path6}`, body || "");
4077
4260
  }
4078
- const controller = new AbortController();
4079
- const timeoutId = setTimeout(() => controller.abort(), this.timeout);
4261
+ let response;
4080
4262
  try {
4081
- const response = await fetch(url, {
4082
- method,
4083
- headers: {
4084
- "Content-Type": "application/json",
4085
- Authorization: `Bearer ${this.apiKey}`
4086
- },
4087
- body: body ? JSON.stringify(body) : void 0,
4088
- signal: controller.signal
4263
+ response = await this._client.request(method, path6, {
4264
+ body,
4265
+ timeout: this.timeout,
4266
+ raw: true
4089
4267
  });
4090
- clearTimeout(timeoutId);
4091
- if (!response.ok) {
4092
- const errorData = await response.json().catch(() => ({}));
4093
- const message = errorData.error || errorData.detail || errorData.message || response.statusText;
4094
- if (this.debug) {
4095
- console.error(`[GitHub SDK] Error ${response.status}:`, message);
4096
- }
4097
- if (response.status === 404) {
4098
- if (message.includes("installation")) {
4099
- throw new NoInstallationError(message);
4100
- }
4101
- throw new NotFoundError(message);
4102
- }
4103
- if (response.status === 403) {
4104
- throw new PermissionError(message);
4105
- }
4106
- 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");
4107
4271
  }
4108
- 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;
4109
4277
  if (this.debug) {
4110
- console.log(`[GitHub SDK] Response:`, JSON.stringify(data).slice(0, 200));
4278
+ console.error(`[GitHub SDK] Error ${response.status}:`, message);
4111
4279
  }
4112
- return data;
4113
- } catch (error) {
4114
- clearTimeout(timeoutId);
4115
- if (error instanceof GitHubError) {
4116
- throw error;
4280
+ if (response.status === 404) {
4281
+ if (message.includes("installation")) {
4282
+ throw new NoInstallationError(message);
4283
+ }
4284
+ throw new NotFoundError(message);
4117
4285
  }
4118
- if (error instanceof Error && error.name === "AbortError") {
4119
- throw new GitHubError("Request timeout", 408, "TIMEOUT");
4286
+ if (response.status === 403) {
4287
+ throw new PermissionError(message);
4120
4288
  }
4121
- throw new GitHubError(
4122
- error instanceof Error ? error.message : "Unknown error",
4123
- 500,
4124
- "UNKNOWN"
4125
- );
4289
+ throw new GitHubError(message, response.status, errorData.code);
4290
+ }
4291
+ const data = await response.json();
4292
+ if (this.debug) {
4293
+ console.log(`[GitHub SDK] Response:`, JSON.stringify(data).slice(0, 200));
4126
4294
  }
4295
+ return data;
4127
4296
  }
4128
4297
  /**
4129
4298
  * Get the installation ID to use for a request
@@ -4317,18 +4486,28 @@ var import_isomorphic_git = __toESM(require("isomorphic-git"), 1);
4317
4486
  var import_node = __toESM(require("isomorphic-git/http/node"), 1);
4318
4487
  var import_fs2 = __toESM(require("fs"), 1);
4319
4488
  var DEFAULT_PROXY_URL = "https://repos.morphllm.com";
4320
- var MorphGit = class {
4489
+ var MorphGit = class extends APIResource {
4321
4490
  apiKey;
4322
4491
  proxyUrl;
4323
- constructor(config) {
4324
- if (!config.apiKey) {
4325
- throw new Error("API key is required. Get one at https://morphllm.com/dashboard");
4326
- }
4327
- if (!config.apiKey.startsWith("sk-") && !config.apiKey.startsWith("morph-")) {
4328
- 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
+ }
4329
4501
  }
4330
- this.apiKey = config.apiKey;
4331
- 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;
4332
4511
  }
4333
4512
  /**
4334
4513
  * Get auth callback for isomorphic-git operations
@@ -4856,87 +5035,212 @@ var MorphGit = class {
4856
5035
  var import_isomorphic_git2 = __toESM(require("isomorphic-git"), 1);
4857
5036
  var import_node2 = __toESM(require("isomorphic-git/http/node"), 1);
4858
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
+
4859
5181
  // modelrouter/core.ts
4860
5182
  init_logger();
4861
- var DEFAULT_CONFIG3 = {
4862
- apiUrl: "https://api.morphllm.com",
4863
- timeout: 5e3,
4864
- // 5 seconds (responses typically <500ms)
4865
- debug: false
4866
- };
4867
- var BaseRouter = class {
4868
- 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 {
4869
5196
  provider;
4870
- constructor(provider, config = {}) {
5197
+ timeout;
5198
+ constructor(provider, clientOrConfig = {}) {
5199
+ super(resolveClient3(clientOrConfig));
4871
5200
  this.provider = provider;
4872
- this.config = {
4873
- apiKey: config.apiKey,
4874
- apiUrl: config.apiUrl || DEFAULT_CONFIG3.apiUrl,
4875
- timeout: config.timeout || DEFAULT_CONFIG3.timeout,
4876
- debug: config.debug || DEFAULT_CONFIG3.debug,
4877
- retryConfig: config.retryConfig
4878
- };
5201
+ const cfg = clientOrConfig instanceof MorphAPIClient ? {} : clientOrConfig;
5202
+ this.timeout = cfg.timeout ?? DEFAULT_TIMEOUT6;
4879
5203
  }
4880
- /**
4881
- * Select the optimal model for a given input and mode
4882
- */
4883
- async selectModel(input) {
4884
- const mode = input.mode || "balanced";
4885
- const apiKey = this.config.apiKey || (typeof process !== "undefined" ? process.env?.MORPH_API_KEY : void 0);
4886
- if (!apiKey) {
5204
+ /** Throw the historical "API key is required" message when no key is resolvable. */
5205
+ requireApiKey() {
5206
+ if (!this._client.resolveApiKey()) {
4887
5207
  throw new Error(
4888
5208
  "Morph API key is required. Set MORPH_API_KEY environment variable or pass apiKey in config."
4889
5209
  );
4890
5210
  }
4891
- const url = `${this.config.apiUrl}/v1/router/${this.provider}`;
4892
- const payload = {
4893
- input: input.input,
4894
- mode
4895
- };
4896
- 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) {
4897
5214
  try {
4898
- const fetchPromise = fetchWithRetry(
4899
- url,
4900
- {
4901
- method: "POST",
4902
- headers: {
4903
- "Content-Type": "application/json",
4904
- Authorization: `Bearer ${apiKey}`
4905
- },
4906
- body: JSON.stringify(payload)
4907
- },
4908
- this.config.retryConfig
4909
- );
4910
- const response = await withTimeout(
4911
- fetchPromise,
4912
- this.config.timeout,
4913
- `Router API request timed out after ${this.config.timeout}ms`
4914
- );
4915
- if (!response.ok) {
4916
- const errorText = await response.text();
4917
- throw new Error(
4918
- `Router API error (${response.status}): ${errorText || response.statusText}`
4919
- );
4920
- }
4921
- const apiResult = await response.json();
4922
- const result = {
4923
- model: apiResult.model
4924
- };
4925
- logger.debug("ModelRouter", "selected", { provider: this.provider, model: apiResult.model, confidence: apiResult.confidence });
4926
- 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
+ });
4927
5219
  } catch (error) {
4928
- 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
+ }
4929
5223
  throw error;
4930
5224
  }
4931
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
+ }
4932
5236
  };
4933
5237
  var OpenAIRouter = class extends BaseRouter {
4934
- constructor(config = {}) {
4935
- super("openai", config);
5238
+ constructor(clientOrConfig = {}) {
5239
+ super("openai", clientOrConfig);
4936
5240
  }
4937
5241
  /**
4938
5242
  * Select optimal GPT-5 model
4939
- *
5243
+ *
4940
5244
  * @param input - User input and mode
4941
5245
  * @returns Selected model name (gpt-5-mini | gpt-5-low | gpt-5-medium | gpt-5-high)
4942
5246
  */
@@ -4945,12 +5249,12 @@ var OpenAIRouter = class extends BaseRouter {
4945
5249
  }
4946
5250
  };
4947
5251
  var AnthropicRouter = class extends BaseRouter {
4948
- constructor(config = {}) {
4949
- super("anthropic", config);
5252
+ constructor(clientOrConfig = {}) {
5253
+ super("anthropic", clientOrConfig);
4950
5254
  }
4951
5255
  /**
4952
5256
  * Select optimal Claude model
4953
- *
5257
+ *
4954
5258
  * @param input - User input and mode
4955
5259
  * @returns Selected model name (claude-4.5-haiku | claude-4.5-sonnet)
4956
5260
  */
@@ -4959,12 +5263,12 @@ var AnthropicRouter = class extends BaseRouter {
4959
5263
  }
4960
5264
  };
4961
5265
  var GeminiRouter = class extends BaseRouter {
4962
- constructor(config = {}) {
4963
- super("gemini", config);
5266
+ constructor(clientOrConfig = {}) {
5267
+ super("gemini", clientOrConfig);
4964
5268
  }
4965
5269
  /**
4966
5270
  * Select optimal Gemini model
4967
- *
5271
+ *
4968
5272
  * @param input - User input and mode
4969
5273
  * @returns Selected model name (gemini-2.5-flash | gemini-2.5-pro)
4970
5274
  */
@@ -4973,69 +5277,27 @@ var GeminiRouter = class extends BaseRouter {
4973
5277
  }
4974
5278
  };
4975
5279
  var RawRouter = class extends BaseRouter {
4976
- constructor(config = {}) {
4977
- super("raw", config);
5280
+ constructor(clientOrConfig = {}) {
5281
+ super("raw", clientOrConfig);
4978
5282
  }
4979
5283
  /**
4980
5284
  * Get raw difficulty classification
4981
- *
5285
+ *
4982
5286
  * @param input - User input and mode
4983
5287
  * @returns Raw difficulty (easy | medium | hard | needs_info)
4984
5288
  */
4985
5289
  async classify(input) {
4986
- const mode = input.mode || "balanced";
4987
- const apiKey = this.config.apiKey || (typeof process !== "undefined" ? process.env?.MORPH_API_KEY : void 0);
4988
- if (!apiKey) {
4989
- throw new Error(
4990
- "Morph API key is required. Set MORPH_API_KEY environment variable or pass apiKey in config."
4991
- );
4992
- }
4993
- const url = `${this.config.apiUrl}/v1/router/raw`;
4994
- const payload = {
4995
- input: input.input,
4996
- mode
4997
- };
4998
- logger.debug("RawRouter", "request", { mode, input_len: input.input.length, url });
4999
- try {
5000
- const fetchPromise = fetchWithRetry(
5001
- url,
5002
- {
5003
- method: "POST",
5004
- headers: {
5005
- "Content-Type": "application/json",
5006
- Authorization: `Bearer ${apiKey}`
5007
- },
5008
- body: JSON.stringify(payload)
5009
- },
5010
- this.config.retryConfig
5011
- );
5012
- const response = await withTimeout(
5013
- fetchPromise,
5014
- this.config.timeout,
5015
- `Router API request timed out after ${this.config.timeout}ms`
5016
- );
5017
- if (!response.ok) {
5018
- const errorText = await response.text();
5019
- throw new Error(
5020
- `Router API error (${response.status}): ${errorText || response.statusText}`
5021
- );
5022
- }
5023
- const apiResult = await response.json();
5024
- let difficulty;
5025
- if (apiResult.difficulty === "") {
5026
- difficulty = "medium";
5027
- } else {
5028
- difficulty = apiResult.difficulty || apiResult.model;
5029
- }
5030
- const result = {
5031
- difficulty
5032
- };
5033
- logger.debug("RawRouter", "classified", { difficulty });
5034
- return result;
5035
- } catch (error) {
5036
- logger.error("RawRouter", "error", { error: error instanceof Error ? error.message : String(error) });
5037
- 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;
5038
5298
  }
5299
+ logger.debug("RawRouter", "classified", { difficulty });
5300
+ return { difficulty };
5039
5301
  }
5040
5302
  };
5041
5303
 
@@ -6418,7 +6680,7 @@ var VercelToolFactory = class {
6418
6680
  };
6419
6681
 
6420
6682
  // client.ts
6421
- var MorphClient = class {
6683
+ var MorphClient = class extends MorphAPIClient {
6422
6684
  /** Client configuration */
6423
6685
  config;
6424
6686
  /** FastApply tool for editing files with AI-powered merge */
@@ -6443,6 +6705,8 @@ var MorphClient = class {
6443
6705
  vercel;
6444
6706
  /** Compact context with line ranges */
6445
6707
  compact;
6708
+ /** Reflex: train and serve small text classifiers */
6709
+ reflex;
6446
6710
  /**
6447
6711
  * Create a new Morph SDK client
6448
6712
  *
@@ -6458,78 +6722,32 @@ var MorphClient = class {
6458
6722
  * ```
6459
6723
  */
6460
6724
  constructor(config = {}) {
6461
- this.config = config;
6462
- if (config.debug) {
6463
- logger.enable();
6464
- }
6465
- logger.debug("MorphClient", "initialized", { debug: !!config.debug, timeout: config.timeout });
6466
- this.fastApply = new FastApplyClient({
6467
- apiKey: config.apiKey,
6468
- debug: config.debug,
6469
- timeout: config.timeout,
6470
- retryConfig: config.retryConfig
6471
- });
6472
- this.codebaseSearch = new CodebaseSearchClient({
6473
- apiKey: config.apiKey,
6474
- debug: config.debug,
6475
- timeout: config.timeout,
6476
- retryConfig: config.retryConfig
6477
- });
6478
- this.warpGrep = new WarpGrepClient({
6479
- morphApiKey: config.apiKey,
6480
- debug: config.debug,
6481
- timeout: config.timeout,
6482
- retryConfig: config.retryConfig
6483
- });
6484
- this.browser = new BrowserClient({
6485
- apiKey: config.apiKey,
6486
- debug: config.debug,
6487
- timeout: config.timeout,
6488
- retryConfig: config.retryConfig
6489
- });
6490
- this.github = new GitHubClient({
6491
- apiKey: config.apiKey,
6492
- debug: config.debug,
6493
- timeout: config.timeout,
6494
- installationId: config.github?.installationId
6495
- });
6496
- this.git = new MorphGit({
6725
+ super({
6497
6726
  apiKey: config.apiKey,
6498
- retryConfig: config.retryConfig
6499
- });
6500
- this.routers = {
6501
- openai: new OpenAIRouter({
6502
- apiKey: config.apiKey,
6503
- debug: config.debug,
6504
- timeout: config.timeout,
6505
- retryConfig: config.retryConfig
6506
- }),
6507
- anthropic: new AnthropicRouter({
6508
- apiKey: config.apiKey,
6509
- debug: config.debug,
6510
- timeout: config.timeout,
6511
- retryConfig: config.retryConfig
6512
- }),
6513
- gemini: new GeminiRouter({
6514
- apiKey: config.apiKey,
6515
- debug: config.debug,
6516
- timeout: config.timeout,
6517
- retryConfig: config.retryConfig
6518
- }),
6519
- raw: new RawRouter({
6520
- apiKey: config.apiKey,
6521
- debug: config.debug,
6522
- timeout: config.timeout,
6523
- retryConfig: config.retryConfig
6524
- })
6525
- };
6526
- const compactClient = new CompactClient({
6527
- morphApiKey: config.apiKey,
6528
6727
  timeout: config.timeout,
6529
6728
  retryConfig: config.retryConfig,
6530
6729
  debug: config.debug
6531
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);
6532
6749
  this.compact = compactClient.compact.bind(compactClient);
6750
+ this.reflex = new ReflexClient(this);
6533
6751
  this.openai = new OpenAIToolFactory(config);
6534
6752
  this.anthropic = new AnthropicToolFactory(config);
6535
6753
  this.vercel = new VercelToolFactory(config);
@@ -6573,6 +6791,7 @@ var warpGrepInputSchema = import_zod5.z.object({
6573
6791
  });
6574
6792
  // Annotate the CommonJS export names for ESM import in node:
6575
6793
  0 && (module.exports = {
6794
+ APIResource,
6576
6795
  AnthropicRouter,
6577
6796
  AnthropicToolFactory,
6578
6797
  BrowserClient,
@@ -6583,6 +6802,7 @@ var warpGrepInputSchema = import_zod5.z.object({
6583
6802
  GitHubClient,
6584
6803
  GitHubError,
6585
6804
  LocalRipgrepProvider,
6805
+ MorphAPIClient,
6586
6806
  MorphClient,
6587
6807
  MorphGit,
6588
6808
  NoInstallationError,
@@ -6591,6 +6811,8 @@ var warpGrepInputSchema = import_zod5.z.object({
6591
6811
  OpenAIToolFactory,
6592
6812
  PermissionError,
6593
6813
  RawRouter,
6814
+ ReflexClient,
6815
+ ReflexJobsResource,
6594
6816
  SDK_VERSION,
6595
6817
  VercelToolFactory,
6596
6818
  WarpGrepClient,