@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
|
@@ -1,2169 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// tools/browser/index.ts
|
|
31
|
-
var browser_exports = {};
|
|
32
|
-
__export(browser_exports, {
|
|
33
|
-
BROWSER_SYSTEM_PROMPT: () => BROWSER_SYSTEM_PROMPT,
|
|
34
|
-
BROWSER_TOOL_DESCRIPTION: () => BROWSER_TOOL_DESCRIPTION,
|
|
35
|
-
BrowserClient: () => BrowserClient,
|
|
36
|
-
LIVE_PRESETS: () => LIVE_PRESETS,
|
|
37
|
-
MorphAPIError: () => MorphAPIError,
|
|
38
|
-
MorphAuthenticationError: () => MorphAuthenticationError,
|
|
39
|
-
MorphError: () => MorphError2,
|
|
40
|
-
MorphNotFoundError: () => MorphNotFoundError,
|
|
41
|
-
MorphProfileLimitError: () => MorphProfileLimitError,
|
|
42
|
-
MorphRateLimitError: () => MorphRateLimitError,
|
|
43
|
-
MorphValidationError: () => MorphValidationError,
|
|
44
|
-
ProfilesClient: () => ProfilesClient,
|
|
45
|
-
anthropic: () => anthropic_exports,
|
|
46
|
-
buildEmbedCode: () => buildEmbedCode,
|
|
47
|
-
buildLiveIframe: () => buildLiveIframe,
|
|
48
|
-
buildLiveUrl: () => buildLiveUrl,
|
|
49
|
-
checkHealth: () => checkHealth,
|
|
50
|
-
executeBrowserTask: () => executeBrowserTask,
|
|
51
|
-
executeWithRecording: () => executeWithRecording,
|
|
52
|
-
gemini: () => gemini_exports,
|
|
53
|
-
getErrors: () => getErrors,
|
|
54
|
-
getRecording: () => getRecording,
|
|
55
|
-
getWebp: () => getWebp,
|
|
56
|
-
openai: () => openai_exports,
|
|
57
|
-
parseAPIError: () => parseAPIError,
|
|
58
|
-
vercel: () => vercel_exports,
|
|
59
|
-
waitForRecording: () => waitForRecording
|
|
60
|
-
});
|
|
61
|
-
module.exports = __toCommonJS(browser_exports);
|
|
62
|
-
|
|
63
|
-
// package.json
|
|
64
|
-
var package_default = {
|
|
65
|
-
name: "@morphllm/morphsdk",
|
|
66
|
-
version: "0.2.197",
|
|
67
|
-
description: "TypeScript SDK and CLI for Morph Fast Apply integration",
|
|
68
|
-
type: "module",
|
|
69
|
-
main: "./dist/index.cjs",
|
|
70
|
-
module: "./dist/index.js",
|
|
71
|
-
types: "./dist/index.d.ts",
|
|
72
|
-
exports: {
|
|
73
|
-
".": {
|
|
74
|
-
types: "./dist/index.d.ts",
|
|
75
|
-
import: "./dist/index.js",
|
|
76
|
-
require: "./dist/index.cjs"
|
|
77
|
-
},
|
|
78
|
-
"./logger": {
|
|
79
|
-
types: "./dist/logger.d.ts",
|
|
80
|
-
import: "./dist/logger.js",
|
|
81
|
-
require: "./dist/logger.cjs"
|
|
82
|
-
},
|
|
83
|
-
"./edge": {
|
|
84
|
-
types: "./dist/edge.d.ts",
|
|
85
|
-
import: "./dist/edge.js",
|
|
86
|
-
require: "./dist/edge.cjs"
|
|
87
|
-
},
|
|
88
|
-
"./tools/warp-grep": {
|
|
89
|
-
types: "./dist/tools/warp_grep/index.d.ts",
|
|
90
|
-
import: "./dist/tools/warp_grep/index.js",
|
|
91
|
-
require: "./dist/tools/warp_grep/index.cjs"
|
|
92
|
-
},
|
|
93
|
-
"./tools/warp-grep/openai": {
|
|
94
|
-
types: "./dist/tools/warp_grep/openai.d.ts",
|
|
95
|
-
import: "./dist/tools/warp_grep/openai.js",
|
|
96
|
-
require: "./dist/tools/warp_grep/openai.cjs"
|
|
97
|
-
},
|
|
98
|
-
"./tools/warp-grep/anthropic": {
|
|
99
|
-
types: "./dist/tools/warp_grep/anthropic.d.ts",
|
|
100
|
-
import: "./dist/tools/warp_grep/anthropic.js",
|
|
101
|
-
require: "./dist/tools/warp_grep/anthropic.cjs"
|
|
102
|
-
},
|
|
103
|
-
"./tools/warp-grep/vercel": {
|
|
104
|
-
types: "./dist/tools/warp_grep/vercel.d.ts",
|
|
105
|
-
import: "./dist/tools/warp_grep/vercel.js",
|
|
106
|
-
require: "./dist/tools/warp_grep/vercel.cjs"
|
|
107
|
-
},
|
|
108
|
-
"./tools/warp-grep/client": {
|
|
109
|
-
types: "./dist/tools/warp_grep/client.d.ts",
|
|
110
|
-
import: "./dist/tools/warp_grep/client.js",
|
|
111
|
-
require: "./dist/tools/warp_grep/client.cjs"
|
|
112
|
-
},
|
|
113
|
-
"./tools/warp-grep/gemini": {
|
|
114
|
-
types: "./dist/tools/warp_grep/gemini.d.ts",
|
|
115
|
-
import: "./dist/tools/warp_grep/gemini.js",
|
|
116
|
-
require: "./dist/tools/warp_grep/gemini.cjs"
|
|
117
|
-
},
|
|
118
|
-
"./tools/warp-grep/harness": {
|
|
119
|
-
types: "./dist/tools/warp_grep/harness.d.ts",
|
|
120
|
-
import: "./dist/tools/warp_grep/harness.js",
|
|
121
|
-
require: "./dist/tools/warp_grep/harness.cjs"
|
|
122
|
-
},
|
|
123
|
-
"./tracing": {
|
|
124
|
-
types: "./dist/tracing/index.d.ts",
|
|
125
|
-
import: "./dist/tracing/index.js",
|
|
126
|
-
require: "./dist/tracing/index.cjs"
|
|
127
|
-
},
|
|
128
|
-
"./tracing/otel": {
|
|
129
|
-
types: "./dist/tracing/otel.d.ts",
|
|
130
|
-
import: "./dist/tracing/otel.js",
|
|
131
|
-
require: "./dist/tracing/otel.cjs"
|
|
132
|
-
},
|
|
133
|
-
"./tools/fastapply": {
|
|
134
|
-
types: "./dist/tools/fastapply/index.d.ts",
|
|
135
|
-
import: "./dist/tools/fastapply/index.js",
|
|
136
|
-
require: "./dist/tools/fastapply/index.cjs"
|
|
137
|
-
},
|
|
138
|
-
"./tools/fastapply/anthropic": {
|
|
139
|
-
types: "./dist/tools/fastapply/anthropic.d.ts",
|
|
140
|
-
import: "./dist/tools/fastapply/anthropic.js",
|
|
141
|
-
require: "./dist/tools/fastapply/anthropic.cjs"
|
|
142
|
-
},
|
|
143
|
-
"./tools/fastapply/openai": {
|
|
144
|
-
types: "./dist/tools/fastapply/openai.d.ts",
|
|
145
|
-
import: "./dist/tools/fastapply/openai.js",
|
|
146
|
-
require: "./dist/tools/fastapply/openai.cjs"
|
|
147
|
-
},
|
|
148
|
-
"./tools/fastapply/vercel": {
|
|
149
|
-
types: "./dist/tools/fastapply/vercel.d.ts",
|
|
150
|
-
import: "./dist/tools/fastapply/vercel.js",
|
|
151
|
-
require: "./dist/tools/fastapply/vercel.cjs"
|
|
152
|
-
},
|
|
153
|
-
"./tools/codebase-search": {
|
|
154
|
-
types: "./dist/tools/codebase_search/index.d.ts",
|
|
155
|
-
import: "./dist/tools/codebase_search/index.js",
|
|
156
|
-
require: "./dist/tools/codebase_search/index.cjs"
|
|
157
|
-
},
|
|
158
|
-
"./tools/codebase-search/anthropic": {
|
|
159
|
-
types: "./dist/tools/codebase_search/anthropic.d.ts",
|
|
160
|
-
import: "./dist/tools/codebase_search/anthropic.js",
|
|
161
|
-
require: "./dist/tools/codebase_search/anthropic.cjs"
|
|
162
|
-
},
|
|
163
|
-
"./tools/codebase-search/openai": {
|
|
164
|
-
types: "./dist/tools/codebase_search/openai.d.ts",
|
|
165
|
-
import: "./dist/tools/codebase_search/openai.js",
|
|
166
|
-
require: "./dist/tools/codebase_search/openai.cjs"
|
|
167
|
-
},
|
|
168
|
-
"./tools/codebase-search/vercel": {
|
|
169
|
-
types: "./dist/tools/codebase_search/vercel.d.ts",
|
|
170
|
-
import: "./dist/tools/codebase_search/vercel.js",
|
|
171
|
-
require: "./dist/tools/codebase_search/vercel.cjs"
|
|
172
|
-
},
|
|
173
|
-
"./tools/browser": {
|
|
174
|
-
types: "./dist/tools/browser/index.d.ts",
|
|
175
|
-
import: "./dist/tools/browser/index.js",
|
|
176
|
-
require: "./dist/tools/browser/index.cjs"
|
|
177
|
-
},
|
|
178
|
-
"./tools/browser/anthropic": {
|
|
179
|
-
types: "./dist/tools/browser/anthropic.d.ts",
|
|
180
|
-
import: "./dist/tools/browser/anthropic.js",
|
|
181
|
-
require: "./dist/tools/browser/anthropic.cjs"
|
|
182
|
-
},
|
|
183
|
-
"./tools/browser/openai": {
|
|
184
|
-
types: "./dist/tools/browser/openai.d.ts",
|
|
185
|
-
import: "./dist/tools/browser/openai.js",
|
|
186
|
-
require: "./dist/tools/browser/openai.cjs"
|
|
187
|
-
},
|
|
188
|
-
"./tools/browser/vercel": {
|
|
189
|
-
types: "./dist/tools/browser/vercel.d.ts",
|
|
190
|
-
import: "./dist/tools/browser/vercel.js",
|
|
191
|
-
require: "./dist/tools/browser/vercel.cjs"
|
|
192
|
-
},
|
|
193
|
-
"./tools/browser/profiles": {
|
|
194
|
-
types: "./dist/tools/browser/profiles/index.d.ts",
|
|
195
|
-
import: "./dist/tools/browser/profiles/index.js",
|
|
196
|
-
require: "./dist/tools/browser/profiles/index.cjs"
|
|
197
|
-
},
|
|
198
|
-
"./modelrouter": {
|
|
199
|
-
types: "./dist/modelrouter/index.d.ts",
|
|
200
|
-
import: "./dist/modelrouter/index.js",
|
|
201
|
-
require: "./dist/modelrouter/index.cjs"
|
|
202
|
-
},
|
|
203
|
-
"./tools/compact": {
|
|
204
|
-
types: "./dist/tools/compact/index.d.ts",
|
|
205
|
-
import: "./dist/tools/compact/index.js",
|
|
206
|
-
require: "./dist/tools/compact/index.cjs"
|
|
207
|
-
},
|
|
208
|
-
"./tools/reflex": {
|
|
209
|
-
types: "./dist/tools/reflex/index.d.ts",
|
|
210
|
-
import: "./dist/tools/reflex/index.js",
|
|
211
|
-
require: "./dist/tools/reflex/index.cjs"
|
|
212
|
-
},
|
|
213
|
-
"./tools/traces": {
|
|
214
|
-
types: "./dist/tools/traces/index.d.ts",
|
|
215
|
-
import: "./dist/tools/traces/index.js",
|
|
216
|
-
require: "./dist/tools/traces/index.cjs"
|
|
217
|
-
},
|
|
218
|
-
"./subagents": {
|
|
219
|
-
types: "./dist/subagents/index.d.ts",
|
|
220
|
-
import: "./dist/subagents/index.js",
|
|
221
|
-
require: "./dist/subagents/index.cjs"
|
|
222
|
-
},
|
|
223
|
-
"./subagents/vercel": {
|
|
224
|
-
types: "./dist/subagents/vercel.d.ts",
|
|
225
|
-
import: "./dist/subagents/vercel.js",
|
|
226
|
-
require: "./dist/subagents/vercel.cjs"
|
|
227
|
-
},
|
|
228
|
-
"./subagents/anthropic": {
|
|
229
|
-
types: "./dist/subagents/anthropic.d.ts",
|
|
230
|
-
import: "./dist/subagents/anthropic.js",
|
|
231
|
-
require: "./dist/subagents/anthropic.cjs"
|
|
232
|
-
},
|
|
233
|
-
"./ai-sdk": {
|
|
234
|
-
types: "./dist/ai-sdk/index.d.ts",
|
|
235
|
-
import: "./dist/ai-sdk/index.js",
|
|
236
|
-
require: "./dist/ai-sdk/index.cjs"
|
|
237
|
-
}
|
|
238
|
-
},
|
|
239
|
-
files: [
|
|
240
|
-
"dist/**/*.js",
|
|
241
|
-
"dist/**/*.cjs",
|
|
242
|
-
"dist/**/*.d.ts",
|
|
243
|
-
"dist/**/*.map",
|
|
244
|
-
"!dist/**/__tests__/**",
|
|
245
|
-
"!dist/**/*.test.*"
|
|
246
|
-
],
|
|
247
|
-
scripts: {
|
|
248
|
-
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 tools/browser/index.ts tools/browser/core.ts tools/browser/types.ts tools/browser/prompts.ts tools/browser/anthropic.ts tools/browser/openai.ts tools/browser/vercel.ts tools/browser/live.ts tools/browser/errors.ts tools/browser/profiles/index.ts tools/browser/profiles/core.ts tools/browser/profiles/types.ts modelrouter/index.ts modelrouter/core.ts modelrouter/types.ts tools/compact/index.ts tools/compact/core.ts tools/compact/types.ts tools/reflex/index.ts tools/reflex/core.ts tools/reflex/types.ts tools/traces/index.ts tools/traces/core.ts tools/traces/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",
|
|
249
|
-
prepare: "npm run build",
|
|
250
|
-
typecheck: "tsc --noEmit && tsc --noEmit -p ai-sdk/tsconfig.json",
|
|
251
|
-
lint: "eslint .",
|
|
252
|
-
test: "vitest run",
|
|
253
|
-
"test:watch": "vitest watch",
|
|
254
|
-
"test:anthropic": "vitest run anthropic",
|
|
255
|
-
"test:openai": "vitest run openai",
|
|
256
|
-
"test:vercel": "vitest run vercel",
|
|
257
|
-
"test:git": "vitest run git",
|
|
258
|
-
"test:browser": "vitest run browser",
|
|
259
|
-
"test:agent": "npx tsx tests/fullAgentTest.ts",
|
|
260
|
-
"test:integration": "npx tsx tests/fullIntegrationTest.ts",
|
|
261
|
-
"test:e2e": "vitest run --config vitest.e2e.config.ts",
|
|
262
|
-
"release:patch": "npm version patch && npm publish",
|
|
263
|
-
"release:minor": "npm version minor && npm publish",
|
|
264
|
-
"release:major": "npm version major && npm publish"
|
|
265
|
-
},
|
|
266
|
-
keywords: [
|
|
267
|
-
"morph",
|
|
268
|
-
"fast-apply",
|
|
269
|
-
"cli",
|
|
270
|
-
"sdk",
|
|
271
|
-
"edit-file"
|
|
272
|
-
],
|
|
273
|
-
engines: {
|
|
274
|
-
node: ">=18"
|
|
275
|
-
},
|
|
276
|
-
license: "MIT",
|
|
277
|
-
dependencies: {
|
|
278
|
-
"@opentelemetry/api": "^1.9.0",
|
|
279
|
-
"@opentelemetry/exporter-trace-otlp-http": "^0.203.0",
|
|
280
|
-
"@opentelemetry/sdk-trace-base": "^2.7.1",
|
|
281
|
-
"@traceloop/node-server-sdk": "^0.27.0",
|
|
282
|
-
"@vscode/ripgrep": "^1.17.0",
|
|
283
|
-
ai: ">=5.0.0",
|
|
284
|
-
diff: "^7.0.0",
|
|
285
|
-
openai: "^4.52.7",
|
|
286
|
-
zod: ">=3.23.0"
|
|
287
|
-
},
|
|
288
|
-
devDependencies: {
|
|
289
|
-
"@ai-sdk/anthropic": "^2.0.70",
|
|
290
|
-
"@ai-sdk/openai": "^2.0.35",
|
|
291
|
-
"@anthropic-ai/sdk": "^0.30.1",
|
|
292
|
-
"@google/generative-ai": "^0.24.1",
|
|
293
|
-
"@types/diff": "^7.0.2",
|
|
294
|
-
"@types/node": "^20.14.10",
|
|
295
|
-
"@typescript-eslint/eslint-plugin": "^7.18.0",
|
|
296
|
-
"@typescript-eslint/parser": "^7.18.0",
|
|
297
|
-
dotenv: "^16.4.5",
|
|
298
|
-
eslint: "^8.57.0",
|
|
299
|
-
shx: "^0.3.4",
|
|
300
|
-
tsup: "^8.5.0",
|
|
301
|
-
tsx: "^4.16.2",
|
|
302
|
-
typescript: "^5.5.4",
|
|
303
|
-
vitest: "^2.1.6"
|
|
304
|
-
},
|
|
305
|
-
peerDependencies: {
|
|
306
|
-
"@ai-sdk/openai-compatible": ">=2.0.74 <4",
|
|
307
|
-
"@anthropic-ai/sdk": ">=0.25.0",
|
|
308
|
-
"@google/generative-ai": ">=0.21.0",
|
|
309
|
-
ai: ">=5.0.0",
|
|
310
|
-
zod: ">=3.23.0"
|
|
311
|
-
},
|
|
312
|
-
peerDependenciesMeta: {
|
|
313
|
-
"@anthropic-ai/sdk": {
|
|
314
|
-
optional: true
|
|
315
|
-
},
|
|
316
|
-
"@google/generative-ai": {
|
|
317
|
-
optional: true
|
|
318
|
-
},
|
|
319
|
-
ai: {
|
|
320
|
-
optional: true
|
|
321
|
-
},
|
|
322
|
-
zod: {
|
|
323
|
-
optional: true
|
|
324
|
-
}
|
|
325
|
-
},
|
|
326
|
-
publishConfig: {
|
|
327
|
-
access: "public"
|
|
328
|
-
}
|
|
329
|
-
};
|
|
330
|
-
|
|
331
|
-
// version.ts
|
|
332
|
-
var SDK_VERSION = package_default.version;
|
|
333
|
-
|
|
334
|
-
// tools/utils/resilience.ts
|
|
335
|
-
var DEFAULT_RETRY_CONFIG = {
|
|
336
|
-
maxRetries: 3,
|
|
337
|
-
initialDelay: 1e3,
|
|
338
|
-
maxDelay: 3e4,
|
|
339
|
-
backoffMultiplier: 2,
|
|
340
|
-
retryableErrors: ["ECONNREFUSED", "ETIMEDOUT", "ENOTFOUND"]
|
|
341
|
-
};
|
|
342
|
-
async function fetchWithRetry(url, options, retryConfig = {}) {
|
|
343
|
-
const {
|
|
344
|
-
maxRetries = DEFAULT_RETRY_CONFIG.maxRetries,
|
|
345
|
-
initialDelay = DEFAULT_RETRY_CONFIG.initialDelay,
|
|
346
|
-
maxDelay = DEFAULT_RETRY_CONFIG.maxDelay,
|
|
347
|
-
backoffMultiplier = DEFAULT_RETRY_CONFIG.backoffMultiplier,
|
|
348
|
-
retryableErrors = DEFAULT_RETRY_CONFIG.retryableErrors,
|
|
349
|
-
onRetry
|
|
350
|
-
} = retryConfig;
|
|
351
|
-
let lastError = null;
|
|
352
|
-
let delay = initialDelay;
|
|
353
|
-
options = { ...options, headers: { "X-Morph-SDK-Version": SDK_VERSION, ...options.headers } };
|
|
354
|
-
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
355
|
-
try {
|
|
356
|
-
const response = await fetch(url, options);
|
|
357
|
-
if (response.status === 429 || response.status === 503) {
|
|
358
|
-
if (attempt < maxRetries) {
|
|
359
|
-
const retryAfter = response.headers.get("Retry-After");
|
|
360
|
-
const waitTime = retryAfter ? parseInt(retryAfter) * 1e3 : Math.min(delay, maxDelay);
|
|
361
|
-
const error = new Error(`HTTP ${response.status}: Retrying after ${waitTime}ms`);
|
|
362
|
-
if (onRetry) {
|
|
363
|
-
onRetry(attempt + 1, error);
|
|
364
|
-
}
|
|
365
|
-
await sleep(waitTime);
|
|
366
|
-
delay *= backoffMultiplier;
|
|
367
|
-
continue;
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
return response;
|
|
371
|
-
} catch (error) {
|
|
372
|
-
lastError = error;
|
|
373
|
-
const isRetryable = retryableErrors.some(
|
|
374
|
-
(errType) => lastError?.message?.includes(errType)
|
|
375
|
-
);
|
|
376
|
-
if (!isRetryable || attempt === maxRetries) {
|
|
377
|
-
throw lastError;
|
|
378
|
-
}
|
|
379
|
-
const waitTime = Math.min(delay, maxDelay);
|
|
380
|
-
if (onRetry) {
|
|
381
|
-
onRetry(attempt + 1, lastError);
|
|
382
|
-
}
|
|
383
|
-
await sleep(waitTime);
|
|
384
|
-
delay *= backoffMultiplier;
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
throw lastError || new Error("Max retries exceeded");
|
|
388
|
-
}
|
|
389
|
-
async function withTimeout(promise, timeoutMs, errorMessage) {
|
|
390
|
-
let timeoutId;
|
|
391
|
-
const timeoutPromise = new Promise((_, reject) => {
|
|
392
|
-
timeoutId = setTimeout(() => {
|
|
393
|
-
reject(new Error(errorMessage || `Operation timed out after ${timeoutMs}ms`));
|
|
394
|
-
}, timeoutMs);
|
|
395
|
-
});
|
|
396
|
-
try {
|
|
397
|
-
const result = await Promise.race([promise, timeoutPromise]);
|
|
398
|
-
clearTimeout(timeoutId);
|
|
399
|
-
return result;
|
|
400
|
-
} catch (error) {
|
|
401
|
-
clearTimeout(timeoutId);
|
|
402
|
-
throw error;
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
function sleep(ms) {
|
|
406
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
407
|
-
}
|
|
408
|
-
var MorphError = class extends Error {
|
|
409
|
-
constructor(message, code, statusCode, retryable = false) {
|
|
410
|
-
super(message);
|
|
411
|
-
this.code = code;
|
|
412
|
-
this.statusCode = statusCode;
|
|
413
|
-
this.retryable = retryable;
|
|
414
|
-
this.name = "MorphError";
|
|
415
|
-
}
|
|
416
|
-
};
|
|
417
|
-
|
|
418
|
-
// logger.ts
|
|
419
|
-
var MorphLogger = class {
|
|
420
|
-
enabled;
|
|
421
|
-
fileStream;
|
|
422
|
-
/** Resolves once the file stream is initialized (or immediately if no file logging). */
|
|
423
|
-
ready;
|
|
424
|
-
constructor() {
|
|
425
|
-
this.enabled = typeof process !== "undefined" && (process.env.MORPH_DEBUG === "1" || !!process.env.MORPH_LOG_FILE);
|
|
426
|
-
this.fileStream = null;
|
|
427
|
-
const f = typeof process !== "undefined" ? process.env.MORPH_LOG_FILE : void 0;
|
|
428
|
-
if (f) {
|
|
429
|
-
this.ready = import("fs").then((fs) => {
|
|
430
|
-
this.fileStream = fs.createWriteStream(f, { flags: "a" });
|
|
431
|
-
}).catch(() => {
|
|
432
|
-
});
|
|
433
|
-
} else {
|
|
434
|
-
this.ready = Promise.resolve();
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
debug(component, msg, data) {
|
|
438
|
-
this._log("debug", component, msg, data);
|
|
439
|
-
}
|
|
440
|
-
info(component, msg, data) {
|
|
441
|
-
this._log("info", component, msg, data);
|
|
442
|
-
}
|
|
443
|
-
warn(component, msg, data) {
|
|
444
|
-
this._log("warn", component, msg, data);
|
|
445
|
-
}
|
|
446
|
-
error(component, msg, data) {
|
|
447
|
-
this._log("error", component, msg, data);
|
|
448
|
-
}
|
|
449
|
-
enable() {
|
|
450
|
-
this.enabled = true;
|
|
451
|
-
}
|
|
452
|
-
get isEnabled() {
|
|
453
|
-
return this.enabled;
|
|
454
|
-
}
|
|
455
|
-
_log(level, component, msg, data) {
|
|
456
|
-
if (level !== "error" && !this.enabled) return;
|
|
457
|
-
const ts = (/* @__PURE__ */ new Date()).toISOString();
|
|
458
|
-
const prefix = `[${ts}] [${level.toUpperCase()}] [${component}]`;
|
|
459
|
-
console.error(data ? `${prefix} ${msg} ${JSON.stringify(data)}` : `${prefix} ${msg}`);
|
|
460
|
-
this.fileStream?.write(JSON.stringify({ ts, level, component, msg, ...data && { data } }) + "\n");
|
|
461
|
-
}
|
|
462
|
-
};
|
|
463
|
-
var logger = new MorphLogger();
|
|
464
|
-
|
|
465
|
-
// tools/browser/live.ts
|
|
466
|
-
var LIVE_PRESETS = {
|
|
467
|
-
/** Read-only monitoring (no interaction) */
|
|
468
|
-
readonly: { interactive: false },
|
|
469
|
-
/** Interactive control (human-in-the-loop) */
|
|
470
|
-
interactive: { interactive: true },
|
|
471
|
-
/** Watch-only without controls */
|
|
472
|
-
monitoring: { interactive: false, showControls: false }
|
|
473
|
-
};
|
|
474
|
-
function buildLiveUrl(debugUrl, options = {}) {
|
|
475
|
-
if (!debugUrl) {
|
|
476
|
-
throw new Error(
|
|
477
|
-
"debugUrl is required. Ensure your backend returns debugUrl in the task response. Contact support@morphllm.com if you need help."
|
|
478
|
-
);
|
|
479
|
-
}
|
|
480
|
-
const normalized = normalizeLiveUrl(debugUrl);
|
|
481
|
-
const url = new URL(normalized);
|
|
482
|
-
if (options.interactive !== void 0) {
|
|
483
|
-
url.searchParams.set("interactive", String(options.interactive));
|
|
484
|
-
}
|
|
485
|
-
if (options.theme) {
|
|
486
|
-
url.searchParams.set("theme", options.theme);
|
|
487
|
-
}
|
|
488
|
-
if (options.showControls !== void 0) {
|
|
489
|
-
url.searchParams.set("showControls", String(options.showControls));
|
|
490
|
-
}
|
|
491
|
-
if (options.pageId) {
|
|
492
|
-
url.searchParams.set("pageId", options.pageId);
|
|
493
|
-
}
|
|
494
|
-
if (options.pageIndex) {
|
|
495
|
-
url.searchParams.set("pageIndex", options.pageIndex);
|
|
496
|
-
}
|
|
497
|
-
return url.toString();
|
|
498
|
-
}
|
|
499
|
-
function cdpToHttps(wsUrl) {
|
|
500
|
-
return wsUrl.replace(/^wss:\/\//, "https://").replace(/^ws:\/\//, "http://");
|
|
501
|
-
}
|
|
502
|
-
function normalizeLiveUrl(debugUrl) {
|
|
503
|
-
const trimmed = debugUrl.trim();
|
|
504
|
-
if (!trimmed) return trimmed;
|
|
505
|
-
if (trimmed.startsWith("wss://") || trimmed.startsWith("ws://")) {
|
|
506
|
-
return `https://live.browser-use.com?wss=${encodeURIComponent(cdpToHttps(trimmed))}`;
|
|
507
|
-
}
|
|
508
|
-
let url;
|
|
509
|
-
try {
|
|
510
|
-
url = new URL(trimmed);
|
|
511
|
-
} catch {
|
|
512
|
-
return trimmed;
|
|
513
|
-
}
|
|
514
|
-
const wssParam = url.searchParams.get("wss");
|
|
515
|
-
if (wssParam && (wssParam.startsWith("wss://") || wssParam.startsWith("ws://"))) {
|
|
516
|
-
url.searchParams.set("wss", cdpToHttps(wssParam));
|
|
517
|
-
}
|
|
518
|
-
return url.toString();
|
|
519
|
-
}
|
|
520
|
-
function buildLiveIframe(debugUrl, options = {}) {
|
|
521
|
-
const {
|
|
522
|
-
width = "100%",
|
|
523
|
-
height = "600px",
|
|
524
|
-
style = "",
|
|
525
|
-
className = "",
|
|
526
|
-
...sessionOptions
|
|
527
|
-
} = options;
|
|
528
|
-
const src = buildLiveUrl(debugUrl, sessionOptions);
|
|
529
|
-
const widthStr = typeof width === "number" ? `${width}px` : width;
|
|
530
|
-
const heightStr = typeof height === "number" ? `${height}px` : height;
|
|
531
|
-
const baseStyle = `width: ${widthStr}; height: ${heightStr}; border: none;`;
|
|
532
|
-
const fullStyle = style ? `${baseStyle} ${style}` : baseStyle;
|
|
533
|
-
const attributes = [
|
|
534
|
-
`src="${src}"`,
|
|
535
|
-
`style="${fullStyle}"`
|
|
536
|
-
];
|
|
537
|
-
if (className) {
|
|
538
|
-
attributes.push(`class="${className}"`);
|
|
539
|
-
}
|
|
540
|
-
return `<iframe ${attributes.join(" ")}></iframe>`;
|
|
541
|
-
}
|
|
542
|
-
function buildEmbedCode(debugUrl, options = {}) {
|
|
543
|
-
const iframe = buildLiveIframe(debugUrl, options);
|
|
544
|
-
return `<!-- Embed Morph Live Session -->
|
|
545
|
-
${iframe}`;
|
|
546
|
-
}
|
|
547
|
-
function resolvePreset(optionsOrPreset) {
|
|
548
|
-
if (!optionsOrPreset) {
|
|
549
|
-
return {};
|
|
550
|
-
}
|
|
551
|
-
if (typeof optionsOrPreset === "string") {
|
|
552
|
-
const preset = LIVE_PRESETS[optionsOrPreset];
|
|
553
|
-
if (!preset) {
|
|
554
|
-
throw new Error(
|
|
555
|
-
`Unknown preset: ${optionsOrPreset}. Available presets: ${Object.keys(LIVE_PRESETS).join(", ")}`
|
|
556
|
-
);
|
|
557
|
-
}
|
|
558
|
-
return preset;
|
|
559
|
-
}
|
|
560
|
-
return optionsOrPreset;
|
|
561
|
-
}
|
|
562
|
-
|
|
563
|
-
// tools/browser/errors.ts
|
|
564
|
-
var MorphError2 = class extends Error {
|
|
565
|
-
/** Error code for programmatic handling */
|
|
566
|
-
code;
|
|
567
|
-
/** Original cause of the error, if any */
|
|
568
|
-
cause;
|
|
569
|
-
constructor(message, code, cause) {
|
|
570
|
-
super(message);
|
|
571
|
-
this.name = "MorphError";
|
|
572
|
-
this.code = code;
|
|
573
|
-
this.cause = cause;
|
|
574
|
-
if (Error.captureStackTrace) {
|
|
575
|
-
Error.captureStackTrace(this, this.constructor);
|
|
576
|
-
}
|
|
577
|
-
}
|
|
578
|
-
/**
|
|
579
|
-
* Returns a JSON representation of the error for logging.
|
|
580
|
-
*/
|
|
581
|
-
toJSON() {
|
|
582
|
-
return {
|
|
583
|
-
name: this.name,
|
|
584
|
-
message: this.message,
|
|
585
|
-
code: this.code,
|
|
586
|
-
cause: this.cause?.message
|
|
587
|
-
};
|
|
588
|
-
}
|
|
589
|
-
};
|
|
590
|
-
var MorphValidationError = class extends MorphError2 {
|
|
591
|
-
/** The field that failed validation */
|
|
592
|
-
field;
|
|
593
|
-
constructor(message, field) {
|
|
594
|
-
super(message, "validation_error");
|
|
595
|
-
this.name = "MorphValidationError";
|
|
596
|
-
this.field = field;
|
|
597
|
-
}
|
|
598
|
-
toJSON() {
|
|
599
|
-
return {
|
|
600
|
-
...super.toJSON(),
|
|
601
|
-
field: this.field
|
|
602
|
-
};
|
|
603
|
-
}
|
|
604
|
-
};
|
|
605
|
-
var MorphAPIError = class extends MorphError2 {
|
|
606
|
-
/** HTTP status code */
|
|
607
|
-
statusCode;
|
|
608
|
-
/** Request ID for debugging (if available) */
|
|
609
|
-
requestId;
|
|
610
|
-
/** Raw response body */
|
|
611
|
-
rawResponse;
|
|
612
|
-
constructor(message, code, statusCode, options) {
|
|
613
|
-
super(message, code, options?.cause);
|
|
614
|
-
this.name = "MorphAPIError";
|
|
615
|
-
this.statusCode = statusCode;
|
|
616
|
-
this.requestId = options?.requestId;
|
|
617
|
-
this.rawResponse = options?.rawResponse;
|
|
618
|
-
}
|
|
619
|
-
toJSON() {
|
|
620
|
-
return {
|
|
621
|
-
...super.toJSON(),
|
|
622
|
-
statusCode: this.statusCode,
|
|
623
|
-
requestId: this.requestId
|
|
624
|
-
};
|
|
625
|
-
}
|
|
626
|
-
};
|
|
627
|
-
var MorphAuthenticationError = class extends MorphAPIError {
|
|
628
|
-
constructor(message = "Authentication required. Please provide a valid API key.") {
|
|
629
|
-
super(message, "authentication_required", 401);
|
|
630
|
-
this.name = "MorphAuthenticationError";
|
|
631
|
-
}
|
|
632
|
-
};
|
|
633
|
-
var MorphRateLimitError = class extends MorphAPIError {
|
|
634
|
-
/** When the rate limit resets (Unix timestamp) */
|
|
635
|
-
resetAt;
|
|
636
|
-
/** Number of seconds until reset */
|
|
637
|
-
retryAfter;
|
|
638
|
-
constructor(message = "Rate limit exceeded. Please retry later.", options) {
|
|
639
|
-
super(message, "rate_limit_exceeded", 429, { requestId: options?.requestId });
|
|
640
|
-
this.name = "MorphRateLimitError";
|
|
641
|
-
this.resetAt = options?.resetAt;
|
|
642
|
-
this.retryAfter = options?.retryAfter;
|
|
643
|
-
}
|
|
644
|
-
toJSON() {
|
|
645
|
-
return {
|
|
646
|
-
...super.toJSON(),
|
|
647
|
-
resetAt: this.resetAt,
|
|
648
|
-
retryAfter: this.retryAfter
|
|
649
|
-
};
|
|
650
|
-
}
|
|
651
|
-
};
|
|
652
|
-
var MorphNotFoundError = class extends MorphAPIError {
|
|
653
|
-
/** The type of resource that was not found */
|
|
654
|
-
resourceType;
|
|
655
|
-
/** The ID of the resource that was not found */
|
|
656
|
-
resourceId;
|
|
657
|
-
constructor(resourceType, resourceId) {
|
|
658
|
-
const message = resourceId ? `${resourceType} '${resourceId}' not found` : `${resourceType} not found`;
|
|
659
|
-
super(message, "resource_not_found", 404);
|
|
660
|
-
this.name = "MorphNotFoundError";
|
|
661
|
-
this.resourceType = resourceType;
|
|
662
|
-
this.resourceId = resourceId;
|
|
663
|
-
}
|
|
664
|
-
toJSON() {
|
|
665
|
-
return {
|
|
666
|
-
...super.toJSON(),
|
|
667
|
-
resourceType: this.resourceType,
|
|
668
|
-
resourceId: this.resourceId
|
|
669
|
-
};
|
|
670
|
-
}
|
|
671
|
-
};
|
|
672
|
-
var MorphProfileLimitError = class extends MorphAPIError {
|
|
673
|
-
/** Current number of profiles */
|
|
674
|
-
currentCount;
|
|
675
|
-
/** Maximum allowed profiles for the plan */
|
|
676
|
-
maxAllowed;
|
|
677
|
-
constructor(message = "Profile limit exceeded for your plan.", options) {
|
|
678
|
-
super(message, "profile_limit_exceeded", 403, { requestId: options?.requestId });
|
|
679
|
-
this.name = "MorphProfileLimitError";
|
|
680
|
-
this.currentCount = options?.currentCount;
|
|
681
|
-
this.maxAllowed = options?.maxAllowed;
|
|
682
|
-
}
|
|
683
|
-
toJSON() {
|
|
684
|
-
return {
|
|
685
|
-
...super.toJSON(),
|
|
686
|
-
currentCount: this.currentCount,
|
|
687
|
-
maxAllowed: this.maxAllowed
|
|
688
|
-
};
|
|
689
|
-
}
|
|
690
|
-
};
|
|
691
|
-
function parseAPIError(statusCode, responseText, requestId) {
|
|
692
|
-
let errorData = {};
|
|
693
|
-
try {
|
|
694
|
-
errorData = JSON.parse(responseText);
|
|
695
|
-
} catch {
|
|
696
|
-
}
|
|
697
|
-
const message = errorData.detail || errorData.message || responseText || "Unknown error";
|
|
698
|
-
const code = errorData.code;
|
|
699
|
-
switch (statusCode) {
|
|
700
|
-
case 401:
|
|
701
|
-
return new MorphAuthenticationError(message);
|
|
702
|
-
case 403:
|
|
703
|
-
if (code === "profile_limit_exceeded" || message.toLowerCase().includes("limit")) {
|
|
704
|
-
return new MorphProfileLimitError(message, { requestId });
|
|
705
|
-
}
|
|
706
|
-
return new MorphAPIError(message, "insufficient_permissions", statusCode, { requestId, rawResponse: responseText });
|
|
707
|
-
case 404:
|
|
708
|
-
if (message.toLowerCase().includes("profile")) {
|
|
709
|
-
return new MorphNotFoundError("Profile", void 0);
|
|
710
|
-
}
|
|
711
|
-
if (message.toLowerCase().includes("session")) {
|
|
712
|
-
return new MorphNotFoundError("Session", void 0);
|
|
713
|
-
}
|
|
714
|
-
return new MorphAPIError(message, "resource_not_found", statusCode, { requestId, rawResponse: responseText });
|
|
715
|
-
case 429:
|
|
716
|
-
return new MorphRateLimitError(message, { requestId });
|
|
717
|
-
case 422:
|
|
718
|
-
return new MorphAPIError(message, "validation_error", statusCode, { requestId, rawResponse: responseText });
|
|
719
|
-
case 500:
|
|
720
|
-
case 502:
|
|
721
|
-
case 503:
|
|
722
|
-
case 504:
|
|
723
|
-
return new MorphAPIError(message, "service_unavailable", statusCode, { requestId, rawResponse: responseText });
|
|
724
|
-
default:
|
|
725
|
-
return new MorphAPIError(message, "network_error", statusCode, { requestId, rawResponse: responseText });
|
|
726
|
-
}
|
|
727
|
-
}
|
|
728
|
-
|
|
729
|
-
// tools/browser/profiles/types.ts
|
|
730
|
-
function transformProfile(api) {
|
|
731
|
-
return {
|
|
732
|
-
id: api.id,
|
|
733
|
-
name: api.name,
|
|
734
|
-
repoId: api.repo_id,
|
|
735
|
-
cookieDomains: api.cookie_domains,
|
|
736
|
-
lastUsedAt: api.last_used_at,
|
|
737
|
-
createdAt: api.created_at,
|
|
738
|
-
updatedAt: api.updated_at
|
|
739
|
-
};
|
|
740
|
-
}
|
|
741
|
-
function transformCreateInput(input) {
|
|
742
|
-
return {
|
|
743
|
-
name: input.name,
|
|
744
|
-
repo_id: input.repoId
|
|
745
|
-
};
|
|
746
|
-
}
|
|
747
|
-
function transformSession(api) {
|
|
748
|
-
return {
|
|
749
|
-
sessionId: api.session_id,
|
|
750
|
-
debugUrl: api.debug_url || ""
|
|
751
|
-
};
|
|
752
|
-
}
|
|
753
|
-
function transformSaveInput(input) {
|
|
754
|
-
return {
|
|
755
|
-
session_id: input.sessionId,
|
|
756
|
-
profile_id: input.profileId
|
|
757
|
-
};
|
|
758
|
-
}
|
|
759
|
-
function transformStateResponse(api) {
|
|
760
|
-
return {
|
|
761
|
-
profileId: api.profile_id,
|
|
762
|
-
stateUrl: api.state_url,
|
|
763
|
-
expiresIn: api.expires_in
|
|
764
|
-
};
|
|
765
|
-
}
|
|
766
|
-
|
|
767
|
-
// tools/browser/profiles/core.ts
|
|
768
|
-
var DEFAULT_API_URL = process.env.MORPH_ENVIRONMENT === "DEV" ? "http://localhost:8000" : "https://browser.morphllm.com";
|
|
769
|
-
var ProfilesClient = class {
|
|
770
|
-
config;
|
|
771
|
-
constructor(config) {
|
|
772
|
-
this.config = config;
|
|
773
|
-
}
|
|
774
|
-
/**
|
|
775
|
-
* Create a new browser profile and immediately start a live session.
|
|
776
|
-
*
|
|
777
|
-
* @param input - Profile creation parameters
|
|
778
|
-
* @returns Profile setup handle with live URL + save()
|
|
779
|
-
* @throws {MorphValidationError} If input validation fails
|
|
780
|
-
* @throws {MorphProfileLimitError} If profile limit is exceeded
|
|
781
|
-
* @throws {MorphAuthenticationError} If API key is missing or invalid
|
|
782
|
-
*
|
|
783
|
-
* @example
|
|
784
|
-
* ```typescript
|
|
785
|
-
* const setup = await morph.browser.profiles.createProfile({
|
|
786
|
-
* name: 'LinkedIn Production',
|
|
787
|
-
* repoId: 'owner/repo'
|
|
788
|
-
* });
|
|
789
|
-
* console.log(setup.session.debugUrl);
|
|
790
|
-
* await setup.save();
|
|
791
|
-
* ```
|
|
792
|
-
*/
|
|
793
|
-
async createProfile(input) {
|
|
794
|
-
return createProfile(input, this.config);
|
|
795
|
-
}
|
|
796
|
-
/**
|
|
797
|
-
* List all profiles for the authenticated user.
|
|
798
|
-
*
|
|
799
|
-
* @param repoId - Optional repository ID to filter by
|
|
800
|
-
* @returns Array of profiles
|
|
801
|
-
*
|
|
802
|
-
* @example
|
|
803
|
-
* ```typescript
|
|
804
|
-
* // List all profiles
|
|
805
|
-
* const allProfiles = await morph.browser.profiles.listProfiles();
|
|
806
|
-
*
|
|
807
|
-
* // List profiles for a specific repo
|
|
808
|
-
* const repoProfiles = await morph.browser.profiles.listProfiles('owner/repo');
|
|
809
|
-
* ```
|
|
810
|
-
*/
|
|
811
|
-
async listProfiles(repoId) {
|
|
812
|
-
return listProfiles(this.config, repoId);
|
|
813
|
-
}
|
|
814
|
-
/**
|
|
815
|
-
* Get a profile by ID with convenience methods.
|
|
816
|
-
*
|
|
817
|
-
* @param id - Profile ID
|
|
818
|
-
* @returns Profile with attached methods
|
|
819
|
-
* @throws {MorphNotFoundError} If profile is not found
|
|
820
|
-
*
|
|
821
|
-
* @example
|
|
822
|
-
* ```typescript
|
|
823
|
-
* const profile = await morph.browser.profiles.getProfile('profile-id');
|
|
824
|
-
* const state = await profile.getState();
|
|
825
|
-
* await profile.delete();
|
|
826
|
-
* ```
|
|
827
|
-
*/
|
|
828
|
-
async getProfile(id) {
|
|
829
|
-
return getProfile(id, this.config);
|
|
830
|
-
}
|
|
831
|
-
/**
|
|
832
|
-
* Update a profile by opening a live session (no rename).
|
|
833
|
-
*
|
|
834
|
-
* @param id - Profile ID
|
|
835
|
-
* @returns Profile setup handle with live URL + save()
|
|
836
|
-
*/
|
|
837
|
-
async updateProfile(id) {
|
|
838
|
-
return updateProfile(id, this.config);
|
|
839
|
-
}
|
|
840
|
-
/**
|
|
841
|
-
* Delete a profile.
|
|
842
|
-
*
|
|
843
|
-
* @param id - Profile ID
|
|
844
|
-
* @throws {MorphNotFoundError} If profile is not found
|
|
845
|
-
*/
|
|
846
|
-
async deleteProfile(id) {
|
|
847
|
-
return deleteProfile(id, this.config);
|
|
848
|
-
}
|
|
849
|
-
/**
|
|
850
|
-
* Start a browser session for profile setup.
|
|
851
|
-
*
|
|
852
|
-
* Returns a live URL where the user can sign into accounts.
|
|
853
|
-
* After signing in, call `saveSession` to persist the state.
|
|
854
|
-
*
|
|
855
|
-
* @param input - Optional session parameters
|
|
856
|
-
* @returns Session with debug URL
|
|
857
|
-
*
|
|
858
|
-
* @example
|
|
859
|
-
* ```typescript
|
|
860
|
-
* const session = await morph.browser.profiles.startSession();
|
|
861
|
-
* console.log('Sign in at:', session.debugUrl);
|
|
862
|
-
* // Open debugUrl in browser, user signs in...
|
|
863
|
-
* await morph.browser.profiles.saveSession(session.sessionId, profile.id);
|
|
864
|
-
* ```
|
|
865
|
-
*/
|
|
866
|
-
async startSession(input) {
|
|
867
|
-
return startProfileSession(this.config, input);
|
|
868
|
-
}
|
|
869
|
-
/**
|
|
870
|
-
* Save browser state from a session to a profile.
|
|
871
|
-
*
|
|
872
|
-
* Call this after the user is done signing into accounts.
|
|
873
|
-
* Extracts cookies, localStorage, and sessionStorage.
|
|
874
|
-
*
|
|
875
|
-
* @param sessionId - Browser session ID from startSession
|
|
876
|
-
* @param profileId - Profile ID to save state to
|
|
877
|
-
* @returns Updated profile with cookie domains
|
|
878
|
-
*/
|
|
879
|
-
async saveSession(sessionId, profileId) {
|
|
880
|
-
return saveProfileSession({ sessionId, profileId }, this.config);
|
|
881
|
-
}
|
|
882
|
-
/**
|
|
883
|
-
* List available repo IDs (discovery).
|
|
884
|
-
*
|
|
885
|
-
* @returns Repo summaries with profile counts
|
|
886
|
-
*/
|
|
887
|
-
async listRepos() {
|
|
888
|
-
return listRepos(this.config);
|
|
889
|
-
}
|
|
890
|
-
/**
|
|
891
|
-
* Get the presigned URL for a profile's state.
|
|
892
|
-
*
|
|
893
|
-
* Use this to download the raw state JSON for debugging
|
|
894
|
-
* or to restore state manually.
|
|
895
|
-
*
|
|
896
|
-
* @param profileId - Profile ID
|
|
897
|
-
* @returns State URL with expiry information
|
|
898
|
-
*/
|
|
899
|
-
async getProfileState(profileId) {
|
|
900
|
-
return getProfileState(profileId, this.config);
|
|
901
|
-
}
|
|
902
|
-
};
|
|
903
|
-
function validateCreateInput(input) {
|
|
904
|
-
if (!input.name || typeof input.name !== "string") {
|
|
905
|
-
throw new MorphValidationError("name is required", "name");
|
|
906
|
-
}
|
|
907
|
-
const trimmedName = input.name.trim();
|
|
908
|
-
if (trimmedName.length === 0) {
|
|
909
|
-
throw new MorphValidationError("name cannot be empty", "name");
|
|
910
|
-
}
|
|
911
|
-
if (trimmedName.length > 100) {
|
|
912
|
-
throw new MorphValidationError("name must be 100 characters or less", "name");
|
|
913
|
-
}
|
|
914
|
-
if (!input.repoId || typeof input.repoId !== "string") {
|
|
915
|
-
throw new MorphValidationError("repoId is required", "repoId");
|
|
916
|
-
}
|
|
917
|
-
if (input.repoId.trim().length === 0) {
|
|
918
|
-
throw new MorphValidationError("repoId cannot be empty", "repoId");
|
|
919
|
-
}
|
|
920
|
-
}
|
|
921
|
-
function validateId(id, fieldName) {
|
|
922
|
-
if (!id || typeof id !== "string") {
|
|
923
|
-
throw new MorphValidationError(`${fieldName} is required`, fieldName);
|
|
924
|
-
}
|
|
925
|
-
if (id.trim().length === 0) {
|
|
926
|
-
throw new MorphValidationError(`${fieldName} cannot be empty`, fieldName);
|
|
927
|
-
}
|
|
928
|
-
}
|
|
929
|
-
async function createProfile(input, config = {}) {
|
|
930
|
-
validateCreateInput(input);
|
|
931
|
-
const apiUrl = config.apiUrl || DEFAULT_API_URL;
|
|
932
|
-
const headers = buildHeaders(config);
|
|
933
|
-
const response = await fetchWithRetry(
|
|
934
|
-
`${apiUrl}/profiles`,
|
|
935
|
-
{
|
|
936
|
-
method: "POST",
|
|
937
|
-
headers,
|
|
938
|
-
body: JSON.stringify(transformCreateInput(input))
|
|
939
|
-
},
|
|
940
|
-
config.retryConfig
|
|
941
|
-
);
|
|
942
|
-
if (!response.ok) {
|
|
943
|
-
const errorText = await response.text().catch(() => response.statusText);
|
|
944
|
-
const requestId = response.headers.get("x-request-id") || void 0;
|
|
945
|
-
throw parseAPIError(response.status, errorText, requestId);
|
|
946
|
-
}
|
|
947
|
-
const apiProfile = await response.json();
|
|
948
|
-
const profile = transformProfile(apiProfile);
|
|
949
|
-
const session = await startProfileSession(config, { profileId: profile.id });
|
|
950
|
-
return buildProfileSetup(profile, session, config);
|
|
951
|
-
}
|
|
952
|
-
async function listProfiles(config = {}, repoId) {
|
|
953
|
-
const apiUrl = config.apiUrl || DEFAULT_API_URL;
|
|
954
|
-
const headers = buildHeaders(config);
|
|
955
|
-
const url = repoId ? `${apiUrl}/profiles?repo_id=${encodeURIComponent(repoId)}` : `${apiUrl}/profiles`;
|
|
956
|
-
const response = await fetchWithRetry(
|
|
957
|
-
url,
|
|
958
|
-
{ method: "GET", headers },
|
|
959
|
-
config.retryConfig
|
|
960
|
-
);
|
|
961
|
-
if (!response.ok) {
|
|
962
|
-
const errorText = await response.text().catch(() => response.statusText);
|
|
963
|
-
const requestId = response.headers.get("x-request-id") || void 0;
|
|
964
|
-
throw parseAPIError(response.status, errorText, requestId);
|
|
965
|
-
}
|
|
966
|
-
const data = await response.json();
|
|
967
|
-
return data.profiles.map(transformProfile);
|
|
968
|
-
}
|
|
969
|
-
async function getProfile(id, config = {}) {
|
|
970
|
-
validateId(id, "id");
|
|
971
|
-
const apiUrl = config.apiUrl || DEFAULT_API_URL;
|
|
972
|
-
const headers = buildHeaders(config);
|
|
973
|
-
const response = await fetchWithRetry(
|
|
974
|
-
`${apiUrl}/profiles/${encodeURIComponent(id)}`,
|
|
975
|
-
{ method: "GET", headers },
|
|
976
|
-
config.retryConfig
|
|
977
|
-
);
|
|
978
|
-
if (!response.ok) {
|
|
979
|
-
const errorText = await response.text().catch(() => response.statusText);
|
|
980
|
-
const requestId = response.headers.get("x-request-id") || void 0;
|
|
981
|
-
throw parseAPIError(response.status, errorText, requestId);
|
|
982
|
-
}
|
|
983
|
-
const apiProfile = await response.json();
|
|
984
|
-
const profile = transformProfile(apiProfile);
|
|
985
|
-
return {
|
|
986
|
-
...profile,
|
|
987
|
-
getState: () => getProfileState(id, config),
|
|
988
|
-
delete: () => deleteProfile(id, config)
|
|
989
|
-
};
|
|
990
|
-
}
|
|
991
|
-
async function updateProfile(id, config = {}) {
|
|
992
|
-
validateId(id, "id");
|
|
993
|
-
const profile = await fetchProfile(id, config);
|
|
994
|
-
const session = await startProfileSession(config, { profileId: profile.id });
|
|
995
|
-
return buildProfileSetup(profile, session, config);
|
|
996
|
-
}
|
|
997
|
-
async function deleteProfile(id, config = {}) {
|
|
998
|
-
validateId(id, "id");
|
|
999
|
-
const apiUrl = config.apiUrl || DEFAULT_API_URL;
|
|
1000
|
-
const headers = buildHeaders(config);
|
|
1001
|
-
const response = await fetchWithRetry(
|
|
1002
|
-
`${apiUrl}/profiles/${encodeURIComponent(id)}`,
|
|
1003
|
-
{ method: "DELETE", headers },
|
|
1004
|
-
config.retryConfig
|
|
1005
|
-
);
|
|
1006
|
-
if (!response.ok) {
|
|
1007
|
-
const errorText = await response.text().catch(() => response.statusText);
|
|
1008
|
-
const requestId = response.headers.get("x-request-id") || void 0;
|
|
1009
|
-
throw parseAPIError(response.status, errorText, requestId);
|
|
1010
|
-
}
|
|
1011
|
-
}
|
|
1012
|
-
async function startProfileSession(config = {}, input) {
|
|
1013
|
-
if (!config.apiKey) {
|
|
1014
|
-
throw new MorphAuthenticationError();
|
|
1015
|
-
}
|
|
1016
|
-
const apiUrl = config.apiUrl || DEFAULT_API_URL;
|
|
1017
|
-
const headers = buildHeaders(config);
|
|
1018
|
-
const body = input?.profileId ? { profile_id: input.profileId } : {};
|
|
1019
|
-
const response = await fetchWithRetry(
|
|
1020
|
-
`${apiUrl}/profiles/session/start`,
|
|
1021
|
-
{
|
|
1022
|
-
method: "POST",
|
|
1023
|
-
headers,
|
|
1024
|
-
body: JSON.stringify(body)
|
|
1025
|
-
},
|
|
1026
|
-
config.retryConfig
|
|
1027
|
-
);
|
|
1028
|
-
if (!response.ok) {
|
|
1029
|
-
const errorText = await response.text().catch(() => response.statusText);
|
|
1030
|
-
const requestId = response.headers.get("x-request-id") || void 0;
|
|
1031
|
-
throw parseAPIError(response.status, errorText, requestId);
|
|
1032
|
-
}
|
|
1033
|
-
const apiSession = await response.json();
|
|
1034
|
-
return transformSession(apiSession);
|
|
1035
|
-
}
|
|
1036
|
-
async function saveProfileSession(input, config = {}) {
|
|
1037
|
-
validateId(input.sessionId, "sessionId");
|
|
1038
|
-
validateId(input.profileId, "profileId");
|
|
1039
|
-
const apiUrl = config.apiUrl || DEFAULT_API_URL;
|
|
1040
|
-
const headers = buildHeaders(config);
|
|
1041
|
-
const response = await fetchWithRetry(
|
|
1042
|
-
`${apiUrl}/profiles/session/save`,
|
|
1043
|
-
{
|
|
1044
|
-
method: "POST",
|
|
1045
|
-
headers,
|
|
1046
|
-
body: JSON.stringify(transformSaveInput(input))
|
|
1047
|
-
},
|
|
1048
|
-
config.retryConfig
|
|
1049
|
-
);
|
|
1050
|
-
if (!response.ok) {
|
|
1051
|
-
const errorText = await response.text().catch(() => response.statusText);
|
|
1052
|
-
const requestId = response.headers.get("x-request-id") || void 0;
|
|
1053
|
-
throw parseAPIError(response.status, errorText, requestId);
|
|
1054
|
-
}
|
|
1055
|
-
const apiProfile = await response.json();
|
|
1056
|
-
return transformProfile(apiProfile);
|
|
1057
|
-
}
|
|
1058
|
-
async function listRepos(config = {}) {
|
|
1059
|
-
const apiUrl = config.apiUrl || DEFAULT_API_URL;
|
|
1060
|
-
const headers = buildHeaders(config);
|
|
1061
|
-
const response = await fetchWithRetry(
|
|
1062
|
-
`${apiUrl}/repos`,
|
|
1063
|
-
{ method: "GET", headers },
|
|
1064
|
-
config.retryConfig
|
|
1065
|
-
);
|
|
1066
|
-
if (!response.ok) {
|
|
1067
|
-
const errorText = await response.text().catch(() => response.statusText);
|
|
1068
|
-
const requestId = response.headers.get("x-request-id") || void 0;
|
|
1069
|
-
throw parseAPIError(response.status, errorText, requestId);
|
|
1070
|
-
}
|
|
1071
|
-
const data = await response.json();
|
|
1072
|
-
const repos = Array.isArray(data?.repos) ? data.repos : [];
|
|
1073
|
-
return repos.map((repo) => ({
|
|
1074
|
-
repoId: repo.repo_id,
|
|
1075
|
-
repoFullName: repo.repo_full_name,
|
|
1076
|
-
profileCount: repo.profile_count ?? 0
|
|
1077
|
-
}));
|
|
1078
|
-
}
|
|
1079
|
-
async function getProfileState(profileId, config = {}) {
|
|
1080
|
-
validateId(profileId, "profileId");
|
|
1081
|
-
const apiUrl = config.apiUrl || DEFAULT_API_URL;
|
|
1082
|
-
const headers = buildHeaders(config);
|
|
1083
|
-
const response = await fetchWithRetry(
|
|
1084
|
-
`${apiUrl}/profiles/${encodeURIComponent(profileId)}/state`,
|
|
1085
|
-
{ method: "GET", headers },
|
|
1086
|
-
config.retryConfig
|
|
1087
|
-
);
|
|
1088
|
-
if (!response.ok) {
|
|
1089
|
-
const errorText = await response.text().catch(() => response.statusText);
|
|
1090
|
-
const requestId = response.headers.get("x-request-id") || void 0;
|
|
1091
|
-
throw parseAPIError(response.status, errorText, requestId);
|
|
1092
|
-
}
|
|
1093
|
-
const apiState = await response.json();
|
|
1094
|
-
return transformStateResponse(apiState);
|
|
1095
|
-
}
|
|
1096
|
-
function buildHeaders(config) {
|
|
1097
|
-
const headers = { "Content-Type": "application/json" };
|
|
1098
|
-
if (config.apiKey) {
|
|
1099
|
-
headers["Authorization"] = `Bearer ${config.apiKey}`;
|
|
1100
|
-
}
|
|
1101
|
-
return headers;
|
|
1102
|
-
}
|
|
1103
|
-
async function fetchProfile(id, config) {
|
|
1104
|
-
const apiUrl = config.apiUrl || DEFAULT_API_URL;
|
|
1105
|
-
const headers = buildHeaders(config);
|
|
1106
|
-
const response = await fetchWithRetry(
|
|
1107
|
-
`${apiUrl}/profiles/${encodeURIComponent(id)}`,
|
|
1108
|
-
{ method: "GET", headers },
|
|
1109
|
-
config.retryConfig
|
|
1110
|
-
);
|
|
1111
|
-
if (!response.ok) {
|
|
1112
|
-
const errorText = await response.text().catch(() => response.statusText);
|
|
1113
|
-
const requestId = response.headers.get("x-request-id") || void 0;
|
|
1114
|
-
throw parseAPIError(response.status, errorText, requestId);
|
|
1115
|
-
}
|
|
1116
|
-
const apiProfile = await response.json();
|
|
1117
|
-
return transformProfile(apiProfile);
|
|
1118
|
-
}
|
|
1119
|
-
function buildProfileSetup(profile, session, config) {
|
|
1120
|
-
return {
|
|
1121
|
-
profile,
|
|
1122
|
-
session,
|
|
1123
|
-
save: () => saveProfileSession({ sessionId: session.sessionId, profileId: profile.id }, config)
|
|
1124
|
-
};
|
|
1125
|
-
}
|
|
1126
|
-
|
|
1127
|
-
// core/error.ts
|
|
1128
|
-
async function toMorphError(response) {
|
|
1129
|
-
let message = `Morph API request failed (${response.status})`;
|
|
1130
|
-
let code = "api_error";
|
|
1131
|
-
try {
|
|
1132
|
-
const body = await response.json();
|
|
1133
|
-
message = body.error?.message ?? body.message ?? message;
|
|
1134
|
-
code = body.error?.code ?? body.error?.type ?? code;
|
|
1135
|
-
} catch {
|
|
1136
|
-
}
|
|
1137
|
-
if (response.status === 401) code = "authentication_error";
|
|
1138
|
-
if (response.status === 429) code = "rate_limit_exceeded";
|
|
1139
|
-
const retryable = response.status === 429 || response.status === 503;
|
|
1140
|
-
return new MorphError(message, code, response.status, retryable);
|
|
1141
|
-
}
|
|
1142
|
-
|
|
1143
|
-
// core/client.ts
|
|
1144
|
-
var DEFAULT_BASE_URL = "https://api.morphllm.com";
|
|
1145
|
-
var DEFAULT_REPOS_URL = "https://repos.morphllm.com";
|
|
1146
|
-
var DEFAULT_BROWSER_URL = "https://browser.morphllm.com";
|
|
1147
|
-
var DEFAULT_TIMEOUT = 6e4;
|
|
1148
|
-
var env = (name) => typeof process !== "undefined" ? process.env?.[name] : void 0;
|
|
1149
|
-
var stripTrailingSlash = (url) => url.replace(/\/+$/, "");
|
|
1150
|
-
var MorphAPIClient = class {
|
|
1151
|
-
/** Explicit key as provided; resolved against env at request time. */
|
|
1152
|
-
apiKey;
|
|
1153
|
-
baseURL;
|
|
1154
|
-
reposURL;
|
|
1155
|
-
browserURL;
|
|
1156
|
-
/** Explicit default timeout (ms), if set. The request default is applied lazily so
|
|
1157
|
-
* resources can read an undefined value and supply their own fallback. */
|
|
1158
|
-
timeout;
|
|
1159
|
-
retryConfig;
|
|
1160
|
-
debug;
|
|
1161
|
-
constructor(options = {}) {
|
|
1162
|
-
this.apiKey = options.apiKey;
|
|
1163
|
-
this.baseURL = stripTrailingSlash(options.baseURL ?? DEFAULT_BASE_URL);
|
|
1164
|
-
this.reposURL = stripTrailingSlash(options.reposURL ?? env("MORPH_SEARCH_URL") ?? DEFAULT_REPOS_URL);
|
|
1165
|
-
this.browserURL = stripTrailingSlash(
|
|
1166
|
-
options.browserURL ?? (env("MORPH_ENVIRONMENT") === "DEV" ? "http://localhost:8000" : DEFAULT_BROWSER_URL)
|
|
1167
|
-
);
|
|
1168
|
-
this.timeout = options.timeout;
|
|
1169
|
-
this.retryConfig = options.retryConfig;
|
|
1170
|
-
this.debug = options.debug ?? false;
|
|
1171
|
-
if (this.debug) logger.enable();
|
|
1172
|
-
}
|
|
1173
|
-
/** The key actually used for requests: explicit, else `MORPH_API_KEY`. */
|
|
1174
|
-
resolveApiKey() {
|
|
1175
|
-
return this.apiKey ?? env("MORPH_API_KEY");
|
|
1176
|
-
}
|
|
1177
|
-
/** Headers shared with tools that bring their own HTTP client (FastApply/WarpGrep via the `openai` package). */
|
|
1178
|
-
defaultHeaders() {
|
|
1179
|
-
return { "X-Morph-SDK-Version": SDK_VERSION };
|
|
1180
|
-
}
|
|
1181
|
-
buildURL(path, baseURL) {
|
|
1182
|
-
if (/^https?:\/\//i.test(path)) return path;
|
|
1183
|
-
const base = stripTrailingSlash(baseURL ?? this.baseURL);
|
|
1184
|
-
return `${base}${path.startsWith("/") ? "" : "/"}${path}`;
|
|
1185
|
-
}
|
|
1186
|
-
buildHeaders(apiKey, extra) {
|
|
1187
|
-
return {
|
|
1188
|
-
"Content-Type": "application/json",
|
|
1189
|
-
"X-Morph-SDK-Version": SDK_VERSION,
|
|
1190
|
-
Authorization: `Bearer ${apiKey}`,
|
|
1191
|
-
...extra
|
|
1192
|
-
};
|
|
1193
|
-
}
|
|
1194
|
-
applyQuery(url, query) {
|
|
1195
|
-
if (!query) return url;
|
|
1196
|
-
const params = new URLSearchParams();
|
|
1197
|
-
for (const [key, value] of Object.entries(query)) {
|
|
1198
|
-
if (value !== void 0 && value !== null) params.set(key, String(value));
|
|
1199
|
-
}
|
|
1200
|
-
const qs = params.toString();
|
|
1201
|
-
return qs ? `${url}${url.includes("?") ? "&" : "?"}${qs}` : url;
|
|
1202
|
-
}
|
|
1203
|
-
async request(method, path, opts = {}) {
|
|
1204
|
-
const apiKey = this.resolveApiKey();
|
|
1205
|
-
if (!apiKey) {
|
|
1206
|
-
throw new MorphError(
|
|
1207
|
-
"Morph API key not found. Set the MORPH_API_KEY environment variable or pass apiKey in config.",
|
|
1208
|
-
"missing_api_key",
|
|
1209
|
-
401
|
|
1210
|
-
);
|
|
1211
|
-
}
|
|
1212
|
-
const url = this.applyQuery(this.buildURL(path, opts.baseURL), opts.query);
|
|
1213
|
-
const timeout = opts.timeout ?? this.timeout ?? DEFAULT_TIMEOUT;
|
|
1214
|
-
const init = {
|
|
1215
|
-
method,
|
|
1216
|
-
headers: this.buildHeaders(apiKey, opts.headers),
|
|
1217
|
-
...opts.body !== void 0 ? { body: JSON.stringify(opts.body) } : {},
|
|
1218
|
-
...opts.signal ? { signal: opts.signal } : {}
|
|
1219
|
-
};
|
|
1220
|
-
logger.debug("MorphAPIClient", "request", { method, url });
|
|
1221
|
-
const response = await withTimeout(
|
|
1222
|
-
fetchWithRetry(url, init, this.retryConfig ?? {}),
|
|
1223
|
-
timeout,
|
|
1224
|
-
`Morph request to ${url} timed out after ${timeout}ms`
|
|
1225
|
-
);
|
|
1226
|
-
if (opts.raw) return response;
|
|
1227
|
-
if (!response.ok) throw await toMorphError(response);
|
|
1228
|
-
if (opts.stream) return response;
|
|
1229
|
-
if (response.status === 204) return void 0;
|
|
1230
|
-
const text = await response.text();
|
|
1231
|
-
return text ? JSON.parse(text) : void 0;
|
|
1232
|
-
}
|
|
1233
|
-
get(path, opts) {
|
|
1234
|
-
return this.request("GET", path, opts);
|
|
1235
|
-
}
|
|
1236
|
-
post(path, opts) {
|
|
1237
|
-
return this.request("POST", path, opts);
|
|
1238
|
-
}
|
|
1239
|
-
delete(path, opts) {
|
|
1240
|
-
return this.request("DELETE", path, opts);
|
|
1241
|
-
}
|
|
1242
|
-
};
|
|
1243
|
-
|
|
1244
|
-
// core/resource.ts
|
|
1245
|
-
var APIResource = class {
|
|
1246
|
-
_client;
|
|
1247
|
-
constructor(client) {
|
|
1248
|
-
this._client = client;
|
|
1249
|
-
}
|
|
1250
|
-
};
|
|
1251
|
-
|
|
1252
|
-
// tools/browser/core.ts
|
|
1253
|
-
var DEFAULT_CONFIG = {
|
|
1254
|
-
apiUrl: process.env.MORPH_ENVIRONMENT === "DEV" ? "http://localhost:8000" : "https://browser.morphllm.com",
|
|
1255
|
-
timeout: 1e6,
|
|
1256
|
-
// 10 minutes for complex tasks
|
|
1257
|
-
debug: false
|
|
1258
|
-
};
|
|
1259
|
-
var BrowserClient = class extends APIResource {
|
|
1260
|
-
config;
|
|
1261
|
-
/**
|
|
1262
|
-
* Profile management - create and manage browser profiles for storing login state.
|
|
1263
|
-
*/
|
|
1264
|
-
profiles;
|
|
1265
|
-
constructor(clientOrConfig = {}) {
|
|
1266
|
-
const isClient = clientOrConfig instanceof MorphAPIClient;
|
|
1267
|
-
super(
|
|
1268
|
-
isClient ? clientOrConfig : new MorphAPIClient({
|
|
1269
|
-
apiKey: clientOrConfig.apiKey,
|
|
1270
|
-
browserURL: clientOrConfig.apiUrl,
|
|
1271
|
-
timeout: clientOrConfig.timeout,
|
|
1272
|
-
retryConfig: clientOrConfig.retryConfig,
|
|
1273
|
-
debug: clientOrConfig.debug
|
|
1274
|
-
})
|
|
1275
|
-
);
|
|
1276
|
-
this.config = isClient ? {
|
|
1277
|
-
...DEFAULT_CONFIG,
|
|
1278
|
-
apiUrl: clientOrConfig.browserURL,
|
|
1279
|
-
apiKey: clientOrConfig.resolveApiKey(),
|
|
1280
|
-
retryConfig: clientOrConfig.retryConfig,
|
|
1281
|
-
debug: clientOrConfig.debug
|
|
1282
|
-
} : { ...DEFAULT_CONFIG, ...clientOrConfig };
|
|
1283
|
-
this.profiles = new ProfilesClient(this.config);
|
|
1284
|
-
}
|
|
1285
|
-
/**
|
|
1286
|
-
* Execute a browser automation task
|
|
1287
|
-
*/
|
|
1288
|
-
async execute(input) {
|
|
1289
|
-
return executeBrowserTask(input, this.config);
|
|
1290
|
-
}
|
|
1291
|
-
async createTask(input) {
|
|
1292
|
-
const apiUrl = this.config.apiUrl || DEFAULT_CONFIG.apiUrl;
|
|
1293
|
-
const debug = this.config.debug || false;
|
|
1294
|
-
const hasTask = typeof input.task === "string" && input.task.trim().length > 0;
|
|
1295
|
-
const hasDiff = typeof input.diff === "string" && input.diff.trim().length > 0;
|
|
1296
|
-
if (!hasTask && !hasDiff) {
|
|
1297
|
-
throw new Error('Browser task requires either "task" (natural language) or "diff" (PR-review planning)');
|
|
1298
|
-
}
|
|
1299
|
-
logger.debug("Browser", "create_task", { task: (input.task ?? "").slice(0, 100), url: input.url, endpoint: `${apiUrl}/browser-task/async` });
|
|
1300
|
-
const headers = { "Content-Type": "application/json" };
|
|
1301
|
-
if (this.config.apiKey) headers["Authorization"] = `Bearer ${this.config.apiKey}`;
|
|
1302
|
-
const response = await fetch(`${apiUrl}/browser-task/async`, {
|
|
1303
|
-
method: "POST",
|
|
1304
|
-
headers,
|
|
1305
|
-
body: JSON.stringify({
|
|
1306
|
-
task: input.task,
|
|
1307
|
-
diff: input.diff,
|
|
1308
|
-
url: input.url,
|
|
1309
|
-
max_steps: input.maxSteps ?? 10,
|
|
1310
|
-
model: input.model ?? "morph-computer-use-v0",
|
|
1311
|
-
viewport_width: input.viewportWidth ?? 1280,
|
|
1312
|
-
viewport_height: input.viewportHeight ?? 720,
|
|
1313
|
-
external_id: input.externalId,
|
|
1314
|
-
repo_id: input.repoId,
|
|
1315
|
-
repo_full_name: input.repoFullName,
|
|
1316
|
-
commit_id: input.commitId,
|
|
1317
|
-
record_video: input.recordVideo ?? false,
|
|
1318
|
-
video_width: input.videoWidth ?? input.viewportWidth ?? 1280,
|
|
1319
|
-
video_height: input.videoHeight ?? input.viewportHeight ?? 720,
|
|
1320
|
-
allow_resizing: input.allowResizing ?? false,
|
|
1321
|
-
structured_output: "schema" in input ? stringifyStructuredOutput(input.schema) : void 0,
|
|
1322
|
-
auth: input.auth,
|
|
1323
|
-
profile_id: input.profileId,
|
|
1324
|
-
force_query_params: input.forceQueryParams
|
|
1325
|
-
})
|
|
1326
|
-
});
|
|
1327
|
-
if (!response.ok) {
|
|
1328
|
-
const errorText = await response.text().catch(() => response.statusText);
|
|
1329
|
-
logger.error("Browser", "create_task_error", { status: response.status, error: errorText });
|
|
1330
|
-
throw new Error(`HTTP ${response.status}: ${errorText}`);
|
|
1331
|
-
}
|
|
1332
|
-
const result = mapTaskResult(await response.json());
|
|
1333
|
-
logger.debug("Browser", "task_created", { recording_id: result.recordingId, task_id: result.taskId, debug_url: !!result.debugUrl });
|
|
1334
|
-
if ("schema" in input) {
|
|
1335
|
-
return wrapTaskResponseWithSchema(result, this.config, input.schema);
|
|
1336
|
-
} else {
|
|
1337
|
-
return wrapTaskResponse(result, this.config);
|
|
1338
|
-
}
|
|
1339
|
-
}
|
|
1340
|
-
/**
|
|
1341
|
-
* Execute task with recording and wait for video to be ready
|
|
1342
|
-
*/
|
|
1343
|
-
async executeWithRecording(input) {
|
|
1344
|
-
return executeWithRecording(input, this.config);
|
|
1345
|
-
}
|
|
1346
|
-
/**
|
|
1347
|
-
* Get recording status and URLs
|
|
1348
|
-
*/
|
|
1349
|
-
async getRecording(recordingId) {
|
|
1350
|
-
return getRecording(recordingId, this.config);
|
|
1351
|
-
}
|
|
1352
|
-
/**
|
|
1353
|
-
* Wait for recording to complete with automatic polling
|
|
1354
|
-
*/
|
|
1355
|
-
async waitForRecording(recordingId, options) {
|
|
1356
|
-
return waitForRecording(recordingId, this.config, options);
|
|
1357
|
-
}
|
|
1358
|
-
/**
|
|
1359
|
-
* Get errors from recording with screenshots
|
|
1360
|
-
*/
|
|
1361
|
-
async getErrors(recordingId) {
|
|
1362
|
-
return getErrors(recordingId, this.config);
|
|
1363
|
-
}
|
|
1364
|
-
/**
|
|
1365
|
-
* Get animated WebP preview of recording
|
|
1366
|
-
*/
|
|
1367
|
-
async getWebp(recordingId, options) {
|
|
1368
|
-
return getWebp(recordingId, this.config, options);
|
|
1369
|
-
}
|
|
1370
|
-
/**
|
|
1371
|
-
* Check if browser worker service is healthy
|
|
1372
|
-
*/
|
|
1373
|
-
async checkHealth() {
|
|
1374
|
-
return checkHealth(this.config);
|
|
1375
|
-
}
|
|
1376
|
-
};
|
|
1377
|
-
async function executeBrowserTask(input, config = {}) {
|
|
1378
|
-
const apiUrl = config.apiUrl || DEFAULT_CONFIG.apiUrl;
|
|
1379
|
-
const timeout = config.timeout || DEFAULT_CONFIG.timeout;
|
|
1380
|
-
const debug = config.debug || false;
|
|
1381
|
-
if (!input.task || input.task.trim().length === 0) {
|
|
1382
|
-
return {
|
|
1383
|
-
success: false,
|
|
1384
|
-
error: 'Task description is required. Example: "Go to example.com and click the login button"'
|
|
1385
|
-
};
|
|
1386
|
-
}
|
|
1387
|
-
if (input.maxSteps !== void 0 && (input.maxSteps < 1 || input.maxSteps > 50)) {
|
|
1388
|
-
return {
|
|
1389
|
-
success: false,
|
|
1390
|
-
error: "maxSteps must be between 1 and 50. Use more steps for complex multi-page flows."
|
|
1391
|
-
};
|
|
1392
|
-
}
|
|
1393
|
-
logger.debug("Browser", "execute_start", { task: input.task.slice(0, 100), url: input.url, max_steps: input.maxSteps ?? 10, record_video: input.recordVideo ?? false });
|
|
1394
|
-
const startTime = Date.now();
|
|
1395
|
-
try {
|
|
1396
|
-
const headers = { "Content-Type": "application/json" };
|
|
1397
|
-
if (config.apiKey) headers["Authorization"] = `Bearer ${config.apiKey}`;
|
|
1398
|
-
const fetchPromise = fetchWithRetry(
|
|
1399
|
-
`${apiUrl}/browser-task`,
|
|
1400
|
-
{
|
|
1401
|
-
method: "POST",
|
|
1402
|
-
headers,
|
|
1403
|
-
body: JSON.stringify({
|
|
1404
|
-
task: input.task,
|
|
1405
|
-
url: input.url,
|
|
1406
|
-
max_steps: input.maxSteps ?? 10,
|
|
1407
|
-
model: input.model ?? "morph-computer-use-v0",
|
|
1408
|
-
viewport_width: input.viewportWidth ?? 1280,
|
|
1409
|
-
viewport_height: input.viewportHeight ?? 720,
|
|
1410
|
-
external_id: input.externalId,
|
|
1411
|
-
repo_id: input.repoId,
|
|
1412
|
-
commit_id: input.commitId,
|
|
1413
|
-
record_video: input.recordVideo ?? false,
|
|
1414
|
-
video_width: input.videoWidth ?? input.viewportWidth ?? 1280,
|
|
1415
|
-
video_height: input.videoHeight ?? input.viewportHeight ?? 720,
|
|
1416
|
-
allow_resizing: input.allowResizing ?? false,
|
|
1417
|
-
structured_output: input.structuredOutput,
|
|
1418
|
-
auth: input.auth,
|
|
1419
|
-
profile_id: input.profileId,
|
|
1420
|
-
force_query_params: input.forceQueryParams
|
|
1421
|
-
})
|
|
1422
|
-
},
|
|
1423
|
-
config.retryConfig
|
|
1424
|
-
);
|
|
1425
|
-
const response = await withTimeout(
|
|
1426
|
-
fetchPromise,
|
|
1427
|
-
timeout,
|
|
1428
|
-
`Browser task timed out after ${timeout}ms. Consider increasing timeout or reducing maxSteps.`
|
|
1429
|
-
);
|
|
1430
|
-
if (!response.ok) {
|
|
1431
|
-
const errorText = await response.text().catch(() => response.statusText);
|
|
1432
|
-
logger.error("Browser", "execute_error", { status: response.status, error: errorText });
|
|
1433
|
-
throw new Error(`HTTP ${response.status}: ${errorText}`);
|
|
1434
|
-
}
|
|
1435
|
-
const result = mapTaskResult(await response.json());
|
|
1436
|
-
const elapsed = Date.now() - startTime;
|
|
1437
|
-
logger.debug("Browser", "execute_complete", { success: result.success, latency_ms: elapsed, steps: result.stepsTaken ?? 0, recording_id: result.recordingId });
|
|
1438
|
-
return result;
|
|
1439
|
-
} catch (error) {
|
|
1440
|
-
if (error instanceof Error) {
|
|
1441
|
-
if (error.message.includes("ECONNREFUSED") || error.message.includes("fetch failed")) {
|
|
1442
|
-
return {
|
|
1443
|
-
success: false,
|
|
1444
|
-
error: `Cannot connect to browser worker at ${apiUrl}. Ensure the service is running and accessible. For local dev, set MORPH_ENVIRONMENT=DEV.`
|
|
1445
|
-
};
|
|
1446
|
-
}
|
|
1447
|
-
return {
|
|
1448
|
-
success: false,
|
|
1449
|
-
error: error.message
|
|
1450
|
-
};
|
|
1451
|
-
}
|
|
1452
|
-
return {
|
|
1453
|
-
success: false,
|
|
1454
|
-
error: String(error)
|
|
1455
|
-
};
|
|
1456
|
-
}
|
|
1457
|
-
}
|
|
1458
|
-
async function getRecording(recordingId, config = {}) {
|
|
1459
|
-
const apiUrl = config.apiUrl || DEFAULT_CONFIG.apiUrl;
|
|
1460
|
-
const debug = config.debug || false;
|
|
1461
|
-
if (!config.apiKey) {
|
|
1462
|
-
throw new Error("API key required for getRecording");
|
|
1463
|
-
}
|
|
1464
|
-
if (debug) console.log(`[Browser] getRecording: ${recordingId}`);
|
|
1465
|
-
const response = await fetch(`${apiUrl}/recordings/${recordingId}`, {
|
|
1466
|
-
method: "GET",
|
|
1467
|
-
headers: { "Authorization": `Bearer ${config.apiKey}` }
|
|
1468
|
-
});
|
|
1469
|
-
if (!response.ok) {
|
|
1470
|
-
const errorText = await response.text().catch(() => response.statusText);
|
|
1471
|
-
if (debug) console.error(`[Browser] getRecording error: ${response.status} - ${errorText}`);
|
|
1472
|
-
throw new Error(`HTTP ${response.status}: ${errorText}`);
|
|
1473
|
-
}
|
|
1474
|
-
const data = mapRecordingStatus(await response.json());
|
|
1475
|
-
if (debug) console.log(`[Browser] Recording status: ${data.status}`);
|
|
1476
|
-
return {
|
|
1477
|
-
...data,
|
|
1478
|
-
getWebp: (options) => getWebp(recordingId, config, options),
|
|
1479
|
-
getErrors: () => getErrors(recordingId, config)
|
|
1480
|
-
};
|
|
1481
|
-
}
|
|
1482
|
-
async function waitForRecording(recordingId, config = {}, options = {}) {
|
|
1483
|
-
const timeout = options.timeout ?? 6e4;
|
|
1484
|
-
const pollInterval = options.pollInterval ?? 2e3;
|
|
1485
|
-
const startTime = Date.now();
|
|
1486
|
-
while (Date.now() - startTime < timeout) {
|
|
1487
|
-
const status = await getRecording(recordingId, config);
|
|
1488
|
-
if (status.status === "COMPLETED" || status.status === "ERROR") {
|
|
1489
|
-
return status;
|
|
1490
|
-
}
|
|
1491
|
-
await new Promise((resolve) => setTimeout(resolve, pollInterval));
|
|
1492
|
-
}
|
|
1493
|
-
throw new Error(`Recording timeout after ${timeout}ms - status still pending`);
|
|
1494
|
-
}
|
|
1495
|
-
async function executeWithRecording(input, config = {}) {
|
|
1496
|
-
const taskResult = await executeBrowserTask(input, config);
|
|
1497
|
-
if (taskResult.recordingId) {
|
|
1498
|
-
try {
|
|
1499
|
-
const recording = await waitForRecording(
|
|
1500
|
-
taskResult.recordingId,
|
|
1501
|
-
config,
|
|
1502
|
-
{ timeout: 6e4, pollInterval: 2e3 }
|
|
1503
|
-
);
|
|
1504
|
-
return {
|
|
1505
|
-
...taskResult,
|
|
1506
|
-
recording
|
|
1507
|
-
};
|
|
1508
|
-
} catch (error) {
|
|
1509
|
-
const errorRecording = {
|
|
1510
|
-
id: taskResult.recordingId,
|
|
1511
|
-
status: "ERROR",
|
|
1512
|
-
error: error instanceof Error ? error.message : String(error),
|
|
1513
|
-
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1514
|
-
getWebp: (options) => getWebp(taskResult.recordingId, config, options),
|
|
1515
|
-
getErrors: () => getErrors(taskResult.recordingId, config)
|
|
1516
|
-
};
|
|
1517
|
-
return {
|
|
1518
|
-
...taskResult,
|
|
1519
|
-
recording: errorRecording
|
|
1520
|
-
};
|
|
1521
|
-
}
|
|
1522
|
-
}
|
|
1523
|
-
return taskResult;
|
|
1524
|
-
}
|
|
1525
|
-
async function getErrors(recordingId, config = {}) {
|
|
1526
|
-
const apiUrl = config.apiUrl || DEFAULT_CONFIG.apiUrl;
|
|
1527
|
-
const debug = config.debug || false;
|
|
1528
|
-
if (!config.apiKey) {
|
|
1529
|
-
throw new Error("API key required for getErrors");
|
|
1530
|
-
}
|
|
1531
|
-
if (debug) console.log(`[Browser] getErrors: ${recordingId}`);
|
|
1532
|
-
const response = await fetch(`${apiUrl}/recordings/${recordingId}/errors`, {
|
|
1533
|
-
method: "GET",
|
|
1534
|
-
headers: { "Authorization": `Bearer ${config.apiKey}` }
|
|
1535
|
-
});
|
|
1536
|
-
if (!response.ok) {
|
|
1537
|
-
const errorText = await response.text().catch(() => response.statusText);
|
|
1538
|
-
if (debug) console.error(`[Browser] getErrors error: ${response.status} - ${errorText}`);
|
|
1539
|
-
throw new Error(`HTTP ${response.status}: ${errorText}`);
|
|
1540
|
-
}
|
|
1541
|
-
const errors = mapErrorsResponse(await response.json());
|
|
1542
|
-
if (debug) console.log(`[Browser] Found ${errors.totalErrors} errors`);
|
|
1543
|
-
return errors;
|
|
1544
|
-
}
|
|
1545
|
-
function stringifyStructuredOutput(schema) {
|
|
1546
|
-
try {
|
|
1547
|
-
return JSON.stringify({
|
|
1548
|
-
type: "object",
|
|
1549
|
-
description: "Zod schema definition (Zod v3)",
|
|
1550
|
-
zodDef: schema._def
|
|
1551
|
-
});
|
|
1552
|
-
} catch (error) {
|
|
1553
|
-
console.warn("[Browser] Failed to serialize Zod schema:", error);
|
|
1554
|
-
return JSON.stringify({
|
|
1555
|
-
type: "object",
|
|
1556
|
-
description: "Schema serialization failed"
|
|
1557
|
-
});
|
|
1558
|
-
}
|
|
1559
|
-
}
|
|
1560
|
-
function parseStructuredTaskOutput(result, schema) {
|
|
1561
|
-
if (!result.output) {
|
|
1562
|
-
return { ...result, parsed: null };
|
|
1563
|
-
}
|
|
1564
|
-
try {
|
|
1565
|
-
const parsed = JSON.parse(result.output);
|
|
1566
|
-
const validated = schema.parse(parsed);
|
|
1567
|
-
return { ...result, parsed: validated };
|
|
1568
|
-
} catch (error) {
|
|
1569
|
-
if (error instanceof SyntaxError) {
|
|
1570
|
-
return { ...result, parsed: null };
|
|
1571
|
-
}
|
|
1572
|
-
throw error;
|
|
1573
|
-
}
|
|
1574
|
-
}
|
|
1575
|
-
function mapTaskResult(api) {
|
|
1576
|
-
if (!api || typeof api !== "object") {
|
|
1577
|
-
return api;
|
|
1578
|
-
}
|
|
1579
|
-
return {
|
|
1580
|
-
success: api.success,
|
|
1581
|
-
result: api.result,
|
|
1582
|
-
error: api.error,
|
|
1583
|
-
stepsTaken: api.steps_taken,
|
|
1584
|
-
executionTimeMs: api.execution_time_ms,
|
|
1585
|
-
urls: api.urls,
|
|
1586
|
-
actionNames: api.action_names,
|
|
1587
|
-
errors: api.errors,
|
|
1588
|
-
modelActions: api.model_actions,
|
|
1589
|
-
isDone: api.is_done,
|
|
1590
|
-
actionHistory: api.action_history,
|
|
1591
|
-
actionResults: api.action_results,
|
|
1592
|
-
hasErrors: api.has_errors,
|
|
1593
|
-
numberOfSteps: api.number_of_steps,
|
|
1594
|
-
judgement: api.judgement,
|
|
1595
|
-
isValidated: api.is_validated,
|
|
1596
|
-
replayId: api.replay_id,
|
|
1597
|
-
replayUrl: api.replay_url,
|
|
1598
|
-
recordingId: api.recording_id,
|
|
1599
|
-
recordingStatus: api.recording_status,
|
|
1600
|
-
taskId: api.task_id,
|
|
1601
|
-
status: api.status,
|
|
1602
|
-
output: api.output,
|
|
1603
|
-
debugUrl: api.debug_url
|
|
1604
|
-
};
|
|
1605
|
-
}
|
|
1606
|
-
function mapRecordingStatus(api) {
|
|
1607
|
-
return {
|
|
1608
|
-
id: api.id,
|
|
1609
|
-
status: api.status,
|
|
1610
|
-
replayUrl: api.replay_url,
|
|
1611
|
-
networkUrl: api.network_url,
|
|
1612
|
-
consoleUrl: api.console_url,
|
|
1613
|
-
videoUrl: api.video_url,
|
|
1614
|
-
result: api.result,
|
|
1615
|
-
totalEvents: api.total_events,
|
|
1616
|
-
fileSize: api.file_size,
|
|
1617
|
-
duration: api.duration,
|
|
1618
|
-
error: api.error,
|
|
1619
|
-
createdAt: api.created_at
|
|
1620
|
-
};
|
|
1621
|
-
}
|
|
1622
|
-
function mapBrowserError(api) {
|
|
1623
|
-
return {
|
|
1624
|
-
type: api.type,
|
|
1625
|
-
message: api.message,
|
|
1626
|
-
url: api.url,
|
|
1627
|
-
timestamp: api.timestamp,
|
|
1628
|
-
screenshotUrl: api.screenshot_url,
|
|
1629
|
-
capturedAt: api.captured_at,
|
|
1630
|
-
status: api.status
|
|
1631
|
-
};
|
|
1632
|
-
}
|
|
1633
|
-
function mapErrorsResponse(api) {
|
|
1634
|
-
return {
|
|
1635
|
-
recordingId: api.recording_id,
|
|
1636
|
-
totalErrors: api.total_errors,
|
|
1637
|
-
errors: Array.isArray(api.errors) ? api.errors.map(mapBrowserError) : []
|
|
1638
|
-
};
|
|
1639
|
-
}
|
|
1640
|
-
function mapWebpResponse(api) {
|
|
1641
|
-
return {
|
|
1642
|
-
webpUrl: api.webp_url,
|
|
1643
|
-
cached: api.cached,
|
|
1644
|
-
width: api.width,
|
|
1645
|
-
fps: api.fps,
|
|
1646
|
-
maxDuration: api.max_duration,
|
|
1647
|
-
fileSize: api.file_size,
|
|
1648
|
-
maxSizeMb: api.max_size_mb,
|
|
1649
|
-
budgetMet: api.budget_met,
|
|
1650
|
-
qualityUsed: api.quality_used,
|
|
1651
|
-
attempts: api.attempts
|
|
1652
|
-
};
|
|
1653
|
-
}
|
|
1654
|
-
async function getTaskStatus(taskId, config) {
|
|
1655
|
-
const apiUrl = config.apiUrl || DEFAULT_CONFIG.apiUrl;
|
|
1656
|
-
const debug = config.debug || false;
|
|
1657
|
-
if (debug) console.log(`[Browser] getTaskStatus: ${taskId}`);
|
|
1658
|
-
const headers = {};
|
|
1659
|
-
if (config.apiKey) headers["Authorization"] = `Bearer ${config.apiKey}`;
|
|
1660
|
-
const response = await fetch(`${apiUrl}/tasks/${taskId}`, {
|
|
1661
|
-
method: "GET",
|
|
1662
|
-
headers
|
|
1663
|
-
});
|
|
1664
|
-
if (!response.ok) {
|
|
1665
|
-
const errorText = await response.text().catch(() => response.statusText);
|
|
1666
|
-
if (debug) console.error(`[Browser] getTaskStatus error: ${response.status} - ${errorText}`);
|
|
1667
|
-
throw new Error(`HTTP ${response.status}: ${errorText}`);
|
|
1668
|
-
}
|
|
1669
|
-
const result = mapTaskResult(await response.json());
|
|
1670
|
-
if (debug) console.log(`[Browser] Task status: ${result.status}`);
|
|
1671
|
-
return result;
|
|
1672
|
-
}
|
|
1673
|
-
function generateLiveUrl(taskId, config) {
|
|
1674
|
-
const apiUrl = config.apiUrl || DEFAULT_CONFIG.apiUrl;
|
|
1675
|
-
const baseUrl = apiUrl.replace("/api", "");
|
|
1676
|
-
return `${baseUrl}/tasks/${taskId}/live`;
|
|
1677
|
-
}
|
|
1678
|
-
async function pollTaskUntilComplete(taskId, config, pollConfig = {}) {
|
|
1679
|
-
const interval = pollConfig.interval ?? 2e3;
|
|
1680
|
-
const timeout = pollConfig.timeout ?? 3e5;
|
|
1681
|
-
const startTime = Date.now();
|
|
1682
|
-
while (Date.now() - startTime < timeout) {
|
|
1683
|
-
const status = await getTaskStatus(taskId, config);
|
|
1684
|
-
if (status.status === "completed" || status.status === "failed") {
|
|
1685
|
-
return status;
|
|
1686
|
-
}
|
|
1687
|
-
await new Promise((resolve) => setTimeout(resolve, interval));
|
|
1688
|
-
}
|
|
1689
|
-
throw new Error(`Task polling timeout after ${timeout}ms`);
|
|
1690
|
-
}
|
|
1691
|
-
function wrapTaskResponse(result, config) {
|
|
1692
|
-
const debugUrl = result.debugUrl ?? "";
|
|
1693
|
-
const wrapped = {
|
|
1694
|
-
...result,
|
|
1695
|
-
debugUrl,
|
|
1696
|
-
taskId: result.taskId || "",
|
|
1697
|
-
liveUrl: result.taskId ? generateLiveUrl(result.taskId, config) : debugUrl,
|
|
1698
|
-
complete: async (pollConfig) => {
|
|
1699
|
-
if (result.taskId) {
|
|
1700
|
-
return pollTaskUntilComplete(result.taskId, config, pollConfig);
|
|
1701
|
-
}
|
|
1702
|
-
if (result.recordingId) {
|
|
1703
|
-
const recording = await waitForRecording(
|
|
1704
|
-
result.recordingId,
|
|
1705
|
-
config,
|
|
1706
|
-
pollConfig
|
|
1707
|
-
);
|
|
1708
|
-
return {
|
|
1709
|
-
...result,
|
|
1710
|
-
recordingStatus: recording.status
|
|
1711
|
-
};
|
|
1712
|
-
}
|
|
1713
|
-
throw new Error("Cannot poll completion: no taskId or recordingId available");
|
|
1714
|
-
},
|
|
1715
|
-
// Add Steel live session helpers - either functional or error-throwing
|
|
1716
|
-
getLiveUrl: debugUrl ? (options) => buildLiveUrl(debugUrl, options) : () => {
|
|
1717
|
-
throw new Error(
|
|
1718
|
-
"Live sessions not available. Your backend must return a debugUrl in the response. Contact support@morphllm.com if you need help."
|
|
1719
|
-
);
|
|
1720
|
-
},
|
|
1721
|
-
getLiveIframe: debugUrl ? (optionsOrPreset) => {
|
|
1722
|
-
const options = resolvePreset(optionsOrPreset);
|
|
1723
|
-
return buildLiveIframe(debugUrl, options);
|
|
1724
|
-
} : () => {
|
|
1725
|
-
throw new Error(
|
|
1726
|
-
"Live sessions not available. Your backend must return a debugUrl in the response. Contact support@morphllm.com if you need help."
|
|
1727
|
-
);
|
|
1728
|
-
},
|
|
1729
|
-
getEmbedCode: debugUrl ? () => buildEmbedCode(debugUrl) : () => {
|
|
1730
|
-
throw new Error(
|
|
1731
|
-
"Live sessions not available. Your backend must return a debugUrl in the response. Contact support@morphllm.com if you need help."
|
|
1732
|
-
);
|
|
1733
|
-
}
|
|
1734
|
-
};
|
|
1735
|
-
return wrapped;
|
|
1736
|
-
}
|
|
1737
|
-
function wrapTaskResponseWithSchema(result, config, schema) {
|
|
1738
|
-
const debugUrl = result.debugUrl ?? "";
|
|
1739
|
-
const parsed = result.output ? parseStructuredTaskOutput(result, schema) : { ...result, parsed: null };
|
|
1740
|
-
const wrapped = {
|
|
1741
|
-
...parsed,
|
|
1742
|
-
debugUrl,
|
|
1743
|
-
taskId: result.taskId || "",
|
|
1744
|
-
liveUrl: result.taskId ? generateLiveUrl(result.taskId, config) : debugUrl,
|
|
1745
|
-
complete: async (pollConfig) => {
|
|
1746
|
-
if (result.taskId) {
|
|
1747
|
-
const finalResult = await pollTaskUntilComplete(result.taskId, config, pollConfig);
|
|
1748
|
-
return parseStructuredTaskOutput(finalResult, schema);
|
|
1749
|
-
}
|
|
1750
|
-
if (result.recordingId) {
|
|
1751
|
-
const recording = await waitForRecording(
|
|
1752
|
-
result.recordingId,
|
|
1753
|
-
config,
|
|
1754
|
-
pollConfig
|
|
1755
|
-
);
|
|
1756
|
-
return {
|
|
1757
|
-
...parsed,
|
|
1758
|
-
recordingStatus: recording.status
|
|
1759
|
-
};
|
|
1760
|
-
}
|
|
1761
|
-
throw new Error("Cannot poll completion: no taskId or recordingId available");
|
|
1762
|
-
},
|
|
1763
|
-
// Add Steel live session helpers - either functional or error-throwing
|
|
1764
|
-
getLiveUrl: debugUrl ? (options) => buildLiveUrl(debugUrl, options) : () => {
|
|
1765
|
-
throw new Error(
|
|
1766
|
-
"Live sessions not available. Your backend must return a debugUrl in the response. Contact support@morphllm.com if you need help enabling live sessions. "
|
|
1767
|
-
);
|
|
1768
|
-
},
|
|
1769
|
-
getLiveIframe: debugUrl ? (optionsOrPreset) => {
|
|
1770
|
-
const options = resolvePreset(optionsOrPreset);
|
|
1771
|
-
return buildLiveIframe(debugUrl, options);
|
|
1772
|
-
} : () => {
|
|
1773
|
-
throw new Error(
|
|
1774
|
-
"Live sessions not available. Your backend must return a debugUrl in the response. Contact support@morphllm.com if you need help enabling live sessions."
|
|
1775
|
-
);
|
|
1776
|
-
},
|
|
1777
|
-
getEmbedCode: debugUrl ? () => buildEmbedCode(debugUrl) : () => {
|
|
1778
|
-
throw new Error(
|
|
1779
|
-
"Live sessions not available. Your backend must return a debugUrl in the response. Contact support@morphllm.com if you need help enabling live sessions."
|
|
1780
|
-
);
|
|
1781
|
-
}
|
|
1782
|
-
};
|
|
1783
|
-
return wrapped;
|
|
1784
|
-
}
|
|
1785
|
-
async function getWebp(recordingId, config = {}, options = {}) {
|
|
1786
|
-
const apiUrl = config.apiUrl || DEFAULT_CONFIG.apiUrl;
|
|
1787
|
-
const debug = config.debug || false;
|
|
1788
|
-
if (!config.apiKey) {
|
|
1789
|
-
throw new Error("API key required for getWebp");
|
|
1790
|
-
}
|
|
1791
|
-
const params = new URLSearchParams();
|
|
1792
|
-
if (options.maxDuration !== void 0) params.set("max_duration", String(options.maxDuration));
|
|
1793
|
-
if (options.fps !== void 0) params.set("fps", String(options.fps));
|
|
1794
|
-
if (options.width !== void 0) params.set("width", String(options.width));
|
|
1795
|
-
if (options.quality !== void 0) params.set("quality", String(options.quality));
|
|
1796
|
-
if (options.maxSizeMb !== void 0) params.set("max_size_mb", String(options.maxSizeMb));
|
|
1797
|
-
const url = `${apiUrl}/recordings/${recordingId}/webp${params.toString() ? "?" + params.toString() : ""}`;
|
|
1798
|
-
if (debug) console.log(`[Browser] getWebp: ${url}`);
|
|
1799
|
-
const response = await fetch(url, {
|
|
1800
|
-
method: "GET",
|
|
1801
|
-
headers: { "Authorization": `Bearer ${config.apiKey}` }
|
|
1802
|
-
});
|
|
1803
|
-
if (!response.ok) {
|
|
1804
|
-
const errorText = await response.text().catch(() => response.statusText);
|
|
1805
|
-
if (debug) console.error(`[Browser] getWebp error: ${response.status} - ${errorText}`);
|
|
1806
|
-
throw new Error(`HTTP ${response.status}: ${errorText}`);
|
|
1807
|
-
}
|
|
1808
|
-
const result = mapWebpResponse(await response.json());
|
|
1809
|
-
if (debug) console.log(`[Browser] WebP ready: ${result.webpUrl} (cached: ${result.cached})`);
|
|
1810
|
-
return result;
|
|
1811
|
-
}
|
|
1812
|
-
async function checkHealth(config = {}) {
|
|
1813
|
-
const apiUrl = config.apiUrl || DEFAULT_CONFIG.apiUrl;
|
|
1814
|
-
try {
|
|
1815
|
-
const response = await fetch(`${apiUrl}/health`, {
|
|
1816
|
-
method: "GET",
|
|
1817
|
-
headers: config.apiKey ? { "Authorization": `Bearer ${config.apiKey}` } : {}
|
|
1818
|
-
});
|
|
1819
|
-
if (!response.ok) {
|
|
1820
|
-
throw new Error(`HTTP ${response.status}`);
|
|
1821
|
-
}
|
|
1822
|
-
const data = await response.json();
|
|
1823
|
-
return {
|
|
1824
|
-
ok: true,
|
|
1825
|
-
google_configured: data.google_configured ?? false,
|
|
1826
|
-
database_configured: data.database_configured ?? false,
|
|
1827
|
-
s3_configured: data.s3_configured ?? false
|
|
1828
|
-
};
|
|
1829
|
-
} catch (error) {
|
|
1830
|
-
return {
|
|
1831
|
-
ok: false,
|
|
1832
|
-
google_configured: false,
|
|
1833
|
-
database_configured: false,
|
|
1834
|
-
s3_configured: false,
|
|
1835
|
-
error: error instanceof Error ? error.message : String(error)
|
|
1836
|
-
};
|
|
1837
|
-
}
|
|
1838
|
-
}
|
|
1839
|
-
|
|
1840
|
-
// tools/browser/prompts.ts
|
|
1841
|
-
var BROWSER_TOOL_DESCRIPTION = `Test and verify your implemented code in a live browser. This tool executes natural language test instructions and returns a video recording plus detailed logs to help you debug issues.
|
|
1842
|
-
|
|
1843
|
-
## When to Use
|
|
1844
|
-
Use this AFTER coding is complete to verify your implementation:
|
|
1845
|
-
- You've finished writing/modifying code and need to verify it works
|
|
1846
|
-
- You need to test user interactions end-to-end (clicks, forms, navigation)
|
|
1847
|
-
- You want to catch runtime errors, console warnings, or network failures
|
|
1848
|
-
- You need visual confirmation that UI elements render and behave correctly
|
|
1849
|
-
|
|
1850
|
-
## What You Get Back
|
|
1851
|
-
The tool returns debugging artifacts to help you identify and fix issues:
|
|
1852
|
-
- **Video recording**: Watch exactly what happened in the browser session
|
|
1853
|
-
- **Console logs**: All console.log, warnings, and errors with timestamps
|
|
1854
|
-
- **Network logs**: Failed requests, 404s, API errors with screenshots
|
|
1855
|
-
- **Error screenshots**: Visual snapshots captured when errors occur
|
|
1856
|
-
|
|
1857
|
-
## How to Write Good Tests
|
|
1858
|
-
Be specific about the user journey you're testing:
|
|
1859
|
-
\u274C Bad: "Test the login feature"
|
|
1860
|
-
\u2705 Good: "Navigate to /login, enter 'test@example.com' and 'password123', click the Login button, verify we reach the /dashboard page"
|
|
1861
|
-
|
|
1862
|
-
Include verification steps:
|
|
1863
|
-
\u2705 "Click the Add Item button, verify the item appears in the list"
|
|
1864
|
-
\u2705 "Submit the form, verify a success message is displayed"
|
|
1865
|
-
|
|
1866
|
-
## Iterating on Failures
|
|
1867
|
-
1. Run the test and review the video + logs
|
|
1868
|
-
2. Identify the specific issue (console error, failed request, wrong behavior)
|
|
1869
|
-
3. Fix the code based on the evidence
|
|
1870
|
-
4. Re-run the test to verify the fix
|
|
1871
|
-
5. Repeat until test passes
|
|
1872
|
-
|
|
1873
|
-
## Requirements
|
|
1874
|
-
- **URL**: Must be publicly accessible (use tunnels like ngrok, Cloudflare, or deploy to staging)
|
|
1875
|
-
- **Timing**: Use this after implementation, not during coding
|
|
1876
|
-
- **Complexity**: Set maxSteps higher (20-30) for multi-step user workflows`;
|
|
1877
|
-
var BROWSER_SYSTEM_PROMPT = `You are an AI agent designed to automate browser tasks to accomplish the <user_request>. Respond with a valid JSON object in the format: {"thinking": "Reason step-by-step about your current state, history, and the user request to decide your next goal and action. Analyze the browser state and screenshot to confirm the outcome of your last action.", "evaluation_previous_goal": "A concise, one-sentence evaluation of your last action's outcome (e.g., Success, Failure, or Uncertain).", "memory": "1-3 sentences summarizing key information and progress so far. This helps you track progress across multiple steps (e.g., items collected, pages visited).", "next_goal": "A clear, one-sentence description of your immediate next objective.", "action": [{"action_name": {"parameter": "value"}}]}`;
|
|
1878
|
-
|
|
1879
|
-
// tools/browser/anthropic.ts
|
|
1880
|
-
var anthropic_exports = {};
|
|
1881
|
-
__export(anthropic_exports, {
|
|
1882
|
-
browserTool: () => browserTool,
|
|
1883
|
-
createBrowserTool: () => createBrowserTool
|
|
1884
|
-
});
|
|
1885
|
-
var browserTool = {
|
|
1886
|
-
name: "browser_task",
|
|
1887
|
-
description: BROWSER_TOOL_DESCRIPTION,
|
|
1888
|
-
input_schema: {
|
|
1889
|
-
type: "object",
|
|
1890
|
-
properties: {
|
|
1891
|
-
task: {
|
|
1892
|
-
type: "string",
|
|
1893
|
-
description: 'Natural language description of what to do (e.g., "Test checkout flow for buying a pineapple")'
|
|
1894
|
-
},
|
|
1895
|
-
url: {
|
|
1896
|
-
type: "string",
|
|
1897
|
-
description: "Starting URL (e.g., https://3000-xyz.e2b.dev). Required if navigating to a specific page."
|
|
1898
|
-
},
|
|
1899
|
-
maxSteps: {
|
|
1900
|
-
type: "number",
|
|
1901
|
-
description: "Maximum number of browser actions to take (1-50). Default: 10. Use 15-30 for complex flows.",
|
|
1902
|
-
default: 10
|
|
1903
|
-
},
|
|
1904
|
-
region: {
|
|
1905
|
-
type: "string",
|
|
1906
|
-
enum: ["sfo", "lon"],
|
|
1907
|
-
description: "Browserless region: sfo (US West Coast) or lon (Europe). Default: sfo.",
|
|
1908
|
-
default: "sfo"
|
|
1909
|
-
}
|
|
1910
|
-
},
|
|
1911
|
-
required: ["task"]
|
|
1912
|
-
}
|
|
1913
|
-
};
|
|
1914
|
-
function formatResult(result) {
|
|
1915
|
-
if (result.success) {
|
|
1916
|
-
const parts = [
|
|
1917
|
-
"\u2705 Browser task completed successfully",
|
|
1918
|
-
`Steps taken: ${result.stepsTaken ?? 0}`,
|
|
1919
|
-
result.executionTimeMs ? `Execution time: ${result.executionTimeMs}ms` : null,
|
|
1920
|
-
"",
|
|
1921
|
-
"Result:",
|
|
1922
|
-
result.result || "Task completed"
|
|
1923
|
-
];
|
|
1924
|
-
return parts.filter(Boolean).join("\n");
|
|
1925
|
-
}
|
|
1926
|
-
return `\u274C Browser task failed: ${result.error || "Unknown error"}`;
|
|
1927
|
-
}
|
|
1928
|
-
function createBrowserTool(config) {
|
|
1929
|
-
return Object.assign({}, browserTool, {
|
|
1930
|
-
execute: async (input) => {
|
|
1931
|
-
return executeBrowserTask(input, config);
|
|
1932
|
-
},
|
|
1933
|
-
formatResult: (result) => {
|
|
1934
|
-
return formatResult(result);
|
|
1935
|
-
},
|
|
1936
|
-
getSystemPrompt: () => {
|
|
1937
|
-
return BROWSER_SYSTEM_PROMPT;
|
|
1938
|
-
}
|
|
1939
|
-
});
|
|
1940
|
-
}
|
|
1941
|
-
|
|
1942
|
-
// tools/browser/openai.ts
|
|
1943
|
-
var openai_exports = {};
|
|
1944
|
-
__export(openai_exports, {
|
|
1945
|
-
browserTool: () => browserTool2,
|
|
1946
|
-
createBrowserTool: () => createBrowserTool2,
|
|
1947
|
-
execute: () => execute,
|
|
1948
|
-
formatResult: () => formatResult2,
|
|
1949
|
-
getSystemPrompt: () => getSystemPrompt
|
|
1950
|
-
});
|
|
1951
|
-
var browserTool2 = {
|
|
1952
|
-
type: "function",
|
|
1953
|
-
function: {
|
|
1954
|
-
name: "browser_task",
|
|
1955
|
-
description: BROWSER_TOOL_DESCRIPTION,
|
|
1956
|
-
parameters: {
|
|
1957
|
-
type: "object",
|
|
1958
|
-
properties: {
|
|
1959
|
-
task: {
|
|
1960
|
-
type: "string",
|
|
1961
|
-
description: 'Natural language description of what to do (e.g., "Test checkout flow for buying a pineapple")'
|
|
1962
|
-
},
|
|
1963
|
-
url: {
|
|
1964
|
-
type: "string",
|
|
1965
|
-
description: "Starting URL (e.g., https://3000-xyz.e2b.dev). Required if navigating to a specific page."
|
|
1966
|
-
},
|
|
1967
|
-
maxSteps: {
|
|
1968
|
-
type: "number",
|
|
1969
|
-
description: "Maximum number of browser actions to take (1-50). Default: 10. Use 15-30 for complex flows.",
|
|
1970
|
-
default: 10
|
|
1971
|
-
},
|
|
1972
|
-
region: {
|
|
1973
|
-
type: "string",
|
|
1974
|
-
enum: ["sfo", "lon"],
|
|
1975
|
-
description: "Browserless region: sfo (US West Coast) or lon (Europe). Default: sfo.",
|
|
1976
|
-
default: "sfo"
|
|
1977
|
-
}
|
|
1978
|
-
},
|
|
1979
|
-
required: ["task"]
|
|
1980
|
-
}
|
|
1981
|
-
}
|
|
1982
|
-
};
|
|
1983
|
-
async function execute(input, config) {
|
|
1984
|
-
const parsedInput = typeof input === "string" ? JSON.parse(input) : input;
|
|
1985
|
-
return executeBrowserTask(parsedInput, config);
|
|
1986
|
-
}
|
|
1987
|
-
function formatResult2(result) {
|
|
1988
|
-
if (result.success) {
|
|
1989
|
-
const parts = [
|
|
1990
|
-
"\u2705 Browser task completed successfully",
|
|
1991
|
-
`Steps taken: ${result.stepsTaken ?? 0}`,
|
|
1992
|
-
result.executionTimeMs ? `Execution time: ${result.executionTimeMs}ms` : null,
|
|
1993
|
-
"",
|
|
1994
|
-
"Result:",
|
|
1995
|
-
result.result || "Task completed"
|
|
1996
|
-
];
|
|
1997
|
-
return parts.filter(Boolean).join("\n");
|
|
1998
|
-
}
|
|
1999
|
-
return `\u274C Browser task failed: ${result.error || "Unknown error"}`;
|
|
2000
|
-
}
|
|
2001
|
-
function getSystemPrompt() {
|
|
2002
|
-
return BROWSER_SYSTEM_PROMPT;
|
|
2003
|
-
}
|
|
2004
|
-
function createBrowserTool2(config) {
|
|
2005
|
-
return Object.assign({}, browserTool2, {
|
|
2006
|
-
execute: async (input) => {
|
|
2007
|
-
return execute(input, config);
|
|
2008
|
-
},
|
|
2009
|
-
formatResult: (result) => {
|
|
2010
|
-
return formatResult2(result);
|
|
2011
|
-
},
|
|
2012
|
-
getSystemPrompt: () => {
|
|
2013
|
-
return getSystemPrompt();
|
|
2014
|
-
}
|
|
2015
|
-
});
|
|
2016
|
-
}
|
|
2017
|
-
|
|
2018
|
-
// tools/browser/vercel.ts
|
|
2019
|
-
var vercel_exports = {};
|
|
2020
|
-
__export(vercel_exports, {
|
|
2021
|
-
browserTool: () => browserTool3,
|
|
2022
|
-
createBrowserTool: () => createBrowserTool3
|
|
2023
|
-
});
|
|
2024
|
-
var import_ai = require("ai");
|
|
2025
|
-
var import_zod = require("zod");
|
|
2026
|
-
function createBrowserTool3(config) {
|
|
2027
|
-
const schema = import_zod.z.object({
|
|
2028
|
-
task: import_zod.z.string().describe('Natural language description of what to do (e.g., "Test checkout flow for buying a pineapple")'),
|
|
2029
|
-
url: import_zod.z.string().optional().describe("Starting URL (e.g., https://3000-xyz.e2b.dev)"),
|
|
2030
|
-
maxSteps: import_zod.z.number().min(1).max(50).default(10).describe("Maximum number of browser actions to take"),
|
|
2031
|
-
region: import_zod.z.enum(["sfo", "lon"]).default("sfo").describe("Browserless region: sfo (US West) or lon (Europe)")
|
|
2032
|
-
});
|
|
2033
|
-
return (0, import_ai.tool)({
|
|
2034
|
-
description: BROWSER_TOOL_DESCRIPTION,
|
|
2035
|
-
inputSchema: schema,
|
|
2036
|
-
execute: async (params) => {
|
|
2037
|
-
const { task, url, maxSteps, region } = params;
|
|
2038
|
-
const result = await executeBrowserTask(
|
|
2039
|
-
{ task, url, maxSteps, region },
|
|
2040
|
-
config
|
|
2041
|
-
);
|
|
2042
|
-
if (result.success) {
|
|
2043
|
-
return {
|
|
2044
|
-
success: true,
|
|
2045
|
-
result: result.result,
|
|
2046
|
-
stepsTaken: result.stepsTaken,
|
|
2047
|
-
executionTimeMs: result.executionTimeMs
|
|
2048
|
-
};
|
|
2049
|
-
}
|
|
2050
|
-
return {
|
|
2051
|
-
success: false,
|
|
2052
|
-
error: result.error
|
|
2053
|
-
};
|
|
2054
|
-
}
|
|
2055
|
-
});
|
|
2056
|
-
}
|
|
2057
|
-
var browserTool3 = createBrowserTool3();
|
|
2058
|
-
|
|
2059
|
-
// tools/browser/gemini.ts
|
|
2060
|
-
var gemini_exports = {};
|
|
2061
|
-
__export(gemini_exports, {
|
|
2062
|
-
browserFunctionDeclaration: () => browserFunctionDeclaration,
|
|
2063
|
-
browserTool: () => browserTool4,
|
|
2064
|
-
createBrowserTool: () => createBrowserTool4,
|
|
2065
|
-
default: () => gemini_default,
|
|
2066
|
-
execute: () => execute2,
|
|
2067
|
-
formatResult: () => formatResult3,
|
|
2068
|
-
getSystemPrompt: () => getSystemPrompt2
|
|
2069
|
-
});
|
|
2070
|
-
var import_generative_ai = require("@google/generative-ai");
|
|
2071
|
-
var TOOL_PARAMETERS = {
|
|
2072
|
-
type: import_generative_ai.SchemaType.OBJECT,
|
|
2073
|
-
properties: {
|
|
2074
|
-
task: {
|
|
2075
|
-
type: import_generative_ai.SchemaType.STRING,
|
|
2076
|
-
description: 'Natural language description of what to do (e.g., "Test checkout flow for buying a pineapple")'
|
|
2077
|
-
},
|
|
2078
|
-
url: {
|
|
2079
|
-
type: import_generative_ai.SchemaType.STRING,
|
|
2080
|
-
description: "Starting URL (e.g., https://3000-xyz.e2b.dev). Required if navigating to a specific page."
|
|
2081
|
-
},
|
|
2082
|
-
maxSteps: {
|
|
2083
|
-
type: import_generative_ai.SchemaType.NUMBER,
|
|
2084
|
-
description: "Maximum number of browser actions to take (1-50). Default: 10. Use 15-30 for complex flows."
|
|
2085
|
-
},
|
|
2086
|
-
region: {
|
|
2087
|
-
type: import_generative_ai.SchemaType.STRING,
|
|
2088
|
-
description: "Browserless region: sfo (US West Coast) or lon (Europe). Default: sfo."
|
|
2089
|
-
}
|
|
2090
|
-
},
|
|
2091
|
-
required: ["task"]
|
|
2092
|
-
};
|
|
2093
|
-
var browserFunctionDeclaration = {
|
|
2094
|
-
name: "browser_task",
|
|
2095
|
-
description: BROWSER_TOOL_DESCRIPTION,
|
|
2096
|
-
parameters: TOOL_PARAMETERS
|
|
2097
|
-
};
|
|
2098
|
-
async function execute2(input, config) {
|
|
2099
|
-
const parsedInput = typeof input === "string" ? JSON.parse(input) : input;
|
|
2100
|
-
return executeBrowserTask(parsedInput, config);
|
|
2101
|
-
}
|
|
2102
|
-
function formatResult3(result) {
|
|
2103
|
-
if (result.success) {
|
|
2104
|
-
const parts = [
|
|
2105
|
-
"\u2705 Browser task completed successfully",
|
|
2106
|
-
`Steps taken: ${result.stepsTaken ?? 0}`,
|
|
2107
|
-
result.executionTimeMs ? `Execution time: ${result.executionTimeMs}ms` : null,
|
|
2108
|
-
"",
|
|
2109
|
-
"Result:",
|
|
2110
|
-
result.result || "Task completed"
|
|
2111
|
-
];
|
|
2112
|
-
return parts.filter(Boolean).join("\n");
|
|
2113
|
-
}
|
|
2114
|
-
return `\u274C Browser task failed: ${result.error || "Unknown error"}`;
|
|
2115
|
-
}
|
|
2116
|
-
function getSystemPrompt2() {
|
|
2117
|
-
return BROWSER_SYSTEM_PROMPT;
|
|
2118
|
-
}
|
|
2119
|
-
function createBrowserTool4(config) {
|
|
2120
|
-
const declaration = {
|
|
2121
|
-
name: "browser_task",
|
|
2122
|
-
description: BROWSER_TOOL_DESCRIPTION,
|
|
2123
|
-
parameters: TOOL_PARAMETERS
|
|
2124
|
-
};
|
|
2125
|
-
return Object.assign(declaration, {
|
|
2126
|
-
execute: async (input) => {
|
|
2127
|
-
return execute2(input, config);
|
|
2128
|
-
},
|
|
2129
|
-
formatResult: (result) => {
|
|
2130
|
-
return formatResult3(result);
|
|
2131
|
-
},
|
|
2132
|
-
getSystemPrompt: () => {
|
|
2133
|
-
return getSystemPrompt2();
|
|
2134
|
-
}
|
|
2135
|
-
});
|
|
2136
|
-
}
|
|
2137
|
-
var browserTool4 = browserFunctionDeclaration;
|
|
2138
|
-
var gemini_default = browserFunctionDeclaration;
|
|
2139
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
2140
|
-
0 && (module.exports = {
|
|
2141
|
-
BROWSER_SYSTEM_PROMPT,
|
|
2142
|
-
BROWSER_TOOL_DESCRIPTION,
|
|
2143
|
-
BrowserClient,
|
|
2144
|
-
LIVE_PRESETS,
|
|
2145
|
-
MorphAPIError,
|
|
2146
|
-
MorphAuthenticationError,
|
|
2147
|
-
MorphError,
|
|
2148
|
-
MorphNotFoundError,
|
|
2149
|
-
MorphProfileLimitError,
|
|
2150
|
-
MorphRateLimitError,
|
|
2151
|
-
MorphValidationError,
|
|
2152
|
-
ProfilesClient,
|
|
2153
|
-
anthropic,
|
|
2154
|
-
buildEmbedCode,
|
|
2155
|
-
buildLiveIframe,
|
|
2156
|
-
buildLiveUrl,
|
|
2157
|
-
checkHealth,
|
|
2158
|
-
executeBrowserTask,
|
|
2159
|
-
executeWithRecording,
|
|
2160
|
-
gemini,
|
|
2161
|
-
getErrors,
|
|
2162
|
-
getRecording,
|
|
2163
|
-
getWebp,
|
|
2164
|
-
openai,
|
|
2165
|
-
parseAPIError,
|
|
2166
|
-
vercel,
|
|
2167
|
-
waitForRecording
|
|
2168
|
-
});
|
|
2169
|
-
//# sourceMappingURL=index.cjs.map
|