@morphllm/morphsdk 0.2.197 → 0.2.199
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.
- package/README.md +1 -147
- package/dist/{chunk-GE5MNVT7.js → chunk-5KQ2WRBU.js} +2 -2
- package/dist/{chunk-LKFZBBTD.js → chunk-5TOJD2C5.js} +1 -1
- package/dist/chunk-5TOJD2C5.js.map +1 -0
- package/dist/{chunk-PQCOBN7L.js → chunk-7UU4NF4G.js} +4 -10
- package/dist/chunk-7UU4NF4G.js.map +1 -0
- package/dist/{chunk-6YZCPCAY.js → chunk-BLCCGRKT.js} +2 -2
- package/dist/{chunk-2BT4UGKH.js → chunk-BTMMUG3E.js} +2 -2
- package/dist/{chunk-VJD6MF3M.js → chunk-CEXBKXWU.js} +4 -4
- package/dist/{chunk-UOS3XKJD.js → chunk-DP2PT36G.js} +2 -2
- package/dist/{chunk-CZ74CRGH.js → chunk-EMURAU6J.js} +4 -6
- package/dist/chunk-EMURAU6J.js.map +1 -0
- package/dist/chunk-GKRPR5PZ.js +322 -0
- package/dist/chunk-GKRPR5PZ.js.map +1 -0
- package/dist/{chunk-DNL4DMMS.js → chunk-GTV27THY.js} +2 -2
- package/dist/{chunk-ATAKRJQZ.js → chunk-IDMKQWQG.js} +1 -36
- package/dist/chunk-IDMKQWQG.js.map +1 -0
- package/dist/{chunk-EGI642TV.js → chunk-JOC3ZI56.js} +3 -39
- package/dist/chunk-JOC3ZI56.js.map +1 -0
- package/dist/{chunk-VGCPVDFP.js → chunk-K2JR2NFQ.js} +4 -4
- package/dist/{chunk-DHGXGVHC.js → chunk-KXEPBLVD.js} +8 -8
- package/dist/{chunk-SVD3YRWM.js → chunk-MEZTHMB2.js} +4 -4
- package/dist/{chunk-BECYWCEZ.js → chunk-O7LJEVZO.js} +2 -2
- package/dist/{chunk-7QOGUY4A.js → chunk-PKJ7ODTG.js} +4 -4
- package/dist/{chunk-2HXELZI5.js → chunk-PW6K6OJL.js} +2 -2
- package/dist/chunk-PW6K6OJL.js.map +1 -0
- package/dist/{chunk-YVKRPVOM.js → chunk-Q3NH3NPD.js} +2 -2
- package/dist/{chunk-ZA3UJRSE.js → chunk-RL3ZTXT3.js} +4 -4
- package/dist/{chunk-WN6YLBEH.js → chunk-ULHHMZRL.js} +4 -4
- package/dist/{chunk-TJUZAO7T.js → chunk-UT3NQLCF.js} +2 -2
- package/dist/{chunk-DW6ZIVCM.js → chunk-VS5F2ORN.js} +4 -4
- package/dist/{chunk-UZA2ODNU.js → chunk-W37OFBSG.js} +2 -2
- package/dist/{chunk-JU6TCHVI.js → chunk-WDBYAXZ5.js} +2 -2
- package/dist/{chunk-2XDSHAB5.js → chunk-YSFEKIYQ.js} +2 -2
- package/dist/{chunk-WDLDKJHT.js → chunk-ZHB57ORD.js} +6 -6
- package/dist/client-CGW0Cevz.d.ts +402 -0
- package/dist/client.cjs +195 -2068
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.ts +3 -11
- package/dist/client.js +28 -35
- package/dist/core/client.cjs +2 -44
- package/dist/core/client.cjs.map +1 -1
- package/dist/core/client.d.ts +2 -10
- package/dist/core/client.js +4 -4
- package/dist/core/error.cjs +2 -38
- package/dist/core/error.cjs.map +1 -1
- package/dist/core/error.d.ts +1 -1
- package/dist/core/error.js +3 -3
- package/dist/core/index.cjs +2 -44
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.js +5 -5
- package/dist/core/resource.cjs.map +1 -1
- package/dist/core/resource.d.ts +1 -1
- package/dist/core/resource.js +1 -1
- package/dist/edge.cjs +2 -44
- package/dist/edge.cjs.map +1 -1
- package/dist/edge.js +8 -8
- package/dist/index.cjs +195 -2086
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -9
- package/dist/index.js +30 -58
- package/dist/modelrouter/core.cjs +2 -44
- package/dist/modelrouter/core.cjs.map +1 -1
- package/dist/modelrouter/core.js +6 -6
- package/dist/modelrouter/index.cjs +2 -44
- package/dist/modelrouter/index.cjs.map +1 -1
- package/dist/modelrouter/index.js +6 -6
- package/dist/subagents/anthropic.cjs +2 -44
- package/dist/subagents/anthropic.cjs.map +1 -1
- package/dist/subagents/anthropic.js +12 -12
- package/dist/subagents/vercel.cjs +2 -44
- package/dist/subagents/vercel.cjs.map +1 -1
- package/dist/subagents/vercel.js +12 -12
- package/dist/tools/codebase_search/anthropic.cjs +2 -44
- package/dist/tools/codebase_search/anthropic.cjs.map +1 -1
- package/dist/tools/codebase_search/anthropic.js +7 -7
- package/dist/tools/codebase_search/core.cjs +2 -44
- package/dist/tools/codebase_search/core.cjs.map +1 -1
- package/dist/tools/codebase_search/core.js +6 -6
- package/dist/tools/codebase_search/index.cjs +2 -44
- package/dist/tools/codebase_search/index.cjs.map +1 -1
- package/dist/tools/codebase_search/index.js +11 -11
- package/dist/tools/codebase_search/openai.cjs +2 -44
- package/dist/tools/codebase_search/openai.cjs.map +1 -1
- package/dist/tools/codebase_search/openai.js +7 -7
- package/dist/tools/codebase_search/vercel.cjs +2 -44
- package/dist/tools/codebase_search/vercel.cjs.map +1 -1
- package/dist/tools/codebase_search/vercel.js +7 -7
- package/dist/tools/compact/core.cjs +2 -44
- package/dist/tools/compact/core.cjs.map +1 -1
- package/dist/tools/compact/core.js +6 -6
- package/dist/tools/compact/index.cjs +2 -44
- package/dist/tools/compact/index.cjs.map +1 -1
- package/dist/tools/compact/index.js +7 -7
- package/dist/tools/fastapply/anthropic.cjs +2 -38
- package/dist/tools/fastapply/anthropic.cjs.map +1 -1
- package/dist/tools/fastapply/anthropic.js +8 -8
- package/dist/tools/fastapply/apply.cjs +2 -38
- package/dist/tools/fastapply/apply.cjs.map +1 -1
- package/dist/tools/fastapply/apply.js +2 -2
- package/dist/tools/fastapply/core.cjs +2 -44
- package/dist/tools/fastapply/core.cjs.map +1 -1
- package/dist/tools/fastapply/core.js +7 -7
- package/dist/tools/fastapply/index.cjs +2 -38
- package/dist/tools/fastapply/index.cjs.map +1 -1
- package/dist/tools/fastapply/index.js +12 -12
- package/dist/tools/fastapply/openai.cjs +2 -38
- package/dist/tools/fastapply/openai.cjs.map +1 -1
- package/dist/tools/fastapply/openai.js +8 -8
- package/dist/tools/fastapply/vercel.cjs +2 -38
- package/dist/tools/fastapply/vercel.cjs.map +1 -1
- package/dist/tools/fastapply/vercel.js +8 -8
- package/dist/tools/index.cjs +2 -38
- package/dist/tools/index.cjs.map +1 -1
- package/dist/tools/index.js +12 -12
- package/dist/tools/utils/resilience.cjs +2 -38
- package/dist/tools/utils/resilience.cjs.map +1 -1
- package/dist/tools/utils/resilience.js +2 -2
- package/dist/tools/warp_grep/agent/runner.cjs +2 -38
- package/dist/tools/warp_grep/agent/runner.cjs.map +1 -1
- package/dist/tools/warp_grep/agent/runner.js +3 -3
- package/dist/tools/warp_grep/anthropic.cjs +2 -44
- package/dist/tools/warp_grep/anthropic.cjs.map +1 -1
- package/dist/tools/warp_grep/anthropic.js +12 -12
- package/dist/tools/warp_grep/client.cjs +2 -44
- package/dist/tools/warp_grep/client.cjs.map +1 -1
- package/dist/tools/warp_grep/client.js +11 -11
- package/dist/tools/warp_grep/gemini.cjs +2 -44
- package/dist/tools/warp_grep/gemini.cjs.map +1 -1
- package/dist/tools/warp_grep/gemini.js +11 -11
- package/dist/tools/warp_grep/harness.js +7 -7
- package/dist/tools/warp_grep/index.cjs +2 -44
- package/dist/tools/warp_grep/index.cjs.map +1 -1
- package/dist/tools/warp_grep/index.js +14 -14
- package/dist/tools/warp_grep/openai.cjs +2 -44
- package/dist/tools/warp_grep/openai.cjs.map +1 -1
- package/dist/tools/warp_grep/openai.js +12 -12
- package/dist/tools/warp_grep/vercel.cjs +2 -44
- package/dist/tools/warp_grep/vercel.cjs.map +1 -1
- package/dist/tools/warp_grep/vercel.js +12 -12
- package/dist/tracing/core.cjs +2 -34
- package/dist/tracing/core.cjs.map +1 -1
- package/dist/tracing/core.d.ts +1 -2
- package/dist/tracing/core.js +2 -2
- package/dist/tracing/index.cjs +4 -42
- package/dist/tracing/index.cjs.map +1 -1
- package/dist/tracing/index.d.ts +0 -34
- package/dist/tracing/index.js +3 -10
- package/dist/tracing/interaction.cjs +0 -30
- package/dist/tracing/interaction.cjs.map +1 -1
- package/dist/tracing/interaction.js +1 -1
- package/dist/tracing/types.cjs.map +1 -1
- package/dist/tracing/types.d.ts +1 -27
- package/dist/version.cjs +2 -38
- package/dist/version.cjs.map +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -38
- package/dist/anthropic-B6my2oBx.d.ts +0 -56
- package/dist/chunk-2AMEQAO2.js +0 -46
- package/dist/chunk-2AMEQAO2.js.map +0 -1
- package/dist/chunk-2HMEZZKK.js +0 -44
- package/dist/chunk-2HMEZZKK.js.map +0 -1
- package/dist/chunk-2HXELZI5.js.map +0 -1
- package/dist/chunk-2VERUKO2.js +0 -177
- package/dist/chunk-2VERUKO2.js.map +0 -1
- package/dist/chunk-4FWK3CEH.js +0 -692
- package/dist/chunk-4FWK3CEH.js.map +0 -1
- package/dist/chunk-ATAKRJQZ.js.map +0 -1
- package/dist/chunk-CZ74CRGH.js.map +0 -1
- package/dist/chunk-EGI642TV.js.map +0 -1
- package/dist/chunk-FLWBVHDC.js +0 -622
- package/dist/chunk-FLWBVHDC.js.map +0 -1
- package/dist/chunk-JZJY2XFQ.js +0 -96
- package/dist/chunk-JZJY2XFQ.js.map +0 -1
- package/dist/chunk-LKFZBBTD.js.map +0 -1
- package/dist/chunk-LRHJVSSD.js +0 -57
- package/dist/chunk-LRHJVSSD.js.map +0 -1
- package/dist/chunk-NKFAMQF2.js +0 -202
- package/dist/chunk-NKFAMQF2.js.map +0 -1
- package/dist/chunk-PQCOBN7L.js.map +0 -1
- package/dist/chunk-TCCZBGG5.js +0 -46
- package/dist/chunk-TCCZBGG5.js.map +0 -1
- package/dist/chunk-W34BUTVR.js +0 -389
- package/dist/chunk-W34BUTVR.js.map +0 -1
- package/dist/chunk-WFOGTZF6.js +0 -80
- package/dist/chunk-WFOGTZF6.js.map +0 -1
- package/dist/chunk-YTYCHRQ2.js +0 -106
- package/dist/chunk-YTYCHRQ2.js.map +0 -1
- package/dist/client-B3fWTCcL.d.ts +0 -1021
- package/dist/openai-BQMeDFef.d.ts +0 -81
- package/dist/tools/browser/anthropic.cjs +0 -655
- package/dist/tools/browser/anthropic.cjs.map +0 -1
- package/dist/tools/browser/anthropic.d.ts +0 -4
- package/dist/tools/browser/anthropic.js +0 -22
- package/dist/tools/browser/anthropic.js.map +0 -1
- package/dist/tools/browser/core.cjs +0 -1831
- package/dist/tools/browser/core.cjs.map +0 -1
- package/dist/tools/browser/core.d.ts +0 -245
- package/dist/tools/browser/core.js +0 -32
- package/dist/tools/browser/core.js.map +0 -1
- package/dist/tools/browser/errors.cjs +0 -208
- package/dist/tools/browser/errors.cjs.map +0 -1
- package/dist/tools/browser/errors.d.ts +0 -158
- package/dist/tools/browser/errors.js +0 -22
- package/dist/tools/browser/errors.js.map +0 -1
- package/dist/tools/browser/index.cjs +0 -2169
- package/dist/tools/browser/index.cjs.map +0 -1
- package/dist/tools/browser/index.d.ts +0 -134
- package/dist/tools/browser/index.js +0 -163
- package/dist/tools/browser/index.js.map +0 -1
- package/dist/tools/browser/live.cjs +0 -134
- package/dist/tools/browser/live.cjs.map +0 -1
- package/dist/tools/browser/live.d.ts +0 -75
- package/dist/tools/browser/live.js +0 -16
- package/dist/tools/browser/live.js.map +0 -1
- package/dist/tools/browser/openai.cjs +0 -671
- package/dist/tools/browser/openai.cjs.map +0 -1
- package/dist/tools/browser/openai.d.ts +0 -4
- package/dist/tools/browser/openai.js +0 -28
- package/dist/tools/browser/openai.js.map +0 -1
- package/dist/tools/browser/profiles/core.cjs +0 -942
- package/dist/tools/browser/profiles/core.cjs.map +0 -1
- package/dist/tools/browser/profiles/core.d.ts +0 -187
- package/dist/tools/browser/profiles/core.js +0 -30
- package/dist/tools/browser/profiles/core.js.map +0 -1
- package/dist/tools/browser/profiles/index.cjs +0 -942
- package/dist/tools/browser/profiles/index.cjs.map +0 -1
- package/dist/tools/browser/profiles/index.d.ts +0 -4
- package/dist/tools/browser/profiles/index.js +0 -30
- package/dist/tools/browser/profiles/index.js.map +0 -1
- package/dist/tools/browser/profiles/types.cjs +0 -74
- package/dist/tools/browser/profiles/types.cjs.map +0 -1
- package/dist/tools/browser/profiles/types.d.ts +0 -195
- package/dist/tools/browser/profiles/types.js +0 -16
- package/dist/tools/browser/profiles/types.js.map +0 -1
- package/dist/tools/browser/prompts.cjs +0 -69
- package/dist/tools/browser/prompts.cjs.map +0 -1
- package/dist/tools/browser/prompts.d.ts +0 -7
- package/dist/tools/browser/prompts.js +0 -10
- package/dist/tools/browser/prompts.js.map +0 -1
- package/dist/tools/browser/types.cjs +0 -19
- package/dist/tools/browser/types.cjs.map +0 -1
- package/dist/tools/browser/types.d.ts +0 -338
- package/dist/tools/browser/types.js +0 -1
- package/dist/tools/browser/types.js.map +0 -1
- package/dist/tools/browser/vercel.cjs +0 -632
- package/dist/tools/browser/vercel.cjs.map +0 -1
- package/dist/tools/browser/vercel.d.ts +0 -4
- package/dist/tools/browser/vercel.js +0 -22
- package/dist/tools/browser/vercel.js.map +0 -1
- package/dist/tools/reflex/core.cjs +0 -756
- package/dist/tools/reflex/core.cjs.map +0 -1
- package/dist/tools/reflex/core.d.ts +0 -59
- package/dist/tools/reflex/core.js +0 -16
- package/dist/tools/reflex/core.js.map +0 -1
- package/dist/tools/reflex/index.cjs +0 -756
- package/dist/tools/reflex/index.cjs.map +0 -1
- package/dist/tools/reflex/index.d.ts +0 -5
- package/dist/tools/reflex/index.js +0 -16
- package/dist/tools/reflex/index.js.map +0 -1
- package/dist/tools/reflex/types.cjs +0 -19
- package/dist/tools/reflex/types.cjs.map +0 -1
- package/dist/tools/reflex/types.d.ts +0 -171
- package/dist/tools/reflex/types.js +0 -1
- package/dist/tools/reflex/types.js.map +0 -1
- package/dist/tools/traces/core.cjs +0 -76
- package/dist/tools/traces/core.cjs.map +0 -1
- package/dist/tools/traces/core.d.ts +0 -24
- package/dist/tools/traces/core.js +0 -9
- package/dist/tools/traces/core.js.map +0 -1
- package/dist/tools/traces/index.cjs +0 -76
- package/dist/tools/traces/index.cjs.map +0 -1
- package/dist/tools/traces/index.d.ts +0 -5
- package/dist/tools/traces/index.js +0 -9
- package/dist/tools/traces/index.js.map +0 -1
- package/dist/tools/traces/types.cjs +0 -19
- package/dist/tools/traces/types.cjs.map +0 -1
- package/dist/tools/traces/types.d.ts +0 -56
- package/dist/tools/traces/types.js +0 -1
- package/dist/tools/traces/types.js.map +0 -1
- package/dist/vercel-CVF27qFK.d.ts +0 -74
- /package/dist/{chunk-GE5MNVT7.js.map → chunk-5KQ2WRBU.js.map} +0 -0
- /package/dist/{chunk-6YZCPCAY.js.map → chunk-BLCCGRKT.js.map} +0 -0
- /package/dist/{chunk-2BT4UGKH.js.map → chunk-BTMMUG3E.js.map} +0 -0
- /package/dist/{chunk-VJD6MF3M.js.map → chunk-CEXBKXWU.js.map} +0 -0
- /package/dist/{chunk-UOS3XKJD.js.map → chunk-DP2PT36G.js.map} +0 -0
- /package/dist/{chunk-DNL4DMMS.js.map → chunk-GTV27THY.js.map} +0 -0
- /package/dist/{chunk-VGCPVDFP.js.map → chunk-K2JR2NFQ.js.map} +0 -0
- /package/dist/{chunk-DHGXGVHC.js.map → chunk-KXEPBLVD.js.map} +0 -0
- /package/dist/{chunk-SVD3YRWM.js.map → chunk-MEZTHMB2.js.map} +0 -0
- /package/dist/{chunk-BECYWCEZ.js.map → chunk-O7LJEVZO.js.map} +0 -0
- /package/dist/{chunk-7QOGUY4A.js.map → chunk-PKJ7ODTG.js.map} +0 -0
- /package/dist/{chunk-YVKRPVOM.js.map → chunk-Q3NH3NPD.js.map} +0 -0
- /package/dist/{chunk-ZA3UJRSE.js.map → chunk-RL3ZTXT3.js.map} +0 -0
- /package/dist/{chunk-WN6YLBEH.js.map → chunk-ULHHMZRL.js.map} +0 -0
- /package/dist/{chunk-TJUZAO7T.js.map → chunk-UT3NQLCF.js.map} +0 -0
- /package/dist/{chunk-DW6ZIVCM.js.map → chunk-VS5F2ORN.js.map} +0 -0
- /package/dist/{chunk-UZA2ODNU.js.map → chunk-W37OFBSG.js.map} +0 -0
- /package/dist/{chunk-JU6TCHVI.js.map → chunk-WDBYAXZ5.js.map} +0 -0
- /package/dist/{chunk-2XDSHAB5.js.map → chunk-YSFEKIYQ.js.map} +0 -0
- /package/dist/{chunk-WDLDKJHT.js.map → chunk-ZHB57ORD.js.map} +0 -0
package/dist/client.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.
|
|
39
|
+
version: "0.2.199",
|
|
40
40
|
description: "TypeScript SDK and CLI for Morph Fast Apply integration",
|
|
41
41
|
type: "module",
|
|
42
42
|
main: "./dist/index.cjs",
|
|
@@ -143,31 +143,6 @@ var init_package = __esm({
|
|
|
143
143
|
import: "./dist/tools/codebase_search/vercel.js",
|
|
144
144
|
require: "./dist/tools/codebase_search/vercel.cjs"
|
|
145
145
|
},
|
|
146
|
-
"./tools/browser": {
|
|
147
|
-
types: "./dist/tools/browser/index.d.ts",
|
|
148
|
-
import: "./dist/tools/browser/index.js",
|
|
149
|
-
require: "./dist/tools/browser/index.cjs"
|
|
150
|
-
},
|
|
151
|
-
"./tools/browser/anthropic": {
|
|
152
|
-
types: "./dist/tools/browser/anthropic.d.ts",
|
|
153
|
-
import: "./dist/tools/browser/anthropic.js",
|
|
154
|
-
require: "./dist/tools/browser/anthropic.cjs"
|
|
155
|
-
},
|
|
156
|
-
"./tools/browser/openai": {
|
|
157
|
-
types: "./dist/tools/browser/openai.d.ts",
|
|
158
|
-
import: "./dist/tools/browser/openai.js",
|
|
159
|
-
require: "./dist/tools/browser/openai.cjs"
|
|
160
|
-
},
|
|
161
|
-
"./tools/browser/vercel": {
|
|
162
|
-
types: "./dist/tools/browser/vercel.d.ts",
|
|
163
|
-
import: "./dist/tools/browser/vercel.js",
|
|
164
|
-
require: "./dist/tools/browser/vercel.cjs"
|
|
165
|
-
},
|
|
166
|
-
"./tools/browser/profiles": {
|
|
167
|
-
types: "./dist/tools/browser/profiles/index.d.ts",
|
|
168
|
-
import: "./dist/tools/browser/profiles/index.js",
|
|
169
|
-
require: "./dist/tools/browser/profiles/index.cjs"
|
|
170
|
-
},
|
|
171
146
|
"./modelrouter": {
|
|
172
147
|
types: "./dist/modelrouter/index.d.ts",
|
|
173
148
|
import: "./dist/modelrouter/index.js",
|
|
@@ -178,16 +153,6 @@ var init_package = __esm({
|
|
|
178
153
|
import: "./dist/tools/compact/index.js",
|
|
179
154
|
require: "./dist/tools/compact/index.cjs"
|
|
180
155
|
},
|
|
181
|
-
"./tools/reflex": {
|
|
182
|
-
types: "./dist/tools/reflex/index.d.ts",
|
|
183
|
-
import: "./dist/tools/reflex/index.js",
|
|
184
|
-
require: "./dist/tools/reflex/index.cjs"
|
|
185
|
-
},
|
|
186
|
-
"./tools/traces": {
|
|
187
|
-
types: "./dist/tools/traces/index.d.ts",
|
|
188
|
-
import: "./dist/tools/traces/index.js",
|
|
189
|
-
require: "./dist/tools/traces/index.cjs"
|
|
190
|
-
},
|
|
191
156
|
"./subagents": {
|
|
192
157
|
types: "./dist/subagents/index.d.ts",
|
|
193
158
|
import: "./dist/subagents/index.js",
|
|
@@ -218,7 +183,7 @@ var init_package = __esm({
|
|
|
218
183
|
"!dist/**/*.test.*"
|
|
219
184
|
],
|
|
220
185
|
scripts: {
|
|
221
|
-
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
|
|
186
|
+
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 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 tracing/index.ts tracing/core.ts tracing/interaction.ts tracing/otel.ts tracing/types.ts --format esm,cjs --sourcemap --clean --dts --dts-resolve && tsup ai-sdk/index.ts --format esm,cjs --sourcemap --dts --no-clean --out-dir dist/ai-sdk",
|
|
222
187
|
prepare: "npm run build",
|
|
223
188
|
typecheck: "tsc --noEmit && tsc --noEmit -p ai-sdk/tsconfig.json",
|
|
224
189
|
lint: "eslint .",
|
|
@@ -228,7 +193,6 @@ var init_package = __esm({
|
|
|
228
193
|
"test:openai": "vitest run openai",
|
|
229
194
|
"test:vercel": "vitest run vercel",
|
|
230
195
|
"test:git": "vitest run git",
|
|
231
|
-
"test:browser": "vitest run browser",
|
|
232
196
|
"test:agent": "npx tsx tests/fullAgentTest.ts",
|
|
233
197
|
"test:integration": "npx tsx tests/fullIntegrationTest.ts",
|
|
234
198
|
"test:e2e": "vitest run --config vitest.e2e.config.ts",
|
|
@@ -1474,7 +1438,6 @@ async function toMorphError(response) {
|
|
|
1474
1438
|
// core/client.ts
|
|
1475
1439
|
var DEFAULT_BASE_URL = "https://api.morphllm.com";
|
|
1476
1440
|
var DEFAULT_REPOS_URL = "https://repos.morphllm.com";
|
|
1477
|
-
var DEFAULT_BROWSER_URL = "https://browser.morphllm.com";
|
|
1478
1441
|
var DEFAULT_TIMEOUT = 6e4;
|
|
1479
1442
|
var env = (name) => typeof process !== "undefined" ? process.env?.[name] : void 0;
|
|
1480
1443
|
var stripTrailingSlash = (url) => url.replace(/\/+$/, "");
|
|
@@ -1483,7 +1446,6 @@ var MorphAPIClient = class {
|
|
|
1483
1446
|
apiKey;
|
|
1484
1447
|
baseURL;
|
|
1485
1448
|
reposURL;
|
|
1486
|
-
browserURL;
|
|
1487
1449
|
/** Explicit default timeout (ms), if set. The request default is applied lazily so
|
|
1488
1450
|
* resources can read an undefined value and supply their own fallback. */
|
|
1489
1451
|
timeout;
|
|
@@ -1493,9 +1455,6 @@ var MorphAPIClient = class {
|
|
|
1493
1455
|
this.apiKey = options.apiKey;
|
|
1494
1456
|
this.baseURL = stripTrailingSlash(options.baseURL ?? DEFAULT_BASE_URL);
|
|
1495
1457
|
this.reposURL = stripTrailingSlash(options.reposURL ?? env("MORPH_SEARCH_URL") ?? DEFAULT_REPOS_URL);
|
|
1496
|
-
this.browserURL = stripTrailingSlash(
|
|
1497
|
-
options.browserURL ?? (env("MORPH_ENVIRONMENT") === "DEV" ? "http://localhost:8000" : DEFAULT_BROWSER_URL)
|
|
1498
|
-
);
|
|
1499
1458
|
this.timeout = options.timeout;
|
|
1500
1459
|
this.retryConfig = options.retryConfig;
|
|
1501
1460
|
this.debug = options.debug ?? false;
|
|
@@ -1554,7 +1513,6 @@ var MorphAPIClient = class {
|
|
|
1554
1513
|
timeout,
|
|
1555
1514
|
`Morph request to ${url} timed out after ${timeout}ms`
|
|
1556
1515
|
);
|
|
1557
|
-
if (opts.raw) return response;
|
|
1558
1516
|
if (!response.ok) throw await toMorphError(response);
|
|
1559
1517
|
if (opts.stream) return response;
|
|
1560
1518
|
if (response.status === 204) return void 0;
|
|
@@ -1800,1460 +1758,207 @@ async function executeCodebaseSearch(input, config) {
|
|
|
1800
1758
|
return runSearch(client, input, config.repoId, config.timeout ?? DEFAULT_TIMEOUT3, config.searchUrl);
|
|
1801
1759
|
}
|
|
1802
1760
|
|
|
1803
|
-
// tools/
|
|
1804
|
-
|
|
1761
|
+
// tools/warp_grep/agent/runner.ts
|
|
1762
|
+
init_config();
|
|
1805
1763
|
|
|
1806
|
-
// tools/
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
"debugUrl is required. Ensure your backend returns debugUrl in the task response. Contact support@morphllm.com if you need help."
|
|
1819
|
-
);
|
|
1820
|
-
}
|
|
1821
|
-
const normalized = normalizeLiveUrl(debugUrl);
|
|
1822
|
-
const url = new URL(normalized);
|
|
1823
|
-
if (options.interactive !== void 0) {
|
|
1824
|
-
url.searchParams.set("interactive", String(options.interactive));
|
|
1825
|
-
}
|
|
1826
|
-
if (options.theme) {
|
|
1827
|
-
url.searchParams.set("theme", options.theme);
|
|
1828
|
-
}
|
|
1829
|
-
if (options.showControls !== void 0) {
|
|
1830
|
-
url.searchParams.set("showControls", String(options.showControls));
|
|
1831
|
-
}
|
|
1832
|
-
if (options.pageId) {
|
|
1833
|
-
url.searchParams.set("pageId", options.pageId);
|
|
1834
|
-
}
|
|
1835
|
-
if (options.pageIndex) {
|
|
1836
|
-
url.searchParams.set("pageIndex", options.pageIndex);
|
|
1764
|
+
// tools/warp_grep/agent/parser.ts
|
|
1765
|
+
function parseReadLines(linesStr) {
|
|
1766
|
+
const ranges = [];
|
|
1767
|
+
for (const rangeStr of linesStr.split(",")) {
|
|
1768
|
+
const trimmed = rangeStr.trim();
|
|
1769
|
+
if (!trimmed) continue;
|
|
1770
|
+
const parts = trimmed.split("-").map((v) => parseInt(v.trim(), 10));
|
|
1771
|
+
if (parts.length >= 2 && Number.isFinite(parts[0]) && Number.isFinite(parts[1])) {
|
|
1772
|
+
ranges.push([parts[0], parts[1]]);
|
|
1773
|
+
} else if (Number.isFinite(parts[0])) {
|
|
1774
|
+
ranges.push([parts[0], parts[0]]);
|
|
1775
|
+
}
|
|
1837
1776
|
}
|
|
1838
|
-
|
|
1839
|
-
}
|
|
1840
|
-
|
|
1841
|
-
return wsUrl.replace(/^wss:\/\//, "https://").replace(/^ws:\/\//, "http://");
|
|
1777
|
+
if (ranges.length === 1) return { start: ranges[0][0], end: ranges[0][1] };
|
|
1778
|
+
if (ranges.length > 1) return { lines: ranges };
|
|
1779
|
+
return {};
|
|
1842
1780
|
}
|
|
1843
|
-
function
|
|
1844
|
-
const
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1781
|
+
function parseFinishFiles(filesStr) {
|
|
1782
|
+
const files = [];
|
|
1783
|
+
for (const line of filesStr.trim().split(/\s+/)) {
|
|
1784
|
+
const trimmed = line.trim();
|
|
1785
|
+
if (!trimmed) continue;
|
|
1786
|
+
const searchFrom = /^[A-Za-z]:/.test(trimmed) ? 2 : 0;
|
|
1787
|
+
const colonIdx = trimmed.indexOf(":", searchFrom);
|
|
1788
|
+
if (colonIdx === -1) {
|
|
1789
|
+
files.push({ path: trimmed, lines: "*" });
|
|
1790
|
+
continue;
|
|
1791
|
+
}
|
|
1792
|
+
const filePath = trimmed.slice(0, colonIdx);
|
|
1793
|
+
const rangesPart = trimmed.slice(colonIdx + 1);
|
|
1794
|
+
if (!rangesPart.trim() || rangesPart.trim() === "*") {
|
|
1795
|
+
files.push({ path: filePath, lines: "*" });
|
|
1796
|
+
continue;
|
|
1797
|
+
}
|
|
1798
|
+
const ranges = [];
|
|
1799
|
+
for (const rangeStr of rangesPart.split(",")) {
|
|
1800
|
+
const rt = rangeStr.trim();
|
|
1801
|
+
if (!rt) continue;
|
|
1802
|
+
const parts = rt.split("-").map((v) => parseInt(v.trim(), 10));
|
|
1803
|
+
if (parts.length >= 2 && Number.isFinite(parts[0]) && Number.isFinite(parts[1])) {
|
|
1804
|
+
ranges.push([parts[0], parts[1]]);
|
|
1805
|
+
} else if (Number.isFinite(parts[0])) {
|
|
1806
|
+
ranges.push([parts[0], parts[0]]);
|
|
1807
|
+
}
|
|
1808
|
+
}
|
|
1809
|
+
files.push({ path: filePath, lines: ranges.length > 0 ? ranges : "*" });
|
|
1858
1810
|
}
|
|
1859
|
-
return
|
|
1860
|
-
}
|
|
1861
|
-
function buildLiveIframe(debugUrl, options = {}) {
|
|
1862
|
-
const {
|
|
1863
|
-
width = "100%",
|
|
1864
|
-
height = "600px",
|
|
1865
|
-
style = "",
|
|
1866
|
-
className = "",
|
|
1867
|
-
...sessionOptions
|
|
1868
|
-
} = options;
|
|
1869
|
-
const src = buildLiveUrl(debugUrl, sessionOptions);
|
|
1870
|
-
const widthStr = typeof width === "number" ? `${width}px` : width;
|
|
1871
|
-
const heightStr = typeof height === "number" ? `${height}px` : height;
|
|
1872
|
-
const baseStyle = `width: ${widthStr}; height: ${heightStr}; border: none;`;
|
|
1873
|
-
const fullStyle = style ? `${baseStyle} ${style}` : baseStyle;
|
|
1874
|
-
const attributes = [
|
|
1875
|
-
`src="${src}"`,
|
|
1876
|
-
`style="${fullStyle}"`
|
|
1877
|
-
];
|
|
1878
|
-
if (className) {
|
|
1879
|
-
attributes.push(`class="${className}"`);
|
|
1880
|
-
}
|
|
1881
|
-
return `<iframe ${attributes.join(" ")}></iframe>`;
|
|
1811
|
+
return files;
|
|
1882
1812
|
}
|
|
1883
|
-
function
|
|
1884
|
-
const
|
|
1885
|
-
|
|
1886
|
-
|
|
1813
|
+
function extractPathFromCommand(command) {
|
|
1814
|
+
const tokens = command.trim().split(/\s+/);
|
|
1815
|
+
const pathTokens = tokens.slice(1).filter((t) => !t.startsWith("-") && !t.startsWith("|") && !t.startsWith("\\("));
|
|
1816
|
+
return pathTokens[0] || ".";
|
|
1887
1817
|
}
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1818
|
+
|
|
1819
|
+
// tools/warp_grep/agent/tools/grep.ts
|
|
1820
|
+
async function toolGrep(provider, args) {
|
|
1821
|
+
const res = await provider.grep(args);
|
|
1822
|
+
if (res.error) {
|
|
1823
|
+
return { output: res.error };
|
|
1891
1824
|
}
|
|
1892
|
-
if (
|
|
1893
|
-
|
|
1894
|
-
if (!preset) {
|
|
1895
|
-
throw new Error(
|
|
1896
|
-
`Unknown preset: ${optionsOrPreset}. Available presets: ${Object.keys(LIVE_PRESETS).join(", ")}`
|
|
1897
|
-
);
|
|
1898
|
-
}
|
|
1899
|
-
return preset;
|
|
1825
|
+
if (!res.lines.length) {
|
|
1826
|
+
return { output: "no matches" };
|
|
1900
1827
|
}
|
|
1901
|
-
return
|
|
1828
|
+
return { output: res.lines.join("\n") };
|
|
1902
1829
|
}
|
|
1903
1830
|
|
|
1904
|
-
// tools/
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
if (Error.captureStackTrace) {
|
|
1916
|
-
Error.captureStackTrace(this, this.constructor);
|
|
1831
|
+
// tools/warp_grep/agent/tools/read.ts
|
|
1832
|
+
function isValidRange(start, end) {
|
|
1833
|
+
return typeof start === "number" && typeof end === "number" && Number.isFinite(start) && Number.isFinite(end) && start > 0 && end >= start;
|
|
1834
|
+
}
|
|
1835
|
+
async function toolRead(provider, args) {
|
|
1836
|
+
if (args.lines && Array.isArray(args.lines) && args.lines.length > 0) {
|
|
1837
|
+
const validRanges = [];
|
|
1838
|
+
for (const range of args.lines) {
|
|
1839
|
+
if (Array.isArray(range) && range.length >= 2 && isValidRange(range[0], range[1])) {
|
|
1840
|
+
validRanges.push([range[0], range[1]]);
|
|
1841
|
+
}
|
|
1917
1842
|
}
|
|
1843
|
+
if (validRanges.length === 0) {
|
|
1844
|
+
const res2 = await provider.read({ path: args.path });
|
|
1845
|
+
if (res2.error) return res2.error;
|
|
1846
|
+
if (!res2.lines.length) return "(empty file)";
|
|
1847
|
+
return res2.lines.join("\n");
|
|
1848
|
+
}
|
|
1849
|
+
const chunks = [];
|
|
1850
|
+
for (const [start, end] of validRanges) {
|
|
1851
|
+
const res2 = await provider.read({ path: args.path, start, end });
|
|
1852
|
+
if (res2.error) return res2.error;
|
|
1853
|
+
chunks.push(res2.lines.join("\n"));
|
|
1854
|
+
}
|
|
1855
|
+
if (chunks.every((c) => c === "")) return "(empty file)";
|
|
1856
|
+
return chunks.join("\n...\n");
|
|
1918
1857
|
}
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
toJSON() {
|
|
1923
|
-
return {
|
|
1924
|
-
name: this.name,
|
|
1925
|
-
message: this.message,
|
|
1926
|
-
code: this.code,
|
|
1927
|
-
cause: this.cause?.message
|
|
1928
|
-
};
|
|
1929
|
-
}
|
|
1930
|
-
};
|
|
1931
|
-
var MorphValidationError = class extends MorphError2 {
|
|
1932
|
-
/** The field that failed validation */
|
|
1933
|
-
field;
|
|
1934
|
-
constructor(message, field) {
|
|
1935
|
-
super(message, "validation_error");
|
|
1936
|
-
this.name = "MorphValidationError";
|
|
1937
|
-
this.field = field;
|
|
1938
|
-
}
|
|
1939
|
-
toJSON() {
|
|
1940
|
-
return {
|
|
1941
|
-
...super.toJSON(),
|
|
1942
|
-
field: this.field
|
|
1943
|
-
};
|
|
1944
|
-
}
|
|
1945
|
-
};
|
|
1946
|
-
var MorphAPIError = class extends MorphError2 {
|
|
1947
|
-
/** HTTP status code */
|
|
1948
|
-
statusCode;
|
|
1949
|
-
/** Request ID for debugging (if available) */
|
|
1950
|
-
requestId;
|
|
1951
|
-
/** Raw response body */
|
|
1952
|
-
rawResponse;
|
|
1953
|
-
constructor(message, code, statusCode, options) {
|
|
1954
|
-
super(message, code, options?.cause);
|
|
1955
|
-
this.name = "MorphAPIError";
|
|
1956
|
-
this.statusCode = statusCode;
|
|
1957
|
-
this.requestId = options?.requestId;
|
|
1958
|
-
this.rawResponse = options?.rawResponse;
|
|
1959
|
-
}
|
|
1960
|
-
toJSON() {
|
|
1961
|
-
return {
|
|
1962
|
-
...super.toJSON(),
|
|
1963
|
-
statusCode: this.statusCode,
|
|
1964
|
-
requestId: this.requestId
|
|
1965
|
-
};
|
|
1966
|
-
}
|
|
1967
|
-
};
|
|
1968
|
-
var MorphAuthenticationError = class extends MorphAPIError {
|
|
1969
|
-
constructor(message = "Authentication required. Please provide a valid API key.") {
|
|
1970
|
-
super(message, "authentication_required", 401);
|
|
1971
|
-
this.name = "MorphAuthenticationError";
|
|
1972
|
-
}
|
|
1973
|
-
};
|
|
1974
|
-
var MorphRateLimitError = class extends MorphAPIError {
|
|
1975
|
-
/** When the rate limit resets (Unix timestamp) */
|
|
1976
|
-
resetAt;
|
|
1977
|
-
/** Number of seconds until reset */
|
|
1978
|
-
retryAfter;
|
|
1979
|
-
constructor(message = "Rate limit exceeded. Please retry later.", options) {
|
|
1980
|
-
super(message, "rate_limit_exceeded", 429, { requestId: options?.requestId });
|
|
1981
|
-
this.name = "MorphRateLimitError";
|
|
1982
|
-
this.resetAt = options?.resetAt;
|
|
1983
|
-
this.retryAfter = options?.retryAfter;
|
|
1984
|
-
}
|
|
1985
|
-
toJSON() {
|
|
1986
|
-
return {
|
|
1987
|
-
...super.toJSON(),
|
|
1988
|
-
resetAt: this.resetAt,
|
|
1989
|
-
retryAfter: this.retryAfter
|
|
1990
|
-
};
|
|
1991
|
-
}
|
|
1992
|
-
};
|
|
1993
|
-
var MorphNotFoundError = class extends MorphAPIError {
|
|
1994
|
-
/** The type of resource that was not found */
|
|
1995
|
-
resourceType;
|
|
1996
|
-
/** The ID of the resource that was not found */
|
|
1997
|
-
resourceId;
|
|
1998
|
-
constructor(resourceType, resourceId) {
|
|
1999
|
-
const message = resourceId ? `${resourceType} '${resourceId}' not found` : `${resourceType} not found`;
|
|
2000
|
-
super(message, "resource_not_found", 404);
|
|
2001
|
-
this.name = "MorphNotFoundError";
|
|
2002
|
-
this.resourceType = resourceType;
|
|
2003
|
-
this.resourceId = resourceId;
|
|
2004
|
-
}
|
|
2005
|
-
toJSON() {
|
|
2006
|
-
return {
|
|
2007
|
-
...super.toJSON(),
|
|
2008
|
-
resourceType: this.resourceType,
|
|
2009
|
-
resourceId: this.resourceId
|
|
2010
|
-
};
|
|
1858
|
+
const res = await provider.read({ path: args.path, start: args.start, end: args.end });
|
|
1859
|
+
if (res.error) {
|
|
1860
|
+
return res.error;
|
|
2011
1861
|
}
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
1862
|
+
if (!res.lines.length) return "(empty file)";
|
|
1863
|
+
return res.lines.join("\n");
|
|
1864
|
+
}
|
|
1865
|
+
|
|
1866
|
+
// tools/warp_grep/agent/tools/list_directory.ts
|
|
1867
|
+
init_config();
|
|
1868
|
+
var import_path2 = __toESM(require("path"), 1);
|
|
1869
|
+
async function toolListDirectory(provider, args, repoRoot) {
|
|
1870
|
+
const maxResults = args.maxResults ?? AGENT_CONFIG.MAX_LIST_RESULTS;
|
|
1871
|
+
const maxDepth = args.maxDepth ?? AGENT_CONFIG.MAX_LIST_DEPTH;
|
|
1872
|
+
const entries = await provider.listDirectory({
|
|
1873
|
+
path: args.path,
|
|
1874
|
+
pattern: args.pattern ?? null,
|
|
1875
|
+
maxResults,
|
|
1876
|
+
maxDepth
|
|
1877
|
+
});
|
|
1878
|
+
if (!entries.length) return "empty";
|
|
1879
|
+
if (repoRoot) {
|
|
1880
|
+
const absRoot = repoRoot;
|
|
1881
|
+
const lines = entries.map((e) => import_path2.default.join(absRoot, e.path));
|
|
1882
|
+
return lines.join("\n");
|
|
2030
1883
|
}
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
1884
|
+
return entries.map((e) => e.path).join("\n");
|
|
1885
|
+
}
|
|
1886
|
+
|
|
1887
|
+
// tools/warp_grep/agent/tools/glob.ts
|
|
1888
|
+
async function toolGlob(provider, args) {
|
|
1889
|
+
const res = await provider.glob(args);
|
|
1890
|
+
if (res.error) {
|
|
1891
|
+
return res.error;
|
|
2037
1892
|
}
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
switch (statusCode) {
|
|
2041
|
-
case 401:
|
|
2042
|
-
return new MorphAuthenticationError(message);
|
|
2043
|
-
case 403:
|
|
2044
|
-
if (code === "profile_limit_exceeded" || message.toLowerCase().includes("limit")) {
|
|
2045
|
-
return new MorphProfileLimitError(message, { requestId });
|
|
2046
|
-
}
|
|
2047
|
-
return new MorphAPIError(message, "insufficient_permissions", statusCode, { requestId, rawResponse: responseText });
|
|
2048
|
-
case 404:
|
|
2049
|
-
if (message.toLowerCase().includes("profile")) {
|
|
2050
|
-
return new MorphNotFoundError("Profile", void 0);
|
|
2051
|
-
}
|
|
2052
|
-
if (message.toLowerCase().includes("session")) {
|
|
2053
|
-
return new MorphNotFoundError("Session", void 0);
|
|
2054
|
-
}
|
|
2055
|
-
return new MorphAPIError(message, "resource_not_found", statusCode, { requestId, rawResponse: responseText });
|
|
2056
|
-
case 429:
|
|
2057
|
-
return new MorphRateLimitError(message, { requestId });
|
|
2058
|
-
case 422:
|
|
2059
|
-
return new MorphAPIError(message, "validation_error", statusCode, { requestId, rawResponse: responseText });
|
|
2060
|
-
case 500:
|
|
2061
|
-
case 502:
|
|
2062
|
-
case 503:
|
|
2063
|
-
case 504:
|
|
2064
|
-
return new MorphAPIError(message, "service_unavailable", statusCode, { requestId, rawResponse: responseText });
|
|
2065
|
-
default:
|
|
2066
|
-
return new MorphAPIError(message, "network_error", statusCode, { requestId, rawResponse: responseText });
|
|
1893
|
+
if (!res.files.length) {
|
|
1894
|
+
return "no matches";
|
|
2067
1895
|
}
|
|
1896
|
+
const header = `Found ${res.totalFound} file(s) matching "${args.pattern}" within ${res.searchDir}, sorted by modification time (newest first):`;
|
|
1897
|
+
const body = res.files.join("\n");
|
|
1898
|
+
const truncated = res.totalFound > res.files.length ? `
|
|
1899
|
+
[${res.totalFound - res.files.length} files truncated]` : "";
|
|
1900
|
+
return `${header}
|
|
1901
|
+
---
|
|
1902
|
+
${body}
|
|
1903
|
+
---${truncated}`;
|
|
2068
1904
|
}
|
|
2069
1905
|
|
|
2070
|
-
// tools/
|
|
2071
|
-
function
|
|
2072
|
-
return
|
|
2073
|
-
id: api.id,
|
|
2074
|
-
name: api.name,
|
|
2075
|
-
repoId: api.repo_id,
|
|
2076
|
-
cookieDomains: api.cookie_domains,
|
|
2077
|
-
lastUsedAt: api.last_used_at,
|
|
2078
|
-
createdAt: api.created_at,
|
|
2079
|
-
updatedAt: api.updated_at
|
|
2080
|
-
};
|
|
2081
|
-
}
|
|
2082
|
-
function transformCreateInput(input) {
|
|
2083
|
-
return {
|
|
2084
|
-
name: input.name,
|
|
2085
|
-
repo_id: input.repoId
|
|
2086
|
-
};
|
|
1906
|
+
// tools/warp_grep/agent/tools/finish.ts
|
|
1907
|
+
function isValidRange2(range) {
|
|
1908
|
+
return Array.isArray(range) && range.length >= 2 && typeof range[0] === "number" && typeof range[1] === "number" && Number.isFinite(range[0]) && Number.isFinite(range[1]) && range[0] > 0 && range[1] >= range[0];
|
|
2087
1909
|
}
|
|
2088
|
-
function
|
|
2089
|
-
return
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
1910
|
+
function extractValidRanges(lines) {
|
|
1911
|
+
if (!Array.isArray(lines)) return null;
|
|
1912
|
+
const valid = [];
|
|
1913
|
+
for (const range of lines) {
|
|
1914
|
+
if (isValidRange2(range)) {
|
|
1915
|
+
valid.push([range[0], range[1]]);
|
|
1916
|
+
}
|
|
1917
|
+
}
|
|
1918
|
+
return valid.length > 0 ? valid : null;
|
|
2093
1919
|
}
|
|
2094
|
-
function
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
1920
|
+
async function readFinishFiles(repoRoot, files, reader) {
|
|
1921
|
+
const out = [];
|
|
1922
|
+
for (const f of files) {
|
|
1923
|
+
const validRanges = f.lines === "*" ? null : extractValidRanges(f.lines);
|
|
1924
|
+
if (f.lines === "*" || !validRanges) {
|
|
1925
|
+
const lines = await reader(f.path);
|
|
1926
|
+
out.push({ path: f.path, ranges: "*", content: lines.join("\n") });
|
|
1927
|
+
} else {
|
|
1928
|
+
const ranges = mergeRanges(validRanges);
|
|
1929
|
+
const chunks = [];
|
|
1930
|
+
for (let i = 0; i < ranges.length; i++) {
|
|
1931
|
+
const [s, e] = ranges[i];
|
|
1932
|
+
if (i === 0 && s > 1) {
|
|
1933
|
+
chunks.push(`// ... existing code, block starting at line ${s} ...`);
|
|
1934
|
+
} else if (i > 0) {
|
|
1935
|
+
chunks.push(`// ... existing code, block starting at line ${s} ...`);
|
|
1936
|
+
}
|
|
1937
|
+
const lines = await reader(f.path, s, e);
|
|
1938
|
+
chunks.push(lines.join("\n"));
|
|
1939
|
+
}
|
|
1940
|
+
out.push({ path: f.path, ranges, content: chunks.join("\n") });
|
|
1941
|
+
}
|
|
1942
|
+
}
|
|
1943
|
+
return out;
|
|
2099
1944
|
}
|
|
2100
|
-
function
|
|
2101
|
-
return
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
}
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
*
|
|
2118
|
-
* @param input - Profile creation parameters
|
|
2119
|
-
* @returns Profile setup handle with live URL + save()
|
|
2120
|
-
* @throws {MorphValidationError} If input validation fails
|
|
2121
|
-
* @throws {MorphProfileLimitError} If profile limit is exceeded
|
|
2122
|
-
* @throws {MorphAuthenticationError} If API key is missing or invalid
|
|
2123
|
-
*
|
|
2124
|
-
* @example
|
|
2125
|
-
* ```typescript
|
|
2126
|
-
* const setup = await morph.browser.profiles.createProfile({
|
|
2127
|
-
* name: 'LinkedIn Production',
|
|
2128
|
-
* repoId: 'owner/repo'
|
|
2129
|
-
* });
|
|
2130
|
-
* console.log(setup.session.debugUrl);
|
|
2131
|
-
* await setup.save();
|
|
2132
|
-
* ```
|
|
2133
|
-
*/
|
|
2134
|
-
async createProfile(input) {
|
|
2135
|
-
return createProfile(input, this.config);
|
|
2136
|
-
}
|
|
2137
|
-
/**
|
|
2138
|
-
* List all profiles for the authenticated user.
|
|
2139
|
-
*
|
|
2140
|
-
* @param repoId - Optional repository ID to filter by
|
|
2141
|
-
* @returns Array of profiles
|
|
2142
|
-
*
|
|
2143
|
-
* @example
|
|
2144
|
-
* ```typescript
|
|
2145
|
-
* // List all profiles
|
|
2146
|
-
* const allProfiles = await morph.browser.profiles.listProfiles();
|
|
2147
|
-
*
|
|
2148
|
-
* // List profiles for a specific repo
|
|
2149
|
-
* const repoProfiles = await morph.browser.profiles.listProfiles('owner/repo');
|
|
2150
|
-
* ```
|
|
2151
|
-
*/
|
|
2152
|
-
async listProfiles(repoId) {
|
|
2153
|
-
return listProfiles(this.config, repoId);
|
|
2154
|
-
}
|
|
2155
|
-
/**
|
|
2156
|
-
* Get a profile by ID with convenience methods.
|
|
2157
|
-
*
|
|
2158
|
-
* @param id - Profile ID
|
|
2159
|
-
* @returns Profile with attached methods
|
|
2160
|
-
* @throws {MorphNotFoundError} If profile is not found
|
|
2161
|
-
*
|
|
2162
|
-
* @example
|
|
2163
|
-
* ```typescript
|
|
2164
|
-
* const profile = await morph.browser.profiles.getProfile('profile-id');
|
|
2165
|
-
* const state = await profile.getState();
|
|
2166
|
-
* await profile.delete();
|
|
2167
|
-
* ```
|
|
2168
|
-
*/
|
|
2169
|
-
async getProfile(id) {
|
|
2170
|
-
return getProfile(id, this.config);
|
|
2171
|
-
}
|
|
2172
|
-
/**
|
|
2173
|
-
* Update a profile by opening a live session (no rename).
|
|
2174
|
-
*
|
|
2175
|
-
* @param id - Profile ID
|
|
2176
|
-
* @returns Profile setup handle with live URL + save()
|
|
2177
|
-
*/
|
|
2178
|
-
async updateProfile(id) {
|
|
2179
|
-
return updateProfile(id, this.config);
|
|
2180
|
-
}
|
|
2181
|
-
/**
|
|
2182
|
-
* Delete a profile.
|
|
2183
|
-
*
|
|
2184
|
-
* @param id - Profile ID
|
|
2185
|
-
* @throws {MorphNotFoundError} If profile is not found
|
|
2186
|
-
*/
|
|
2187
|
-
async deleteProfile(id) {
|
|
2188
|
-
return deleteProfile(id, this.config);
|
|
2189
|
-
}
|
|
2190
|
-
/**
|
|
2191
|
-
* Start a browser session for profile setup.
|
|
2192
|
-
*
|
|
2193
|
-
* Returns a live URL where the user can sign into accounts.
|
|
2194
|
-
* After signing in, call `saveSession` to persist the state.
|
|
2195
|
-
*
|
|
2196
|
-
* @param input - Optional session parameters
|
|
2197
|
-
* @returns Session with debug URL
|
|
2198
|
-
*
|
|
2199
|
-
* @example
|
|
2200
|
-
* ```typescript
|
|
2201
|
-
* const session = await morph.browser.profiles.startSession();
|
|
2202
|
-
* console.log('Sign in at:', session.debugUrl);
|
|
2203
|
-
* // Open debugUrl in browser, user signs in...
|
|
2204
|
-
* await morph.browser.profiles.saveSession(session.sessionId, profile.id);
|
|
2205
|
-
* ```
|
|
2206
|
-
*/
|
|
2207
|
-
async startSession(input) {
|
|
2208
|
-
return startProfileSession(this.config, input);
|
|
2209
|
-
}
|
|
2210
|
-
/**
|
|
2211
|
-
* Save browser state from a session to a profile.
|
|
2212
|
-
*
|
|
2213
|
-
* Call this after the user is done signing into accounts.
|
|
2214
|
-
* Extracts cookies, localStorage, and sessionStorage.
|
|
2215
|
-
*
|
|
2216
|
-
* @param sessionId - Browser session ID from startSession
|
|
2217
|
-
* @param profileId - Profile ID to save state to
|
|
2218
|
-
* @returns Updated profile with cookie domains
|
|
2219
|
-
*/
|
|
2220
|
-
async saveSession(sessionId, profileId) {
|
|
2221
|
-
return saveProfileSession({ sessionId, profileId }, this.config);
|
|
2222
|
-
}
|
|
2223
|
-
/**
|
|
2224
|
-
* List available repo IDs (discovery).
|
|
2225
|
-
*
|
|
2226
|
-
* @returns Repo summaries with profile counts
|
|
2227
|
-
*/
|
|
2228
|
-
async listRepos() {
|
|
2229
|
-
return listRepos(this.config);
|
|
2230
|
-
}
|
|
2231
|
-
/**
|
|
2232
|
-
* Get the presigned URL for a profile's state.
|
|
2233
|
-
*
|
|
2234
|
-
* Use this to download the raw state JSON for debugging
|
|
2235
|
-
* or to restore state manually.
|
|
2236
|
-
*
|
|
2237
|
-
* @param profileId - Profile ID
|
|
2238
|
-
* @returns State URL with expiry information
|
|
2239
|
-
*/
|
|
2240
|
-
async getProfileState(profileId) {
|
|
2241
|
-
return getProfileState(profileId, this.config);
|
|
2242
|
-
}
|
|
2243
|
-
};
|
|
2244
|
-
function validateCreateInput(input) {
|
|
2245
|
-
if (!input.name || typeof input.name !== "string") {
|
|
2246
|
-
throw new MorphValidationError("name is required", "name");
|
|
2247
|
-
}
|
|
2248
|
-
const trimmedName = input.name.trim();
|
|
2249
|
-
if (trimmedName.length === 0) {
|
|
2250
|
-
throw new MorphValidationError("name cannot be empty", "name");
|
|
2251
|
-
}
|
|
2252
|
-
if (trimmedName.length > 100) {
|
|
2253
|
-
throw new MorphValidationError("name must be 100 characters or less", "name");
|
|
2254
|
-
}
|
|
2255
|
-
if (!input.repoId || typeof input.repoId !== "string") {
|
|
2256
|
-
throw new MorphValidationError("repoId is required", "repoId");
|
|
2257
|
-
}
|
|
2258
|
-
if (input.repoId.trim().length === 0) {
|
|
2259
|
-
throw new MorphValidationError("repoId cannot be empty", "repoId");
|
|
2260
|
-
}
|
|
2261
|
-
}
|
|
2262
|
-
function validateId(id, fieldName) {
|
|
2263
|
-
if (!id || typeof id !== "string") {
|
|
2264
|
-
throw new MorphValidationError(`${fieldName} is required`, fieldName);
|
|
2265
|
-
}
|
|
2266
|
-
if (id.trim().length === 0) {
|
|
2267
|
-
throw new MorphValidationError(`${fieldName} cannot be empty`, fieldName);
|
|
2268
|
-
}
|
|
2269
|
-
}
|
|
2270
|
-
async function createProfile(input, config = {}) {
|
|
2271
|
-
validateCreateInput(input);
|
|
2272
|
-
const apiUrl = config.apiUrl || DEFAULT_API_URL2;
|
|
2273
|
-
const headers = buildHeaders(config);
|
|
2274
|
-
const response = await fetchWithRetry(
|
|
2275
|
-
`${apiUrl}/profiles`,
|
|
2276
|
-
{
|
|
2277
|
-
method: "POST",
|
|
2278
|
-
headers,
|
|
2279
|
-
body: JSON.stringify(transformCreateInput(input))
|
|
2280
|
-
},
|
|
2281
|
-
config.retryConfig
|
|
2282
|
-
);
|
|
2283
|
-
if (!response.ok) {
|
|
2284
|
-
const errorText = await response.text().catch(() => response.statusText);
|
|
2285
|
-
const requestId = response.headers.get("x-request-id") || void 0;
|
|
2286
|
-
throw parseAPIError(response.status, errorText, requestId);
|
|
2287
|
-
}
|
|
2288
|
-
const apiProfile = await response.json();
|
|
2289
|
-
const profile = transformProfile(apiProfile);
|
|
2290
|
-
const session = await startProfileSession(config, { profileId: profile.id });
|
|
2291
|
-
return buildProfileSetup(profile, session, config);
|
|
2292
|
-
}
|
|
2293
|
-
async function listProfiles(config = {}, repoId) {
|
|
2294
|
-
const apiUrl = config.apiUrl || DEFAULT_API_URL2;
|
|
2295
|
-
const headers = buildHeaders(config);
|
|
2296
|
-
const url = repoId ? `${apiUrl}/profiles?repo_id=${encodeURIComponent(repoId)}` : `${apiUrl}/profiles`;
|
|
2297
|
-
const response = await fetchWithRetry(
|
|
2298
|
-
url,
|
|
2299
|
-
{ method: "GET", headers },
|
|
2300
|
-
config.retryConfig
|
|
2301
|
-
);
|
|
2302
|
-
if (!response.ok) {
|
|
2303
|
-
const errorText = await response.text().catch(() => response.statusText);
|
|
2304
|
-
const requestId = response.headers.get("x-request-id") || void 0;
|
|
2305
|
-
throw parseAPIError(response.status, errorText, requestId);
|
|
2306
|
-
}
|
|
2307
|
-
const data = await response.json();
|
|
2308
|
-
return data.profiles.map(transformProfile);
|
|
2309
|
-
}
|
|
2310
|
-
async function getProfile(id, config = {}) {
|
|
2311
|
-
validateId(id, "id");
|
|
2312
|
-
const apiUrl = config.apiUrl || DEFAULT_API_URL2;
|
|
2313
|
-
const headers = buildHeaders(config);
|
|
2314
|
-
const response = await fetchWithRetry(
|
|
2315
|
-
`${apiUrl}/profiles/${encodeURIComponent(id)}`,
|
|
2316
|
-
{ method: "GET", headers },
|
|
2317
|
-
config.retryConfig
|
|
2318
|
-
);
|
|
2319
|
-
if (!response.ok) {
|
|
2320
|
-
const errorText = await response.text().catch(() => response.statusText);
|
|
2321
|
-
const requestId = response.headers.get("x-request-id") || void 0;
|
|
2322
|
-
throw parseAPIError(response.status, errorText, requestId);
|
|
2323
|
-
}
|
|
2324
|
-
const apiProfile = await response.json();
|
|
2325
|
-
const profile = transformProfile(apiProfile);
|
|
2326
|
-
return {
|
|
2327
|
-
...profile,
|
|
2328
|
-
getState: () => getProfileState(id, config),
|
|
2329
|
-
delete: () => deleteProfile(id, config)
|
|
2330
|
-
};
|
|
2331
|
-
}
|
|
2332
|
-
async function updateProfile(id, config = {}) {
|
|
2333
|
-
validateId(id, "id");
|
|
2334
|
-
const profile = await fetchProfile(id, config);
|
|
2335
|
-
const session = await startProfileSession(config, { profileId: profile.id });
|
|
2336
|
-
return buildProfileSetup(profile, session, config);
|
|
2337
|
-
}
|
|
2338
|
-
async function deleteProfile(id, config = {}) {
|
|
2339
|
-
validateId(id, "id");
|
|
2340
|
-
const apiUrl = config.apiUrl || DEFAULT_API_URL2;
|
|
2341
|
-
const headers = buildHeaders(config);
|
|
2342
|
-
const response = await fetchWithRetry(
|
|
2343
|
-
`${apiUrl}/profiles/${encodeURIComponent(id)}`,
|
|
2344
|
-
{ method: "DELETE", headers },
|
|
2345
|
-
config.retryConfig
|
|
2346
|
-
);
|
|
2347
|
-
if (!response.ok) {
|
|
2348
|
-
const errorText = await response.text().catch(() => response.statusText);
|
|
2349
|
-
const requestId = response.headers.get("x-request-id") || void 0;
|
|
2350
|
-
throw parseAPIError(response.status, errorText, requestId);
|
|
2351
|
-
}
|
|
2352
|
-
}
|
|
2353
|
-
async function startProfileSession(config = {}, input) {
|
|
2354
|
-
if (!config.apiKey) {
|
|
2355
|
-
throw new MorphAuthenticationError();
|
|
2356
|
-
}
|
|
2357
|
-
const apiUrl = config.apiUrl || DEFAULT_API_URL2;
|
|
2358
|
-
const headers = buildHeaders(config);
|
|
2359
|
-
const body = input?.profileId ? { profile_id: input.profileId } : {};
|
|
2360
|
-
const response = await fetchWithRetry(
|
|
2361
|
-
`${apiUrl}/profiles/session/start`,
|
|
2362
|
-
{
|
|
2363
|
-
method: "POST",
|
|
2364
|
-
headers,
|
|
2365
|
-
body: JSON.stringify(body)
|
|
2366
|
-
},
|
|
2367
|
-
config.retryConfig
|
|
2368
|
-
);
|
|
2369
|
-
if (!response.ok) {
|
|
2370
|
-
const errorText = await response.text().catch(() => response.statusText);
|
|
2371
|
-
const requestId = response.headers.get("x-request-id") || void 0;
|
|
2372
|
-
throw parseAPIError(response.status, errorText, requestId);
|
|
2373
|
-
}
|
|
2374
|
-
const apiSession = await response.json();
|
|
2375
|
-
return transformSession(apiSession);
|
|
2376
|
-
}
|
|
2377
|
-
async function saveProfileSession(input, config = {}) {
|
|
2378
|
-
validateId(input.sessionId, "sessionId");
|
|
2379
|
-
validateId(input.profileId, "profileId");
|
|
2380
|
-
const apiUrl = config.apiUrl || DEFAULT_API_URL2;
|
|
2381
|
-
const headers = buildHeaders(config);
|
|
2382
|
-
const response = await fetchWithRetry(
|
|
2383
|
-
`${apiUrl}/profiles/session/save`,
|
|
2384
|
-
{
|
|
2385
|
-
method: "POST",
|
|
2386
|
-
headers,
|
|
2387
|
-
body: JSON.stringify(transformSaveInput(input))
|
|
2388
|
-
},
|
|
2389
|
-
config.retryConfig
|
|
2390
|
-
);
|
|
2391
|
-
if (!response.ok) {
|
|
2392
|
-
const errorText = await response.text().catch(() => response.statusText);
|
|
2393
|
-
const requestId = response.headers.get("x-request-id") || void 0;
|
|
2394
|
-
throw parseAPIError(response.status, errorText, requestId);
|
|
2395
|
-
}
|
|
2396
|
-
const apiProfile = await response.json();
|
|
2397
|
-
return transformProfile(apiProfile);
|
|
2398
|
-
}
|
|
2399
|
-
async function listRepos(config = {}) {
|
|
2400
|
-
const apiUrl = config.apiUrl || DEFAULT_API_URL2;
|
|
2401
|
-
const headers = buildHeaders(config);
|
|
2402
|
-
const response = await fetchWithRetry(
|
|
2403
|
-
`${apiUrl}/repos`,
|
|
2404
|
-
{ method: "GET", headers },
|
|
2405
|
-
config.retryConfig
|
|
2406
|
-
);
|
|
2407
|
-
if (!response.ok) {
|
|
2408
|
-
const errorText = await response.text().catch(() => response.statusText);
|
|
2409
|
-
const requestId = response.headers.get("x-request-id") || void 0;
|
|
2410
|
-
throw parseAPIError(response.status, errorText, requestId);
|
|
2411
|
-
}
|
|
2412
|
-
const data = await response.json();
|
|
2413
|
-
const repos = Array.isArray(data?.repos) ? data.repos : [];
|
|
2414
|
-
return repos.map((repo) => ({
|
|
2415
|
-
repoId: repo.repo_id,
|
|
2416
|
-
repoFullName: repo.repo_full_name,
|
|
2417
|
-
profileCount: repo.profile_count ?? 0
|
|
2418
|
-
}));
|
|
2419
|
-
}
|
|
2420
|
-
async function getProfileState(profileId, config = {}) {
|
|
2421
|
-
validateId(profileId, "profileId");
|
|
2422
|
-
const apiUrl = config.apiUrl || DEFAULT_API_URL2;
|
|
2423
|
-
const headers = buildHeaders(config);
|
|
2424
|
-
const response = await fetchWithRetry(
|
|
2425
|
-
`${apiUrl}/profiles/${encodeURIComponent(profileId)}/state`,
|
|
2426
|
-
{ method: "GET", headers },
|
|
2427
|
-
config.retryConfig
|
|
2428
|
-
);
|
|
2429
|
-
if (!response.ok) {
|
|
2430
|
-
const errorText = await response.text().catch(() => response.statusText);
|
|
2431
|
-
const requestId = response.headers.get("x-request-id") || void 0;
|
|
2432
|
-
throw parseAPIError(response.status, errorText, requestId);
|
|
2433
|
-
}
|
|
2434
|
-
const apiState = await response.json();
|
|
2435
|
-
return transformStateResponse(apiState);
|
|
2436
|
-
}
|
|
2437
|
-
function buildHeaders(config) {
|
|
2438
|
-
const headers = { "Content-Type": "application/json" };
|
|
2439
|
-
if (config.apiKey) {
|
|
2440
|
-
headers["Authorization"] = `Bearer ${config.apiKey}`;
|
|
2441
|
-
}
|
|
2442
|
-
return headers;
|
|
2443
|
-
}
|
|
2444
|
-
async function fetchProfile(id, config) {
|
|
2445
|
-
const apiUrl = config.apiUrl || DEFAULT_API_URL2;
|
|
2446
|
-
const headers = buildHeaders(config);
|
|
2447
|
-
const response = await fetchWithRetry(
|
|
2448
|
-
`${apiUrl}/profiles/${encodeURIComponent(id)}`,
|
|
2449
|
-
{ method: "GET", headers },
|
|
2450
|
-
config.retryConfig
|
|
2451
|
-
);
|
|
2452
|
-
if (!response.ok) {
|
|
2453
|
-
const errorText = await response.text().catch(() => response.statusText);
|
|
2454
|
-
const requestId = response.headers.get("x-request-id") || void 0;
|
|
2455
|
-
throw parseAPIError(response.status, errorText, requestId);
|
|
2456
|
-
}
|
|
2457
|
-
const apiProfile = await response.json();
|
|
2458
|
-
return transformProfile(apiProfile);
|
|
2459
|
-
}
|
|
2460
|
-
function buildProfileSetup(profile, session, config) {
|
|
2461
|
-
return {
|
|
2462
|
-
profile,
|
|
2463
|
-
session,
|
|
2464
|
-
save: () => saveProfileSession({ sessionId: session.sessionId, profileId: profile.id }, config)
|
|
2465
|
-
};
|
|
2466
|
-
}
|
|
2467
|
-
|
|
2468
|
-
// tools/browser/core.ts
|
|
2469
|
-
var DEFAULT_CONFIG2 = {
|
|
2470
|
-
apiUrl: process.env.MORPH_ENVIRONMENT === "DEV" ? "http://localhost:8000" : "https://browser.morphllm.com",
|
|
2471
|
-
timeout: 1e6,
|
|
2472
|
-
// 10 minutes for complex tasks
|
|
2473
|
-
debug: false
|
|
2474
|
-
};
|
|
2475
|
-
var BrowserClient = class extends APIResource {
|
|
2476
|
-
config;
|
|
2477
|
-
/**
|
|
2478
|
-
* Profile management - create and manage browser profiles for storing login state.
|
|
2479
|
-
*/
|
|
2480
|
-
profiles;
|
|
2481
|
-
constructor(clientOrConfig = {}) {
|
|
2482
|
-
const isClient = clientOrConfig instanceof MorphAPIClient;
|
|
2483
|
-
super(
|
|
2484
|
-
isClient ? clientOrConfig : new MorphAPIClient({
|
|
2485
|
-
apiKey: clientOrConfig.apiKey,
|
|
2486
|
-
browserURL: clientOrConfig.apiUrl,
|
|
2487
|
-
timeout: clientOrConfig.timeout,
|
|
2488
|
-
retryConfig: clientOrConfig.retryConfig,
|
|
2489
|
-
debug: clientOrConfig.debug
|
|
2490
|
-
})
|
|
2491
|
-
);
|
|
2492
|
-
this.config = isClient ? {
|
|
2493
|
-
...DEFAULT_CONFIG2,
|
|
2494
|
-
apiUrl: clientOrConfig.browserURL,
|
|
2495
|
-
apiKey: clientOrConfig.resolveApiKey(),
|
|
2496
|
-
retryConfig: clientOrConfig.retryConfig,
|
|
2497
|
-
debug: clientOrConfig.debug
|
|
2498
|
-
} : { ...DEFAULT_CONFIG2, ...clientOrConfig };
|
|
2499
|
-
this.profiles = new ProfilesClient(this.config);
|
|
2500
|
-
}
|
|
2501
|
-
/**
|
|
2502
|
-
* Execute a browser automation task
|
|
2503
|
-
*/
|
|
2504
|
-
async execute(input) {
|
|
2505
|
-
return executeBrowserTask(input, this.config);
|
|
2506
|
-
}
|
|
2507
|
-
async createTask(input) {
|
|
2508
|
-
const apiUrl = this.config.apiUrl || DEFAULT_CONFIG2.apiUrl;
|
|
2509
|
-
const debug = this.config.debug || false;
|
|
2510
|
-
const hasTask = typeof input.task === "string" && input.task.trim().length > 0;
|
|
2511
|
-
const hasDiff = typeof input.diff === "string" && input.diff.trim().length > 0;
|
|
2512
|
-
if (!hasTask && !hasDiff) {
|
|
2513
|
-
throw new Error('Browser task requires either "task" (natural language) or "diff" (PR-review planning)');
|
|
2514
|
-
}
|
|
2515
|
-
logger.debug("Browser", "create_task", { task: (input.task ?? "").slice(0, 100), url: input.url, endpoint: `${apiUrl}/browser-task/async` });
|
|
2516
|
-
const headers = { "Content-Type": "application/json" };
|
|
2517
|
-
if (this.config.apiKey) headers["Authorization"] = `Bearer ${this.config.apiKey}`;
|
|
2518
|
-
const response = await fetch(`${apiUrl}/browser-task/async`, {
|
|
2519
|
-
method: "POST",
|
|
2520
|
-
headers,
|
|
2521
|
-
body: JSON.stringify({
|
|
2522
|
-
task: input.task,
|
|
2523
|
-
diff: input.diff,
|
|
2524
|
-
url: input.url,
|
|
2525
|
-
max_steps: input.maxSteps ?? 10,
|
|
2526
|
-
model: input.model ?? "morph-computer-use-v0",
|
|
2527
|
-
viewport_width: input.viewportWidth ?? 1280,
|
|
2528
|
-
viewport_height: input.viewportHeight ?? 720,
|
|
2529
|
-
external_id: input.externalId,
|
|
2530
|
-
repo_id: input.repoId,
|
|
2531
|
-
repo_full_name: input.repoFullName,
|
|
2532
|
-
commit_id: input.commitId,
|
|
2533
|
-
record_video: input.recordVideo ?? false,
|
|
2534
|
-
video_width: input.videoWidth ?? input.viewportWidth ?? 1280,
|
|
2535
|
-
video_height: input.videoHeight ?? input.viewportHeight ?? 720,
|
|
2536
|
-
allow_resizing: input.allowResizing ?? false,
|
|
2537
|
-
structured_output: "schema" in input ? stringifyStructuredOutput(input.schema) : void 0,
|
|
2538
|
-
auth: input.auth,
|
|
2539
|
-
profile_id: input.profileId,
|
|
2540
|
-
force_query_params: input.forceQueryParams
|
|
2541
|
-
})
|
|
2542
|
-
});
|
|
2543
|
-
if (!response.ok) {
|
|
2544
|
-
const errorText = await response.text().catch(() => response.statusText);
|
|
2545
|
-
logger.error("Browser", "create_task_error", { status: response.status, error: errorText });
|
|
2546
|
-
throw new Error(`HTTP ${response.status}: ${errorText}`);
|
|
2547
|
-
}
|
|
2548
|
-
const result = mapTaskResult(await response.json());
|
|
2549
|
-
logger.debug("Browser", "task_created", { recording_id: result.recordingId, task_id: result.taskId, debug_url: !!result.debugUrl });
|
|
2550
|
-
if ("schema" in input) {
|
|
2551
|
-
return wrapTaskResponseWithSchema(result, this.config, input.schema);
|
|
2552
|
-
} else {
|
|
2553
|
-
return wrapTaskResponse(result, this.config);
|
|
2554
|
-
}
|
|
2555
|
-
}
|
|
2556
|
-
/**
|
|
2557
|
-
* Execute task with recording and wait for video to be ready
|
|
2558
|
-
*/
|
|
2559
|
-
async executeWithRecording(input) {
|
|
2560
|
-
return executeWithRecording(input, this.config);
|
|
2561
|
-
}
|
|
2562
|
-
/**
|
|
2563
|
-
* Get recording status and URLs
|
|
2564
|
-
*/
|
|
2565
|
-
async getRecording(recordingId) {
|
|
2566
|
-
return getRecording(recordingId, this.config);
|
|
2567
|
-
}
|
|
2568
|
-
/**
|
|
2569
|
-
* Wait for recording to complete with automatic polling
|
|
2570
|
-
*/
|
|
2571
|
-
async waitForRecording(recordingId, options) {
|
|
2572
|
-
return waitForRecording(recordingId, this.config, options);
|
|
2573
|
-
}
|
|
2574
|
-
/**
|
|
2575
|
-
* Get errors from recording with screenshots
|
|
2576
|
-
*/
|
|
2577
|
-
async getErrors(recordingId) {
|
|
2578
|
-
return getErrors(recordingId, this.config);
|
|
2579
|
-
}
|
|
2580
|
-
/**
|
|
2581
|
-
* Get animated WebP preview of recording
|
|
2582
|
-
*/
|
|
2583
|
-
async getWebp(recordingId, options) {
|
|
2584
|
-
return getWebp(recordingId, this.config, options);
|
|
2585
|
-
}
|
|
2586
|
-
/**
|
|
2587
|
-
* Check if browser worker service is healthy
|
|
2588
|
-
*/
|
|
2589
|
-
async checkHealth() {
|
|
2590
|
-
return checkHealth(this.config);
|
|
2591
|
-
}
|
|
2592
|
-
};
|
|
2593
|
-
async function executeBrowserTask(input, config = {}) {
|
|
2594
|
-
const apiUrl = config.apiUrl || DEFAULT_CONFIG2.apiUrl;
|
|
2595
|
-
const timeout = config.timeout || DEFAULT_CONFIG2.timeout;
|
|
2596
|
-
const debug = config.debug || false;
|
|
2597
|
-
if (!input.task || input.task.trim().length === 0) {
|
|
2598
|
-
return {
|
|
2599
|
-
success: false,
|
|
2600
|
-
error: 'Task description is required. Example: "Go to example.com and click the login button"'
|
|
2601
|
-
};
|
|
2602
|
-
}
|
|
2603
|
-
if (input.maxSteps !== void 0 && (input.maxSteps < 1 || input.maxSteps > 50)) {
|
|
2604
|
-
return {
|
|
2605
|
-
success: false,
|
|
2606
|
-
error: "maxSteps must be between 1 and 50. Use more steps for complex multi-page flows."
|
|
2607
|
-
};
|
|
2608
|
-
}
|
|
2609
|
-
logger.debug("Browser", "execute_start", { task: input.task.slice(0, 100), url: input.url, max_steps: input.maxSteps ?? 10, record_video: input.recordVideo ?? false });
|
|
2610
|
-
const startTime = Date.now();
|
|
2611
|
-
try {
|
|
2612
|
-
const headers = { "Content-Type": "application/json" };
|
|
2613
|
-
if (config.apiKey) headers["Authorization"] = `Bearer ${config.apiKey}`;
|
|
2614
|
-
const fetchPromise = fetchWithRetry(
|
|
2615
|
-
`${apiUrl}/browser-task`,
|
|
2616
|
-
{
|
|
2617
|
-
method: "POST",
|
|
2618
|
-
headers,
|
|
2619
|
-
body: JSON.stringify({
|
|
2620
|
-
task: input.task,
|
|
2621
|
-
url: input.url,
|
|
2622
|
-
max_steps: input.maxSteps ?? 10,
|
|
2623
|
-
model: input.model ?? "morph-computer-use-v0",
|
|
2624
|
-
viewport_width: input.viewportWidth ?? 1280,
|
|
2625
|
-
viewport_height: input.viewportHeight ?? 720,
|
|
2626
|
-
external_id: input.externalId,
|
|
2627
|
-
repo_id: input.repoId,
|
|
2628
|
-
commit_id: input.commitId,
|
|
2629
|
-
record_video: input.recordVideo ?? false,
|
|
2630
|
-
video_width: input.videoWidth ?? input.viewportWidth ?? 1280,
|
|
2631
|
-
video_height: input.videoHeight ?? input.viewportHeight ?? 720,
|
|
2632
|
-
allow_resizing: input.allowResizing ?? false,
|
|
2633
|
-
structured_output: input.structuredOutput,
|
|
2634
|
-
auth: input.auth,
|
|
2635
|
-
profile_id: input.profileId,
|
|
2636
|
-
force_query_params: input.forceQueryParams
|
|
2637
|
-
})
|
|
2638
|
-
},
|
|
2639
|
-
config.retryConfig
|
|
2640
|
-
);
|
|
2641
|
-
const response = await withTimeout(
|
|
2642
|
-
fetchPromise,
|
|
2643
|
-
timeout,
|
|
2644
|
-
`Browser task timed out after ${timeout}ms. Consider increasing timeout or reducing maxSteps.`
|
|
2645
|
-
);
|
|
2646
|
-
if (!response.ok) {
|
|
2647
|
-
const errorText = await response.text().catch(() => response.statusText);
|
|
2648
|
-
logger.error("Browser", "execute_error", { status: response.status, error: errorText });
|
|
2649
|
-
throw new Error(`HTTP ${response.status}: ${errorText}`);
|
|
2650
|
-
}
|
|
2651
|
-
const result = mapTaskResult(await response.json());
|
|
2652
|
-
const elapsed = Date.now() - startTime;
|
|
2653
|
-
logger.debug("Browser", "execute_complete", { success: result.success, latency_ms: elapsed, steps: result.stepsTaken ?? 0, recording_id: result.recordingId });
|
|
2654
|
-
return result;
|
|
2655
|
-
} catch (error) {
|
|
2656
|
-
if (error instanceof Error) {
|
|
2657
|
-
if (error.message.includes("ECONNREFUSED") || error.message.includes("fetch failed")) {
|
|
2658
|
-
return {
|
|
2659
|
-
success: false,
|
|
2660
|
-
error: `Cannot connect to browser worker at ${apiUrl}. Ensure the service is running and accessible. For local dev, set MORPH_ENVIRONMENT=DEV.`
|
|
2661
|
-
};
|
|
2662
|
-
}
|
|
2663
|
-
return {
|
|
2664
|
-
success: false,
|
|
2665
|
-
error: error.message
|
|
2666
|
-
};
|
|
2667
|
-
}
|
|
2668
|
-
return {
|
|
2669
|
-
success: false,
|
|
2670
|
-
error: String(error)
|
|
2671
|
-
};
|
|
2672
|
-
}
|
|
2673
|
-
}
|
|
2674
|
-
async function getRecording(recordingId, config = {}) {
|
|
2675
|
-
const apiUrl = config.apiUrl || DEFAULT_CONFIG2.apiUrl;
|
|
2676
|
-
const debug = config.debug || false;
|
|
2677
|
-
if (!config.apiKey) {
|
|
2678
|
-
throw new Error("API key required for getRecording");
|
|
2679
|
-
}
|
|
2680
|
-
if (debug) console.log(`[Browser] getRecording: ${recordingId}`);
|
|
2681
|
-
const response = await fetch(`${apiUrl}/recordings/${recordingId}`, {
|
|
2682
|
-
method: "GET",
|
|
2683
|
-
headers: { "Authorization": `Bearer ${config.apiKey}` }
|
|
2684
|
-
});
|
|
2685
|
-
if (!response.ok) {
|
|
2686
|
-
const errorText = await response.text().catch(() => response.statusText);
|
|
2687
|
-
if (debug) console.error(`[Browser] getRecording error: ${response.status} - ${errorText}`);
|
|
2688
|
-
throw new Error(`HTTP ${response.status}: ${errorText}`);
|
|
2689
|
-
}
|
|
2690
|
-
const data = mapRecordingStatus(await response.json());
|
|
2691
|
-
if (debug) console.log(`[Browser] Recording status: ${data.status}`);
|
|
2692
|
-
return {
|
|
2693
|
-
...data,
|
|
2694
|
-
getWebp: (options) => getWebp(recordingId, config, options),
|
|
2695
|
-
getErrors: () => getErrors(recordingId, config)
|
|
2696
|
-
};
|
|
2697
|
-
}
|
|
2698
|
-
async function waitForRecording(recordingId, config = {}, options = {}) {
|
|
2699
|
-
const timeout = options.timeout ?? 6e4;
|
|
2700
|
-
const pollInterval = options.pollInterval ?? 2e3;
|
|
2701
|
-
const startTime = Date.now();
|
|
2702
|
-
while (Date.now() - startTime < timeout) {
|
|
2703
|
-
const status = await getRecording(recordingId, config);
|
|
2704
|
-
if (status.status === "COMPLETED" || status.status === "ERROR") {
|
|
2705
|
-
return status;
|
|
2706
|
-
}
|
|
2707
|
-
await new Promise((resolve2) => setTimeout(resolve2, pollInterval));
|
|
2708
|
-
}
|
|
2709
|
-
throw new Error(`Recording timeout after ${timeout}ms - status still pending`);
|
|
2710
|
-
}
|
|
2711
|
-
async function executeWithRecording(input, config = {}) {
|
|
2712
|
-
const taskResult = await executeBrowserTask(input, config);
|
|
2713
|
-
if (taskResult.recordingId) {
|
|
2714
|
-
try {
|
|
2715
|
-
const recording = await waitForRecording(
|
|
2716
|
-
taskResult.recordingId,
|
|
2717
|
-
config,
|
|
2718
|
-
{ timeout: 6e4, pollInterval: 2e3 }
|
|
2719
|
-
);
|
|
2720
|
-
return {
|
|
2721
|
-
...taskResult,
|
|
2722
|
-
recording
|
|
2723
|
-
};
|
|
2724
|
-
} catch (error) {
|
|
2725
|
-
const errorRecording = {
|
|
2726
|
-
id: taskResult.recordingId,
|
|
2727
|
-
status: "ERROR",
|
|
2728
|
-
error: error instanceof Error ? error.message : String(error),
|
|
2729
|
-
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2730
|
-
getWebp: (options) => getWebp(taskResult.recordingId, config, options),
|
|
2731
|
-
getErrors: () => getErrors(taskResult.recordingId, config)
|
|
2732
|
-
};
|
|
2733
|
-
return {
|
|
2734
|
-
...taskResult,
|
|
2735
|
-
recording: errorRecording
|
|
2736
|
-
};
|
|
2737
|
-
}
|
|
2738
|
-
}
|
|
2739
|
-
return taskResult;
|
|
2740
|
-
}
|
|
2741
|
-
async function getErrors(recordingId, config = {}) {
|
|
2742
|
-
const apiUrl = config.apiUrl || DEFAULT_CONFIG2.apiUrl;
|
|
2743
|
-
const debug = config.debug || false;
|
|
2744
|
-
if (!config.apiKey) {
|
|
2745
|
-
throw new Error("API key required for getErrors");
|
|
2746
|
-
}
|
|
2747
|
-
if (debug) console.log(`[Browser] getErrors: ${recordingId}`);
|
|
2748
|
-
const response = await fetch(`${apiUrl}/recordings/${recordingId}/errors`, {
|
|
2749
|
-
method: "GET",
|
|
2750
|
-
headers: { "Authorization": `Bearer ${config.apiKey}` }
|
|
2751
|
-
});
|
|
2752
|
-
if (!response.ok) {
|
|
2753
|
-
const errorText = await response.text().catch(() => response.statusText);
|
|
2754
|
-
if (debug) console.error(`[Browser] getErrors error: ${response.status} - ${errorText}`);
|
|
2755
|
-
throw new Error(`HTTP ${response.status}: ${errorText}`);
|
|
2756
|
-
}
|
|
2757
|
-
const errors = mapErrorsResponse(await response.json());
|
|
2758
|
-
if (debug) console.log(`[Browser] Found ${errors.totalErrors} errors`);
|
|
2759
|
-
return errors;
|
|
2760
|
-
}
|
|
2761
|
-
function stringifyStructuredOutput(schema) {
|
|
2762
|
-
try {
|
|
2763
|
-
return JSON.stringify({
|
|
2764
|
-
type: "object",
|
|
2765
|
-
description: "Zod schema definition (Zod v3)",
|
|
2766
|
-
zodDef: schema._def
|
|
2767
|
-
});
|
|
2768
|
-
} catch (error) {
|
|
2769
|
-
console.warn("[Browser] Failed to serialize Zod schema:", error);
|
|
2770
|
-
return JSON.stringify({
|
|
2771
|
-
type: "object",
|
|
2772
|
-
description: "Schema serialization failed"
|
|
2773
|
-
});
|
|
2774
|
-
}
|
|
2775
|
-
}
|
|
2776
|
-
function parseStructuredTaskOutput(result, schema) {
|
|
2777
|
-
if (!result.output) {
|
|
2778
|
-
return { ...result, parsed: null };
|
|
2779
|
-
}
|
|
2780
|
-
try {
|
|
2781
|
-
const parsed = JSON.parse(result.output);
|
|
2782
|
-
const validated = schema.parse(parsed);
|
|
2783
|
-
return { ...result, parsed: validated };
|
|
2784
|
-
} catch (error) {
|
|
2785
|
-
if (error instanceof SyntaxError) {
|
|
2786
|
-
return { ...result, parsed: null };
|
|
2787
|
-
}
|
|
2788
|
-
throw error;
|
|
2789
|
-
}
|
|
2790
|
-
}
|
|
2791
|
-
function mapTaskResult(api) {
|
|
2792
|
-
if (!api || typeof api !== "object") {
|
|
2793
|
-
return api;
|
|
2794
|
-
}
|
|
2795
|
-
return {
|
|
2796
|
-
success: api.success,
|
|
2797
|
-
result: api.result,
|
|
2798
|
-
error: api.error,
|
|
2799
|
-
stepsTaken: api.steps_taken,
|
|
2800
|
-
executionTimeMs: api.execution_time_ms,
|
|
2801
|
-
urls: api.urls,
|
|
2802
|
-
actionNames: api.action_names,
|
|
2803
|
-
errors: api.errors,
|
|
2804
|
-
modelActions: api.model_actions,
|
|
2805
|
-
isDone: api.is_done,
|
|
2806
|
-
actionHistory: api.action_history,
|
|
2807
|
-
actionResults: api.action_results,
|
|
2808
|
-
hasErrors: api.has_errors,
|
|
2809
|
-
numberOfSteps: api.number_of_steps,
|
|
2810
|
-
judgement: api.judgement,
|
|
2811
|
-
isValidated: api.is_validated,
|
|
2812
|
-
replayId: api.replay_id,
|
|
2813
|
-
replayUrl: api.replay_url,
|
|
2814
|
-
recordingId: api.recording_id,
|
|
2815
|
-
recordingStatus: api.recording_status,
|
|
2816
|
-
taskId: api.task_id,
|
|
2817
|
-
status: api.status,
|
|
2818
|
-
output: api.output,
|
|
2819
|
-
debugUrl: api.debug_url
|
|
2820
|
-
};
|
|
2821
|
-
}
|
|
2822
|
-
function mapRecordingStatus(api) {
|
|
2823
|
-
return {
|
|
2824
|
-
id: api.id,
|
|
2825
|
-
status: api.status,
|
|
2826
|
-
replayUrl: api.replay_url,
|
|
2827
|
-
networkUrl: api.network_url,
|
|
2828
|
-
consoleUrl: api.console_url,
|
|
2829
|
-
videoUrl: api.video_url,
|
|
2830
|
-
result: api.result,
|
|
2831
|
-
totalEvents: api.total_events,
|
|
2832
|
-
fileSize: api.file_size,
|
|
2833
|
-
duration: api.duration,
|
|
2834
|
-
error: api.error,
|
|
2835
|
-
createdAt: api.created_at
|
|
2836
|
-
};
|
|
2837
|
-
}
|
|
2838
|
-
function mapBrowserError(api) {
|
|
2839
|
-
return {
|
|
2840
|
-
type: api.type,
|
|
2841
|
-
message: api.message,
|
|
2842
|
-
url: api.url,
|
|
2843
|
-
timestamp: api.timestamp,
|
|
2844
|
-
screenshotUrl: api.screenshot_url,
|
|
2845
|
-
capturedAt: api.captured_at,
|
|
2846
|
-
status: api.status
|
|
2847
|
-
};
|
|
2848
|
-
}
|
|
2849
|
-
function mapErrorsResponse(api) {
|
|
2850
|
-
return {
|
|
2851
|
-
recordingId: api.recording_id,
|
|
2852
|
-
totalErrors: api.total_errors,
|
|
2853
|
-
errors: Array.isArray(api.errors) ? api.errors.map(mapBrowserError) : []
|
|
2854
|
-
};
|
|
2855
|
-
}
|
|
2856
|
-
function mapWebpResponse(api) {
|
|
2857
|
-
return {
|
|
2858
|
-
webpUrl: api.webp_url,
|
|
2859
|
-
cached: api.cached,
|
|
2860
|
-
width: api.width,
|
|
2861
|
-
fps: api.fps,
|
|
2862
|
-
maxDuration: api.max_duration,
|
|
2863
|
-
fileSize: api.file_size,
|
|
2864
|
-
maxSizeMb: api.max_size_mb,
|
|
2865
|
-
budgetMet: api.budget_met,
|
|
2866
|
-
qualityUsed: api.quality_used,
|
|
2867
|
-
attempts: api.attempts
|
|
2868
|
-
};
|
|
2869
|
-
}
|
|
2870
|
-
async function getTaskStatus(taskId, config) {
|
|
2871
|
-
const apiUrl = config.apiUrl || DEFAULT_CONFIG2.apiUrl;
|
|
2872
|
-
const debug = config.debug || false;
|
|
2873
|
-
if (debug) console.log(`[Browser] getTaskStatus: ${taskId}`);
|
|
2874
|
-
const headers = {};
|
|
2875
|
-
if (config.apiKey) headers["Authorization"] = `Bearer ${config.apiKey}`;
|
|
2876
|
-
const response = await fetch(`${apiUrl}/tasks/${taskId}`, {
|
|
2877
|
-
method: "GET",
|
|
2878
|
-
headers
|
|
2879
|
-
});
|
|
2880
|
-
if (!response.ok) {
|
|
2881
|
-
const errorText = await response.text().catch(() => response.statusText);
|
|
2882
|
-
if (debug) console.error(`[Browser] getTaskStatus error: ${response.status} - ${errorText}`);
|
|
2883
|
-
throw new Error(`HTTP ${response.status}: ${errorText}`);
|
|
2884
|
-
}
|
|
2885
|
-
const result = mapTaskResult(await response.json());
|
|
2886
|
-
if (debug) console.log(`[Browser] Task status: ${result.status}`);
|
|
2887
|
-
return result;
|
|
2888
|
-
}
|
|
2889
|
-
function generateLiveUrl(taskId, config) {
|
|
2890
|
-
const apiUrl = config.apiUrl || DEFAULT_CONFIG2.apiUrl;
|
|
2891
|
-
const baseUrl = apiUrl.replace("/api", "");
|
|
2892
|
-
return `${baseUrl}/tasks/${taskId}/live`;
|
|
2893
|
-
}
|
|
2894
|
-
async function pollTaskUntilComplete(taskId, config, pollConfig = {}) {
|
|
2895
|
-
const interval = pollConfig.interval ?? 2e3;
|
|
2896
|
-
const timeout = pollConfig.timeout ?? 3e5;
|
|
2897
|
-
const startTime = Date.now();
|
|
2898
|
-
while (Date.now() - startTime < timeout) {
|
|
2899
|
-
const status = await getTaskStatus(taskId, config);
|
|
2900
|
-
if (status.status === "completed" || status.status === "failed") {
|
|
2901
|
-
return status;
|
|
2902
|
-
}
|
|
2903
|
-
await new Promise((resolve2) => setTimeout(resolve2, interval));
|
|
2904
|
-
}
|
|
2905
|
-
throw new Error(`Task polling timeout after ${timeout}ms`);
|
|
2906
|
-
}
|
|
2907
|
-
function wrapTaskResponse(result, config) {
|
|
2908
|
-
const debugUrl = result.debugUrl ?? "";
|
|
2909
|
-
const wrapped = {
|
|
2910
|
-
...result,
|
|
2911
|
-
debugUrl,
|
|
2912
|
-
taskId: result.taskId || "",
|
|
2913
|
-
liveUrl: result.taskId ? generateLiveUrl(result.taskId, config) : debugUrl,
|
|
2914
|
-
complete: async (pollConfig) => {
|
|
2915
|
-
if (result.taskId) {
|
|
2916
|
-
return pollTaskUntilComplete(result.taskId, config, pollConfig);
|
|
2917
|
-
}
|
|
2918
|
-
if (result.recordingId) {
|
|
2919
|
-
const recording = await waitForRecording(
|
|
2920
|
-
result.recordingId,
|
|
2921
|
-
config,
|
|
2922
|
-
pollConfig
|
|
2923
|
-
);
|
|
2924
|
-
return {
|
|
2925
|
-
...result,
|
|
2926
|
-
recordingStatus: recording.status
|
|
2927
|
-
};
|
|
2928
|
-
}
|
|
2929
|
-
throw new Error("Cannot poll completion: no taskId or recordingId available");
|
|
2930
|
-
},
|
|
2931
|
-
// Add Steel live session helpers - either functional or error-throwing
|
|
2932
|
-
getLiveUrl: debugUrl ? (options) => buildLiveUrl(debugUrl, options) : () => {
|
|
2933
|
-
throw new Error(
|
|
2934
|
-
"Live sessions not available. Your backend must return a debugUrl in the response. Contact support@morphllm.com if you need help."
|
|
2935
|
-
);
|
|
2936
|
-
},
|
|
2937
|
-
getLiveIframe: debugUrl ? (optionsOrPreset) => {
|
|
2938
|
-
const options = resolvePreset(optionsOrPreset);
|
|
2939
|
-
return buildLiveIframe(debugUrl, options);
|
|
2940
|
-
} : () => {
|
|
2941
|
-
throw new Error(
|
|
2942
|
-
"Live sessions not available. Your backend must return a debugUrl in the response. Contact support@morphllm.com if you need help."
|
|
2943
|
-
);
|
|
2944
|
-
},
|
|
2945
|
-
getEmbedCode: debugUrl ? () => buildEmbedCode(debugUrl) : () => {
|
|
2946
|
-
throw new Error(
|
|
2947
|
-
"Live sessions not available. Your backend must return a debugUrl in the response. Contact support@morphllm.com if you need help."
|
|
2948
|
-
);
|
|
2949
|
-
}
|
|
2950
|
-
};
|
|
2951
|
-
return wrapped;
|
|
2952
|
-
}
|
|
2953
|
-
function wrapTaskResponseWithSchema(result, config, schema) {
|
|
2954
|
-
const debugUrl = result.debugUrl ?? "";
|
|
2955
|
-
const parsed = result.output ? parseStructuredTaskOutput(result, schema) : { ...result, parsed: null };
|
|
2956
|
-
const wrapped = {
|
|
2957
|
-
...parsed,
|
|
2958
|
-
debugUrl,
|
|
2959
|
-
taskId: result.taskId || "",
|
|
2960
|
-
liveUrl: result.taskId ? generateLiveUrl(result.taskId, config) : debugUrl,
|
|
2961
|
-
complete: async (pollConfig) => {
|
|
2962
|
-
if (result.taskId) {
|
|
2963
|
-
const finalResult = await pollTaskUntilComplete(result.taskId, config, pollConfig);
|
|
2964
|
-
return parseStructuredTaskOutput(finalResult, schema);
|
|
2965
|
-
}
|
|
2966
|
-
if (result.recordingId) {
|
|
2967
|
-
const recording = await waitForRecording(
|
|
2968
|
-
result.recordingId,
|
|
2969
|
-
config,
|
|
2970
|
-
pollConfig
|
|
2971
|
-
);
|
|
2972
|
-
return {
|
|
2973
|
-
...parsed,
|
|
2974
|
-
recordingStatus: recording.status
|
|
2975
|
-
};
|
|
2976
|
-
}
|
|
2977
|
-
throw new Error("Cannot poll completion: no taskId or recordingId available");
|
|
2978
|
-
},
|
|
2979
|
-
// Add Steel live session helpers - either functional or error-throwing
|
|
2980
|
-
getLiveUrl: debugUrl ? (options) => buildLiveUrl(debugUrl, options) : () => {
|
|
2981
|
-
throw new Error(
|
|
2982
|
-
"Live sessions not available. Your backend must return a debugUrl in the response. Contact support@morphllm.com if you need help enabling live sessions. "
|
|
2983
|
-
);
|
|
2984
|
-
},
|
|
2985
|
-
getLiveIframe: debugUrl ? (optionsOrPreset) => {
|
|
2986
|
-
const options = resolvePreset(optionsOrPreset);
|
|
2987
|
-
return buildLiveIframe(debugUrl, options);
|
|
2988
|
-
} : () => {
|
|
2989
|
-
throw new Error(
|
|
2990
|
-
"Live sessions not available. Your backend must return a debugUrl in the response. Contact support@morphllm.com if you need help enabling live sessions."
|
|
2991
|
-
);
|
|
2992
|
-
},
|
|
2993
|
-
getEmbedCode: debugUrl ? () => buildEmbedCode(debugUrl) : () => {
|
|
2994
|
-
throw new Error(
|
|
2995
|
-
"Live sessions not available. Your backend must return a debugUrl in the response. Contact support@morphllm.com if you need help enabling live sessions."
|
|
2996
|
-
);
|
|
2997
|
-
}
|
|
2998
|
-
};
|
|
2999
|
-
return wrapped;
|
|
3000
|
-
}
|
|
3001
|
-
async function getWebp(recordingId, config = {}, options = {}) {
|
|
3002
|
-
const apiUrl = config.apiUrl || DEFAULT_CONFIG2.apiUrl;
|
|
3003
|
-
const debug = config.debug || false;
|
|
3004
|
-
if (!config.apiKey) {
|
|
3005
|
-
throw new Error("API key required for getWebp");
|
|
3006
|
-
}
|
|
3007
|
-
const params = new URLSearchParams();
|
|
3008
|
-
if (options.maxDuration !== void 0) params.set("max_duration", String(options.maxDuration));
|
|
3009
|
-
if (options.fps !== void 0) params.set("fps", String(options.fps));
|
|
3010
|
-
if (options.width !== void 0) params.set("width", String(options.width));
|
|
3011
|
-
if (options.quality !== void 0) params.set("quality", String(options.quality));
|
|
3012
|
-
if (options.maxSizeMb !== void 0) params.set("max_size_mb", String(options.maxSizeMb));
|
|
3013
|
-
const url = `${apiUrl}/recordings/${recordingId}/webp${params.toString() ? "?" + params.toString() : ""}`;
|
|
3014
|
-
if (debug) console.log(`[Browser] getWebp: ${url}`);
|
|
3015
|
-
const response = await fetch(url, {
|
|
3016
|
-
method: "GET",
|
|
3017
|
-
headers: { "Authorization": `Bearer ${config.apiKey}` }
|
|
3018
|
-
});
|
|
3019
|
-
if (!response.ok) {
|
|
3020
|
-
const errorText = await response.text().catch(() => response.statusText);
|
|
3021
|
-
if (debug) console.error(`[Browser] getWebp error: ${response.status} - ${errorText}`);
|
|
3022
|
-
throw new Error(`HTTP ${response.status}: ${errorText}`);
|
|
3023
|
-
}
|
|
3024
|
-
const result = mapWebpResponse(await response.json());
|
|
3025
|
-
if (debug) console.log(`[Browser] WebP ready: ${result.webpUrl} (cached: ${result.cached})`);
|
|
3026
|
-
return result;
|
|
3027
|
-
}
|
|
3028
|
-
async function checkHealth(config = {}) {
|
|
3029
|
-
const apiUrl = config.apiUrl || DEFAULT_CONFIG2.apiUrl;
|
|
3030
|
-
try {
|
|
3031
|
-
const response = await fetch(`${apiUrl}/health`, {
|
|
3032
|
-
method: "GET",
|
|
3033
|
-
headers: config.apiKey ? { "Authorization": `Bearer ${config.apiKey}` } : {}
|
|
3034
|
-
});
|
|
3035
|
-
if (!response.ok) {
|
|
3036
|
-
throw new Error(`HTTP ${response.status}`);
|
|
3037
|
-
}
|
|
3038
|
-
const data = await response.json();
|
|
3039
|
-
return {
|
|
3040
|
-
ok: true,
|
|
3041
|
-
google_configured: data.google_configured ?? false,
|
|
3042
|
-
database_configured: data.database_configured ?? false,
|
|
3043
|
-
s3_configured: data.s3_configured ?? false
|
|
3044
|
-
};
|
|
3045
|
-
} catch (error) {
|
|
3046
|
-
return {
|
|
3047
|
-
ok: false,
|
|
3048
|
-
google_configured: false,
|
|
3049
|
-
database_configured: false,
|
|
3050
|
-
s3_configured: false,
|
|
3051
|
-
error: error instanceof Error ? error.message : String(error)
|
|
3052
|
-
};
|
|
3053
|
-
}
|
|
3054
|
-
}
|
|
3055
|
-
|
|
3056
|
-
// tools/warp_grep/agent/runner.ts
|
|
3057
|
-
init_config();
|
|
3058
|
-
|
|
3059
|
-
// tools/warp_grep/agent/parser.ts
|
|
3060
|
-
function parseReadLines(linesStr) {
|
|
3061
|
-
const ranges = [];
|
|
3062
|
-
for (const rangeStr of linesStr.split(",")) {
|
|
3063
|
-
const trimmed = rangeStr.trim();
|
|
3064
|
-
if (!trimmed) continue;
|
|
3065
|
-
const parts = trimmed.split("-").map((v) => parseInt(v.trim(), 10));
|
|
3066
|
-
if (parts.length >= 2 && Number.isFinite(parts[0]) && Number.isFinite(parts[1])) {
|
|
3067
|
-
ranges.push([parts[0], parts[1]]);
|
|
3068
|
-
} else if (Number.isFinite(parts[0])) {
|
|
3069
|
-
ranges.push([parts[0], parts[0]]);
|
|
3070
|
-
}
|
|
3071
|
-
}
|
|
3072
|
-
if (ranges.length === 1) return { start: ranges[0][0], end: ranges[0][1] };
|
|
3073
|
-
if (ranges.length > 1) return { lines: ranges };
|
|
3074
|
-
return {};
|
|
3075
|
-
}
|
|
3076
|
-
function parseFinishFiles(filesStr) {
|
|
3077
|
-
const files = [];
|
|
3078
|
-
for (const line of filesStr.trim().split(/\s+/)) {
|
|
3079
|
-
const trimmed = line.trim();
|
|
3080
|
-
if (!trimmed) continue;
|
|
3081
|
-
const searchFrom = /^[A-Za-z]:/.test(trimmed) ? 2 : 0;
|
|
3082
|
-
const colonIdx = trimmed.indexOf(":", searchFrom);
|
|
3083
|
-
if (colonIdx === -1) {
|
|
3084
|
-
files.push({ path: trimmed, lines: "*" });
|
|
3085
|
-
continue;
|
|
3086
|
-
}
|
|
3087
|
-
const filePath = trimmed.slice(0, colonIdx);
|
|
3088
|
-
const rangesPart = trimmed.slice(colonIdx + 1);
|
|
3089
|
-
if (!rangesPart.trim() || rangesPart.trim() === "*") {
|
|
3090
|
-
files.push({ path: filePath, lines: "*" });
|
|
3091
|
-
continue;
|
|
3092
|
-
}
|
|
3093
|
-
const ranges = [];
|
|
3094
|
-
for (const rangeStr of rangesPart.split(",")) {
|
|
3095
|
-
const rt = rangeStr.trim();
|
|
3096
|
-
if (!rt) continue;
|
|
3097
|
-
const parts = rt.split("-").map((v) => parseInt(v.trim(), 10));
|
|
3098
|
-
if (parts.length >= 2 && Number.isFinite(parts[0]) && Number.isFinite(parts[1])) {
|
|
3099
|
-
ranges.push([parts[0], parts[1]]);
|
|
3100
|
-
} else if (Number.isFinite(parts[0])) {
|
|
3101
|
-
ranges.push([parts[0], parts[0]]);
|
|
3102
|
-
}
|
|
3103
|
-
}
|
|
3104
|
-
files.push({ path: filePath, lines: ranges.length > 0 ? ranges : "*" });
|
|
3105
|
-
}
|
|
3106
|
-
return files;
|
|
3107
|
-
}
|
|
3108
|
-
function extractPathFromCommand(command) {
|
|
3109
|
-
const tokens = command.trim().split(/\s+/);
|
|
3110
|
-
const pathTokens = tokens.slice(1).filter((t) => !t.startsWith("-") && !t.startsWith("|") && !t.startsWith("\\("));
|
|
3111
|
-
return pathTokens[0] || ".";
|
|
3112
|
-
}
|
|
3113
|
-
|
|
3114
|
-
// tools/warp_grep/agent/tools/grep.ts
|
|
3115
|
-
async function toolGrep(provider, args) {
|
|
3116
|
-
const res = await provider.grep(args);
|
|
3117
|
-
if (res.error) {
|
|
3118
|
-
return { output: res.error };
|
|
3119
|
-
}
|
|
3120
|
-
if (!res.lines.length) {
|
|
3121
|
-
return { output: "no matches" };
|
|
3122
|
-
}
|
|
3123
|
-
return { output: res.lines.join("\n") };
|
|
3124
|
-
}
|
|
3125
|
-
|
|
3126
|
-
// tools/warp_grep/agent/tools/read.ts
|
|
3127
|
-
function isValidRange(start, end) {
|
|
3128
|
-
return typeof start === "number" && typeof end === "number" && Number.isFinite(start) && Number.isFinite(end) && start > 0 && end >= start;
|
|
3129
|
-
}
|
|
3130
|
-
async function toolRead(provider, args) {
|
|
3131
|
-
if (args.lines && Array.isArray(args.lines) && args.lines.length > 0) {
|
|
3132
|
-
const validRanges = [];
|
|
3133
|
-
for (const range of args.lines) {
|
|
3134
|
-
if (Array.isArray(range) && range.length >= 2 && isValidRange(range[0], range[1])) {
|
|
3135
|
-
validRanges.push([range[0], range[1]]);
|
|
3136
|
-
}
|
|
3137
|
-
}
|
|
3138
|
-
if (validRanges.length === 0) {
|
|
3139
|
-
const res2 = await provider.read({ path: args.path });
|
|
3140
|
-
if (res2.error) return res2.error;
|
|
3141
|
-
if (!res2.lines.length) return "(empty file)";
|
|
3142
|
-
return res2.lines.join("\n");
|
|
3143
|
-
}
|
|
3144
|
-
const chunks = [];
|
|
3145
|
-
for (const [start, end] of validRanges) {
|
|
3146
|
-
const res2 = await provider.read({ path: args.path, start, end });
|
|
3147
|
-
if (res2.error) return res2.error;
|
|
3148
|
-
chunks.push(res2.lines.join("\n"));
|
|
3149
|
-
}
|
|
3150
|
-
if (chunks.every((c) => c === "")) return "(empty file)";
|
|
3151
|
-
return chunks.join("\n...\n");
|
|
3152
|
-
}
|
|
3153
|
-
const res = await provider.read({ path: args.path, start: args.start, end: args.end });
|
|
3154
|
-
if (res.error) {
|
|
3155
|
-
return res.error;
|
|
3156
|
-
}
|
|
3157
|
-
if (!res.lines.length) return "(empty file)";
|
|
3158
|
-
return res.lines.join("\n");
|
|
3159
|
-
}
|
|
3160
|
-
|
|
3161
|
-
// tools/warp_grep/agent/tools/list_directory.ts
|
|
3162
|
-
init_config();
|
|
3163
|
-
var import_path2 = __toESM(require("path"), 1);
|
|
3164
|
-
async function toolListDirectory(provider, args, repoRoot) {
|
|
3165
|
-
const maxResults = args.maxResults ?? AGENT_CONFIG.MAX_LIST_RESULTS;
|
|
3166
|
-
const maxDepth = args.maxDepth ?? AGENT_CONFIG.MAX_LIST_DEPTH;
|
|
3167
|
-
const entries = await provider.listDirectory({
|
|
3168
|
-
path: args.path,
|
|
3169
|
-
pattern: args.pattern ?? null,
|
|
3170
|
-
maxResults,
|
|
3171
|
-
maxDepth
|
|
3172
|
-
});
|
|
3173
|
-
if (!entries.length) return "empty";
|
|
3174
|
-
if (repoRoot) {
|
|
3175
|
-
const absRoot = repoRoot;
|
|
3176
|
-
const lines = entries.map((e) => import_path2.default.join(absRoot, e.path));
|
|
3177
|
-
return lines.join("\n");
|
|
3178
|
-
}
|
|
3179
|
-
return entries.map((e) => e.path).join("\n");
|
|
3180
|
-
}
|
|
3181
|
-
|
|
3182
|
-
// tools/warp_grep/agent/tools/glob.ts
|
|
3183
|
-
async function toolGlob(provider, args) {
|
|
3184
|
-
const res = await provider.glob(args);
|
|
3185
|
-
if (res.error) {
|
|
3186
|
-
return res.error;
|
|
3187
|
-
}
|
|
3188
|
-
if (!res.files.length) {
|
|
3189
|
-
return "no matches";
|
|
3190
|
-
}
|
|
3191
|
-
const header = `Found ${res.totalFound} file(s) matching "${args.pattern}" within ${res.searchDir}, sorted by modification time (newest first):`;
|
|
3192
|
-
const body = res.files.join("\n");
|
|
3193
|
-
const truncated = res.totalFound > res.files.length ? `
|
|
3194
|
-
[${res.totalFound - res.files.length} files truncated]` : "";
|
|
3195
|
-
return `${header}
|
|
3196
|
-
---
|
|
3197
|
-
${body}
|
|
3198
|
-
---${truncated}`;
|
|
3199
|
-
}
|
|
3200
|
-
|
|
3201
|
-
// tools/warp_grep/agent/tools/finish.ts
|
|
3202
|
-
function isValidRange2(range) {
|
|
3203
|
-
return Array.isArray(range) && range.length >= 2 && typeof range[0] === "number" && typeof range[1] === "number" && Number.isFinite(range[0]) && Number.isFinite(range[1]) && range[0] > 0 && range[1] >= range[0];
|
|
3204
|
-
}
|
|
3205
|
-
function extractValidRanges(lines) {
|
|
3206
|
-
if (!Array.isArray(lines)) return null;
|
|
3207
|
-
const valid = [];
|
|
3208
|
-
for (const range of lines) {
|
|
3209
|
-
if (isValidRange2(range)) {
|
|
3210
|
-
valid.push([range[0], range[1]]);
|
|
3211
|
-
}
|
|
3212
|
-
}
|
|
3213
|
-
return valid.length > 0 ? valid : null;
|
|
3214
|
-
}
|
|
3215
|
-
async function readFinishFiles(repoRoot, files, reader) {
|
|
3216
|
-
const out = [];
|
|
3217
|
-
for (const f of files) {
|
|
3218
|
-
const validRanges = f.lines === "*" ? null : extractValidRanges(f.lines);
|
|
3219
|
-
if (f.lines === "*" || !validRanges) {
|
|
3220
|
-
const lines = await reader(f.path);
|
|
3221
|
-
out.push({ path: f.path, ranges: "*", content: lines.join("\n") });
|
|
3222
|
-
} else {
|
|
3223
|
-
const ranges = mergeRanges(validRanges);
|
|
3224
|
-
const chunks = [];
|
|
3225
|
-
for (let i = 0; i < ranges.length; i++) {
|
|
3226
|
-
const [s, e] = ranges[i];
|
|
3227
|
-
if (i === 0 && s > 1) {
|
|
3228
|
-
chunks.push(`// ... existing code, block starting at line ${s} ...`);
|
|
3229
|
-
} else if (i > 0) {
|
|
3230
|
-
chunks.push(`// ... existing code, block starting at line ${s} ...`);
|
|
3231
|
-
}
|
|
3232
|
-
const lines = await reader(f.path, s, e);
|
|
3233
|
-
chunks.push(lines.join("\n"));
|
|
3234
|
-
}
|
|
3235
|
-
out.push({ path: f.path, ranges, content: chunks.join("\n") });
|
|
3236
|
-
}
|
|
3237
|
-
}
|
|
3238
|
-
return out;
|
|
3239
|
-
}
|
|
3240
|
-
function mergeRanges(ranges) {
|
|
3241
|
-
if (!ranges.length) return [];
|
|
3242
|
-
const sorted = [...ranges].sort((a, b) => a[0] - b[0]);
|
|
3243
|
-
const merged = [];
|
|
3244
|
-
let [cs, ce] = sorted[0];
|
|
3245
|
-
for (let i = 1; i < sorted.length; i++) {
|
|
3246
|
-
const [s, e] = sorted[i];
|
|
3247
|
-
if (s <= ce + 1) {
|
|
3248
|
-
ce = Math.max(ce, e);
|
|
3249
|
-
} else {
|
|
3250
|
-
merged.push([cs, ce]);
|
|
3251
|
-
cs = s;
|
|
3252
|
-
ce = e;
|
|
3253
|
-
}
|
|
3254
|
-
}
|
|
3255
|
-
merged.push([cs, ce]);
|
|
3256
|
-
return merged;
|
|
1945
|
+
function mergeRanges(ranges) {
|
|
1946
|
+
if (!ranges.length) return [];
|
|
1947
|
+
const sorted = [...ranges].sort((a, b) => a[0] - b[0]);
|
|
1948
|
+
const merged = [];
|
|
1949
|
+
let [cs, ce] = sorted[0];
|
|
1950
|
+
for (let i = 1; i < sorted.length; i++) {
|
|
1951
|
+
const [s, e] = sorted[i];
|
|
1952
|
+
if (s <= ce + 1) {
|
|
1953
|
+
ce = Math.max(ce, e);
|
|
1954
|
+
} else {
|
|
1955
|
+
merged.push([cs, ce]);
|
|
1956
|
+
cs = s;
|
|
1957
|
+
ce = e;
|
|
1958
|
+
}
|
|
1959
|
+
}
|
|
1960
|
+
merged.push([cs, ce]);
|
|
1961
|
+
return merged;
|
|
3257
1962
|
}
|
|
3258
1963
|
|
|
3259
1964
|
// tools/warp_grep/agent/helpers.ts
|
|
@@ -3362,7 +2067,7 @@ var import_openai2 = __toESM(require("openai"), 1);
|
|
|
3362
2067
|
init_version();
|
|
3363
2068
|
var import_path4 = __toESM(require("path"), 1);
|
|
3364
2069
|
init_logger();
|
|
3365
|
-
var
|
|
2070
|
+
var DEFAULT_API_URL2 = "https://api.morphllm.com";
|
|
3366
2071
|
var TOOL_SPECS = [
|
|
3367
2072
|
{
|
|
3368
2073
|
type: "function",
|
|
@@ -3471,7 +2176,7 @@ var TOOL_SPECS = [
|
|
|
3471
2176
|
}
|
|
3472
2177
|
];
|
|
3473
2178
|
async function callModel(messages, model, options = {}) {
|
|
3474
|
-
const baseUrl = options.morphApiUrl ||
|
|
2179
|
+
const baseUrl = options.morphApiUrl || DEFAULT_API_URL2;
|
|
3475
2180
|
const apiKey = options.morphApiKey || process.env.MORPH_API_KEY || "";
|
|
3476
2181
|
const timeoutMs = options.timeout ?? AGENT_CONFIG.TIMEOUT_MS;
|
|
3477
2182
|
const parsedUrl = new URL(baseUrl);
|
|
@@ -4025,13 +2730,13 @@ function parseGitHubUrl(input) {
|
|
|
4025
2730
|
}
|
|
4026
2731
|
|
|
4027
2732
|
// tools/compact/core.ts
|
|
4028
|
-
var
|
|
2733
|
+
var DEFAULT_API_URL3 = "https://api.morphllm.com";
|
|
4029
2734
|
var DEFAULT_TIMEOUT4 = 12e4;
|
|
4030
2735
|
function resolveClient(clientOrConfig) {
|
|
4031
2736
|
if (clientOrConfig instanceof MorphAPIClient) return clientOrConfig;
|
|
4032
2737
|
return new MorphAPIClient({
|
|
4033
2738
|
apiKey: clientOrConfig.morphApiKey,
|
|
4034
|
-
baseURL: clientOrConfig.morphApiUrl ??
|
|
2739
|
+
baseURL: clientOrConfig.morphApiUrl ?? DEFAULT_API_URL3,
|
|
4035
2740
|
timeout: clientOrConfig.timeout ?? DEFAULT_TIMEOUT4,
|
|
4036
2741
|
retryConfig: clientOrConfig.retryConfig,
|
|
4037
2742
|
debug: clientOrConfig.debug
|
|
@@ -4412,582 +3117,16 @@ function formatResult(result) {
|
|
|
4412
3117
|
return parts.join("\n");
|
|
4413
3118
|
}
|
|
4414
3119
|
|
|
4415
|
-
// tools/github/types.ts
|
|
4416
|
-
var GitHubError = class extends Error {
|
|
4417
|
-
/** HTTP status code */
|
|
4418
|
-
status;
|
|
4419
|
-
/** Error code from API */
|
|
4420
|
-
code;
|
|
4421
|
-
constructor(message, status, code) {
|
|
4422
|
-
super(message);
|
|
4423
|
-
this.name = "GitHubError";
|
|
4424
|
-
this.status = status;
|
|
4425
|
-
this.code = code;
|
|
4426
|
-
}
|
|
4427
|
-
};
|
|
4428
|
-
var NoInstallationError = class extends GitHubError {
|
|
4429
|
-
constructor(message = "No GitHub installation found. Connect GitHub at morphllm.com/dashboard/integrations/github") {
|
|
4430
|
-
super(message, 404, "NO_INSTALLATION");
|
|
4431
|
-
}
|
|
4432
|
-
};
|
|
4433
|
-
var NotFoundError = class extends GitHubError {
|
|
4434
|
-
constructor(resource) {
|
|
4435
|
-
super(`${resource} not found`, 404, "NOT_FOUND");
|
|
4436
|
-
}
|
|
4437
|
-
};
|
|
4438
|
-
var PermissionError = class extends GitHubError {
|
|
4439
|
-
constructor(message = "Insufficient permissions for this operation") {
|
|
4440
|
-
super(message, 403, "PERMISSION_DENIED");
|
|
4441
|
-
}
|
|
4442
|
-
};
|
|
4443
|
-
|
|
4444
|
-
// tools/github/core.ts
|
|
4445
|
-
var DEFAULT_BASE_URL2 = "https://api.morphllm.com";
|
|
4446
|
-
var DEFAULT_TIMEOUT5 = 3e4;
|
|
4447
|
-
var GitHubClient = class extends APIResource {
|
|
4448
|
-
timeout;
|
|
4449
|
-
debug;
|
|
4450
|
-
defaultInstallationId;
|
|
4451
|
-
/** Installation operations */
|
|
4452
|
-
installations;
|
|
4453
|
-
/** Repository operations */
|
|
4454
|
-
repos;
|
|
4455
|
-
/** Project operations (monorepo sub-projects) */
|
|
4456
|
-
projects;
|
|
4457
|
-
/** Pull request operations */
|
|
4458
|
-
pullRequests;
|
|
4459
|
-
/** Deployment operations */
|
|
4460
|
-
deployments;
|
|
4461
|
-
/** Comment operations */
|
|
4462
|
-
comments;
|
|
4463
|
-
/** Check run operations */
|
|
4464
|
-
checkRuns;
|
|
4465
|
-
/**
|
|
4466
|
-
* Get the GitHub App installation URL.
|
|
4467
|
-
* Users visit this URL once to install the Morph GitHub App on their account/org.
|
|
4468
|
-
*/
|
|
4469
|
-
getInstallUrl() {
|
|
4470
|
-
return "https://github.com/apps/morph-subagents/installations/new";
|
|
4471
|
-
}
|
|
4472
|
-
constructor(clientOrConfig = {}, options = {}) {
|
|
4473
|
-
const isClient = clientOrConfig instanceof MorphAPIClient;
|
|
4474
|
-
const config = isClient ? {} : clientOrConfig;
|
|
4475
|
-
super(
|
|
4476
|
-
isClient ? clientOrConfig : new MorphAPIClient({
|
|
4477
|
-
apiKey: config.apiKey,
|
|
4478
|
-
baseURL: config.baseUrl ?? DEFAULT_BASE_URL2,
|
|
4479
|
-
timeout: config.timeout ?? DEFAULT_TIMEOUT5,
|
|
4480
|
-
debug: config.debug
|
|
4481
|
-
})
|
|
4482
|
-
);
|
|
4483
|
-
this.timeout = config.timeout || DEFAULT_TIMEOUT5;
|
|
4484
|
-
this.debug = config.debug || false;
|
|
4485
|
-
this.defaultInstallationId = isClient ? options.installationId : config.installationId;
|
|
4486
|
-
if (!this._client.resolveApiKey()) {
|
|
4487
|
-
throw new Error("API key required. Set MORPH_API_KEY or pass apiKey in config.");
|
|
4488
|
-
}
|
|
4489
|
-
this.installations = {
|
|
4490
|
-
list: this.listInstallations.bind(this),
|
|
4491
|
-
get: this.getInstallation.bind(this),
|
|
4492
|
-
update: this.updateInstallation.bind(this),
|
|
4493
|
-
disconnect: this.disconnectInstallation.bind(this)
|
|
4494
|
-
};
|
|
4495
|
-
this.repos = {
|
|
4496
|
-
list: this.listRepos.bind(this),
|
|
4497
|
-
get: this.getRepo.bind(this),
|
|
4498
|
-
update: this.updateRepo.bind(this),
|
|
4499
|
-
remove: this.removeRepo.bind(this),
|
|
4500
|
-
sync: this.syncRepos.bind(this)
|
|
4501
|
-
};
|
|
4502
|
-
this.projects = {
|
|
4503
|
-
list: this.listProjects.bind(this),
|
|
4504
|
-
create: this.createProject.bind(this),
|
|
4505
|
-
update: this.updateProject.bind(this),
|
|
4506
|
-
delete: this.deleteProject.bind(this)
|
|
4507
|
-
};
|
|
4508
|
-
this.pullRequests = {
|
|
4509
|
-
list: this.listPullRequests.bind(this),
|
|
4510
|
-
get: this.getPullRequest.bind(this)
|
|
4511
|
-
};
|
|
4512
|
-
this.deployments = {
|
|
4513
|
-
list: this.listDeployments.bind(this)
|
|
4514
|
-
};
|
|
4515
|
-
this.comments = {
|
|
4516
|
-
list: this.listComments.bind(this),
|
|
4517
|
-
create: this.createComment.bind(this),
|
|
4518
|
-
update: this.updateComment.bind(this),
|
|
4519
|
-
delete: this.deleteComment.bind(this)
|
|
4520
|
-
};
|
|
4521
|
-
this.checkRuns = {
|
|
4522
|
-
create: this.createCheckRun.bind(this),
|
|
4523
|
-
update: this.updateCheckRun.bind(this)
|
|
4524
|
-
};
|
|
4525
|
-
}
|
|
4526
|
-
/**
|
|
4527
|
-
* Make an authenticated API request
|
|
4528
|
-
*/
|
|
4529
|
-
async request(method, path6, body) {
|
|
4530
|
-
if (this.debug) {
|
|
4531
|
-
console.log(`[GitHub SDK] ${method} ${path6}`, body || "");
|
|
4532
|
-
}
|
|
4533
|
-
let response;
|
|
4534
|
-
try {
|
|
4535
|
-
response = await this._client.request(method, path6, {
|
|
4536
|
-
body,
|
|
4537
|
-
timeout: this.timeout,
|
|
4538
|
-
raw: true
|
|
4539
|
-
});
|
|
4540
|
-
} catch (error) {
|
|
4541
|
-
if (error instanceof Error && /timed out/i.test(error.message)) {
|
|
4542
|
-
throw new GitHubError("Request timeout", 408, "TIMEOUT");
|
|
4543
|
-
}
|
|
4544
|
-
throw new GitHubError(error instanceof Error ? error.message : "Unknown error", 500, "UNKNOWN");
|
|
4545
|
-
}
|
|
4546
|
-
if (!response.ok) {
|
|
4547
|
-
const errorData = await response.json().catch(() => ({}));
|
|
4548
|
-
const message = errorData.error || errorData.detail || errorData.message || response.statusText;
|
|
4549
|
-
if (this.debug) {
|
|
4550
|
-
console.error(`[GitHub SDK] Error ${response.status}:`, message);
|
|
4551
|
-
}
|
|
4552
|
-
if (response.status === 404) {
|
|
4553
|
-
if (message.includes("installation")) {
|
|
4554
|
-
throw new NoInstallationError(message);
|
|
4555
|
-
}
|
|
4556
|
-
throw new NotFoundError(message);
|
|
4557
|
-
}
|
|
4558
|
-
if (response.status === 403) {
|
|
4559
|
-
throw new PermissionError(message);
|
|
4560
|
-
}
|
|
4561
|
-
throw new GitHubError(message, response.status, errorData.code);
|
|
4562
|
-
}
|
|
4563
|
-
const data = await response.json();
|
|
4564
|
-
if (this.debug) {
|
|
4565
|
-
console.log(`[GitHub SDK] Response:`, JSON.stringify(data).slice(0, 200));
|
|
4566
|
-
}
|
|
4567
|
-
return data;
|
|
4568
|
-
}
|
|
4569
|
-
/**
|
|
4570
|
-
* Get the installation ID to use for a request
|
|
4571
|
-
*/
|
|
4572
|
-
getInstallationId(input) {
|
|
4573
|
-
return input?.installationId || this.defaultInstallationId;
|
|
4574
|
-
}
|
|
4575
|
-
// ==========================================================================
|
|
4576
|
-
// Installations
|
|
4577
|
-
// ==========================================================================
|
|
4578
|
-
async listInstallations() {
|
|
4579
|
-
return this.request("GET", "/api/v1/github/installations");
|
|
4580
|
-
}
|
|
4581
|
-
async getInstallation(installationId) {
|
|
4582
|
-
return this.request("GET", `/api/v1/github/installations/${installationId}`);
|
|
4583
|
-
}
|
|
4584
|
-
async updateInstallation(input) {
|
|
4585
|
-
if (this.debug) console.log("[GitHub SDK] updateInstallation", input.installationId);
|
|
4586
|
-
const { installationId, ...body } = input;
|
|
4587
|
-
return this.request("PATCH", `/api/v1/github/installations/${installationId}`, body);
|
|
4588
|
-
}
|
|
4589
|
-
async disconnectInstallation(installationId) {
|
|
4590
|
-
if (this.debug) console.log("[GitHub SDK] disconnectInstallation", installationId);
|
|
4591
|
-
return this.request("DELETE", `/api/v1/github/installations/${installationId}`);
|
|
4592
|
-
}
|
|
4593
|
-
// ==========================================================================
|
|
4594
|
-
// Repositories
|
|
4595
|
-
// ==========================================================================
|
|
4596
|
-
async listRepos(input) {
|
|
4597
|
-
const installationId = input.installationId || this.defaultInstallationId;
|
|
4598
|
-
if (!installationId) {
|
|
4599
|
-
throw new NoInstallationError("installationId required. Call installations.list() first.");
|
|
4600
|
-
}
|
|
4601
|
-
return this.request("GET", `/api/v1/github/installations/${installationId}/repos`);
|
|
4602
|
-
}
|
|
4603
|
-
async getRepo(repoId) {
|
|
4604
|
-
if (this.debug) console.log("[GitHub SDK] getRepo", repoId);
|
|
4605
|
-
return this.request("GET", `/api/v1/github/repos/${repoId}`);
|
|
4606
|
-
}
|
|
4607
|
-
async updateRepo(input) {
|
|
4608
|
-
if (this.debug) console.log("[GitHub SDK] updateRepo", input.repoId);
|
|
4609
|
-
const { repoId, ...body } = input;
|
|
4610
|
-
return this.request("PATCH", `/api/v1/github/repos/${repoId}`, body);
|
|
4611
|
-
}
|
|
4612
|
-
async removeRepo(repoId) {
|
|
4613
|
-
if (this.debug) console.log("[GitHub SDK] removeRepo", repoId);
|
|
4614
|
-
return this.request("DELETE", `/api/v1/github/repos/${repoId}`);
|
|
4615
|
-
}
|
|
4616
|
-
async syncRepos(input) {
|
|
4617
|
-
const installationId = input.installationId || this.defaultInstallationId;
|
|
4618
|
-
if (!installationId) {
|
|
4619
|
-
throw new NoInstallationError("installationId required. Call installations.list() first.");
|
|
4620
|
-
}
|
|
4621
|
-
if (this.debug) console.log("[GitHub SDK] syncRepos", installationId);
|
|
4622
|
-
return this.request("POST", `/api/v1/github/installations/${installationId}/repos/sync`);
|
|
4623
|
-
}
|
|
4624
|
-
// ==========================================================================
|
|
4625
|
-
// Projects (monorepo sub-projects)
|
|
4626
|
-
// ==========================================================================
|
|
4627
|
-
async listProjects(input) {
|
|
4628
|
-
if (this.debug) console.log("[GitHub SDK] listProjects", input.repoId);
|
|
4629
|
-
return this.request("GET", `/api/v1/github/repos/${input.repoId}/projects`);
|
|
4630
|
-
}
|
|
4631
|
-
async createProject(input) {
|
|
4632
|
-
if (this.debug) console.log("[GitHub SDK] createProject", input.repoId, input.name);
|
|
4633
|
-
const { repoId, ...body } = input;
|
|
4634
|
-
return this.request("POST", `/api/v1/github/repos/${repoId}/projects`, body);
|
|
4635
|
-
}
|
|
4636
|
-
async updateProject(input) {
|
|
4637
|
-
if (this.debug) console.log("[GitHub SDK] updateProject", input.projectId);
|
|
4638
|
-
const { projectId, ...body } = input;
|
|
4639
|
-
return this.request("PATCH", `/api/v1/github/projects/${projectId}`, body);
|
|
4640
|
-
}
|
|
4641
|
-
async deleteProject(projectId) {
|
|
4642
|
-
if (this.debug) console.log("[GitHub SDK] deleteProject", projectId);
|
|
4643
|
-
return this.request("DELETE", `/api/v1/github/projects/${projectId}`);
|
|
4644
|
-
}
|
|
4645
|
-
// ==========================================================================
|
|
4646
|
-
// Pull Requests
|
|
4647
|
-
// ==========================================================================
|
|
4648
|
-
async listPullRequests(input) {
|
|
4649
|
-
const installationId = this.getInstallationId(input);
|
|
4650
|
-
const params = new URLSearchParams({
|
|
4651
|
-
owner: input.owner,
|
|
4652
|
-
repo: input.repo,
|
|
4653
|
-
...input.state && { state: input.state },
|
|
4654
|
-
...installationId && { installationId }
|
|
4655
|
-
});
|
|
4656
|
-
return this.request("GET", `/api/v1/github/pulls?${params}`);
|
|
4657
|
-
}
|
|
4658
|
-
async getPullRequest(input) {
|
|
4659
|
-
const installationId = this.getInstallationId(input);
|
|
4660
|
-
const params = new URLSearchParams({
|
|
4661
|
-
owner: input.owner,
|
|
4662
|
-
repo: input.repo,
|
|
4663
|
-
...installationId && { installationId }
|
|
4664
|
-
});
|
|
4665
|
-
return this.request(
|
|
4666
|
-
"GET",
|
|
4667
|
-
`/api/v1/github/pulls/${input.number}?${params}`
|
|
4668
|
-
);
|
|
4669
|
-
}
|
|
4670
|
-
// ==========================================================================
|
|
4671
|
-
// Deployments
|
|
4672
|
-
// ==========================================================================
|
|
4673
|
-
async listDeployments(input) {
|
|
4674
|
-
const installationId = this.getInstallationId(input);
|
|
4675
|
-
const params = new URLSearchParams({
|
|
4676
|
-
owner: input.owner,
|
|
4677
|
-
repo: input.repo,
|
|
4678
|
-
...input.sha && { sha: input.sha },
|
|
4679
|
-
...input.environment && { environment: input.environment },
|
|
4680
|
-
...installationId && { installationId }
|
|
4681
|
-
});
|
|
4682
|
-
return this.request("GET", `/api/v1/github/deployments?${params}`);
|
|
4683
|
-
}
|
|
4684
|
-
// ==========================================================================
|
|
4685
|
-
// Comments
|
|
4686
|
-
// ==========================================================================
|
|
4687
|
-
async listComments(input) {
|
|
4688
|
-
const installationId = this.getInstallationId(input);
|
|
4689
|
-
const params = new URLSearchParams({
|
|
4690
|
-
owner: input.owner,
|
|
4691
|
-
repo: input.repo,
|
|
4692
|
-
pr: String(input.pr),
|
|
4693
|
-
...installationId && { installationId }
|
|
4694
|
-
});
|
|
4695
|
-
return this.request("GET", `/api/v1/github/comments?${params}`);
|
|
4696
|
-
}
|
|
4697
|
-
async createComment(input) {
|
|
4698
|
-
const installationId = this.getInstallationId(input);
|
|
4699
|
-
return this.request("POST", "/api/v1/github/comments", {
|
|
4700
|
-
owner: input.owner,
|
|
4701
|
-
repo: input.repo,
|
|
4702
|
-
pr: input.pr,
|
|
4703
|
-
body: input.body,
|
|
4704
|
-
...installationId && { installationId }
|
|
4705
|
-
});
|
|
4706
|
-
}
|
|
4707
|
-
async updateComment(input) {
|
|
4708
|
-
const installationId = this.getInstallationId(input);
|
|
4709
|
-
return this.request("PATCH", `/api/v1/github/comments/${input.commentId}`, {
|
|
4710
|
-
owner: input.owner,
|
|
4711
|
-
repo: input.repo,
|
|
4712
|
-
body: input.body,
|
|
4713
|
-
...installationId && { installationId }
|
|
4714
|
-
});
|
|
4715
|
-
}
|
|
4716
|
-
async deleteComment(input) {
|
|
4717
|
-
const installationId = this.getInstallationId(input);
|
|
4718
|
-
const params = new URLSearchParams({
|
|
4719
|
-
owner: input.owner,
|
|
4720
|
-
repo: input.repo,
|
|
4721
|
-
...installationId && { installationId }
|
|
4722
|
-
});
|
|
4723
|
-
await this.request("DELETE", `/api/v1/github/comments/${input.commentId}?${params}`);
|
|
4724
|
-
}
|
|
4725
|
-
// ==========================================================================
|
|
4726
|
-
// Check Runs
|
|
4727
|
-
// ==========================================================================
|
|
4728
|
-
async createCheckRun(input) {
|
|
4729
|
-
const installationId = this.getInstallationId(input);
|
|
4730
|
-
return this.request("POST", "/api/v1/github/check-runs", {
|
|
4731
|
-
owner: input.owner,
|
|
4732
|
-
repo: input.repo,
|
|
4733
|
-
sha: input.sha,
|
|
4734
|
-
name: input.name,
|
|
4735
|
-
status: input.status,
|
|
4736
|
-
...input.title && { title: input.title },
|
|
4737
|
-
...input.summary && { summary: input.summary },
|
|
4738
|
-
...installationId && { installationId }
|
|
4739
|
-
});
|
|
4740
|
-
}
|
|
4741
|
-
async updateCheckRun(input) {
|
|
4742
|
-
const installationId = this.getInstallationId(input);
|
|
4743
|
-
return this.request("PATCH", `/api/v1/github/check-runs/${input.checkRunId}`, {
|
|
4744
|
-
owner: input.owner,
|
|
4745
|
-
repo: input.repo,
|
|
4746
|
-
...input.status && { status: input.status },
|
|
4747
|
-
...input.conclusion && { conclusion: input.conclusion },
|
|
4748
|
-
...input.title && { title: input.title },
|
|
4749
|
-
...input.summary && { summary: input.summary },
|
|
4750
|
-
...input.text && { text: input.text },
|
|
4751
|
-
...installationId && { installationId }
|
|
4752
|
-
});
|
|
4753
|
-
}
|
|
4754
|
-
};
|
|
4755
|
-
|
|
4756
|
-
// tools/reflex/core.ts
|
|
4757
|
-
var BASE_MODEL = "morph-reflex-v1";
|
|
4758
|
-
function resolveClient2(clientOrConfig) {
|
|
4759
|
-
if (clientOrConfig instanceof MorphAPIClient) return clientOrConfig;
|
|
4760
|
-
return new MorphAPIClient({
|
|
4761
|
-
apiKey: clientOrConfig.apiKey,
|
|
4762
|
-
baseURL: clientOrConfig.baseUrl,
|
|
4763
|
-
timeout: clientOrConfig.timeout,
|
|
4764
|
-
retryConfig: clientOrConfig.retryConfig,
|
|
4765
|
-
debug: clientOrConfig.debug
|
|
4766
|
-
});
|
|
4767
|
-
}
|
|
4768
|
-
var ReflexClient = class extends APIResource {
|
|
4769
|
-
/** Train, retrieve, and manage classifier jobs. */
|
|
4770
|
-
jobs;
|
|
4771
|
-
constructor(clientOrConfig = {}) {
|
|
4772
|
-
super(resolveClient2(clientOrConfig));
|
|
4773
|
-
this.jobs = new ReflexJobsResource(this._client);
|
|
4774
|
-
}
|
|
4775
|
-
/** Classify text against one trained model. The model must be `succeeded`. */
|
|
4776
|
-
async predict(input) {
|
|
4777
|
-
const completionId = input.completionId ?? crypto.randomUUID();
|
|
4778
|
-
const raw = await this._client.post("/v1/reflex/predict", {
|
|
4779
|
-
body: { model: input.model, text: input.text },
|
|
4780
|
-
headers: { "X-Completion-Id": completionId }
|
|
4781
|
-
});
|
|
4782
|
-
return {
|
|
4783
|
-
...toClassification(raw),
|
|
4784
|
-
inferenceTimeMs: raw.inference_time_ms,
|
|
4785
|
-
prefillTokens: raw.prefill_tokens ?? 0,
|
|
4786
|
-
completionId
|
|
4787
|
-
};
|
|
4788
|
-
}
|
|
4789
|
-
/**
|
|
4790
|
-
* Classify text against several models in one request. They share a single
|
|
4791
|
-
* prefill, so the input is tokenized once — cheaper and faster than a call per
|
|
4792
|
-
* model. Each model returns its own prediction (or an `error` if it failed).
|
|
4793
|
-
*/
|
|
4794
|
-
async predictMany(input) {
|
|
4795
|
-
const completionId = input.completionId ?? crypto.randomUUID();
|
|
4796
|
-
const raw = await this._client.post("/v1/reflex/predict", {
|
|
4797
|
-
body: { models: input.models, text: input.text },
|
|
4798
|
-
headers: { "X-Completion-Id": completionId }
|
|
4799
|
-
});
|
|
4800
|
-
return {
|
|
4801
|
-
predictions: (raw.predictions ?? []).map(toPrediction),
|
|
4802
|
-
inferenceTimeMs: raw.inference_time_ms,
|
|
4803
|
-
prefillTokens: raw.prefill_tokens ?? 0,
|
|
4804
|
-
completionId
|
|
4805
|
-
};
|
|
4806
|
-
}
|
|
4807
|
-
};
|
|
4808
|
-
var ReflexJobsResource = class extends APIResource {
|
|
4809
|
-
/** Start a training job from labeled data, a description, or unlabeled text. */
|
|
4810
|
-
async create(input) {
|
|
4811
|
-
return toReflexJob(await this._client.post("/v1/fine_tuning/jobs", { body: createBody(input) }));
|
|
4812
|
-
}
|
|
4813
|
-
/** Fetch a job by id. */
|
|
4814
|
-
async retrieve(id) {
|
|
4815
|
-
return toReflexJob(await this._client.get(`/v1/fine_tuning/jobs/${encodeURIComponent(id)}`));
|
|
4816
|
-
}
|
|
4817
|
-
/** List the caller's jobs, newest first. */
|
|
4818
|
-
async list(input = {}) {
|
|
4819
|
-
const raw = await this._client.get("/v1/fine_tuning/jobs", {
|
|
4820
|
-
query: { limit: input.limit, after: input.after }
|
|
4821
|
-
});
|
|
4822
|
-
return { data: (raw.data ?? []).map(toReflexJob), hasMore: Boolean(raw.has_more) };
|
|
4823
|
-
}
|
|
4824
|
-
/** Stop a queued or running job. */
|
|
4825
|
-
async cancel(id) {
|
|
4826
|
-
return toReflexJob(await this._client.post(`/v1/fine_tuning/jobs/${encodeURIComponent(id)}/cancel`));
|
|
4827
|
-
}
|
|
4828
|
-
/** Delete a job and its trained model. */
|
|
4829
|
-
async delete(id) {
|
|
4830
|
-
const raw = await this._client.delete(
|
|
4831
|
-
`/v1/fine_tuning/jobs/${encodeURIComponent(id)}`
|
|
4832
|
-
);
|
|
4833
|
-
return { id: raw.id, deleted: Boolean(raw.deleted) };
|
|
4834
|
-
}
|
|
4835
|
-
/** The training loss curve as events, plus a terminal event. */
|
|
4836
|
-
async events(id) {
|
|
4837
|
-
const raw = await this._client.get(
|
|
4838
|
-
`/v1/fine_tuning/jobs/${encodeURIComponent(id)}/events`
|
|
4839
|
-
);
|
|
4840
|
-
return (raw.data ?? []).map(toReflexEvent);
|
|
4841
|
-
}
|
|
4842
|
-
/**
|
|
4843
|
-
* Poll until the job reaches a terminal status and return it on success.
|
|
4844
|
-
* Throws a `MorphError` if it fails, is cancelled, or exceeds `timeoutMs`.
|
|
4845
|
-
*/
|
|
4846
|
-
async waitForReady(id, opts = {}) {
|
|
4847
|
-
const pollMs = opts.pollMs ?? 3e3;
|
|
4848
|
-
const deadline = Date.now() + (opts.timeoutMs ?? 15 * 6e4);
|
|
4849
|
-
for (; ; ) {
|
|
4850
|
-
const job = await this.retrieve(id);
|
|
4851
|
-
if (job.status === "succeeded") return job;
|
|
4852
|
-
if (job.status === "failed" || job.status === "cancelled") {
|
|
4853
|
-
throw new MorphError(job.error?.message ?? `Reflex job ${job.status}`, `reflex_job_${job.status}`);
|
|
4854
|
-
}
|
|
4855
|
-
if (Date.now() >= deadline) {
|
|
4856
|
-
throw new MorphError(`Reflex job ${id} did not finish in time`, "reflex_timeout");
|
|
4857
|
-
}
|
|
4858
|
-
await sleep2(pollMs);
|
|
4859
|
-
}
|
|
4860
|
-
}
|
|
4861
|
-
};
|
|
4862
|
-
function createBody(input) {
|
|
4863
|
-
const base = { model: BASE_MODEL };
|
|
4864
|
-
if (input.suffix) base.suffix = input.suffix;
|
|
4865
|
-
if ("trainingData" in input) {
|
|
4866
|
-
if (input.labels) base.labels = input.labels;
|
|
4867
|
-
return { ...base, training_data: input.trainingData };
|
|
4868
|
-
}
|
|
4869
|
-
if ("generate" in input) {
|
|
4870
|
-
return {
|
|
4871
|
-
...base,
|
|
4872
|
-
labels: input.labels,
|
|
4873
|
-
generate: {
|
|
4874
|
-
description: input.generate.description,
|
|
4875
|
-
...input.generate.examplesPerLabel != null ? { examples_per_label: input.generate.examplesPerLabel } : {}
|
|
4876
|
-
}
|
|
4877
|
-
};
|
|
4878
|
-
}
|
|
4879
|
-
return {
|
|
4880
|
-
...base,
|
|
4881
|
-
labels: input.labels,
|
|
4882
|
-
label_data: {
|
|
4883
|
-
texts: input.labelData.texts,
|
|
4884
|
-
...input.labelData.description ? { description: input.labelData.description } : {}
|
|
4885
|
-
}
|
|
4886
|
-
};
|
|
4887
|
-
}
|
|
4888
|
-
function toReflexJob(raw) {
|
|
4889
|
-
return {
|
|
4890
|
-
id: raw.id,
|
|
4891
|
-
object: "fine_tuning.job",
|
|
4892
|
-
model: raw.model,
|
|
4893
|
-
createdAt: raw.created_at,
|
|
4894
|
-
finishedAt: raw.finished_at ?? null,
|
|
4895
|
-
fineTunedModel: raw.fine_tuned_model ?? null,
|
|
4896
|
-
status: raw.status,
|
|
4897
|
-
labels: raw.labels ?? [],
|
|
4898
|
-
trainedExamples: raw.trained_examples ?? 0,
|
|
4899
|
-
result: raw.result ? { accuracy: raw.result.accuracy ?? null, f1Score: raw.result.f1_score ?? null } : null,
|
|
4900
|
-
error: raw.error ? { message: raw.error.message } : null,
|
|
4901
|
-
suffix: raw.suffix ?? null
|
|
4902
|
-
};
|
|
4903
|
-
}
|
|
4904
|
-
function toClassification(raw) {
|
|
4905
|
-
const classes = (raw.classes ?? []).map((c) => ({
|
|
4906
|
-
classId: c.class_id,
|
|
4907
|
-
label: c.label,
|
|
4908
|
-
score: c.score,
|
|
4909
|
-
selected: c.selected
|
|
4910
|
-
}));
|
|
4911
|
-
const selectedClasses = classes.filter((c) => c.selected);
|
|
4912
|
-
const top = selectedClasses.reduce(
|
|
4913
|
-
(best, c) => best === null || c.score > best.score ? c : best,
|
|
4914
|
-
null
|
|
4915
|
-
);
|
|
4916
|
-
return {
|
|
4917
|
-
model: raw.model,
|
|
4918
|
-
mode: raw.mode === "multi_label" ? "multi_label" : "single_label",
|
|
4919
|
-
classes,
|
|
4920
|
-
selected: selectedClasses.map((c) => c.label),
|
|
4921
|
-
label: top ? top.label : null,
|
|
4922
|
-
confidence: top ? top.score : null
|
|
4923
|
-
};
|
|
4924
|
-
}
|
|
4925
|
-
function toPrediction(raw) {
|
|
4926
|
-
const error = raw.error ? { message: typeof raw.error === "string" ? raw.error : raw.error.message } : null;
|
|
4927
|
-
return { ...toClassification(raw), error };
|
|
4928
|
-
}
|
|
4929
|
-
function toReflexEvent(raw) {
|
|
4930
|
-
return {
|
|
4931
|
-
id: raw.id,
|
|
4932
|
-
createdAt: raw.created_at,
|
|
4933
|
-
level: raw.level,
|
|
4934
|
-
message: raw.message,
|
|
4935
|
-
type: raw.type,
|
|
4936
|
-
data: { epoch: raw.data?.epoch ?? 0, step: raw.data?.step ?? 0, trainLoss: raw.data?.train_loss ?? 0 }
|
|
4937
|
-
};
|
|
4938
|
-
}
|
|
4939
|
-
function sleep2(ms) {
|
|
4940
|
-
return new Promise((resolve2) => setTimeout(resolve2, ms));
|
|
4941
|
-
}
|
|
4942
|
-
|
|
4943
|
-
// tools/traces/core.ts
|
|
4944
|
-
var TracesClient = class extends APIResource {
|
|
4945
|
-
/** List traced turns, newest first. Filter by `convoId`; page with `limit`/`offset`. */
|
|
4946
|
-
async list(input = {}) {
|
|
4947
|
-
const raw = await this._client.get("/v1/reflex/traces", {
|
|
4948
|
-
query: { convo_id: input.convoId, limit: input.limit, offset: input.offset }
|
|
4949
|
-
});
|
|
4950
|
-
return {
|
|
4951
|
-
data: (raw.data ?? []).map(toTrace),
|
|
4952
|
-
hasMore: Boolean(raw.has_more),
|
|
4953
|
-
offset: raw.offset ?? 0
|
|
4954
|
-
};
|
|
4955
|
-
}
|
|
4956
|
-
};
|
|
4957
|
-
function toReflexResult(raw) {
|
|
4958
|
-
return {
|
|
4959
|
-
model: raw.model,
|
|
4960
|
-
transform: raw.transform,
|
|
4961
|
-
label: raw.label ?? null,
|
|
4962
|
-
score: raw.score,
|
|
4963
|
-
selected: raw.selected ?? [],
|
|
4964
|
-
status: raw.status,
|
|
4965
|
-
transformVersion: raw.transform_version
|
|
4966
|
-
};
|
|
4967
|
-
}
|
|
4968
|
-
function toTrace(raw) {
|
|
4969
|
-
return {
|
|
4970
|
-
convoId: raw.convo_id,
|
|
4971
|
-
eventId: raw.event_id,
|
|
4972
|
-
spanKind: raw.span_kind,
|
|
4973
|
-
model: raw.model,
|
|
4974
|
-
inputText: raw.input_text,
|
|
4975
|
-
outputText: raw.output_text,
|
|
4976
|
-
startTime: raw.start_time,
|
|
4977
|
-
reflexResults: (raw.reflex_results ?? []).map(toReflexResult)
|
|
4978
|
-
};
|
|
4979
|
-
}
|
|
4980
|
-
|
|
4981
3120
|
// modelrouter/core.ts
|
|
4982
3121
|
init_logger();
|
|
4983
|
-
var
|
|
4984
|
-
var
|
|
4985
|
-
function
|
|
3122
|
+
var DEFAULT_API_URL4 = "https://api.morphllm.com";
|
|
3123
|
+
var DEFAULT_TIMEOUT5 = 5e3;
|
|
3124
|
+
function resolveClient2(clientOrConfig) {
|
|
4986
3125
|
if (clientOrConfig instanceof MorphAPIClient) return clientOrConfig;
|
|
4987
3126
|
return new MorphAPIClient({
|
|
4988
3127
|
apiKey: clientOrConfig.apiKey,
|
|
4989
|
-
baseURL: clientOrConfig.apiUrl ??
|
|
4990
|
-
timeout: clientOrConfig.timeout ??
|
|
3128
|
+
baseURL: clientOrConfig.apiUrl ?? DEFAULT_API_URL4,
|
|
3129
|
+
timeout: clientOrConfig.timeout ?? DEFAULT_TIMEOUT5,
|
|
4991
3130
|
retryConfig: clientOrConfig.retryConfig,
|
|
4992
3131
|
debug: clientOrConfig.debug
|
|
4993
3132
|
});
|
|
@@ -4996,10 +3135,10 @@ var BaseRouter = class extends APIResource {
|
|
|
4996
3135
|
provider;
|
|
4997
3136
|
timeout;
|
|
4998
3137
|
constructor(provider, clientOrConfig = {}) {
|
|
4999
|
-
super(
|
|
3138
|
+
super(resolveClient2(clientOrConfig));
|
|
5000
3139
|
this.provider = provider;
|
|
5001
3140
|
const cfg = clientOrConfig instanceof MorphAPIClient ? {} : clientOrConfig;
|
|
5002
|
-
this.timeout = cfg.timeout ??
|
|
3141
|
+
this.timeout = cfg.timeout ?? DEFAULT_TIMEOUT5;
|
|
5003
3142
|
}
|
|
5004
3143
|
/** Throw the historical "API key is required" message when no key is resolvable. */
|
|
5005
3144
|
requireApiKey() {
|
|
@@ -5103,9 +3242,9 @@ var RawRouter = class extends BaseRouter {
|
|
|
5103
3242
|
var RouterClassifier = class extends APIResource {
|
|
5104
3243
|
timeout;
|
|
5105
3244
|
constructor(clientOrConfig = {}) {
|
|
5106
|
-
super(
|
|
3245
|
+
super(resolveClient2(clientOrConfig));
|
|
5107
3246
|
const cfg = clientOrConfig instanceof MorphAPIClient ? {} : clientOrConfig;
|
|
5108
|
-
this.timeout = cfg.timeout ??
|
|
3247
|
+
this.timeout = cfg.timeout ?? DEFAULT_TIMEOUT5;
|
|
5109
3248
|
}
|
|
5110
3249
|
/** Classify an input across the requested axes (all three by default). */
|
|
5111
3250
|
async classify(input) {
|
|
@@ -6523,10 +4662,6 @@ var MorphClient = class extends MorphAPIClient {
|
|
|
6523
4662
|
codebaseSearch;
|
|
6524
4663
|
/** WarpGrep tool for fast code search using ripgrep */
|
|
6525
4664
|
warpGrep;
|
|
6526
|
-
/** Browser tool for AI-powered browser automation */
|
|
6527
|
-
browser;
|
|
6528
|
-
/** GitHub tool for PR context, comments, and check runs */
|
|
6529
|
-
github;
|
|
6530
4665
|
/** Model routers for intelligent model selection */
|
|
6531
4666
|
routers;
|
|
6532
4667
|
/** OpenAI-compatible tool factories */
|
|
@@ -6537,10 +4672,6 @@ var MorphClient = class extends MorphAPIClient {
|
|
|
6537
4672
|
vercel;
|
|
6538
4673
|
/** Compact context with line ranges */
|
|
6539
4674
|
compact;
|
|
6540
|
-
/** Reflex: train and serve small text classifiers */
|
|
6541
|
-
reflex;
|
|
6542
|
-
/** Traces: read back turns shipped with `morphTracing()`, with their Reflex labels */
|
|
6543
|
-
traces;
|
|
6544
4675
|
/**
|
|
6545
4676
|
* Create a new Morph SDK client
|
|
6546
4677
|
*
|
|
@@ -6570,8 +4701,6 @@ var MorphClient = class extends MorphAPIClient {
|
|
|
6570
4701
|
this.fastApply = new FastApplyClient(this);
|
|
6571
4702
|
this.codebaseSearch = new CodebaseSearchClient(this);
|
|
6572
4703
|
this.warpGrep = new WarpGrepClient(this);
|
|
6573
|
-
this.browser = new BrowserClient(this);
|
|
6574
|
-
this.github = new GitHubClient(this, { installationId: config.github?.installationId });
|
|
6575
4704
|
this.routers = {
|
|
6576
4705
|
openai: new OpenAIRouter(this),
|
|
6577
4706
|
anthropic: new AnthropicRouter(this),
|
|
@@ -6581,8 +4710,6 @@ var MorphClient = class extends MorphAPIClient {
|
|
|
6581
4710
|
};
|
|
6582
4711
|
const compactClient = new CompactClient(this);
|
|
6583
4712
|
this.compact = compactClient.compact.bind(compactClient);
|
|
6584
|
-
this.reflex = new ReflexClient(this);
|
|
6585
|
-
this.traces = new TracesClient(this);
|
|
6586
4713
|
this.openai = new OpenAIToolFactory(config);
|
|
6587
4714
|
this.anthropic = new AnthropicToolFactory(config);
|
|
6588
4715
|
this.vercel = new VercelToolFactory(config);
|