@morphllm/morphsdk 0.2.198 → 0.2.200
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-ZQNTXHBQ.js → chunk-3CCWSLQW.js} +2 -2
- package/dist/{chunk-FESO6TDQ.js → chunk-7I2A7GGJ.js} +2 -2
- package/dist/{chunk-4JUIEYAH.js → chunk-AKSXZBPT.js} +3 -3
- package/dist/chunk-B4X5RWLR.js +271 -0
- package/dist/chunk-B4X5RWLR.js.map +1 -0
- package/dist/{chunk-QKNGVBE2.js → chunk-L6YOMTFU.js} +3 -3
- package/dist/{chunk-YQ2G5YLI.js → chunk-MLROWLS6.js} +4 -4
- package/dist/{chunk-4DNEBVGV.js → chunk-MPL6BDR6.js} +2 -2
- package/dist/{chunk-3XS5P5XH.js → chunk-PD3EDFQD.js} +2 -2
- package/dist/{chunk-CAFREMIT.js → chunk-PJNL35DC.js} +2 -2
- package/dist/{chunk-PEFXG5M6.js → chunk-Q65LL6UM.js} +2 -2
- package/dist/{chunk-YUH3MTP3.js → chunk-QTBFL4DG.js} +2 -2
- package/dist/{chunk-XTFRHVCW.js → chunk-SNYHVDE4.js} +4 -4
- package/dist/{chunk-ZGERT23F.js → chunk-TIMDDHYB.js} +4 -4
- package/dist/{chunk-PV6EF6NG.js → chunk-UHIANNKC.js} +4 -4
- package/dist/{chunk-FUYX2MNM.js → chunk-UKAAT6KT.js} +4 -10
- package/dist/chunk-UKAAT6KT.js.map +1 -0
- package/dist/{chunk-ZU5YYGBJ.js → chunk-UZ42MHTR.js} +3 -63
- package/dist/chunk-UZ42MHTR.js.map +1 -0
- package/dist/{chunk-XK3PQZW6.js → chunk-WTENYKJP.js} +2 -2
- package/dist/{chunk-6XFL2NER.js → chunk-XTLPA7ZP.js} +2 -2
- package/dist/{chunk-D2RFP6R2.js → chunk-Z57GJLCG.js} +3 -3
- package/dist/{chunk-SKN2L5CE.js → chunk-ZE64EWUV.js} +2 -2
- package/dist/client-BWhi-vSj.d.ts +341 -0
- package/dist/client.cjs +88 -2086
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.ts +4 -10
- package/dist/client.js +20 -30
- package/dist/core/client.cjs +2 -68
- package/dist/core/client.cjs.map +1 -1
- package/dist/core/client.d.ts +0 -8
- package/dist/core/client.js +4 -4
- package/dist/core/error.cjs +2 -62
- package/dist/core/error.cjs.map +1 -1
- package/dist/core/error.js +3 -3
- package/dist/core/index.cjs +2 -68
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.js +4 -4
- package/dist/edge.cjs +2 -68
- package/dist/edge.cjs.map +1 -1
- package/dist/edge.js +7 -7
- package/dist/index.cjs +89 -2101
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -8
- package/dist/index.js +21 -47
- package/dist/modelrouter/core.cjs +2 -68
- package/dist/modelrouter/core.cjs.map +1 -1
- package/dist/modelrouter/core.js +5 -5
- package/dist/modelrouter/index.cjs +2 -68
- package/dist/modelrouter/index.cjs.map +1 -1
- package/dist/modelrouter/index.js +5 -5
- package/dist/subagents/anthropic.cjs +2 -68
- package/dist/subagents/anthropic.cjs.map +1 -1
- package/dist/subagents/anthropic.d.ts +1 -1
- package/dist/subagents/anthropic.js +9 -9
- package/dist/subagents/index.d.ts +1 -1
- package/dist/subagents/prompts.d.ts +1 -1
- package/dist/subagents/types.d.ts +1 -1
- package/dist/subagents/vercel.cjs +2 -68
- package/dist/subagents/vercel.cjs.map +1 -1
- package/dist/subagents/vercel.d.ts +1 -1
- package/dist/subagents/vercel.js +9 -9
- package/dist/tools/compact/core.cjs +2 -68
- package/dist/tools/compact/core.cjs.map +1 -1
- package/dist/tools/compact/core.js +5 -5
- package/dist/tools/compact/index.cjs +2 -68
- package/dist/tools/compact/index.cjs.map +1 -1
- package/dist/tools/compact/index.js +6 -6
- package/dist/tools/fastapply/anthropic.cjs +2 -62
- package/dist/tools/fastapply/anthropic.cjs.map +1 -1
- package/dist/tools/fastapply/anthropic.js +7 -7
- package/dist/tools/fastapply/apply.cjs +2 -62
- package/dist/tools/fastapply/apply.cjs.map +1 -1
- package/dist/tools/fastapply/apply.js +2 -2
- package/dist/tools/fastapply/core.cjs +2 -68
- package/dist/tools/fastapply/core.cjs.map +1 -1
- package/dist/tools/fastapply/core.js +6 -6
- package/dist/tools/fastapply/index.cjs +2 -62
- package/dist/tools/fastapply/index.cjs.map +1 -1
- package/dist/tools/fastapply/index.js +13 -13
- package/dist/tools/fastapply/openai.cjs +2 -62
- package/dist/tools/fastapply/openai.cjs.map +1 -1
- package/dist/tools/fastapply/openai.js +7 -7
- package/dist/tools/fastapply/vercel.cjs +2 -62
- package/dist/tools/fastapply/vercel.cjs.map +1 -1
- package/dist/tools/fastapply/vercel.js +7 -7
- package/dist/tools/index.cjs +2 -62
- package/dist/tools/index.cjs.map +1 -1
- package/dist/tools/index.js +13 -13
- package/dist/tools/utils/resilience.cjs +2 -62
- 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 -62
- package/dist/tools/warp_grep/agent/runner.cjs.map +1 -1
- package/dist/tools/warp_grep/agent/runner.js +2 -2
- package/dist/tools/warp_grep/anthropic.cjs +2 -68
- package/dist/tools/warp_grep/anthropic.cjs.map +1 -1
- package/dist/tools/warp_grep/anthropic.d.ts +1 -1
- package/dist/tools/warp_grep/anthropic.js +9 -9
- package/dist/tools/warp_grep/client.cjs +2 -68
- package/dist/tools/warp_grep/client.cjs.map +1 -1
- package/dist/tools/warp_grep/client.d.ts +1 -1
- package/dist/tools/warp_grep/client.js +8 -8
- package/dist/tools/warp_grep/gemini.cjs +2 -68
- package/dist/tools/warp_grep/gemini.cjs.map +1 -1
- package/dist/tools/warp_grep/gemini.d.ts +1 -1
- package/dist/tools/warp_grep/gemini.js +8 -8
- package/dist/tools/warp_grep/index.cjs +2 -68
- package/dist/tools/warp_grep/index.cjs.map +1 -1
- package/dist/tools/warp_grep/index.d.ts +1 -1
- package/dist/tools/warp_grep/index.js +8 -8
- package/dist/tools/warp_grep/openai.cjs +2 -68
- package/dist/tools/warp_grep/openai.cjs.map +1 -1
- package/dist/tools/warp_grep/openai.d.ts +1 -1
- package/dist/tools/warp_grep/openai.js +9 -9
- package/dist/tools/warp_grep/providers/code_storage_http.d.ts +1 -1
- package/dist/tools/warp_grep/providers/remote.d.ts +1 -1
- package/dist/tools/warp_grep/vercel.cjs +2 -68
- package/dist/tools/warp_grep/vercel.cjs.map +1 -1
- package/dist/tools/warp_grep/vercel.d.ts +1 -1
- package/dist/tools/warp_grep/vercel.js +9 -9
- package/dist/{types-qwD753FR.d.ts → types-DxZLPogx.d.ts} +1 -1
- package/dist/version.cjs +2 -62
- package/dist/version.cjs.map +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -62
- 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-2VERUKO2.js +0 -177
- package/dist/chunk-2VERUKO2.js.map +0 -1
- package/dist/chunk-EMURAU6J.js +0 -148
- package/dist/chunk-EMURAU6J.js.map +0 -1
- package/dist/chunk-FUYX2MNM.js.map +0 -1
- package/dist/chunk-GJ42MYUU.js +0 -57
- package/dist/chunk-GJ42MYUU.js.map +0 -1
- package/dist/chunk-IDMKQWQG.js +0 -214
- package/dist/chunk-IDMKQWQG.js.map +0 -1
- package/dist/chunk-KQKLQHJF.js +0 -96
- package/dist/chunk-KQKLQHJF.js.map +0 -1
- package/dist/chunk-O5264GI4.js +0 -58
- package/dist/chunk-O5264GI4.js.map +0 -1
- package/dist/chunk-PIIXU2H3.js +0 -389
- package/dist/chunk-PIIXU2H3.js.map +0 -1
- package/dist/chunk-T6TXYTKH.js +0 -83
- package/dist/chunk-T6TXYTKH.js.map +0 -1
- package/dist/chunk-TLXVGE4R.js +0 -42
- package/dist/chunk-TLXVGE4R.js.map +0 -1
- package/dist/chunk-VBZ7BG47.js +0 -97
- package/dist/chunk-VBZ7BG47.js.map +0 -1
- package/dist/chunk-WLMPQFER.js +0 -128
- package/dist/chunk-WLMPQFER.js.map +0 -1
- package/dist/chunk-XH6KJJDI.js +0 -80
- package/dist/chunk-XH6KJJDI.js.map +0 -1
- package/dist/chunk-YD6TNDR4.js +0 -622
- package/dist/chunk-YD6TNDR4.js.map +0 -1
- package/dist/chunk-YHZJYCOU.js +0 -680
- package/dist/chunk-YHZJYCOU.js.map +0 -1
- package/dist/chunk-YQMPVJ2L.js +0 -32
- package/dist/chunk-YQMPVJ2L.js.map +0 -1
- package/dist/chunk-YTYCHRQ2.js +0 -106
- package/dist/chunk-YTYCHRQ2.js.map +0 -1
- package/dist/chunk-ZU5YYGBJ.js.map +0 -1
- package/dist/client-DCeydotn.d.ts +0 -1015
- package/dist/openai-BQMeDFef.d.ts +0 -81
- package/dist/otel-CG0uqXjp.d.ts +0 -42
- package/dist/tools/browser/anthropic.cjs +0 -645
- 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 -1821
- 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 -2159
- 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 -661
- 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 -932
- 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 -932
- 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 -622
- 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/codebase_search/anthropic.cjs +0 -696
- package/dist/tools/codebase_search/anthropic.cjs.map +0 -1
- package/dist/tools/codebase_search/anthropic.d.ts +0 -40
- package/dist/tools/codebase_search/anthropic.js +0 -16
- package/dist/tools/codebase_search/anthropic.js.map +0 -1
- package/dist/tools/codebase_search/core.cjs +0 -638
- package/dist/tools/codebase_search/core.cjs.map +0 -1
- package/dist/tools/codebase_search/core.d.ts +0 -51
- package/dist/tools/codebase_search/core.js +0 -16
- package/dist/tools/codebase_search/core.js.map +0 -1
- package/dist/tools/codebase_search/index.cjs +0 -821
- package/dist/tools/codebase_search/index.cjs.map +0 -1
- package/dist/tools/codebase_search/index.d.ts +0 -12
- package/dist/tools/codebase_search/index.js +0 -32
- package/dist/tools/codebase_search/index.js.map +0 -1
- package/dist/tools/codebase_search/openai.cjs +0 -745
- package/dist/tools/codebase_search/openai.cjs.map +0 -1
- package/dist/tools/codebase_search/openai.d.ts +0 -87
- package/dist/tools/codebase_search/openai.js +0 -26
- package/dist/tools/codebase_search/openai.js.map +0 -1
- package/dist/tools/codebase_search/prompts.cjs +0 -57
- package/dist/tools/codebase_search/prompts.cjs.map +0 -1
- package/dist/tools/codebase_search/prompts.d.ts +0 -7
- package/dist/tools/codebase_search/prompts.js +0 -10
- package/dist/tools/codebase_search/prompts.js.map +0 -1
- package/dist/tools/codebase_search/types.cjs +0 -19
- package/dist/tools/codebase_search/types.cjs.map +0 -1
- package/dist/tools/codebase_search/types.d.ts +0 -50
- package/dist/tools/codebase_search/types.js +0 -1
- package/dist/tools/codebase_search/types.js.map +0 -1
- package/dist/tools/codebase_search/vercel.cjs +0 -658
- package/dist/tools/codebase_search/vercel.cjs.map +0 -1
- package/dist/tools/codebase_search/vercel.d.ts +0 -65
- package/dist/tools/codebase_search/vercel.js +0 -20
- package/dist/tools/codebase_search/vercel.js.map +0 -1
- package/dist/tracing/core.cjs +0 -410
- package/dist/tracing/core.cjs.map +0 -1
- package/dist/tracing/core.d.ts +0 -58
- package/dist/tracing/core.js +0 -12
- package/dist/tracing/core.js.map +0 -1
- package/dist/tracing/index.cjs +0 -422
- package/dist/tracing/index.cjs.map +0 -1
- package/dist/tracing/index.d.ts +0 -5
- package/dist/tracing/index.js +0 -17
- package/dist/tracing/index.js.map +0 -1
- package/dist/tracing/interaction.cjs +0 -273
- package/dist/tracing/interaction.cjs.map +0 -1
- package/dist/tracing/interaction.d.ts +0 -41
- package/dist/tracing/interaction.js +0 -11
- package/dist/tracing/interaction.js.map +0 -1
- package/dist/tracing/otel.cjs +0 -56
- package/dist/tracing/otel.cjs.map +0 -1
- package/dist/tracing/otel.d.ts +0 -2
- package/dist/tracing/otel.js +0 -10
- package/dist/tracing/otel.js.map +0 -1
- package/dist/tracing/types.cjs +0 -19
- package/dist/tracing/types.cjs.map +0 -1
- package/dist/tracing/types.d.ts +0 -124
- package/dist/tracing/types.js +0 -1
- package/dist/tracing/types.js.map +0 -1
- package/dist/vercel-CVF27qFK.d.ts +0 -74
- /package/dist/{chunk-ZQNTXHBQ.js.map → chunk-3CCWSLQW.js.map} +0 -0
- /package/dist/{chunk-FESO6TDQ.js.map → chunk-7I2A7GGJ.js.map} +0 -0
- /package/dist/{chunk-4JUIEYAH.js.map → chunk-AKSXZBPT.js.map} +0 -0
- /package/dist/{chunk-QKNGVBE2.js.map → chunk-L6YOMTFU.js.map} +0 -0
- /package/dist/{chunk-YQ2G5YLI.js.map → chunk-MLROWLS6.js.map} +0 -0
- /package/dist/{chunk-4DNEBVGV.js.map → chunk-MPL6BDR6.js.map} +0 -0
- /package/dist/{chunk-3XS5P5XH.js.map → chunk-PD3EDFQD.js.map} +0 -0
- /package/dist/{chunk-CAFREMIT.js.map → chunk-PJNL35DC.js.map} +0 -0
- /package/dist/{chunk-PEFXG5M6.js.map → chunk-Q65LL6UM.js.map} +0 -0
- /package/dist/{chunk-YUH3MTP3.js.map → chunk-QTBFL4DG.js.map} +0 -0
- /package/dist/{chunk-XTFRHVCW.js.map → chunk-SNYHVDE4.js.map} +0 -0
- /package/dist/{chunk-ZGERT23F.js.map → chunk-TIMDDHYB.js.map} +0 -0
- /package/dist/{chunk-PV6EF6NG.js.map → chunk-UHIANNKC.js.map} +0 -0
- /package/dist/{chunk-XK3PQZW6.js.map → chunk-WTENYKJP.js.map} +0 -0
- /package/dist/{chunk-6XFL2NER.js.map → chunk-XTLPA7ZP.js.map} +0 -0
- /package/dist/{chunk-D2RFP6R2.js.map → chunk-Z57GJLCG.js.map} +0 -0
- /package/dist/{chunk-SKN2L5CE.js.map → chunk-ZE64EWUV.js.map} +0 -0
package/dist/chunk-YD6TNDR4.js
DELETED
|
@@ -1,622 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ProfilesClient
|
|
3
|
-
} from "./chunk-PIIXU2H3.js";
|
|
4
|
-
import {
|
|
5
|
-
buildEmbedCode,
|
|
6
|
-
buildLiveIframe,
|
|
7
|
-
buildLiveUrl,
|
|
8
|
-
resolvePreset
|
|
9
|
-
} from "./chunk-YTYCHRQ2.js";
|
|
10
|
-
import {
|
|
11
|
-
MorphAPIClient
|
|
12
|
-
} from "./chunk-FUYX2MNM.js";
|
|
13
|
-
import {
|
|
14
|
-
logger
|
|
15
|
-
} from "./chunk-F3NCFNUX.js";
|
|
16
|
-
import {
|
|
17
|
-
fetchWithRetry,
|
|
18
|
-
withTimeout
|
|
19
|
-
} from "./chunk-FESO6TDQ.js";
|
|
20
|
-
import {
|
|
21
|
-
APIResource
|
|
22
|
-
} from "./chunk-5TOJD2C5.js";
|
|
23
|
-
|
|
24
|
-
// tools/browser/core.ts
|
|
25
|
-
var DEFAULT_CONFIG = {
|
|
26
|
-
apiUrl: process.env.MORPH_ENVIRONMENT === "DEV" ? "http://localhost:8000" : "https://browser.morphllm.com",
|
|
27
|
-
timeout: 1e6,
|
|
28
|
-
// 10 minutes for complex tasks
|
|
29
|
-
debug: false
|
|
30
|
-
};
|
|
31
|
-
var BrowserClient = class extends APIResource {
|
|
32
|
-
config;
|
|
33
|
-
/**
|
|
34
|
-
* Profile management - create and manage browser profiles for storing login state.
|
|
35
|
-
*/
|
|
36
|
-
profiles;
|
|
37
|
-
constructor(clientOrConfig = {}) {
|
|
38
|
-
const isClient = clientOrConfig instanceof MorphAPIClient;
|
|
39
|
-
super(
|
|
40
|
-
isClient ? clientOrConfig : new MorphAPIClient({
|
|
41
|
-
apiKey: clientOrConfig.apiKey,
|
|
42
|
-
browserURL: clientOrConfig.apiUrl,
|
|
43
|
-
timeout: clientOrConfig.timeout,
|
|
44
|
-
retryConfig: clientOrConfig.retryConfig,
|
|
45
|
-
debug: clientOrConfig.debug
|
|
46
|
-
})
|
|
47
|
-
);
|
|
48
|
-
this.config = isClient ? {
|
|
49
|
-
...DEFAULT_CONFIG,
|
|
50
|
-
apiUrl: clientOrConfig.browserURL,
|
|
51
|
-
apiKey: clientOrConfig.resolveApiKey(),
|
|
52
|
-
retryConfig: clientOrConfig.retryConfig,
|
|
53
|
-
debug: clientOrConfig.debug
|
|
54
|
-
} : { ...DEFAULT_CONFIG, ...clientOrConfig };
|
|
55
|
-
this.profiles = new ProfilesClient(this.config);
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Execute a browser automation task
|
|
59
|
-
*/
|
|
60
|
-
async execute(input) {
|
|
61
|
-
return executeBrowserTask(input, this.config);
|
|
62
|
-
}
|
|
63
|
-
async createTask(input) {
|
|
64
|
-
const apiUrl = this.config.apiUrl || DEFAULT_CONFIG.apiUrl;
|
|
65
|
-
const debug = this.config.debug || false;
|
|
66
|
-
const hasTask = typeof input.task === "string" && input.task.trim().length > 0;
|
|
67
|
-
const hasDiff = typeof input.diff === "string" && input.diff.trim().length > 0;
|
|
68
|
-
if (!hasTask && !hasDiff) {
|
|
69
|
-
throw new Error('Browser task requires either "task" (natural language) or "diff" (PR-review planning)');
|
|
70
|
-
}
|
|
71
|
-
logger.debug("Browser", "create_task", { task: (input.task ?? "").slice(0, 100), url: input.url, endpoint: `${apiUrl}/browser-task/async` });
|
|
72
|
-
const headers = { "Content-Type": "application/json" };
|
|
73
|
-
if (this.config.apiKey) headers["Authorization"] = `Bearer ${this.config.apiKey}`;
|
|
74
|
-
const response = await fetch(`${apiUrl}/browser-task/async`, {
|
|
75
|
-
method: "POST",
|
|
76
|
-
headers,
|
|
77
|
-
body: JSON.stringify({
|
|
78
|
-
task: input.task,
|
|
79
|
-
diff: input.diff,
|
|
80
|
-
url: input.url,
|
|
81
|
-
max_steps: input.maxSteps ?? 10,
|
|
82
|
-
model: input.model ?? "morph-computer-use-v0",
|
|
83
|
-
viewport_width: input.viewportWidth ?? 1280,
|
|
84
|
-
viewport_height: input.viewportHeight ?? 720,
|
|
85
|
-
external_id: input.externalId,
|
|
86
|
-
repo_id: input.repoId,
|
|
87
|
-
repo_full_name: input.repoFullName,
|
|
88
|
-
commit_id: input.commitId,
|
|
89
|
-
record_video: input.recordVideo ?? false,
|
|
90
|
-
video_width: input.videoWidth ?? input.viewportWidth ?? 1280,
|
|
91
|
-
video_height: input.videoHeight ?? input.viewportHeight ?? 720,
|
|
92
|
-
allow_resizing: input.allowResizing ?? false,
|
|
93
|
-
structured_output: "schema" in input ? stringifyStructuredOutput(input.schema) : void 0,
|
|
94
|
-
auth: input.auth,
|
|
95
|
-
profile_id: input.profileId,
|
|
96
|
-
force_query_params: input.forceQueryParams
|
|
97
|
-
})
|
|
98
|
-
});
|
|
99
|
-
if (!response.ok) {
|
|
100
|
-
const errorText = await response.text().catch(() => response.statusText);
|
|
101
|
-
logger.error("Browser", "create_task_error", { status: response.status, error: errorText });
|
|
102
|
-
throw new Error(`HTTP ${response.status}: ${errorText}`);
|
|
103
|
-
}
|
|
104
|
-
const result = mapTaskResult(await response.json());
|
|
105
|
-
logger.debug("Browser", "task_created", { recording_id: result.recordingId, task_id: result.taskId, debug_url: !!result.debugUrl });
|
|
106
|
-
if ("schema" in input) {
|
|
107
|
-
return wrapTaskResponseWithSchema(result, this.config, input.schema);
|
|
108
|
-
} else {
|
|
109
|
-
return wrapTaskResponse(result, this.config);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Execute task with recording and wait for video to be ready
|
|
114
|
-
*/
|
|
115
|
-
async executeWithRecording(input) {
|
|
116
|
-
return executeWithRecording(input, this.config);
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* Get recording status and URLs
|
|
120
|
-
*/
|
|
121
|
-
async getRecording(recordingId) {
|
|
122
|
-
return getRecording(recordingId, this.config);
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Wait for recording to complete with automatic polling
|
|
126
|
-
*/
|
|
127
|
-
async waitForRecording(recordingId, options) {
|
|
128
|
-
return waitForRecording(recordingId, this.config, options);
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* Get errors from recording with screenshots
|
|
132
|
-
*/
|
|
133
|
-
async getErrors(recordingId) {
|
|
134
|
-
return getErrors(recordingId, this.config);
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* Get animated WebP preview of recording
|
|
138
|
-
*/
|
|
139
|
-
async getWebp(recordingId, options) {
|
|
140
|
-
return getWebp(recordingId, this.config, options);
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* Check if browser worker service is healthy
|
|
144
|
-
*/
|
|
145
|
-
async checkHealth() {
|
|
146
|
-
return checkHealth(this.config);
|
|
147
|
-
}
|
|
148
|
-
};
|
|
149
|
-
async function executeBrowserTask(input, config = {}) {
|
|
150
|
-
const apiUrl = config.apiUrl || DEFAULT_CONFIG.apiUrl;
|
|
151
|
-
const timeout = config.timeout || DEFAULT_CONFIG.timeout;
|
|
152
|
-
const debug = config.debug || false;
|
|
153
|
-
if (!input.task || input.task.trim().length === 0) {
|
|
154
|
-
return {
|
|
155
|
-
success: false,
|
|
156
|
-
error: 'Task description is required. Example: "Go to example.com and click the login button"'
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
if (input.maxSteps !== void 0 && (input.maxSteps < 1 || input.maxSteps > 50)) {
|
|
160
|
-
return {
|
|
161
|
-
success: false,
|
|
162
|
-
error: "maxSteps must be between 1 and 50. Use more steps for complex multi-page flows."
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
logger.debug("Browser", "execute_start", { task: input.task.slice(0, 100), url: input.url, max_steps: input.maxSteps ?? 10, record_video: input.recordVideo ?? false });
|
|
166
|
-
const startTime = Date.now();
|
|
167
|
-
try {
|
|
168
|
-
const headers = { "Content-Type": "application/json" };
|
|
169
|
-
if (config.apiKey) headers["Authorization"] = `Bearer ${config.apiKey}`;
|
|
170
|
-
const fetchPromise = fetchWithRetry(
|
|
171
|
-
`${apiUrl}/browser-task`,
|
|
172
|
-
{
|
|
173
|
-
method: "POST",
|
|
174
|
-
headers,
|
|
175
|
-
body: JSON.stringify({
|
|
176
|
-
task: input.task,
|
|
177
|
-
url: input.url,
|
|
178
|
-
max_steps: input.maxSteps ?? 10,
|
|
179
|
-
model: input.model ?? "morph-computer-use-v0",
|
|
180
|
-
viewport_width: input.viewportWidth ?? 1280,
|
|
181
|
-
viewport_height: input.viewportHeight ?? 720,
|
|
182
|
-
external_id: input.externalId,
|
|
183
|
-
repo_id: input.repoId,
|
|
184
|
-
commit_id: input.commitId,
|
|
185
|
-
record_video: input.recordVideo ?? false,
|
|
186
|
-
video_width: input.videoWidth ?? input.viewportWidth ?? 1280,
|
|
187
|
-
video_height: input.videoHeight ?? input.viewportHeight ?? 720,
|
|
188
|
-
allow_resizing: input.allowResizing ?? false,
|
|
189
|
-
structured_output: input.structuredOutput,
|
|
190
|
-
auth: input.auth,
|
|
191
|
-
profile_id: input.profileId,
|
|
192
|
-
force_query_params: input.forceQueryParams
|
|
193
|
-
})
|
|
194
|
-
},
|
|
195
|
-
config.retryConfig
|
|
196
|
-
);
|
|
197
|
-
const response = await withTimeout(
|
|
198
|
-
fetchPromise,
|
|
199
|
-
timeout,
|
|
200
|
-
`Browser task timed out after ${timeout}ms. Consider increasing timeout or reducing maxSteps.`
|
|
201
|
-
);
|
|
202
|
-
if (!response.ok) {
|
|
203
|
-
const errorText = await response.text().catch(() => response.statusText);
|
|
204
|
-
logger.error("Browser", "execute_error", { status: response.status, error: errorText });
|
|
205
|
-
throw new Error(`HTTP ${response.status}: ${errorText}`);
|
|
206
|
-
}
|
|
207
|
-
const result = mapTaskResult(await response.json());
|
|
208
|
-
const elapsed = Date.now() - startTime;
|
|
209
|
-
logger.debug("Browser", "execute_complete", { success: result.success, latency_ms: elapsed, steps: result.stepsTaken ?? 0, recording_id: result.recordingId });
|
|
210
|
-
return result;
|
|
211
|
-
} catch (error) {
|
|
212
|
-
if (error instanceof Error) {
|
|
213
|
-
if (error.message.includes("ECONNREFUSED") || error.message.includes("fetch failed")) {
|
|
214
|
-
return {
|
|
215
|
-
success: false,
|
|
216
|
-
error: `Cannot connect to browser worker at ${apiUrl}. Ensure the service is running and accessible. For local dev, set MORPH_ENVIRONMENT=DEV.`
|
|
217
|
-
};
|
|
218
|
-
}
|
|
219
|
-
return {
|
|
220
|
-
success: false,
|
|
221
|
-
error: error.message
|
|
222
|
-
};
|
|
223
|
-
}
|
|
224
|
-
return {
|
|
225
|
-
success: false,
|
|
226
|
-
error: String(error)
|
|
227
|
-
};
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
async function getRecording(recordingId, config = {}) {
|
|
231
|
-
const apiUrl = config.apiUrl || DEFAULT_CONFIG.apiUrl;
|
|
232
|
-
const debug = config.debug || false;
|
|
233
|
-
if (!config.apiKey) {
|
|
234
|
-
throw new Error("API key required for getRecording");
|
|
235
|
-
}
|
|
236
|
-
if (debug) console.log(`[Browser] getRecording: ${recordingId}`);
|
|
237
|
-
const response = await fetch(`${apiUrl}/recordings/${recordingId}`, {
|
|
238
|
-
method: "GET",
|
|
239
|
-
headers: { "Authorization": `Bearer ${config.apiKey}` }
|
|
240
|
-
});
|
|
241
|
-
if (!response.ok) {
|
|
242
|
-
const errorText = await response.text().catch(() => response.statusText);
|
|
243
|
-
if (debug) console.error(`[Browser] getRecording error: ${response.status} - ${errorText}`);
|
|
244
|
-
throw new Error(`HTTP ${response.status}: ${errorText}`);
|
|
245
|
-
}
|
|
246
|
-
const data = mapRecordingStatus(await response.json());
|
|
247
|
-
if (debug) console.log(`[Browser] Recording status: ${data.status}`);
|
|
248
|
-
return {
|
|
249
|
-
...data,
|
|
250
|
-
getWebp: (options) => getWebp(recordingId, config, options),
|
|
251
|
-
getErrors: () => getErrors(recordingId, config)
|
|
252
|
-
};
|
|
253
|
-
}
|
|
254
|
-
async function waitForRecording(recordingId, config = {}, options = {}) {
|
|
255
|
-
const timeout = options.timeout ?? 6e4;
|
|
256
|
-
const pollInterval = options.pollInterval ?? 2e3;
|
|
257
|
-
const startTime = Date.now();
|
|
258
|
-
while (Date.now() - startTime < timeout) {
|
|
259
|
-
const status = await getRecording(recordingId, config);
|
|
260
|
-
if (status.status === "COMPLETED" || status.status === "ERROR") {
|
|
261
|
-
return status;
|
|
262
|
-
}
|
|
263
|
-
await new Promise((resolve) => setTimeout(resolve, pollInterval));
|
|
264
|
-
}
|
|
265
|
-
throw new Error(`Recording timeout after ${timeout}ms - status still pending`);
|
|
266
|
-
}
|
|
267
|
-
async function executeWithRecording(input, config = {}) {
|
|
268
|
-
const taskResult = await executeBrowserTask(input, config);
|
|
269
|
-
if (taskResult.recordingId) {
|
|
270
|
-
try {
|
|
271
|
-
const recording = await waitForRecording(
|
|
272
|
-
taskResult.recordingId,
|
|
273
|
-
config,
|
|
274
|
-
{ timeout: 6e4, pollInterval: 2e3 }
|
|
275
|
-
);
|
|
276
|
-
return {
|
|
277
|
-
...taskResult,
|
|
278
|
-
recording
|
|
279
|
-
};
|
|
280
|
-
} catch (error) {
|
|
281
|
-
const errorRecording = {
|
|
282
|
-
id: taskResult.recordingId,
|
|
283
|
-
status: "ERROR",
|
|
284
|
-
error: error instanceof Error ? error.message : String(error),
|
|
285
|
-
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
286
|
-
getWebp: (options) => getWebp(taskResult.recordingId, config, options),
|
|
287
|
-
getErrors: () => getErrors(taskResult.recordingId, config)
|
|
288
|
-
};
|
|
289
|
-
return {
|
|
290
|
-
...taskResult,
|
|
291
|
-
recording: errorRecording
|
|
292
|
-
};
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
return taskResult;
|
|
296
|
-
}
|
|
297
|
-
async function getErrors(recordingId, config = {}) {
|
|
298
|
-
const apiUrl = config.apiUrl || DEFAULT_CONFIG.apiUrl;
|
|
299
|
-
const debug = config.debug || false;
|
|
300
|
-
if (!config.apiKey) {
|
|
301
|
-
throw new Error("API key required for getErrors");
|
|
302
|
-
}
|
|
303
|
-
if (debug) console.log(`[Browser] getErrors: ${recordingId}`);
|
|
304
|
-
const response = await fetch(`${apiUrl}/recordings/${recordingId}/errors`, {
|
|
305
|
-
method: "GET",
|
|
306
|
-
headers: { "Authorization": `Bearer ${config.apiKey}` }
|
|
307
|
-
});
|
|
308
|
-
if (!response.ok) {
|
|
309
|
-
const errorText = await response.text().catch(() => response.statusText);
|
|
310
|
-
if (debug) console.error(`[Browser] getErrors error: ${response.status} - ${errorText}`);
|
|
311
|
-
throw new Error(`HTTP ${response.status}: ${errorText}`);
|
|
312
|
-
}
|
|
313
|
-
const errors = mapErrorsResponse(await response.json());
|
|
314
|
-
if (debug) console.log(`[Browser] Found ${errors.totalErrors} errors`);
|
|
315
|
-
return errors;
|
|
316
|
-
}
|
|
317
|
-
function stringifyStructuredOutput(schema) {
|
|
318
|
-
try {
|
|
319
|
-
return JSON.stringify({
|
|
320
|
-
type: "object",
|
|
321
|
-
description: "Zod schema definition (Zod v3)",
|
|
322
|
-
zodDef: schema._def
|
|
323
|
-
});
|
|
324
|
-
} catch (error) {
|
|
325
|
-
console.warn("[Browser] Failed to serialize Zod schema:", error);
|
|
326
|
-
return JSON.stringify({
|
|
327
|
-
type: "object",
|
|
328
|
-
description: "Schema serialization failed"
|
|
329
|
-
});
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
function parseStructuredTaskOutput(result, schema) {
|
|
333
|
-
if (!result.output) {
|
|
334
|
-
return { ...result, parsed: null };
|
|
335
|
-
}
|
|
336
|
-
try {
|
|
337
|
-
const parsed = JSON.parse(result.output);
|
|
338
|
-
const validated = schema.parse(parsed);
|
|
339
|
-
return { ...result, parsed: validated };
|
|
340
|
-
} catch (error) {
|
|
341
|
-
if (error instanceof SyntaxError) {
|
|
342
|
-
return { ...result, parsed: null };
|
|
343
|
-
}
|
|
344
|
-
throw error;
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
function mapTaskResult(api) {
|
|
348
|
-
if (!api || typeof api !== "object") {
|
|
349
|
-
return api;
|
|
350
|
-
}
|
|
351
|
-
return {
|
|
352
|
-
success: api.success,
|
|
353
|
-
result: api.result,
|
|
354
|
-
error: api.error,
|
|
355
|
-
stepsTaken: api.steps_taken,
|
|
356
|
-
executionTimeMs: api.execution_time_ms,
|
|
357
|
-
urls: api.urls,
|
|
358
|
-
actionNames: api.action_names,
|
|
359
|
-
errors: api.errors,
|
|
360
|
-
modelActions: api.model_actions,
|
|
361
|
-
isDone: api.is_done,
|
|
362
|
-
actionHistory: api.action_history,
|
|
363
|
-
actionResults: api.action_results,
|
|
364
|
-
hasErrors: api.has_errors,
|
|
365
|
-
numberOfSteps: api.number_of_steps,
|
|
366
|
-
judgement: api.judgement,
|
|
367
|
-
isValidated: api.is_validated,
|
|
368
|
-
replayId: api.replay_id,
|
|
369
|
-
replayUrl: api.replay_url,
|
|
370
|
-
recordingId: api.recording_id,
|
|
371
|
-
recordingStatus: api.recording_status,
|
|
372
|
-
taskId: api.task_id,
|
|
373
|
-
status: api.status,
|
|
374
|
-
output: api.output,
|
|
375
|
-
debugUrl: api.debug_url
|
|
376
|
-
};
|
|
377
|
-
}
|
|
378
|
-
function mapRecordingStatus(api) {
|
|
379
|
-
return {
|
|
380
|
-
id: api.id,
|
|
381
|
-
status: api.status,
|
|
382
|
-
replayUrl: api.replay_url,
|
|
383
|
-
networkUrl: api.network_url,
|
|
384
|
-
consoleUrl: api.console_url,
|
|
385
|
-
videoUrl: api.video_url,
|
|
386
|
-
result: api.result,
|
|
387
|
-
totalEvents: api.total_events,
|
|
388
|
-
fileSize: api.file_size,
|
|
389
|
-
duration: api.duration,
|
|
390
|
-
error: api.error,
|
|
391
|
-
createdAt: api.created_at
|
|
392
|
-
};
|
|
393
|
-
}
|
|
394
|
-
function mapBrowserError(api) {
|
|
395
|
-
return {
|
|
396
|
-
type: api.type,
|
|
397
|
-
message: api.message,
|
|
398
|
-
url: api.url,
|
|
399
|
-
timestamp: api.timestamp,
|
|
400
|
-
screenshotUrl: api.screenshot_url,
|
|
401
|
-
capturedAt: api.captured_at,
|
|
402
|
-
status: api.status
|
|
403
|
-
};
|
|
404
|
-
}
|
|
405
|
-
function mapErrorsResponse(api) {
|
|
406
|
-
return {
|
|
407
|
-
recordingId: api.recording_id,
|
|
408
|
-
totalErrors: api.total_errors,
|
|
409
|
-
errors: Array.isArray(api.errors) ? api.errors.map(mapBrowserError) : []
|
|
410
|
-
};
|
|
411
|
-
}
|
|
412
|
-
function mapWebpResponse(api) {
|
|
413
|
-
return {
|
|
414
|
-
webpUrl: api.webp_url,
|
|
415
|
-
cached: api.cached,
|
|
416
|
-
width: api.width,
|
|
417
|
-
fps: api.fps,
|
|
418
|
-
maxDuration: api.max_duration,
|
|
419
|
-
fileSize: api.file_size,
|
|
420
|
-
maxSizeMb: api.max_size_mb,
|
|
421
|
-
budgetMet: api.budget_met,
|
|
422
|
-
qualityUsed: api.quality_used,
|
|
423
|
-
attempts: api.attempts
|
|
424
|
-
};
|
|
425
|
-
}
|
|
426
|
-
async function getTaskStatus(taskId, config) {
|
|
427
|
-
const apiUrl = config.apiUrl || DEFAULT_CONFIG.apiUrl;
|
|
428
|
-
const debug = config.debug || false;
|
|
429
|
-
if (debug) console.log(`[Browser] getTaskStatus: ${taskId}`);
|
|
430
|
-
const headers = {};
|
|
431
|
-
if (config.apiKey) headers["Authorization"] = `Bearer ${config.apiKey}`;
|
|
432
|
-
const response = await fetch(`${apiUrl}/tasks/${taskId}`, {
|
|
433
|
-
method: "GET",
|
|
434
|
-
headers
|
|
435
|
-
});
|
|
436
|
-
if (!response.ok) {
|
|
437
|
-
const errorText = await response.text().catch(() => response.statusText);
|
|
438
|
-
if (debug) console.error(`[Browser] getTaskStatus error: ${response.status} - ${errorText}`);
|
|
439
|
-
throw new Error(`HTTP ${response.status}: ${errorText}`);
|
|
440
|
-
}
|
|
441
|
-
const result = mapTaskResult(await response.json());
|
|
442
|
-
if (debug) console.log(`[Browser] Task status: ${result.status}`);
|
|
443
|
-
return result;
|
|
444
|
-
}
|
|
445
|
-
function generateLiveUrl(taskId, config) {
|
|
446
|
-
const apiUrl = config.apiUrl || DEFAULT_CONFIG.apiUrl;
|
|
447
|
-
const baseUrl = apiUrl.replace("/api", "");
|
|
448
|
-
return `${baseUrl}/tasks/${taskId}/live`;
|
|
449
|
-
}
|
|
450
|
-
async function pollTaskUntilComplete(taskId, config, pollConfig = {}) {
|
|
451
|
-
const interval = pollConfig.interval ?? 2e3;
|
|
452
|
-
const timeout = pollConfig.timeout ?? 3e5;
|
|
453
|
-
const startTime = Date.now();
|
|
454
|
-
while (Date.now() - startTime < timeout) {
|
|
455
|
-
const status = await getTaskStatus(taskId, config);
|
|
456
|
-
if (status.status === "completed" || status.status === "failed") {
|
|
457
|
-
return status;
|
|
458
|
-
}
|
|
459
|
-
await new Promise((resolve) => setTimeout(resolve, interval));
|
|
460
|
-
}
|
|
461
|
-
throw new Error(`Task polling timeout after ${timeout}ms`);
|
|
462
|
-
}
|
|
463
|
-
function wrapTaskResponse(result, config) {
|
|
464
|
-
const debugUrl = result.debugUrl ?? "";
|
|
465
|
-
const wrapped = {
|
|
466
|
-
...result,
|
|
467
|
-
debugUrl,
|
|
468
|
-
taskId: result.taskId || "",
|
|
469
|
-
liveUrl: result.taskId ? generateLiveUrl(result.taskId, config) : debugUrl,
|
|
470
|
-
complete: async (pollConfig) => {
|
|
471
|
-
if (result.taskId) {
|
|
472
|
-
return pollTaskUntilComplete(result.taskId, config, pollConfig);
|
|
473
|
-
}
|
|
474
|
-
if (result.recordingId) {
|
|
475
|
-
const recording = await waitForRecording(
|
|
476
|
-
result.recordingId,
|
|
477
|
-
config,
|
|
478
|
-
pollConfig
|
|
479
|
-
);
|
|
480
|
-
return {
|
|
481
|
-
...result,
|
|
482
|
-
recordingStatus: recording.status
|
|
483
|
-
};
|
|
484
|
-
}
|
|
485
|
-
throw new Error("Cannot poll completion: no taskId or recordingId available");
|
|
486
|
-
},
|
|
487
|
-
// Add Steel live session helpers - either functional or error-throwing
|
|
488
|
-
getLiveUrl: debugUrl ? (options) => buildLiveUrl(debugUrl, options) : () => {
|
|
489
|
-
throw new Error(
|
|
490
|
-
"Live sessions not available. Your backend must return a debugUrl in the response. Contact support@morphllm.com if you need help."
|
|
491
|
-
);
|
|
492
|
-
},
|
|
493
|
-
getLiveIframe: debugUrl ? (optionsOrPreset) => {
|
|
494
|
-
const options = resolvePreset(optionsOrPreset);
|
|
495
|
-
return buildLiveIframe(debugUrl, options);
|
|
496
|
-
} : () => {
|
|
497
|
-
throw new Error(
|
|
498
|
-
"Live sessions not available. Your backend must return a debugUrl in the response. Contact support@morphllm.com if you need help."
|
|
499
|
-
);
|
|
500
|
-
},
|
|
501
|
-
getEmbedCode: debugUrl ? () => buildEmbedCode(debugUrl) : () => {
|
|
502
|
-
throw new Error(
|
|
503
|
-
"Live sessions not available. Your backend must return a debugUrl in the response. Contact support@morphllm.com if you need help."
|
|
504
|
-
);
|
|
505
|
-
}
|
|
506
|
-
};
|
|
507
|
-
return wrapped;
|
|
508
|
-
}
|
|
509
|
-
function wrapTaskResponseWithSchema(result, config, schema) {
|
|
510
|
-
const debugUrl = result.debugUrl ?? "";
|
|
511
|
-
const parsed = result.output ? parseStructuredTaskOutput(result, schema) : { ...result, parsed: null };
|
|
512
|
-
const wrapped = {
|
|
513
|
-
...parsed,
|
|
514
|
-
debugUrl,
|
|
515
|
-
taskId: result.taskId || "",
|
|
516
|
-
liveUrl: result.taskId ? generateLiveUrl(result.taskId, config) : debugUrl,
|
|
517
|
-
complete: async (pollConfig) => {
|
|
518
|
-
if (result.taskId) {
|
|
519
|
-
const finalResult = await pollTaskUntilComplete(result.taskId, config, pollConfig);
|
|
520
|
-
return parseStructuredTaskOutput(finalResult, schema);
|
|
521
|
-
}
|
|
522
|
-
if (result.recordingId) {
|
|
523
|
-
const recording = await waitForRecording(
|
|
524
|
-
result.recordingId,
|
|
525
|
-
config,
|
|
526
|
-
pollConfig
|
|
527
|
-
);
|
|
528
|
-
return {
|
|
529
|
-
...parsed,
|
|
530
|
-
recordingStatus: recording.status
|
|
531
|
-
};
|
|
532
|
-
}
|
|
533
|
-
throw new Error("Cannot poll completion: no taskId or recordingId available");
|
|
534
|
-
},
|
|
535
|
-
// Add Steel live session helpers - either functional or error-throwing
|
|
536
|
-
getLiveUrl: debugUrl ? (options) => buildLiveUrl(debugUrl, options) : () => {
|
|
537
|
-
throw new Error(
|
|
538
|
-
"Live sessions not available. Your backend must return a debugUrl in the response. Contact support@morphllm.com if you need help enabling live sessions. "
|
|
539
|
-
);
|
|
540
|
-
},
|
|
541
|
-
getLiveIframe: debugUrl ? (optionsOrPreset) => {
|
|
542
|
-
const options = resolvePreset(optionsOrPreset);
|
|
543
|
-
return buildLiveIframe(debugUrl, options);
|
|
544
|
-
} : () => {
|
|
545
|
-
throw new Error(
|
|
546
|
-
"Live sessions not available. Your backend must return a debugUrl in the response. Contact support@morphllm.com if you need help enabling live sessions."
|
|
547
|
-
);
|
|
548
|
-
},
|
|
549
|
-
getEmbedCode: debugUrl ? () => buildEmbedCode(debugUrl) : () => {
|
|
550
|
-
throw new Error(
|
|
551
|
-
"Live sessions not available. Your backend must return a debugUrl in the response. Contact support@morphllm.com if you need help enabling live sessions."
|
|
552
|
-
);
|
|
553
|
-
}
|
|
554
|
-
};
|
|
555
|
-
return wrapped;
|
|
556
|
-
}
|
|
557
|
-
async function getWebp(recordingId, config = {}, options = {}) {
|
|
558
|
-
const apiUrl = config.apiUrl || DEFAULT_CONFIG.apiUrl;
|
|
559
|
-
const debug = config.debug || false;
|
|
560
|
-
if (!config.apiKey) {
|
|
561
|
-
throw new Error("API key required for getWebp");
|
|
562
|
-
}
|
|
563
|
-
const params = new URLSearchParams();
|
|
564
|
-
if (options.maxDuration !== void 0) params.set("max_duration", String(options.maxDuration));
|
|
565
|
-
if (options.fps !== void 0) params.set("fps", String(options.fps));
|
|
566
|
-
if (options.width !== void 0) params.set("width", String(options.width));
|
|
567
|
-
if (options.quality !== void 0) params.set("quality", String(options.quality));
|
|
568
|
-
if (options.maxSizeMb !== void 0) params.set("max_size_mb", String(options.maxSizeMb));
|
|
569
|
-
const url = `${apiUrl}/recordings/${recordingId}/webp${params.toString() ? "?" + params.toString() : ""}`;
|
|
570
|
-
if (debug) console.log(`[Browser] getWebp: ${url}`);
|
|
571
|
-
const response = await fetch(url, {
|
|
572
|
-
method: "GET",
|
|
573
|
-
headers: { "Authorization": `Bearer ${config.apiKey}` }
|
|
574
|
-
});
|
|
575
|
-
if (!response.ok) {
|
|
576
|
-
const errorText = await response.text().catch(() => response.statusText);
|
|
577
|
-
if (debug) console.error(`[Browser] getWebp error: ${response.status} - ${errorText}`);
|
|
578
|
-
throw new Error(`HTTP ${response.status}: ${errorText}`);
|
|
579
|
-
}
|
|
580
|
-
const result = mapWebpResponse(await response.json());
|
|
581
|
-
if (debug) console.log(`[Browser] WebP ready: ${result.webpUrl} (cached: ${result.cached})`);
|
|
582
|
-
return result;
|
|
583
|
-
}
|
|
584
|
-
async function checkHealth(config = {}) {
|
|
585
|
-
const apiUrl = config.apiUrl || DEFAULT_CONFIG.apiUrl;
|
|
586
|
-
try {
|
|
587
|
-
const response = await fetch(`${apiUrl}/health`, {
|
|
588
|
-
method: "GET",
|
|
589
|
-
headers: config.apiKey ? { "Authorization": `Bearer ${config.apiKey}` } : {}
|
|
590
|
-
});
|
|
591
|
-
if (!response.ok) {
|
|
592
|
-
throw new Error(`HTTP ${response.status}`);
|
|
593
|
-
}
|
|
594
|
-
const data = await response.json();
|
|
595
|
-
return {
|
|
596
|
-
ok: true,
|
|
597
|
-
google_configured: data.google_configured ?? false,
|
|
598
|
-
database_configured: data.database_configured ?? false,
|
|
599
|
-
s3_configured: data.s3_configured ?? false
|
|
600
|
-
};
|
|
601
|
-
} catch (error) {
|
|
602
|
-
return {
|
|
603
|
-
ok: false,
|
|
604
|
-
google_configured: false,
|
|
605
|
-
database_configured: false,
|
|
606
|
-
s3_configured: false,
|
|
607
|
-
error: error instanceof Error ? error.message : String(error)
|
|
608
|
-
};
|
|
609
|
-
}
|
|
610
|
-
}
|
|
611
|
-
|
|
612
|
-
export {
|
|
613
|
-
BrowserClient,
|
|
614
|
-
executeBrowserTask,
|
|
615
|
-
getRecording,
|
|
616
|
-
waitForRecording,
|
|
617
|
-
executeWithRecording,
|
|
618
|
-
getErrors,
|
|
619
|
-
getWebp,
|
|
620
|
-
checkHealth
|
|
621
|
-
};
|
|
622
|
-
//# sourceMappingURL=chunk-YD6TNDR4.js.map
|