@morphllm/morphsdk 0.2.93 → 0.2.95
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/dist/chunk-2AMEQAO2.js +46 -0
- package/dist/chunk-2AMEQAO2.js.map +1 -0
- package/dist/{chunk-EI4UKP24.js → chunk-2HMEZZKK.js} +2 -2
- package/dist/{chunk-EI4UKP24.js.map → chunk-2HMEZZKK.js.map} +1 -1
- package/dist/chunk-2VERUKO2.js +177 -0
- package/dist/chunk-2VERUKO2.js.map +1 -0
- package/dist/{chunk-VHOWYK66.js → chunk-43LQLGP6.js} +23 -33
- package/dist/chunk-43LQLGP6.js.map +1 -0
- package/dist/{chunk-LMUZ3NGC.js → chunk-73RV6EXR.js} +2 -2
- package/dist/{chunk-PBLPZ6AU.js → chunk-7D6TXC7X.js} +2 -2
- package/dist/{chunk-GU6DACME.js → chunk-O7LDZA52.js} +2 -2
- package/dist/{chunk-5QIWYEHJ.js → chunk-PE4KGDA6.js} +1 -8
- package/dist/chunk-PE4KGDA6.js.map +1 -0
- package/dist/{chunk-SQN4DUQS.js → chunk-Q6Y4R236.js} +26 -2
- package/dist/chunk-Q6Y4R236.js.map +1 -0
- package/dist/{chunk-PUGIOVSP.js → chunk-QAT5UVPX.js} +2 -2
- package/dist/{chunk-MIIJWDOQ.js → chunk-QJP62BXH.js} +166 -71
- package/dist/chunk-QJP62BXH.js.map +1 -0
- package/dist/{chunk-EYGBUH2R.js → chunk-R7IQWNSA.js} +8 -8
- package/dist/chunk-R7IQWNSA.js.map +1 -0
- package/dist/chunk-SI2CKRKJ.js +389 -0
- package/dist/chunk-SI2CKRKJ.js.map +1 -0
- package/dist/{chunk-4WLGDYWQ.js → chunk-TSENDJQI.js} +6 -6
- package/dist/chunk-TSENDJQI.js.map +1 -0
- package/dist/{chunk-IUG2FHNN.js → chunk-XH7P7HVT.js} +1 -8
- package/dist/chunk-XH7P7HVT.js.map +1 -0
- package/dist/{chunk-FNLNDMIX.js → chunk-YZ5NCWO2.js} +6 -6
- package/dist/chunk-YZ5NCWO2.js.map +1 -0
- package/dist/{chunk-IJ54DTJ3.js → chunk-ZYTAKEBW.js} +13 -13
- package/dist/client.cjs +770 -110
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.ts +2 -0
- package/dist/client.js +16 -13
- package/dist/index.cjs +770 -110
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +16 -13
- package/dist/tools/browser/anthropic.cjs +58 -23
- package/dist/tools/browser/anthropic.cjs.map +1 -1
- package/dist/tools/browser/anthropic.js +7 -4
- package/dist/tools/browser/core.cjs +750 -70
- package/dist/tools/browser/core.cjs.map +1 -1
- package/dist/tools/browser/core.d.ts +30 -24
- package/dist/tools/browser/core.js +5 -2
- package/dist/tools/browser/errors.cjs +208 -0
- package/dist/tools/browser/errors.cjs.map +1 -0
- package/dist/tools/browser/errors.d.ts +158 -0
- package/dist/tools/browser/errors.js +22 -0
- package/dist/tools/browser/errors.js.map +1 -0
- package/dist/tools/browser/index.cjs +783 -85
- package/dist/tools/browser/index.cjs.map +1 -1
- package/dist/tools/browser/index.d.ts +5 -2
- package/dist/tools/browser/index.js +32 -9
- package/dist/tools/browser/index.js.map +1 -1
- package/dist/tools/browser/live.cjs +25 -1
- package/dist/tools/browser/live.cjs.map +1 -1
- package/dist/tools/browser/live.js +1 -1
- package/dist/tools/browser/openai.cjs +58 -23
- package/dist/tools/browser/openai.cjs.map +1 -1
- package/dist/tools/browser/openai.js +7 -4
- package/dist/tools/browser/profiles/core.cjs +670 -0
- package/dist/tools/browser/profiles/core.cjs.map +1 -0
- package/dist/tools/browser/profiles/core.d.ts +187 -0
- package/dist/tools/browser/profiles/core.js +29 -0
- package/dist/tools/browser/profiles/core.js.map +1 -0
- package/dist/tools/browser/profiles/index.cjs +670 -0
- package/dist/tools/browser/profiles/index.cjs.map +1 -0
- package/dist/tools/browser/profiles/index.d.ts +4 -0
- package/dist/tools/browser/profiles/index.js +29 -0
- package/dist/tools/browser/profiles/index.js.map +1 -0
- package/dist/tools/browser/profiles/types.cjs +74 -0
- package/dist/tools/browser/profiles/types.cjs.map +1 -0
- package/dist/tools/browser/profiles/types.d.ts +195 -0
- package/dist/tools/browser/profiles/types.js +16 -0
- package/dist/tools/browser/profiles/types.js.map +1 -0
- package/dist/tools/browser/prompts.cjs +1 -1
- package/dist/tools/browser/prompts.cjs.map +1 -1
- package/dist/tools/browser/prompts.d.ts +1 -1
- package/dist/tools/browser/prompts.js +1 -1
- package/dist/tools/browser/types.cjs.map +1 -1
- package/dist/tools/browser/types.d.ts +55 -51
- package/dist/tools/browser/vercel.cjs +60 -25
- package/dist/tools/browser/vercel.cjs.map +1 -1
- package/dist/tools/browser/vercel.d.ts +1 -1
- package/dist/tools/browser/vercel.js +7 -4
- package/dist/tools/fastapply/anthropic.cjs +0 -7
- package/dist/tools/fastapply/anthropic.cjs.map +1 -1
- package/dist/tools/fastapply/anthropic.js +1 -1
- package/dist/tools/fastapply/index.cjs +0 -14
- package/dist/tools/fastapply/index.cjs.map +1 -1
- package/dist/tools/fastapply/index.js +5 -5
- package/dist/tools/fastapply/openai.cjs +0 -7
- package/dist/tools/fastapply/openai.cjs.map +1 -1
- package/dist/tools/fastapply/openai.js +1 -1
- package/dist/tools/index.cjs +0 -14
- package/dist/tools/index.cjs.map +1 -1
- package/dist/tools/index.js +5 -5
- package/dist/tools/warp_grep/agent/runner.cjs +18 -98
- package/dist/tools/warp_grep/agent/runner.cjs.map +1 -1
- package/dist/tools/warp_grep/agent/runner.js +2 -3
- package/dist/tools/warp_grep/anthropic.cjs +18 -98
- package/dist/tools/warp_grep/anthropic.cjs.map +1 -1
- package/dist/tools/warp_grep/anthropic.js +8 -9
- package/dist/tools/warp_grep/client.cjs +18 -98
- package/dist/tools/warp_grep/client.cjs.map +1 -1
- package/dist/tools/warp_grep/client.js +5 -6
- package/dist/tools/warp_grep/gemini.cjs +18 -98
- package/dist/tools/warp_grep/gemini.cjs.map +1 -1
- package/dist/tools/warp_grep/gemini.js +7 -8
- package/dist/tools/warp_grep/gemini.js.map +1 -1
- package/dist/tools/warp_grep/harness.js +10 -10
- package/dist/tools/warp_grep/index.cjs +18 -98
- package/dist/tools/warp_grep/index.cjs.map +1 -1
- package/dist/tools/warp_grep/index.js +8 -9
- package/dist/tools/warp_grep/openai.cjs +18 -98
- package/dist/tools/warp_grep/openai.cjs.map +1 -1
- package/dist/tools/warp_grep/openai.js +8 -9
- package/dist/tools/warp_grep/vercel.cjs +18 -98
- package/dist/tools/warp_grep/vercel.cjs.map +1 -1
- package/dist/tools/warp_grep/vercel.js +8 -9
- package/dist/{vercel-CsnNSdze.d.ts → vercel-CVF27qFK.d.ts} +10 -10
- package/package.json +7 -2
- package/dist/chunk-4WLGDYWQ.js.map +0 -1
- package/dist/chunk-5QIWYEHJ.js.map +0 -1
- package/dist/chunk-EYGBUH2R.js.map +0 -1
- package/dist/chunk-FNLNDMIX.js.map +0 -1
- package/dist/chunk-IUG2FHNN.js.map +0 -1
- package/dist/chunk-MIIJWDOQ.js.map +0 -1
- package/dist/chunk-SQN4DUQS.js.map +0 -1
- package/dist/chunk-VHOWYK66.js.map +0 -1
- /package/dist/{chunk-LMUZ3NGC.js.map → chunk-73RV6EXR.js.map} +0 -0
- /package/dist/{chunk-PBLPZ6AU.js.map → chunk-7D6TXC7X.js.map} +0 -0
- /package/dist/{chunk-GU6DACME.js.map → chunk-O7LDZA52.js.map} +0 -0
- /package/dist/{chunk-PUGIOVSP.js.map → chunk-QAT5UVPX.js.map} +0 -0
- /package/dist/{chunk-IJ54DTJ3.js.map → chunk-ZYTAKEBW.js.map} +0 -0
|
@@ -0,0 +1,389 @@
|
|
|
1
|
+
import {
|
|
2
|
+
transformCreateInput,
|
|
3
|
+
transformProfile,
|
|
4
|
+
transformSaveInput,
|
|
5
|
+
transformSession,
|
|
6
|
+
transformStateResponse
|
|
7
|
+
} from "./chunk-2AMEQAO2.js";
|
|
8
|
+
import {
|
|
9
|
+
MorphAuthenticationError,
|
|
10
|
+
MorphValidationError,
|
|
11
|
+
parseAPIError
|
|
12
|
+
} from "./chunk-2VERUKO2.js";
|
|
13
|
+
import {
|
|
14
|
+
fetchWithRetry
|
|
15
|
+
} from "./chunk-4VWJFZVS.js";
|
|
16
|
+
|
|
17
|
+
// tools/browser/profiles/core.ts
|
|
18
|
+
var DEFAULT_API_URL = process.env.MORPH_ENVIRONMENT === "DEV" ? "http://localhost:8000" : "https://browser.morphllm.com";
|
|
19
|
+
var ProfilesClient = class {
|
|
20
|
+
config;
|
|
21
|
+
constructor(config) {
|
|
22
|
+
this.config = config;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Create a new browser profile and immediately start a live session.
|
|
26
|
+
*
|
|
27
|
+
* @param input - Profile creation parameters
|
|
28
|
+
* @returns Profile setup handle with live URL + save()
|
|
29
|
+
* @throws {MorphValidationError} If input validation fails
|
|
30
|
+
* @throws {MorphProfileLimitError} If profile limit is exceeded
|
|
31
|
+
* @throws {MorphAuthenticationError} If API key is missing or invalid
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* const setup = await morph.browser.profiles.createProfile({
|
|
36
|
+
* name: 'LinkedIn Production',
|
|
37
|
+
* repoId: 'owner/repo'
|
|
38
|
+
* });
|
|
39
|
+
* console.log(setup.session.debugUrl);
|
|
40
|
+
* await setup.save();
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
async createProfile(input) {
|
|
44
|
+
return createProfile(input, this.config);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* List all profiles for the authenticated user.
|
|
48
|
+
*
|
|
49
|
+
* @param repoId - Optional repository ID to filter by
|
|
50
|
+
* @returns Array of profiles
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```typescript
|
|
54
|
+
* // List all profiles
|
|
55
|
+
* const allProfiles = await morph.browser.profiles.listProfiles();
|
|
56
|
+
*
|
|
57
|
+
* // List profiles for a specific repo
|
|
58
|
+
* const repoProfiles = await morph.browser.profiles.listProfiles('owner/repo');
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
async listProfiles(repoId) {
|
|
62
|
+
return listProfiles(this.config, repoId);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Get a profile by ID with convenience methods.
|
|
66
|
+
*
|
|
67
|
+
* @param id - Profile ID
|
|
68
|
+
* @returns Profile with attached methods
|
|
69
|
+
* @throws {MorphNotFoundError} If profile is not found
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```typescript
|
|
73
|
+
* const profile = await morph.browser.profiles.getProfile('profile-id');
|
|
74
|
+
* const state = await profile.getState();
|
|
75
|
+
* await profile.delete();
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
async getProfile(id) {
|
|
79
|
+
return getProfile(id, this.config);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Update a profile by opening a live session (no rename).
|
|
83
|
+
*
|
|
84
|
+
* @param id - Profile ID
|
|
85
|
+
* @returns Profile setup handle with live URL + save()
|
|
86
|
+
*/
|
|
87
|
+
async updateProfile(id) {
|
|
88
|
+
return updateProfile(id, this.config);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Delete a profile.
|
|
92
|
+
*
|
|
93
|
+
* @param id - Profile ID
|
|
94
|
+
* @throws {MorphNotFoundError} If profile is not found
|
|
95
|
+
*/
|
|
96
|
+
async deleteProfile(id) {
|
|
97
|
+
return deleteProfile(id, this.config);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Start a browser session for profile setup.
|
|
101
|
+
*
|
|
102
|
+
* Returns a live URL where the user can sign into accounts.
|
|
103
|
+
* After signing in, call `saveSession` to persist the state.
|
|
104
|
+
*
|
|
105
|
+
* @param input - Optional session parameters
|
|
106
|
+
* @returns Session with debug URL
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```typescript
|
|
110
|
+
* const session = await morph.browser.profiles.startSession();
|
|
111
|
+
* console.log('Sign in at:', session.debugUrl);
|
|
112
|
+
* // Open debugUrl in browser, user signs in...
|
|
113
|
+
* await morph.browser.profiles.saveSession(session.sessionId, profile.id);
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
async startSession(input) {
|
|
117
|
+
return startProfileSession(this.config, input);
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Save browser state from a session to a profile.
|
|
121
|
+
*
|
|
122
|
+
* Call this after the user is done signing into accounts.
|
|
123
|
+
* Extracts cookies, localStorage, and sessionStorage.
|
|
124
|
+
*
|
|
125
|
+
* @param sessionId - Browser session ID from startSession
|
|
126
|
+
* @param profileId - Profile ID to save state to
|
|
127
|
+
* @returns Updated profile with cookie domains
|
|
128
|
+
*/
|
|
129
|
+
async saveSession(sessionId, profileId) {
|
|
130
|
+
return saveProfileSession({ sessionId, profileId }, this.config);
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* List available repo IDs (discovery).
|
|
134
|
+
*
|
|
135
|
+
* @returns Repo summaries with profile counts
|
|
136
|
+
*/
|
|
137
|
+
async listRepos() {
|
|
138
|
+
return listRepos(this.config);
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Get the presigned URL for a profile's state.
|
|
142
|
+
*
|
|
143
|
+
* Use this to download the raw state JSON for debugging
|
|
144
|
+
* or to restore state manually.
|
|
145
|
+
*
|
|
146
|
+
* @param profileId - Profile ID
|
|
147
|
+
* @returns State URL with expiry information
|
|
148
|
+
*/
|
|
149
|
+
async getProfileState(profileId) {
|
|
150
|
+
return getProfileState(profileId, this.config);
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
function validateCreateInput(input) {
|
|
154
|
+
if (!input.name || typeof input.name !== "string") {
|
|
155
|
+
throw new MorphValidationError("name is required", "name");
|
|
156
|
+
}
|
|
157
|
+
const trimmedName = input.name.trim();
|
|
158
|
+
if (trimmedName.length === 0) {
|
|
159
|
+
throw new MorphValidationError("name cannot be empty", "name");
|
|
160
|
+
}
|
|
161
|
+
if (trimmedName.length > 100) {
|
|
162
|
+
throw new MorphValidationError("name must be 100 characters or less", "name");
|
|
163
|
+
}
|
|
164
|
+
if (!input.repoId || typeof input.repoId !== "string") {
|
|
165
|
+
throw new MorphValidationError("repoId is required", "repoId");
|
|
166
|
+
}
|
|
167
|
+
if (input.repoId.trim().length === 0) {
|
|
168
|
+
throw new MorphValidationError("repoId cannot be empty", "repoId");
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
function validateId(id, fieldName) {
|
|
172
|
+
if (!id || typeof id !== "string") {
|
|
173
|
+
throw new MorphValidationError(`${fieldName} is required`, fieldName);
|
|
174
|
+
}
|
|
175
|
+
if (id.trim().length === 0) {
|
|
176
|
+
throw new MorphValidationError(`${fieldName} cannot be empty`, fieldName);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
async function createProfile(input, config = {}) {
|
|
180
|
+
validateCreateInput(input);
|
|
181
|
+
const apiUrl = config.apiUrl || DEFAULT_API_URL;
|
|
182
|
+
const headers = buildHeaders(config);
|
|
183
|
+
const response = await fetchWithRetry(
|
|
184
|
+
`${apiUrl}/profiles`,
|
|
185
|
+
{
|
|
186
|
+
method: "POST",
|
|
187
|
+
headers,
|
|
188
|
+
body: JSON.stringify(transformCreateInput(input))
|
|
189
|
+
},
|
|
190
|
+
config.retryConfig
|
|
191
|
+
);
|
|
192
|
+
if (!response.ok) {
|
|
193
|
+
const errorText = await response.text().catch(() => response.statusText);
|
|
194
|
+
const requestId = response.headers.get("x-request-id") || void 0;
|
|
195
|
+
throw parseAPIError(response.status, errorText, requestId);
|
|
196
|
+
}
|
|
197
|
+
const apiProfile = await response.json();
|
|
198
|
+
const profile = transformProfile(apiProfile);
|
|
199
|
+
const session = await startProfileSession(config, { profileId: profile.id });
|
|
200
|
+
return buildProfileSetup(profile, session, config);
|
|
201
|
+
}
|
|
202
|
+
async function listProfiles(config = {}, repoId) {
|
|
203
|
+
const apiUrl = config.apiUrl || DEFAULT_API_URL;
|
|
204
|
+
const headers = buildHeaders(config);
|
|
205
|
+
const url = repoId ? `${apiUrl}/profiles?repo_id=${encodeURIComponent(repoId)}` : `${apiUrl}/profiles`;
|
|
206
|
+
const response = await fetchWithRetry(
|
|
207
|
+
url,
|
|
208
|
+
{ method: "GET", headers },
|
|
209
|
+
config.retryConfig
|
|
210
|
+
);
|
|
211
|
+
if (!response.ok) {
|
|
212
|
+
const errorText = await response.text().catch(() => response.statusText);
|
|
213
|
+
const requestId = response.headers.get("x-request-id") || void 0;
|
|
214
|
+
throw parseAPIError(response.status, errorText, requestId);
|
|
215
|
+
}
|
|
216
|
+
const data = await response.json();
|
|
217
|
+
return data.profiles.map(transformProfile);
|
|
218
|
+
}
|
|
219
|
+
async function getProfile(id, config = {}) {
|
|
220
|
+
validateId(id, "id");
|
|
221
|
+
const apiUrl = config.apiUrl || DEFAULT_API_URL;
|
|
222
|
+
const headers = buildHeaders(config);
|
|
223
|
+
const response = await fetchWithRetry(
|
|
224
|
+
`${apiUrl}/profiles/${encodeURIComponent(id)}`,
|
|
225
|
+
{ method: "GET", headers },
|
|
226
|
+
config.retryConfig
|
|
227
|
+
);
|
|
228
|
+
if (!response.ok) {
|
|
229
|
+
const errorText = await response.text().catch(() => response.statusText);
|
|
230
|
+
const requestId = response.headers.get("x-request-id") || void 0;
|
|
231
|
+
throw parseAPIError(response.status, errorText, requestId);
|
|
232
|
+
}
|
|
233
|
+
const apiProfile = await response.json();
|
|
234
|
+
const profile = transformProfile(apiProfile);
|
|
235
|
+
return {
|
|
236
|
+
...profile,
|
|
237
|
+
getState: () => getProfileState(id, config),
|
|
238
|
+
delete: () => deleteProfile(id, config)
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
async function updateProfile(id, config = {}) {
|
|
242
|
+
validateId(id, "id");
|
|
243
|
+
const profile = await fetchProfile(id, config);
|
|
244
|
+
const session = await startProfileSession(config, { profileId: profile.id });
|
|
245
|
+
return buildProfileSetup(profile, session, config);
|
|
246
|
+
}
|
|
247
|
+
async function deleteProfile(id, config = {}) {
|
|
248
|
+
validateId(id, "id");
|
|
249
|
+
const apiUrl = config.apiUrl || DEFAULT_API_URL;
|
|
250
|
+
const headers = buildHeaders(config);
|
|
251
|
+
const response = await fetchWithRetry(
|
|
252
|
+
`${apiUrl}/profiles/${encodeURIComponent(id)}`,
|
|
253
|
+
{ method: "DELETE", headers },
|
|
254
|
+
config.retryConfig
|
|
255
|
+
);
|
|
256
|
+
if (!response.ok) {
|
|
257
|
+
const errorText = await response.text().catch(() => response.statusText);
|
|
258
|
+
const requestId = response.headers.get("x-request-id") || void 0;
|
|
259
|
+
throw parseAPIError(response.status, errorText, requestId);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
async function startProfileSession(config = {}, input) {
|
|
263
|
+
if (!config.apiKey) {
|
|
264
|
+
throw new MorphAuthenticationError();
|
|
265
|
+
}
|
|
266
|
+
const apiUrl = config.apiUrl || DEFAULT_API_URL;
|
|
267
|
+
const headers = buildHeaders(config);
|
|
268
|
+
const body = input?.profileId ? { profile_id: input.profileId } : {};
|
|
269
|
+
const response = await fetchWithRetry(
|
|
270
|
+
`${apiUrl}/profiles/session/start`,
|
|
271
|
+
{
|
|
272
|
+
method: "POST",
|
|
273
|
+
headers,
|
|
274
|
+
body: JSON.stringify(body)
|
|
275
|
+
},
|
|
276
|
+
config.retryConfig
|
|
277
|
+
);
|
|
278
|
+
if (!response.ok) {
|
|
279
|
+
const errorText = await response.text().catch(() => response.statusText);
|
|
280
|
+
const requestId = response.headers.get("x-request-id") || void 0;
|
|
281
|
+
throw parseAPIError(response.status, errorText, requestId);
|
|
282
|
+
}
|
|
283
|
+
const apiSession = await response.json();
|
|
284
|
+
return transformSession(apiSession);
|
|
285
|
+
}
|
|
286
|
+
async function saveProfileSession(input, config = {}) {
|
|
287
|
+
validateId(input.sessionId, "sessionId");
|
|
288
|
+
validateId(input.profileId, "profileId");
|
|
289
|
+
const apiUrl = config.apiUrl || DEFAULT_API_URL;
|
|
290
|
+
const headers = buildHeaders(config);
|
|
291
|
+
const response = await fetchWithRetry(
|
|
292
|
+
`${apiUrl}/profiles/session/save`,
|
|
293
|
+
{
|
|
294
|
+
method: "POST",
|
|
295
|
+
headers,
|
|
296
|
+
body: JSON.stringify(transformSaveInput(input))
|
|
297
|
+
},
|
|
298
|
+
config.retryConfig
|
|
299
|
+
);
|
|
300
|
+
if (!response.ok) {
|
|
301
|
+
const errorText = await response.text().catch(() => response.statusText);
|
|
302
|
+
const requestId = response.headers.get("x-request-id") || void 0;
|
|
303
|
+
throw parseAPIError(response.status, errorText, requestId);
|
|
304
|
+
}
|
|
305
|
+
const apiProfile = await response.json();
|
|
306
|
+
return transformProfile(apiProfile);
|
|
307
|
+
}
|
|
308
|
+
async function listRepos(config = {}) {
|
|
309
|
+
const apiUrl = config.apiUrl || DEFAULT_API_URL;
|
|
310
|
+
const headers = buildHeaders(config);
|
|
311
|
+
const response = await fetchWithRetry(
|
|
312
|
+
`${apiUrl}/repos`,
|
|
313
|
+
{ method: "GET", headers },
|
|
314
|
+
config.retryConfig
|
|
315
|
+
);
|
|
316
|
+
if (!response.ok) {
|
|
317
|
+
const errorText = await response.text().catch(() => response.statusText);
|
|
318
|
+
const requestId = response.headers.get("x-request-id") || void 0;
|
|
319
|
+
throw parseAPIError(response.status, errorText, requestId);
|
|
320
|
+
}
|
|
321
|
+
const data = await response.json();
|
|
322
|
+
const repos = Array.isArray(data?.repos) ? data.repos : [];
|
|
323
|
+
return repos.map((repo) => ({
|
|
324
|
+
repoId: repo.repo_id,
|
|
325
|
+
repoFullName: repo.repo_full_name,
|
|
326
|
+
profileCount: repo.profile_count ?? 0
|
|
327
|
+
}));
|
|
328
|
+
}
|
|
329
|
+
async function getProfileState(profileId, config = {}) {
|
|
330
|
+
validateId(profileId, "profileId");
|
|
331
|
+
const apiUrl = config.apiUrl || DEFAULT_API_URL;
|
|
332
|
+
const headers = buildHeaders(config);
|
|
333
|
+
const response = await fetchWithRetry(
|
|
334
|
+
`${apiUrl}/profiles/${encodeURIComponent(profileId)}/state`,
|
|
335
|
+
{ method: "GET", headers },
|
|
336
|
+
config.retryConfig
|
|
337
|
+
);
|
|
338
|
+
if (!response.ok) {
|
|
339
|
+
const errorText = await response.text().catch(() => response.statusText);
|
|
340
|
+
const requestId = response.headers.get("x-request-id") || void 0;
|
|
341
|
+
throw parseAPIError(response.status, errorText, requestId);
|
|
342
|
+
}
|
|
343
|
+
const apiState = await response.json();
|
|
344
|
+
return transformStateResponse(apiState);
|
|
345
|
+
}
|
|
346
|
+
function buildHeaders(config) {
|
|
347
|
+
const headers = { "Content-Type": "application/json" };
|
|
348
|
+
if (config.apiKey) {
|
|
349
|
+
headers["Authorization"] = `Bearer ${config.apiKey}`;
|
|
350
|
+
}
|
|
351
|
+
return headers;
|
|
352
|
+
}
|
|
353
|
+
async function fetchProfile(id, config) {
|
|
354
|
+
const apiUrl = config.apiUrl || DEFAULT_API_URL;
|
|
355
|
+
const headers = buildHeaders(config);
|
|
356
|
+
const response = await fetchWithRetry(
|
|
357
|
+
`${apiUrl}/profiles/${encodeURIComponent(id)}`,
|
|
358
|
+
{ method: "GET", headers },
|
|
359
|
+
config.retryConfig
|
|
360
|
+
);
|
|
361
|
+
if (!response.ok) {
|
|
362
|
+
const errorText = await response.text().catch(() => response.statusText);
|
|
363
|
+
const requestId = response.headers.get("x-request-id") || void 0;
|
|
364
|
+
throw parseAPIError(response.status, errorText, requestId);
|
|
365
|
+
}
|
|
366
|
+
const apiProfile = await response.json();
|
|
367
|
+
return transformProfile(apiProfile);
|
|
368
|
+
}
|
|
369
|
+
function buildProfileSetup(profile, session, config) {
|
|
370
|
+
return {
|
|
371
|
+
profile,
|
|
372
|
+
session,
|
|
373
|
+
save: () => saveProfileSession({ sessionId: session.sessionId, profileId: profile.id }, config)
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
export {
|
|
378
|
+
ProfilesClient,
|
|
379
|
+
createProfile,
|
|
380
|
+
listProfiles,
|
|
381
|
+
getProfile,
|
|
382
|
+
updateProfile,
|
|
383
|
+
deleteProfile,
|
|
384
|
+
startProfileSession,
|
|
385
|
+
saveProfileSession,
|
|
386
|
+
listRepos,
|
|
387
|
+
getProfileState
|
|
388
|
+
};
|
|
389
|
+
//# sourceMappingURL=chunk-SI2CKRKJ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../tools/browser/profiles/core.ts"],"sourcesContent":["/**\n * ProfilesClient - Manage browser profiles for storing login state.\n *\n * @example\n * ```typescript\n * const morph = new MorphClient({ apiKey: '...' });\n *\n * // Create a profile + live setup session\n * const setup = await morph.browser.profiles.createProfile({\n * name: 'LinkedIn',\n * repoId: 'owner/repo'\n * });\n *\n * console.log('Sign in at:', setup.session.debugUrl);\n * // User logs in, then explicitly save\n * await setup.save();\n *\n * // Use profile in browser tasks\n * await morph.browser.execute({\n * task: 'Check notifications',\n * url: 'https://linkedin.com',\n * profileId: profile.id\n * });\n * ```\n */\n\nimport { fetchWithRetry } from '../../utils/resilience.js';\nimport type { BrowserConfig } from '../types.js';\nimport {\n MorphValidationError,\n MorphAuthenticationError,\n parseAPIError,\n} from '../errors.js';\nimport type {\n Profile,\n ProfileSetup,\n ProfileWithMethods,\n CreateProfileInput,\n ProfileListResponse,\n ProfileSession,\n ProfileSessionInput,\n SaveProfileSessionInput,\n ProfileStateResponse,\n RepoSummary,\n RepoListResponse,\n APIProfile,\n APIProfileSession,\n APIProfileStateResponse,\n} from './types.js';\nimport {\n transformProfile,\n transformCreateInput,\n transformSession,\n transformSaveInput,\n transformStateResponse,\n} from './types.js';\n\nconst DEFAULT_API_URL = process.env.MORPH_ENVIRONMENT === 'DEV'\n ? 'http://localhost:8000'\n : 'https://browser.morphllm.com';\n\n/**\n * ProfilesClient class for managing browser profiles.\n *\n * Access via `morph.browser.profiles` on a MorphClient instance.\n */\nexport class ProfilesClient {\n private config: BrowserConfig;\n\n constructor(config: BrowserConfig) {\n this.config = config;\n }\n\n /**\n * Create a new browser profile and immediately start a live session.\n *\n * @param input - Profile creation parameters\n * @returns Profile setup handle with live URL + save()\n * @throws {MorphValidationError} If input validation fails\n * @throws {MorphProfileLimitError} If profile limit is exceeded\n * @throws {MorphAuthenticationError} If API key is missing or invalid\n *\n * @example\n * ```typescript\n * const setup = await morph.browser.profiles.createProfile({\n * name: 'LinkedIn Production',\n * repoId: 'owner/repo'\n * });\n * console.log(setup.session.debugUrl);\n * await setup.save();\n * ```\n */\n async createProfile(input: CreateProfileInput): Promise<ProfileSetup> {\n return createProfile(input, this.config);\n }\n\n /**\n * List all profiles for the authenticated user.\n *\n * @param repoId - Optional repository ID to filter by\n * @returns Array of profiles\n *\n * @example\n * ```typescript\n * // List all profiles\n * const allProfiles = await morph.browser.profiles.listProfiles();\n *\n * // List profiles for a specific repo\n * const repoProfiles = await morph.browser.profiles.listProfiles('owner/repo');\n * ```\n */\n async listProfiles(repoId?: string): Promise<Profile[]> {\n return listProfiles(this.config, repoId);\n }\n\n /**\n * Get a profile by ID with convenience methods.\n *\n * @param id - Profile ID\n * @returns Profile with attached methods\n * @throws {MorphNotFoundError} If profile is not found\n *\n * @example\n * ```typescript\n * const profile = await morph.browser.profiles.getProfile('profile-id');\n * const state = await profile.getState();\n * await profile.delete();\n * ```\n */\n async getProfile(id: string): Promise<ProfileWithMethods> {\n return getProfile(id, this.config);\n }\n\n /**\n * Update a profile by opening a live session (no rename).\n *\n * @param id - Profile ID\n * @returns Profile setup handle with live URL + save()\n */\n async updateProfile(id: string): Promise<ProfileSetup> {\n return updateProfile(id, this.config);\n }\n\n /**\n * Delete a profile.\n *\n * @param id - Profile ID\n * @throws {MorphNotFoundError} If profile is not found\n */\n async deleteProfile(id: string): Promise<void> {\n return deleteProfile(id, this.config);\n }\n\n /**\n * Start a browser session for profile setup.\n *\n * Returns a live URL where the user can sign into accounts.\n * After signing in, call `saveSession` to persist the state.\n *\n * @param input - Optional session parameters\n * @returns Session with debug URL\n *\n * @example\n * ```typescript\n * const session = await morph.browser.profiles.startSession();\n * console.log('Sign in at:', session.debugUrl);\n * // Open debugUrl in browser, user signs in...\n * await morph.browser.profiles.saveSession(session.sessionId, profile.id);\n * ```\n */\n async startSession(input?: ProfileSessionInput): Promise<ProfileSession> {\n return startProfileSession(this.config, input);\n }\n\n /**\n * Save browser state from a session to a profile.\n *\n * Call this after the user is done signing into accounts.\n * Extracts cookies, localStorage, and sessionStorage.\n *\n * @param sessionId - Browser session ID from startSession\n * @param profileId - Profile ID to save state to\n * @returns Updated profile with cookie domains\n */\n async saveSession(sessionId: string, profileId: string): Promise<Profile> {\n return saveProfileSession({ sessionId, profileId }, this.config);\n }\n\n /**\n * List available repo IDs (discovery).\n *\n * @returns Repo summaries with profile counts\n */\n async listRepos(): Promise<RepoSummary[]> {\n return listRepos(this.config);\n }\n\n /**\n * Get the presigned URL for a profile's state.\n *\n * Use this to download the raw state JSON for debugging\n * or to restore state manually.\n *\n * @param profileId - Profile ID\n * @returns State URL with expiry information\n */\n async getProfileState(profileId: string): Promise<ProfileStateResponse> {\n return getProfileState(profileId, this.config);\n }\n}\n\n// ============================================================================\n// Validation Helpers\n// ============================================================================\n\nfunction validateCreateInput(input: CreateProfileInput): void {\n if (!input.name || typeof input.name !== 'string') {\n throw new MorphValidationError('name is required', 'name');\n }\n\n const trimmedName = input.name.trim();\n if (trimmedName.length === 0) {\n throw new MorphValidationError('name cannot be empty', 'name');\n }\n\n if (trimmedName.length > 100) {\n throw new MorphValidationError('name must be 100 characters or less', 'name');\n }\n\n if (!input.repoId || typeof input.repoId !== 'string') {\n throw new MorphValidationError('repoId is required', 'repoId');\n }\n\n if (input.repoId.trim().length === 0) {\n throw new MorphValidationError('repoId cannot be empty', 'repoId');\n }\n}\n\nfunction validateId(id: string, fieldName: string): void {\n if (!id || typeof id !== 'string') {\n throw new MorphValidationError(`${fieldName} is required`, fieldName);\n }\n\n if (id.trim().length === 0) {\n throw new MorphValidationError(`${fieldName} cannot be empty`, fieldName);\n }\n}\n\n// ============================================================================\n// Standalone Functions\n// ============================================================================\n\n/**\n * Create a new browser profile.\n */\nexport async function createProfile(\n input: CreateProfileInput,\n config: BrowserConfig = {}\n): Promise<ProfileSetup> {\n validateCreateInput(input);\n\n const apiUrl = config.apiUrl || DEFAULT_API_URL;\n const headers = buildHeaders(config);\n\n const response = await fetchWithRetry(\n `${apiUrl}/profiles`,\n {\n method: 'POST',\n headers,\n body: JSON.stringify(transformCreateInput(input)),\n },\n config.retryConfig\n );\n\n if (!response.ok) {\n const errorText = await response.text().catch(() => response.statusText);\n const requestId = response.headers.get('x-request-id') || undefined;\n throw parseAPIError(response.status, errorText, requestId);\n }\n\n const apiProfile: APIProfile = await response.json();\n const profile = transformProfile(apiProfile);\n const session = await startProfileSession(config, { profileId: profile.id });\n return buildProfileSetup(profile, session, config);\n}\n\n/**\n * List all profiles for the authenticated user.\n */\nexport async function listProfiles(\n config: BrowserConfig = {},\n repoId?: string\n): Promise<Profile[]> {\n const apiUrl = config.apiUrl || DEFAULT_API_URL;\n const headers = buildHeaders(config);\n\n const url = repoId\n ? `${apiUrl}/profiles?repo_id=${encodeURIComponent(repoId)}`\n : `${apiUrl}/profiles`;\n\n const response = await fetchWithRetry(\n url,\n { method: 'GET', headers },\n config.retryConfig\n );\n\n if (!response.ok) {\n const errorText = await response.text().catch(() => response.statusText);\n const requestId = response.headers.get('x-request-id') || undefined;\n throw parseAPIError(response.status, errorText, requestId);\n }\n\n const data: { profiles: APIProfile[] } = await response.json();\n return data.profiles.map(transformProfile);\n}\n\n/**\n * Get a profile by ID with convenience methods.\n */\nexport async function getProfile(\n id: string,\n config: BrowserConfig = {}\n): Promise<ProfileWithMethods> {\n validateId(id, 'id');\n\n const apiUrl = config.apiUrl || DEFAULT_API_URL;\n const headers = buildHeaders(config);\n\n const response = await fetchWithRetry(\n `${apiUrl}/profiles/${encodeURIComponent(id)}`,\n { method: 'GET', headers },\n config.retryConfig\n );\n\n if (!response.ok) {\n const errorText = await response.text().catch(() => response.statusText);\n const requestId = response.headers.get('x-request-id') || undefined;\n throw parseAPIError(response.status, errorText, requestId);\n }\n\n const apiProfile: APIProfile = await response.json();\n const profile = transformProfile(apiProfile);\n\n // Attach convenience methods\n return {\n ...profile,\n getState: () => getProfileState(id, config),\n delete: () => deleteProfile(id, config),\n };\n}\n\n/**\n * Update a profile.\n */\nexport async function updateProfile(\n id: string,\n config: BrowserConfig = {}\n): Promise<ProfileSetup> {\n validateId(id, 'id');\n const profile = await fetchProfile(id, config);\n const session = await startProfileSession(config, { profileId: profile.id });\n return buildProfileSetup(profile, session, config);\n}\n\n/**\n * Delete a profile.\n */\nexport async function deleteProfile(\n id: string,\n config: BrowserConfig = {}\n): Promise<void> {\n validateId(id, 'id');\n\n const apiUrl = config.apiUrl || DEFAULT_API_URL;\n const headers = buildHeaders(config);\n\n const response = await fetchWithRetry(\n `${apiUrl}/profiles/${encodeURIComponent(id)}`,\n { method: 'DELETE', headers },\n config.retryConfig\n );\n\n if (!response.ok) {\n const errorText = await response.text().catch(() => response.statusText);\n const requestId = response.headers.get('x-request-id') || undefined;\n throw parseAPIError(response.status, errorText, requestId);\n }\n}\n\n/**\n * Start a browser session for profile setup.\n */\nexport async function startProfileSession(\n config: BrowserConfig = {},\n input?: ProfileSessionInput\n): Promise<ProfileSession> {\n if (!config.apiKey) {\n throw new MorphAuthenticationError();\n }\n\n const apiUrl = config.apiUrl || DEFAULT_API_URL;\n const headers = buildHeaders(config);\n\n // Transform input if provided\n const body = input?.profileId\n ? { profile_id: input.profileId }\n : {};\n\n const response = await fetchWithRetry(\n `${apiUrl}/profiles/session/start`,\n {\n method: 'POST',\n headers,\n body: JSON.stringify(body),\n },\n config.retryConfig\n );\n\n if (!response.ok) {\n const errorText = await response.text().catch(() => response.statusText);\n const requestId = response.headers.get('x-request-id') || undefined;\n throw parseAPIError(response.status, errorText, requestId);\n }\n\n const apiSession: APIProfileSession = await response.json();\n return transformSession(apiSession);\n}\n\n/**\n * Save browser state from a session to a profile.\n */\nexport async function saveProfileSession(\n input: SaveProfileSessionInput,\n config: BrowserConfig = {}\n): Promise<Profile> {\n validateId(input.sessionId, 'sessionId');\n validateId(input.profileId, 'profileId');\n\n const apiUrl = config.apiUrl || DEFAULT_API_URL;\n const headers = buildHeaders(config);\n\n const response = await fetchWithRetry(\n `${apiUrl}/profiles/session/save`,\n {\n method: 'POST',\n headers,\n body: JSON.stringify(transformSaveInput(input)),\n },\n config.retryConfig\n );\n\n if (!response.ok) {\n const errorText = await response.text().catch(() => response.statusText);\n const requestId = response.headers.get('x-request-id') || undefined;\n throw parseAPIError(response.status, errorText, requestId);\n }\n\n const apiProfile: APIProfile = await response.json();\n return transformProfile(apiProfile);\n}\n\n/**\n * List repo IDs available to the authenticated user/org.\n */\nexport async function listRepos(config: BrowserConfig = {}): Promise<RepoSummary[]> {\n const apiUrl = config.apiUrl || DEFAULT_API_URL;\n const headers = buildHeaders(config);\n\n const response = await fetchWithRetry(\n `${apiUrl}/repos`,\n { method: 'GET', headers },\n config.retryConfig\n );\n\n if (!response.ok) {\n const errorText = await response.text().catch(() => response.statusText);\n const requestId = response.headers.get('x-request-id') || undefined;\n throw parseAPIError(response.status, errorText, requestId);\n }\n\n const data = await response.json();\n const repos = Array.isArray(data?.repos) ? data.repos : [];\n\n return repos.map((repo: any) => ({\n repoId: repo.repo_id,\n repoFullName: repo.repo_full_name,\n profileCount: repo.profile_count ?? 0,\n })) satisfies RepoSummary[];\n}\n\n/**\n * Get the presigned URL for a profile's state.\n */\nexport async function getProfileState(\n profileId: string,\n config: BrowserConfig = {}\n): Promise<ProfileStateResponse> {\n validateId(profileId, 'profileId');\n\n const apiUrl = config.apiUrl || DEFAULT_API_URL;\n const headers = buildHeaders(config);\n\n const response = await fetchWithRetry(\n `${apiUrl}/profiles/${encodeURIComponent(profileId)}/state`,\n { method: 'GET', headers },\n config.retryConfig\n );\n\n if (!response.ok) {\n const errorText = await response.text().catch(() => response.statusText);\n const requestId = response.headers.get('x-request-id') || undefined;\n throw parseAPIError(response.status, errorText, requestId);\n }\n\n const apiState: APIProfileStateResponse = await response.json();\n return transformStateResponse(apiState);\n}\n\n// ============================================================================\n// Helpers\n// ============================================================================\n\nfunction buildHeaders(config: BrowserConfig): Record<string, string> {\n const headers: Record<string, string> = { 'Content-Type': 'application/json' };\n if (config.apiKey) {\n headers['Authorization'] = `Bearer ${config.apiKey}`;\n }\n return headers;\n}\n\nasync function fetchProfile(id: string, config: BrowserConfig): Promise<Profile> {\n const apiUrl = config.apiUrl || DEFAULT_API_URL;\n const headers = buildHeaders(config);\n\n const response = await fetchWithRetry(\n `${apiUrl}/profiles/${encodeURIComponent(id)}`,\n { method: 'GET', headers },\n config.retryConfig\n );\n\n if (!response.ok) {\n const errorText = await response.text().catch(() => response.statusText);\n const requestId = response.headers.get('x-request-id') || undefined;\n throw parseAPIError(response.status, errorText, requestId);\n }\n\n const apiProfile: APIProfile = await response.json();\n return transformProfile(apiProfile);\n}\n\nfunction buildProfileSetup(profile: Profile, session: ProfileSession, config: BrowserConfig): ProfileSetup {\n return {\n profile,\n session,\n save: () => saveProfileSession({ sessionId: session.sessionId, profileId: profile.id }, config),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAyDA,IAAM,kBAAkB,QAAQ,IAAI,sBAAsB,QACtD,0BACA;AAOG,IAAM,iBAAN,MAAqB;AAAA,EAClB;AAAA,EAER,YAAY,QAAuB;AACjC,SAAK,SAAS;AAAA,EAChB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAqBA,MAAM,cAAc,OAAkD;AACpE,WAAO,cAAc,OAAO,KAAK,MAAM;AAAA,EACzC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;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,MAAM,aAAa,mBAAmB,EAAE,CAAC;AAAA,IAC5C,EAAE,QAAQ,OAAO,QAAQ;AAAA,IACzB,OAAO;AAAA,EACT;AAEA,MAAI,CAAC,SAAS,IAAI;AAChB,UAAM,YAAY,MAAM,SAAS,KAAK,EAAE,MAAM,MAAM,SAAS,UAAU;AACvE,UAAM,YAAY,SAAS,QAAQ,IAAI,cAAc,KAAK;AAC1D,UAAM,cAAc,SAAS,QAAQ,WAAW,SAAS;AAAA,EAC3D;AAEA,QAAM,aAAyB,MAAM,SAAS,KAAK;AACnD,SAAO,iBAAiB,UAAU;AACpC;AAEA,SAAS,kBAAkB,SAAkB,SAAyB,QAAqC;AACzG,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,MAAM,MAAM,mBAAmB,EAAE,WAAW,QAAQ,WAAW,WAAW,QAAQ,GAAG,GAAG,MAAM;AAAA,EAChG;AACF;","names":[]}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
BROWSER_SYSTEM_PROMPT,
|
|
3
3
|
BROWSER_TOOL_DESCRIPTION
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-2HMEZZKK.js";
|
|
5
5
|
import {
|
|
6
6
|
executeBrowserTask
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-QJP62BXH.js";
|
|
8
8
|
import {
|
|
9
9
|
__export
|
|
10
10
|
} from "./chunk-PZ5AY32C.js";
|
|
@@ -29,7 +29,7 @@ var browserTool = {
|
|
|
29
29
|
type: "string",
|
|
30
30
|
description: "Starting URL (e.g., https://3000-xyz.e2b.dev). Required if navigating to a specific page."
|
|
31
31
|
},
|
|
32
|
-
|
|
32
|
+
maxSteps: {
|
|
33
33
|
type: "number",
|
|
34
34
|
description: "Maximum number of browser actions to take (1-50). Default: 10. Use 15-30 for complex flows.",
|
|
35
35
|
default: 10
|
|
@@ -48,8 +48,8 @@ function formatResult(result) {
|
|
|
48
48
|
if (result.success) {
|
|
49
49
|
const parts = [
|
|
50
50
|
"\u2705 Browser task completed successfully",
|
|
51
|
-
`Steps taken: ${result.
|
|
52
|
-
result.
|
|
51
|
+
`Steps taken: ${result.stepsTaken ?? 0}`,
|
|
52
|
+
result.executionTimeMs ? `Execution time: ${result.executionTimeMs}ms` : null,
|
|
53
53
|
"",
|
|
54
54
|
"Result:",
|
|
55
55
|
result.result || "Task completed"
|
|
@@ -77,4 +77,4 @@ export {
|
|
|
77
77
|
createBrowserTool,
|
|
78
78
|
anthropic_exports
|
|
79
79
|
};
|
|
80
|
-
//# sourceMappingURL=chunk-
|
|
80
|
+
//# sourceMappingURL=chunk-TSENDJQI.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../tools/browser/anthropic.ts"],"sourcesContent":["/**\n * Anthropic SDK adapter for browser automation tool\n */\n\nimport type { Tool } from '@anthropic-ai/sdk/resources/messages.mjs';\nimport { executeBrowserTask } from './core.js';\nimport type {\n BrowserConfig,\n BrowserTaskInput,\n BrowserTaskResult,\n} from './types.js';\nimport { BROWSER_TOOL_DESCRIPTION, BROWSER_SYSTEM_PROMPT } from './prompts.js';\n\n/**\n * Anthropic tool definition for browser automation\n */\nexport const browserTool: Tool = {\n name: 'browser_task',\n description: BROWSER_TOOL_DESCRIPTION,\n input_schema: {\n type: 'object',\n properties: {\n task: {\n type: 'string',\n description: 'Natural language description of what to do (e.g., \"Test checkout flow for buying a pineapple\")',\n },\n url: {\n type: 'string',\n description: 'Starting URL (e.g., https://3000-xyz.e2b.dev). Required if navigating to a specific page.',\n },\n maxSteps: {\n type: 'number',\n description: 'Maximum number of browser actions to take (1-50). Default: 10. Use 15-30 for complex flows.',\n default: 10,\n },\n region: {\n type: 'string',\n enum: ['sfo', 'lon'],\n description: 'Browserless region: sfo (US West Coast) or lon (Europe). Default: sfo.',\n default: 'sfo',\n },\n },\n required: ['task'],\n },\n};\n\n/**\n * Format browser task result for Anthropic tool result\n * \n * Returns a concise summary suitable for agent context. The full result object\n * (with urls, errors, action_history, judgement, etc.) is available when calling\n * execute() directly, but this formatted string omits those details to save tokens.\n * \n * @param result - Browser task result with full history data\n * @returns Formatted string summary for tool result\n */\nfunction formatResult(result: BrowserTaskResult): string {\n if (result.success) {\n const parts = [\n '✅ Browser task completed successfully',\n `Steps taken: ${result.stepsTaken ?? 0}`,\n result.executionTimeMs ? `Execution time: ${result.executionTimeMs}ms` : null,\n '',\n 'Result:',\n result.result || 'Task completed',\n ];\n return parts.filter(Boolean).join('\\n');\n }\n\n return `❌ Browser task failed: ${result.error || 'Unknown error'}`;\n}\n\n/**\n * Create a configured browser tool with execute and formatResult methods\n * \n * @param config - Browser worker configuration\n * @returns Tool definition with execute and formatResult methods\n * \n * @example\n * ```typescript\n * import Anthropic from '@anthropic-ai/sdk';\n * import { createBrowserTool } from 'morphsdk/tools/browser/anthropic';\n * \n * const tool = createBrowserTool({\n * apiKey: process.env.MORPH_API_KEY,\n * timeout: 180000\n * });\n * \n * const client = new Anthropic();\n * \n * const response = await client.messages.create({\n * model: 'claude-sonnet-4-5-20250929',\n * tools: [tool], // tool itself is the Tool definition\n * messages: [{\n * role: 'user',\n * content: 'Test the checkout flow at https://3000-abc.e2b.dev'\n * }]\n * });\n * \n * // Execute and format\n * const result = await tool.execute(toolUseBlock.input);\n * const formatted = tool.formatResult(result);\n * ```\n */\nexport function createBrowserTool(config?: BrowserConfig) {\n return Object.assign({}, browserTool, {\n execute: async (input: BrowserTaskInput): Promise<BrowserTaskResult> => {\n return executeBrowserTask(input, config);\n },\n formatResult: (result: BrowserTaskResult): string => {\n return formatResult(result);\n },\n getSystemPrompt: (): string => {\n return BROWSER_SYSTEM_PROMPT;\n },\n });\n}\n"],"mappings":";;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAgBO,IAAM,cAAoB;AAAA,EAC/B,MAAM;AAAA,EACN,aAAa;AAAA,EACb,cAAc;AAAA,IACZ,MAAM;AAAA,IACN,YAAY;AAAA,MACV,MAAM;AAAA,QACJ,MAAM;AAAA,QACN,aAAa;AAAA,MACf;AAAA,MACA,KAAK;AAAA,QACH,MAAM;AAAA,QACN,aAAa;AAAA,MACf;AAAA,MACA,UAAU;AAAA,QACR,MAAM;AAAA,QACN,aAAa;AAAA,QACb,SAAS;AAAA,MACX;AAAA,MACA,QAAQ;AAAA,QACN,MAAM;AAAA,QACN,MAAM,CAAC,OAAO,KAAK;AAAA,QACnB,aAAa;AAAA,QACb,SAAS;AAAA,MACX;AAAA,IACF;AAAA,IACA,UAAU,CAAC,MAAM;AAAA,EACnB;AACF;AAYA,SAAS,aAAa,QAAmC;AACvD,MAAI,OAAO,SAAS;AAClB,UAAM,QAAQ;AAAA,MACZ;AAAA,MACA,gBAAgB,OAAO,cAAc,CAAC;AAAA,MACtC,OAAO,kBAAkB,mBAAmB,OAAO,eAAe,OAAO;AAAA,MACzE;AAAA,MACA;AAAA,MACA,OAAO,UAAU;AAAA,IACnB;AACA,WAAO,MAAM,OAAO,OAAO,EAAE,KAAK,IAAI;AAAA,EACxC;AAEA,SAAO,+BAA0B,OAAO,SAAS,eAAe;AAClE;AAkCO,SAAS,kBAAkB,QAAwB;AACxD,SAAO,OAAO,OAAO,CAAC,GAAG,aAAa;AAAA,IACpC,SAAS,OAAO,UAAwD;AACtE,aAAO,mBAAmB,OAAO,MAAM;AAAA,IACzC;AAAA,IACA,cAAc,CAAC,WAAsC;AACnD,aAAO,aAAa,MAAM;AAAA,IAC5B;AAAA,IACA,iBAAiB,MAAc;AAC7B,aAAO;AAAA,IACT;AAAA,EACF,CAAC;AACH;","names":[]}
|
|
@@ -50,13 +50,6 @@ function formatResult(result) {
|
|
|
50
50
|
changes.linesRemoved && `-${changes.linesRemoved} lines`,
|
|
51
51
|
changes.linesModified && `~${changes.linesModified} lines modified`
|
|
52
52
|
].filter(Boolean).join(", ");
|
|
53
|
-
if (result.udiff) {
|
|
54
|
-
return `Successfully applied changes to ${result.filepath}:
|
|
55
|
-
|
|
56
|
-
${result.udiff}
|
|
57
|
-
|
|
58
|
-
Summary: ${summary}`;
|
|
59
|
-
}
|
|
60
53
|
return `Successfully applied changes to ${result.filepath}. ${summary}`;
|
|
61
54
|
}
|
|
62
55
|
function createEditFileTool(config = {}) {
|
|
@@ -91,4 +84,4 @@ export {
|
|
|
91
84
|
getSystemPrompt,
|
|
92
85
|
anthropic_exports
|
|
93
86
|
};
|
|
94
|
-
//# sourceMappingURL=chunk-
|
|
87
|
+
//# sourceMappingURL=chunk-XH7P7HVT.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../tools/fastapply/anthropic.ts"],"sourcesContent":["/**\n * Anthropic SDK adapter for edit_file tool\n */\n\nimport type { Tool } from '@anthropic-ai/sdk/resources/messages';\nimport { executeEditFile } from './core.js';\nimport { EDIT_FILE_TOOL_DESCRIPTION, EDIT_FILE_SYSTEM_PROMPT } from './prompts.js';\nimport type { EditFileInput, EditFileResult, EditFileConfig } from './types.js';\n\n/**\n * Anthropic-native tool definition for edit_file\n * \n * @example\n * ```ts\n * import Anthropic from '@anthropic-ai/sdk';\n * import { editFileTool } from 'morphsdk/tools/anthropic';\n * \n * const client = new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY });\n * \n * const response = await client.messages.create({\n * model: \"claude-sonnet-4-5-20250929\",\n * tools: [editFileTool],\n * messages: [{ role: \"user\", content: \"Fix the bug in app.ts\" }]\n * });\n * ```\n */\nexport const editFileTool: Tool = {\n name: 'edit_file',\n description: EDIT_FILE_TOOL_DESCRIPTION,\n input_schema: {\n type: 'object',\n properties: {\n target_filepath: {\n type: 'string',\n description: 'The path of the target file to modify',\n },\n instructions: {\n type: 'string',\n description: 'A single sentence describing what you are changing (first person)',\n },\n code_edit: {\n type: 'string',\n description: 'The lazy edit with // ... existing code ... markers',\n },\n },\n required: ['target_filepath', 'instructions', 'code_edit'],\n },\n};\n\n/**\n * Format the result for passing back to Claude\n * \n * @param result - The edit result\n * @returns Formatted string for tool_result\n */\nexport function formatResult(result: EditFileResult): string {\n if (!result.success) {\n return `Error editing file: ${result.error}`;\n }\n \n const { changes } = result;\n const summary = [\n changes.linesAdded && `+${changes.linesAdded} lines`,\n changes.linesRemoved && `-${changes.linesRemoved} lines`,\n changes.linesModified && `~${changes.linesModified} lines modified`,\n ]\n .filter(Boolean)\n .join(', ');\n \n return `Successfully applied changes to ${result.filepath}. ${summary}`;\n}\n\n/**\n * Create a custom edit_file tool with configuration\n * \n * @param config - Configuration options\n * @returns Tool definition with execute and formatResult methods\n * \n * @example\n * ```ts\n * const tool = createEditFileTool({\n * baseDir: './src',\n * generateUdiff: true,\n * morphApiKey: 'sk-...',\n * description: 'Custom tool description for your use case'\n * });\n * \n * // Use as Anthropic tool\n * const response = await client.messages.create({\n * tools: [tool], // tool itself is the Tool definition\n * ...\n * });\n * \n * // Execute and format\n * const result = await tool.execute(toolUseBlock.input);\n * const formatted = tool.formatResult(result);\n * ```\n */\nexport function createEditFileTool(config: EditFileConfig = {}) {\n const toolDef: Tool = {\n ...editFileTool,\n ...(config.description && { description: config.description }),\n };\n \n return Object.assign({}, toolDef, {\n execute: async (input: EditFileInput): Promise<EditFileResult> => {\n return executeEditFile(input, config);\n },\n formatResult: (result: EditFileResult): string => {\n return formatResult(result);\n },\n getSystemPrompt: (): string => {\n return EDIT_FILE_SYSTEM_PROMPT;\n },\n });\n}\n\n/**\n * Execute the edit_file tool with raw input\n * \n * @param input - Tool input from Claude's tool_use\n * @param config - Configuration for Fast Apply\n * @returns Tool result to send back to Claude\n */\nexport async function execute(\n input: EditFileInput,\n config?: EditFileConfig\n): Promise<EditFileResult> {\n return executeEditFile(input, config);\n}\n\n/**\n * Get the system prompt for the edit_file tool\n * \n * @returns System prompt string\n */\nexport function getSystemPrompt(): string {\n return EDIT_FILE_SYSTEM_PROMPT;\n}\n\n"],"mappings":";;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA0BO,IAAM,eAAqB;AAAA,EAChC,MAAM;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}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
BROWSER_SYSTEM_PROMPT,
|
|
3
3
|
BROWSER_TOOL_DESCRIPTION
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-2HMEZZKK.js";
|
|
5
5
|
import {
|
|
6
6
|
executeBrowserTask
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-QJP62BXH.js";
|
|
8
8
|
import {
|
|
9
9
|
__export
|
|
10
10
|
} from "./chunk-PZ5AY32C.js";
|
|
@@ -34,7 +34,7 @@ var browserTool = {
|
|
|
34
34
|
type: "string",
|
|
35
35
|
description: "Starting URL (e.g., https://3000-xyz.e2b.dev). Required if navigating to a specific page."
|
|
36
36
|
},
|
|
37
|
-
|
|
37
|
+
maxSteps: {
|
|
38
38
|
type: "number",
|
|
39
39
|
description: "Maximum number of browser actions to take (1-50). Default: 10. Use 15-30 for complex flows.",
|
|
40
40
|
default: 10
|
|
@@ -58,8 +58,8 @@ function formatResult(result) {
|
|
|
58
58
|
if (result.success) {
|
|
59
59
|
const parts = [
|
|
60
60
|
"\u2705 Browser task completed successfully",
|
|
61
|
-
`Steps taken: ${result.
|
|
62
|
-
result.
|
|
61
|
+
`Steps taken: ${result.stepsTaken ?? 0}`,
|
|
62
|
+
result.executionTimeMs ? `Execution time: ${result.executionTimeMs}ms` : null,
|
|
63
63
|
"",
|
|
64
64
|
"Result:",
|
|
65
65
|
result.result || "Task completed"
|
|
@@ -93,4 +93,4 @@ export {
|
|
|
93
93
|
createBrowserTool,
|
|
94
94
|
openai_exports
|
|
95
95
|
};
|
|
96
|
-
//# sourceMappingURL=chunk-
|
|
96
|
+
//# sourceMappingURL=chunk-YZ5NCWO2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../tools/browser/openai.ts"],"sourcesContent":["/**\n * OpenAI SDK adapter for browser automation tool\n */\n\nimport type { ChatCompletionTool } from 'openai/resources/chat/completions.mjs';\nimport { executeBrowserTask } from './core.js';\nimport type {\n BrowserConfig,\n BrowserTaskInput,\n BrowserTaskResult,\n} from './types.js';\nimport { BROWSER_TOOL_DESCRIPTION, BROWSER_SYSTEM_PROMPT } from './prompts.js';\n\n/**\n * OpenAI tool definition for browser automation\n */\nexport const browserTool: ChatCompletionTool = {\n type: 'function',\n function: {\n name: 'browser_task',\n description: BROWSER_TOOL_DESCRIPTION,\n parameters: {\n type: 'object',\n properties: {\n task: {\n type: 'string',\n description: 'Natural language description of what to do (e.g., \"Test checkout flow for buying a pineapple\")',\n },\n url: {\n type: 'string',\n description: 'Starting URL (e.g., https://3000-xyz.e2b.dev). Required if navigating to a specific page.',\n },\n maxSteps: {\n type: 'number',\n description: 'Maximum number of browser actions to take (1-50). Default: 10. Use 15-30 for complex flows.',\n default: 10,\n },\n region: {\n type: 'string',\n enum: ['sfo', 'lon'],\n description: 'Browserless region: sfo (US West Coast) or lon (Europe). Default: sfo.',\n default: 'sfo',\n },\n },\n required: ['task'],\n },\n },\n};\n\n/**\n * Execute a browser task (for use in tool call handling)\n * \n * @param input - Tool input parameters (may be JSON string)\n * @param config - Optional browser worker configuration\n * @returns Task execution result\n */\nexport async function execute(\n input: BrowserTaskInput | string,\n config?: BrowserConfig\n): Promise<BrowserTaskResult> {\n // Parse input if it's a JSON string (from OpenAI tool call)\n const parsedInput = typeof input === 'string' ? JSON.parse(input) : input;\n return executeBrowserTask(parsedInput, config);\n}\n\n/**\n * Format browser task result for OpenAI tool result\n * \n * Returns a concise summary suitable for agent context. The full result object\n * (with urls, errors, action_history, judgement, etc.) is available when calling\n * execute() directly, but this formatted string omits those details to save tokens.\n * \n * @param result - Browser task result with full history data\n * @returns Formatted string summary for tool result\n */\nexport function formatResult(result: BrowserTaskResult): string {\n if (result.success) {\n const parts = [\n '✅ Browser task completed successfully',\n `Steps taken: ${result.stepsTaken ?? 0}`,\n result.executionTimeMs ? `Execution time: ${result.executionTimeMs}ms` : null,\n '',\n 'Result:',\n result.result || 'Task completed',\n ];\n return parts.filter(Boolean).join('\\n');\n }\n\n return `❌ Browser task failed: ${result.error || 'Unknown error'}`;\n}\n\n/**\n * Get system prompt for browser automation\n */\nexport function getSystemPrompt(): string {\n return BROWSER_SYSTEM_PROMPT;\n}\n\n/**\n * Create a configured browser tool with execute and formatResult methods\n * \n * @param config - Browser worker configuration\n * @returns Tool definition with execute and formatResult methods\n * \n * @example\n * ```typescript\n * import OpenAI from 'openai';\n * import { createBrowserTool } from 'morphsdk/tools/browser/openai';\n * \n * const tool = createBrowserTool({\n * apiUrl: 'https://browser-worker.example.com'\n * });\n * \n * const client = new OpenAI();\n * \n * const response = await client.chat.completions.create({\n * model: 'gpt-4o',\n * tools: [tool], // tool itself is the ChatCompletionTool\n * messages: [{\n * role: 'user',\n * content: 'Test the checkout at https://3000-abc.e2b.dev'\n * }]\n * });\n * \n * // Execute and format\n * const result = await tool.execute(toolCallArgs);\n * const formatted = tool.formatResult(result);\n * ```\n */\nexport function createBrowserTool(config?: BrowserConfig) {\n return Object.assign({}, browserTool, {\n execute: async (input: BrowserTaskInput | string): Promise<BrowserTaskResult> => {\n return execute(input, config);\n },\n formatResult: (result: BrowserTaskResult): string => {\n return formatResult(result);\n },\n getSystemPrompt: (): string => {\n return getSystemPrompt();\n },\n });\n}\n"],"mappings":";;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAgBO,IAAM,cAAkC;AAAA,EAC7C,MAAM;AAAA,EACN,UAAU;AAAA,IACR,MAAM;AAAA,IACN,aAAa;AAAA,IACb,YAAY;AAAA,MACV,MAAM;AAAA,MACN,YAAY;AAAA,QACV,MAAM;AAAA,UACJ,MAAM;AAAA,UACN,aAAa;AAAA,QACf;AAAA,QACA,KAAK;AAAA,UACH,MAAM;AAAA,UACN,aAAa;AAAA,QACf;AAAA,QACA,UAAU;AAAA,UACR,MAAM;AAAA,UACN,aAAa;AAAA,UACb,SAAS;AAAA,QACX;AAAA,QACA,QAAQ;AAAA,UACN,MAAM;AAAA,UACN,MAAM,CAAC,OAAO,KAAK;AAAA,UACnB,aAAa;AAAA,UACb,SAAS;AAAA,QACX;AAAA,MACF;AAAA,MACA,UAAU,CAAC,MAAM;AAAA,IACnB;AAAA,EACF;AACF;AASA,eAAsB,QACpB,OACA,QAC4B;AAE5B,QAAM,cAAc,OAAO,UAAU,WAAW,KAAK,MAAM,KAAK,IAAI;AACpE,SAAO,mBAAmB,aAAa,MAAM;AAC/C;AAYO,SAAS,aAAa,QAAmC;AAC9D,MAAI,OAAO,SAAS;AAClB,UAAM,QAAQ;AAAA,MACZ;AAAA,MACA,gBAAgB,OAAO,cAAc,CAAC;AAAA,MACtC,OAAO,kBAAkB,mBAAmB,OAAO,eAAe,OAAO;AAAA,MACzE;AAAA,MACA;AAAA,MACA,OAAO,UAAU;AAAA,IACnB;AACA,WAAO,MAAM,OAAO,OAAO,EAAE,KAAK,IAAI;AAAA,EACxC;AAEA,SAAO,+BAA0B,OAAO,SAAS,eAAe;AAClE;AAKO,SAAS,kBAA0B;AACxC,SAAO;AACT;AAiCO,SAAS,kBAAkB,QAAwB;AACxD,SAAO,OAAO,OAAO,CAAC,GAAG,aAAa;AAAA,IACpC,SAAS,OAAO,UAAiE;AAC/E,aAAO,QAAQ,OAAO,MAAM;AAAA,IAC9B;AAAA,IACA,cAAc,CAAC,WAAsC;AACnD,aAAO,aAAa,MAAM;AAAA,IAC5B;AAAA,IACA,iBAAiB,MAAc;AAC7B,aAAO,gBAAgB;AAAA,IACzB;AAAA,EACF,CAAC;AACH;","names":[]}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createWarpGrepTool as createWarpGrepTool3
|
|
3
|
+
} from "./chunk-O7LDZA52.js";
|
|
1
4
|
import {
|
|
2
5
|
createWarpGrepTool as createWarpGrepTool2
|
|
3
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-7D6TXC7X.js";
|
|
4
7
|
import {
|
|
5
8
|
createWarpGrepTool
|
|
6
|
-
} from "./chunk-
|
|
7
|
-
import {
|
|
8
|
-
createWarpGrepTool as createWarpGrepTool3
|
|
9
|
-
} from "./chunk-GU6DACME.js";
|
|
9
|
+
} from "./chunk-73RV6EXR.js";
|
|
10
10
|
import {
|
|
11
11
|
WarpGrepClient
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-QAT5UVPX.js";
|
|
13
13
|
import {
|
|
14
14
|
createCodebaseSearchTool as createCodebaseSearchTool3
|
|
15
15
|
} from "./chunk-UBX7QYBD.js";
|
|
@@ -22,21 +22,21 @@ import {
|
|
|
22
22
|
import {
|
|
23
23
|
CodebaseSearchClient
|
|
24
24
|
} from "./chunk-WM77HRKO.js";
|
|
25
|
+
import {
|
|
26
|
+
createEditFileTool as createEditFileTool3
|
|
27
|
+
} from "./chunk-QZNGKOCZ.js";
|
|
25
28
|
import {
|
|
26
29
|
createEditFileTool as createEditFileTool2
|
|
27
|
-
} from "./chunk-
|
|
30
|
+
} from "./chunk-XH7P7HVT.js";
|
|
28
31
|
import {
|
|
29
32
|
createEditFileTool
|
|
30
|
-
} from "./chunk-
|
|
31
|
-
import {
|
|
32
|
-
createEditFileTool as createEditFileTool3
|
|
33
|
-
} from "./chunk-QZNGKOCZ.js";
|
|
33
|
+
} from "./chunk-PE4KGDA6.js";
|
|
34
34
|
import {
|
|
35
35
|
FastApplyClient
|
|
36
36
|
} from "./chunk-CKTA4AXM.js";
|
|
37
37
|
import {
|
|
38
38
|
BrowserClient
|
|
39
|
-
} from "./chunk-
|
|
39
|
+
} from "./chunk-QJP62BXH.js";
|
|
40
40
|
import {
|
|
41
41
|
MorphGit
|
|
42
42
|
} from "./chunk-VJU3BRET.js";
|
|
@@ -280,4 +280,4 @@ export {
|
|
|
280
280
|
VercelToolFactory,
|
|
281
281
|
MorphClient
|
|
282
282
|
};
|
|
283
|
-
//# sourceMappingURL=chunk-
|
|
283
|
+
//# sourceMappingURL=chunk-ZYTAKEBW.js.map
|