@morphllm/morphsdk 0.2.198 → 0.2.199
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -147
- package/dist/{chunk-CAFREMIT.js → chunk-5KQ2WRBU.js} +2 -2
- package/dist/{chunk-FUYX2MNM.js → chunk-7UU4NF4G.js} +4 -10
- package/dist/chunk-7UU4NF4G.js.map +1 -0
- package/dist/{chunk-XTFRHVCW.js → chunk-BLCCGRKT.js} +2 -2
- package/dist/{chunk-6XFL2NER.js → chunk-BTMMUG3E.js} +2 -2
- package/dist/{chunk-4JUIEYAH.js → chunk-CEXBKXWU.js} +3 -3
- package/dist/{chunk-FESO6TDQ.js → chunk-DP2PT36G.js} +2 -2
- package/dist/chunk-GKRPR5PZ.js +322 -0
- package/dist/chunk-GKRPR5PZ.js.map +1 -0
- package/dist/{chunk-ZQNTXHBQ.js → chunk-GTV27THY.js} +2 -2
- package/dist/{chunk-ZU5YYGBJ.js → chunk-JOC3ZI56.js} +3 -29
- package/dist/chunk-JOC3ZI56.js.map +1 -0
- package/dist/{chunk-WLMPQFER.js → chunk-K2JR2NFQ.js} +4 -4
- package/dist/{chunk-YQ2G5YLI.js → chunk-KXEPBLVD.js} +10 -10
- package/dist/{chunk-T6TXYTKH.js → chunk-MEZTHMB2.js} +4 -4
- package/dist/{chunk-ZGERT23F.js → chunk-O7LJEVZO.js} +2 -2
- package/dist/{chunk-LN7GNFET.js → chunk-OPNTDMHH.js} +4 -4
- package/dist/{chunk-QKNGVBE2.js → chunk-PKJ7ODTG.js} +3 -3
- package/dist/{chunk-4DNEBVGV.js → chunk-PW6K6OJL.js} +2 -2
- package/dist/{chunk-PV6EF6NG.js → chunk-Q3NH3NPD.js} +2 -2
- package/dist/{chunk-O5264GI4.js → chunk-RL3ZTXT3.js} +4 -4
- package/dist/{chunk-D2RFP6R2.js → chunk-ULHHMZRL.js} +3 -3
- package/dist/{chunk-PEFXG5M6.js → chunk-UT3NQLCF.js} +2 -2
- package/dist/{chunk-VBZ7BG47.js → chunk-VS5F2ORN.js} +3 -3
- package/dist/{chunk-YUH3MTP3.js → chunk-W37OFBSG.js} +2 -2
- package/dist/{chunk-SKN2L5CE.js → chunk-WDBYAXZ5.js} +2 -2
- package/dist/{chunk-XK3PQZW6.js → chunk-YSFEKIYQ.js} +2 -2
- package/dist/{chunk-3XS5P5XH.js → chunk-ZHB57ORD.js} +6 -6
- package/dist/client-CGW0Cevz.d.ts +402 -0
- package/dist/client.cjs +12 -1644
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.ts +3 -7
- package/dist/client.js +27 -32
- package/dist/core/client.cjs +2 -34
- 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 -28
- package/dist/core/error.cjs.map +1 -1
- package/dist/core/error.js +3 -3
- package/dist/core/index.cjs +2 -34
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.js +4 -4
- package/dist/edge.cjs +2 -34
- package/dist/edge.cjs.map +1 -1
- package/dist/edge.js +7 -7
- package/dist/index.cjs +12 -1656
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -5
- package/dist/index.js +31 -49
- package/dist/modelrouter/core.cjs +2 -34
- package/dist/modelrouter/core.cjs.map +1 -1
- package/dist/modelrouter/core.js +5 -5
- package/dist/modelrouter/index.cjs +2 -34
- package/dist/modelrouter/index.cjs.map +1 -1
- package/dist/modelrouter/index.js +5 -5
- package/dist/subagents/anthropic.cjs +2 -34
- package/dist/subagents/anthropic.cjs.map +1 -1
- package/dist/subagents/anthropic.js +11 -11
- package/dist/subagents/vercel.cjs +2 -34
- package/dist/subagents/vercel.cjs.map +1 -1
- package/dist/subagents/vercel.js +11 -11
- package/dist/tools/codebase_search/anthropic.cjs +2 -34
- package/dist/tools/codebase_search/anthropic.cjs.map +1 -1
- package/dist/tools/codebase_search/anthropic.js +6 -6
- package/dist/tools/codebase_search/core.cjs +2 -34
- package/dist/tools/codebase_search/core.cjs.map +1 -1
- package/dist/tools/codebase_search/core.js +5 -5
- package/dist/tools/codebase_search/index.cjs +2 -34
- package/dist/tools/codebase_search/index.cjs.map +1 -1
- package/dist/tools/codebase_search/index.js +10 -10
- package/dist/tools/codebase_search/openai.cjs +2 -34
- package/dist/tools/codebase_search/openai.cjs.map +1 -1
- package/dist/tools/codebase_search/openai.js +6 -6
- package/dist/tools/codebase_search/vercel.cjs +2 -34
- package/dist/tools/codebase_search/vercel.cjs.map +1 -1
- package/dist/tools/codebase_search/vercel.js +6 -6
- package/dist/tools/compact/core.cjs +2 -34
- package/dist/tools/compact/core.cjs.map +1 -1
- package/dist/tools/compact/core.js +5 -5
- package/dist/tools/compact/index.cjs +2 -34
- package/dist/tools/compact/index.cjs.map +1 -1
- package/dist/tools/compact/index.js +6 -6
- package/dist/tools/fastapply/anthropic.cjs +2 -28
- package/dist/tools/fastapply/anthropic.cjs.map +1 -1
- package/dist/tools/fastapply/anthropic.js +7 -7
- package/dist/tools/fastapply/apply.cjs +2 -28
- package/dist/tools/fastapply/apply.cjs.map +1 -1
- package/dist/tools/fastapply/apply.js +2 -2
- package/dist/tools/fastapply/core.cjs +2 -34
- package/dist/tools/fastapply/core.cjs.map +1 -1
- package/dist/tools/fastapply/core.js +6 -6
- package/dist/tools/fastapply/index.cjs +2 -28
- package/dist/tools/fastapply/index.cjs.map +1 -1
- package/dist/tools/fastapply/index.js +11 -11
- package/dist/tools/fastapply/openai.cjs +2 -28
- package/dist/tools/fastapply/openai.cjs.map +1 -1
- package/dist/tools/fastapply/openai.js +7 -7
- package/dist/tools/fastapply/vercel.cjs +2 -28
- package/dist/tools/fastapply/vercel.cjs.map +1 -1
- package/dist/tools/fastapply/vercel.js +7 -7
- package/dist/tools/index.cjs +2 -28
- package/dist/tools/index.cjs.map +1 -1
- package/dist/tools/index.js +11 -11
- package/dist/tools/utils/resilience.cjs +2 -28
- 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 -28
- package/dist/tools/warp_grep/agent/runner.cjs.map +1 -1
- package/dist/tools/warp_grep/agent/runner.js +3 -3
- package/dist/tools/warp_grep/anthropic.cjs +2 -34
- package/dist/tools/warp_grep/anthropic.cjs.map +1 -1
- package/dist/tools/warp_grep/anthropic.js +11 -11
- package/dist/tools/warp_grep/client.cjs +2 -34
- package/dist/tools/warp_grep/client.cjs.map +1 -1
- package/dist/tools/warp_grep/client.js +10 -10
- package/dist/tools/warp_grep/gemini.cjs +2 -34
- package/dist/tools/warp_grep/gemini.cjs.map +1 -1
- package/dist/tools/warp_grep/gemini.js +10 -10
- package/dist/tools/warp_grep/harness.js +9 -9
- package/dist/tools/warp_grep/index.cjs +2 -34
- package/dist/tools/warp_grep/index.cjs.map +1 -1
- package/dist/tools/warp_grep/index.js +16 -16
- package/dist/tools/warp_grep/openai.cjs +2 -34
- package/dist/tools/warp_grep/openai.cjs.map +1 -1
- package/dist/tools/warp_grep/openai.js +11 -11
- package/dist/tools/warp_grep/providers/local.js +2 -2
- package/dist/tools/warp_grep/vercel.cjs +2 -34
- package/dist/tools/warp_grep/vercel.cjs.map +1 -1
- package/dist/tools/warp_grep/vercel.js +11 -11
- package/dist/version.cjs +2 -28
- package/dist/version.cjs.map +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -28
- 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-FUYX2MNM.js.map +0 -1
- package/dist/chunk-GJ42MYUU.js +0 -57
- package/dist/chunk-GJ42MYUU.js.map +0 -1
- package/dist/chunk-KQKLQHJF.js +0 -96
- package/dist/chunk-KQKLQHJF.js.map +0 -1
- package/dist/chunk-PIIXU2H3.js +0 -389
- package/dist/chunk-PIIXU2H3.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-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/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/vercel-CVF27qFK.d.ts +0 -74
- /package/dist/{chunk-CAFREMIT.js.map → chunk-5KQ2WRBU.js.map} +0 -0
- /package/dist/{chunk-XTFRHVCW.js.map → chunk-BLCCGRKT.js.map} +0 -0
- /package/dist/{chunk-6XFL2NER.js.map → chunk-BTMMUG3E.js.map} +0 -0
- /package/dist/{chunk-4JUIEYAH.js.map → chunk-CEXBKXWU.js.map} +0 -0
- /package/dist/{chunk-FESO6TDQ.js.map → chunk-DP2PT36G.js.map} +0 -0
- /package/dist/{chunk-ZQNTXHBQ.js.map → chunk-GTV27THY.js.map} +0 -0
- /package/dist/{chunk-WLMPQFER.js.map → chunk-K2JR2NFQ.js.map} +0 -0
- /package/dist/{chunk-YQ2G5YLI.js.map → chunk-KXEPBLVD.js.map} +0 -0
- /package/dist/{chunk-T6TXYTKH.js.map → chunk-MEZTHMB2.js.map} +0 -0
- /package/dist/{chunk-ZGERT23F.js.map → chunk-O7LJEVZO.js.map} +0 -0
- /package/dist/{chunk-LN7GNFET.js.map → chunk-OPNTDMHH.js.map} +0 -0
- /package/dist/{chunk-QKNGVBE2.js.map → chunk-PKJ7ODTG.js.map} +0 -0
- /package/dist/{chunk-4DNEBVGV.js.map → chunk-PW6K6OJL.js.map} +0 -0
- /package/dist/{chunk-PV6EF6NG.js.map → chunk-Q3NH3NPD.js.map} +0 -0
- /package/dist/{chunk-O5264GI4.js.map → chunk-RL3ZTXT3.js.map} +0 -0
- /package/dist/{chunk-D2RFP6R2.js.map → chunk-ULHHMZRL.js.map} +0 -0
- /package/dist/{chunk-PEFXG5M6.js.map → chunk-UT3NQLCF.js.map} +0 -0
- /package/dist/{chunk-VBZ7BG47.js.map → chunk-VS5F2ORN.js.map} +0 -0
- /package/dist/{chunk-YUH3MTP3.js.map → chunk-W37OFBSG.js.map} +0 -0
- /package/dist/{chunk-SKN2L5CE.js.map → chunk-WDBYAXZ5.js.map} +0 -0
- /package/dist/{chunk-XK3PQZW6.js.map → chunk-YSFEKIYQ.js.map} +0 -0
- /package/dist/{chunk-3XS5P5XH.js.map → chunk-ZHB57ORD.js.map} +0 -0
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../tools/browser/errors.ts"],"sourcesContent":["/**\n * Custom error classes for browser automation and profiles.\n *\n * @example\n * ```typescript\n * try {\n * await morph.browser.profiles.createProfile({ name: '', repoId: 'owner/repo' });\n * } catch (e) {\n * if (e instanceof MorphValidationError) {\n * console.log('Validation failed:', e.field, e.message);\n * } else if (e instanceof MorphAPIError) {\n * console.log('API error:', e.code, e.statusCode);\n * }\n * }\n * ```\n */\n\n/**\n * Error codes for Morph Browser SDK\n */\nexport type MorphErrorCode =\n // Validation errors\n | 'validation_error'\n | 'invalid_parameter'\n | 'missing_required_field'\n // Authentication errors\n | 'authentication_required'\n | 'invalid_api_key'\n | 'insufficient_permissions'\n // Resource errors\n | 'profile_not_found'\n | 'session_not_found'\n | 'resource_not_found'\n // Limit errors\n | 'profile_limit_exceeded'\n | 'rate_limit_exceeded'\n // Session errors\n | 'session_expired'\n | 'session_save_failed'\n // Network errors\n | 'network_error'\n | 'timeout'\n | 'service_unavailable';\n\n/**\n * Base error class for all Morph SDK errors.\n */\nexport class MorphError extends Error {\n /** Error code for programmatic handling */\n readonly code: MorphErrorCode;\n /** Original cause of the error, if any */\n readonly cause?: Error;\n\n constructor(message: string, code: MorphErrorCode, cause?: Error) {\n super(message);\n this.name = 'MorphError';\n this.code = code;\n this.cause = cause;\n\n // Maintains proper stack trace in V8 environments\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, this.constructor);\n }\n }\n\n /**\n * Returns a JSON representation of the error for logging.\n */\n toJSON() {\n return {\n name: this.name,\n message: this.message,\n code: this.code,\n cause: this.cause?.message,\n };\n }\n}\n\n/**\n * Error thrown when API request validation fails.\n */\nexport class MorphValidationError extends MorphError {\n /** The field that failed validation */\n readonly field?: string;\n\n constructor(message: string, field?: string) {\n super(message, 'validation_error');\n this.name = 'MorphValidationError';\n this.field = field;\n }\n\n toJSON() {\n return {\n ...super.toJSON(),\n field: this.field,\n };\n }\n}\n\n/**\n * Error thrown when an API request fails.\n */\nexport class MorphAPIError extends MorphError {\n /** HTTP status code */\n readonly statusCode: number;\n /** Request ID for debugging (if available) */\n readonly requestId?: string;\n /** Raw response body */\n readonly rawResponse?: string;\n\n constructor(\n message: string,\n code: MorphErrorCode,\n statusCode: number,\n options?: {\n requestId?: string;\n rawResponse?: string;\n cause?: Error;\n }\n ) {\n super(message, code, options?.cause);\n this.name = 'MorphAPIError';\n this.statusCode = statusCode;\n this.requestId = options?.requestId;\n this.rawResponse = options?.rawResponse;\n }\n\n toJSON() {\n return {\n ...super.toJSON(),\n statusCode: this.statusCode,\n requestId: this.requestId,\n };\n }\n}\n\n/**\n * Error thrown when authentication fails.\n */\nexport class MorphAuthenticationError extends MorphAPIError {\n constructor(message: string = 'Authentication required. Please provide a valid API key.') {\n super(message, 'authentication_required', 401);\n this.name = 'MorphAuthenticationError';\n }\n}\n\n/**\n * Error thrown when rate limit is exceeded.\n */\nexport class MorphRateLimitError extends MorphAPIError {\n /** When the rate limit resets (Unix timestamp) */\n readonly resetAt?: number;\n /** Number of seconds until reset */\n readonly retryAfter?: number;\n\n constructor(\n message: string = 'Rate limit exceeded. Please retry later.',\n options?: {\n resetAt?: number;\n retryAfter?: number;\n requestId?: string;\n }\n ) {\n super(message, 'rate_limit_exceeded', 429, { requestId: options?.requestId });\n this.name = 'MorphRateLimitError';\n this.resetAt = options?.resetAt;\n this.retryAfter = options?.retryAfter;\n }\n\n toJSON() {\n return {\n ...super.toJSON(),\n resetAt: this.resetAt,\n retryAfter: this.retryAfter,\n };\n }\n}\n\n/**\n * Error thrown when a resource is not found.\n */\nexport class MorphNotFoundError extends MorphAPIError {\n /** The type of resource that was not found */\n readonly resourceType: string;\n /** The ID of the resource that was not found */\n readonly resourceId?: string;\n\n constructor(resourceType: string, resourceId?: string) {\n const message = resourceId\n ? `${resourceType} '${resourceId}' not found`\n : `${resourceType} not found`;\n super(message, 'resource_not_found', 404);\n this.name = 'MorphNotFoundError';\n this.resourceType = resourceType;\n this.resourceId = resourceId;\n }\n\n toJSON() {\n return {\n ...super.toJSON(),\n resourceType: this.resourceType,\n resourceId: this.resourceId,\n };\n }\n}\n\n/**\n * Error thrown when profile limit is exceeded.\n */\nexport class MorphProfileLimitError extends MorphAPIError {\n /** Current number of profiles */\n readonly currentCount?: number;\n /** Maximum allowed profiles for the plan */\n readonly maxAllowed?: number;\n\n constructor(\n message: string = 'Profile limit exceeded for your plan.',\n options?: {\n currentCount?: number;\n maxAllowed?: number;\n requestId?: string;\n }\n ) {\n super(message, 'profile_limit_exceeded', 403, { requestId: options?.requestId });\n this.name = 'MorphProfileLimitError';\n this.currentCount = options?.currentCount;\n this.maxAllowed = options?.maxAllowed;\n }\n\n toJSON() {\n return {\n ...super.toJSON(),\n currentCount: this.currentCount,\n maxAllowed: this.maxAllowed,\n };\n }\n}\n\n/**\n * Parse an API error response and return the appropriate error class.\n */\nexport function parseAPIError(\n statusCode: number,\n responseText: string,\n requestId?: string\n): MorphAPIError {\n // Try to parse JSON error response\n let errorData: { detail?: string; code?: string; message?: string } = {};\n try {\n errorData = JSON.parse(responseText);\n } catch {\n // Not JSON, use raw text\n }\n\n const message = errorData.detail || errorData.message || responseText || 'Unknown error';\n const code = errorData.code;\n\n // Map status codes to specific error classes\n switch (statusCode) {\n case 401:\n return new MorphAuthenticationError(message);\n\n case 403:\n if (code === 'profile_limit_exceeded' || message.toLowerCase().includes('limit')) {\n return new MorphProfileLimitError(message, { requestId });\n }\n return new MorphAPIError(message, 'insufficient_permissions', statusCode, { requestId, rawResponse: responseText });\n\n case 404:\n if (message.toLowerCase().includes('profile')) {\n return new MorphNotFoundError('Profile', undefined);\n }\n if (message.toLowerCase().includes('session')) {\n return new MorphNotFoundError('Session', undefined);\n }\n return new MorphAPIError(message, 'resource_not_found', statusCode, { requestId, rawResponse: responseText });\n\n case 429:\n return new MorphRateLimitError(message, { requestId });\n\n case 422:\n return new MorphAPIError(message, 'validation_error', statusCode, { requestId, rawResponse: responseText });\n\n case 500:\n case 502:\n case 503:\n case 504:\n return new MorphAPIError(message, 'service_unavailable', statusCode, { requestId, rawResponse: responseText });\n\n default:\n return new MorphAPIError(message, 'network_error', statusCode, { requestId, rawResponse: responseText });\n }\n}\n"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the SDK transport.\n *\n * One place owns authentication, the Morph service hosts, default headers,\n * retries, timeouts, and error mapping. Every resource (FastApply, Compact, …)\n * holds a reference to this client and delegates HTTP to it via\n * `get`/`post`/`delete`/`request`, exactly like the OpenAI SDK.\n *\n * This module is intentionally free of tool imports and Node built-ins so it\n * stays edge-safe (it is reachable from `@morphllm/morphsdk/edge` through the\n * Compact and model-router resources).\n */\nimport { fetchWithRetry, withTimeout, MorphError, type RetryConfig } from '../tools/utils/resilience.js';\nimport { logger } from '../logger.js';\nimport { SDK_VERSION } from '../version.js';\nimport { toMorphError } from './error.js';\n\n/** The Morph services the SDK talks to. */\nconst DEFAULT_BASE_URL = 'https://api.morphllm.com';\nconst DEFAULT_REPOS_URL = 'https://repos.morphllm.com';\nconst DEFAULT_BROWSER_URL = 'https://browser.morphllm.com';\nconst DEFAULT_TIMEOUT = 60_000;\n\nconst env = (name: string): string | undefined =>\n typeof process !== 'undefined' ? process.env?.[name] : undefined;\n\nconst stripTrailingSlash = (url: string): string => url.replace(/\\/+$/, '');\n\nexport interface MorphAPIClientOptions {\n /** Morph API key. Resolved against `MORPH_API_KEY` at request time if omitted. */\n apiKey?: string;\n /** Primary API host (default `https://api.morphllm.com`). */\n baseURL?: string;\n /** Code-storage host for codebase search and git (default `https://repos.morphllm.com`). */\n reposURL?: string;\n /** Browser-automation host (default `https://browser.morphllm.com`). */\n browserURL?: string;\n /** Default per-request timeout in ms (default 60s). Resources may override per call. */\n timeout?: number;\n /** Retry policy for transient failures. */\n retryConfig?: RetryConfig;\n /** Enable debug logging. */\n debug?: boolean;\n}\n\n/** Per-request options accepted by `request`/`get`/`post`/`delete`. */\nexport interface RequestOptions {\n /** JSON body; serialized with `JSON.stringify`. */\n body?: unknown;\n /** Query parameters; `undefined`/`null` values are dropped. */\n query?: Record<string, string | number | boolean | undefined | null>;\n /** Extra headers, merged over (and able to override) the defaults. */\n headers?: Record<string, string>;\n /** Override the timeout for this call. */\n timeout?: number;\n /** Hit a different host than the default (e.g. `this._client.reposURL`). */\n baseURL?: string;\n /** Return the raw `Response` of a successful (2xx) request instead of parsed JSON (for streaming). */\n stream?: boolean;\n /**\n * Return the raw `Response` without throwing on non-2xx and without parsing.\n * For resources that map errors into their own taxonomy (e.g. GitHub).\n */\n raw?: boolean;\n /** Caller-supplied abort signal. */\n signal?: AbortSignal;\n}\n\nexport class MorphAPIClient {\n /** Explicit key as provided; resolved against env at request time. */\n apiKey?: string;\n baseURL: string;\n reposURL: string;\n browserURL: string;\n /** Explicit default timeout (ms), if set. The request default is applied lazily so\n * resources can read an undefined value and supply their own fallback. */\n timeout?: number;\n retryConfig?: RetryConfig;\n debug: boolean;\n\n constructor(options: MorphAPIClientOptions = {}) {\n this.apiKey = options.apiKey;\n this.baseURL = stripTrailingSlash(options.baseURL ?? DEFAULT_BASE_URL);\n this.reposURL = stripTrailingSlash(options.reposURL ?? env('MORPH_SEARCH_URL') ?? DEFAULT_REPOS_URL);\n this.browserURL = stripTrailingSlash(\n options.browserURL ?? (env('MORPH_ENVIRONMENT') === 'DEV' ? 'http://localhost:8000' : DEFAULT_BROWSER_URL),\n );\n this.timeout = options.timeout;\n this.retryConfig = options.retryConfig;\n this.debug = options.debug ?? false;\n if (this.debug) logger.enable();\n }\n\n /** The key actually used for requests: explicit, else `MORPH_API_KEY`. */\n resolveApiKey(): string | undefined {\n return this.apiKey ?? env('MORPH_API_KEY');\n }\n\n /** Headers shared with tools that bring their own HTTP client (FastApply/WarpGrep via the `openai` package). */\n defaultHeaders(): Record<string, string> {\n return { 'X-Morph-SDK-Version': SDK_VERSION };\n }\n\n buildURL(path: string, baseURL?: string): string {\n if (/^https?:\\/\\//i.test(path)) return path;\n const base = stripTrailingSlash(baseURL ?? this.baseURL);\n return `${base}${path.startsWith('/') ? '' : '/'}${path}`;\n }\n\n private buildHeaders(apiKey: string, extra?: Record<string, string>): Record<string, string> {\n return {\n 'Content-Type': 'application/json',\n 'X-Morph-SDK-Version': SDK_VERSION,\n Authorization: `Bearer ${apiKey}`,\n ...extra,\n };\n }\n\n private applyQuery(url: string, query?: RequestOptions['query']): string {\n if (!query) return url;\n const params = new URLSearchParams();\n for (const [key, value] of Object.entries(query)) {\n if (value !== undefined && value !== null) params.set(key, String(value));\n }\n const qs = params.toString();\n return qs ? `${url}${url.includes('?') ? '&' : '?'}${qs}` : url;\n }\n\n async request<T>(method: string, path: string, opts: RequestOptions = {}): Promise<T> {\n const apiKey = this.resolveApiKey();\n if (!apiKey) {\n throw new MorphError(\n 'Morph API key not found. Set the MORPH_API_KEY environment variable or pass apiKey in config.',\n 'missing_api_key',\n 401,\n );\n }\n\n const url = this.applyQuery(this.buildURL(path, opts.baseURL), opts.query);\n const timeout = opts.timeout ?? this.timeout ?? DEFAULT_TIMEOUT;\n\n const init: RequestInit = {\n method,\n headers: this.buildHeaders(apiKey, opts.headers),\n ...(opts.body !== undefined ? { body: JSON.stringify(opts.body) } : {}),\n ...(opts.signal ? { signal: opts.signal } : {}),\n };\n\n logger.debug('MorphAPIClient', 'request', { method, url });\n\n const response = await withTimeout(\n fetchWithRetry(url, init, this.retryConfig ?? {}),\n timeout,\n `Morph request to ${url} timed out after ${timeout}ms`,\n );\n\n if (opts.raw) return response as unknown as T;\n if (!response.ok) throw await toMorphError(response);\n if (opts.stream) return response as unknown as T;\n if (response.status === 204) return undefined as T;\n\n const text = await response.text();\n return (text ? JSON.parse(text) : undefined) as T;\n }\n\n get<T>(path: string, opts?: RequestOptions): Promise<T> {\n return this.request<T>('GET', path, opts);\n }\n\n post<T>(path: string, opts?: RequestOptions): Promise<T> {\n return this.request<T>('POST', path, opts);\n }\n\n delete<T>(path: string, opts?: RequestOptions): Promise<T> {\n return this.request<T>('DELETE', path, opts);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAkBA,IAAM,mBAAmB;AACzB,IAAM,oBAAoB;AAC1B,IAAM,sBAAsB;AAC5B,IAAM,kBAAkB;AAExB,IAAM,MAAM,CAAC,SACX,OAAO,YAAY,cAAc,QAAQ,M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AO,KAAK,MAAM,IAAI,IAAI;AAAA,EACpC;AAAA,EAEA,IAAO,MAAc,MAAmC;AACtD,WAAO,KAAK,QAAW,OAAO,MAAM,IAAI;AAAA,EAC1C;AAAA,EAEA,KAAQ,MAAc,MAAmC;AACvD,WAAO,KAAK,QAAW,QAAQ,MAAM,IAAI;AAAA,EAC3C;AAAA,EAEA,OAAU,MAAc,MAAmC;AACzD,WAAO,KAAK,QAAW,UAAU,MAAM,IAAI;AAAA,EAC7C;AACF;","names":[]}
|
package/dist/chunk-GJ42MYUU.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
BROWSER_TOOL_DESCRIPTION
|
|
3
|
-
} from "./chunk-2HMEZZKK.js";
|
|
4
|
-
import {
|
|
5
|
-
executeBrowserTask
|
|
6
|
-
} from "./chunk-YD6TNDR4.js";
|
|
7
|
-
import {
|
|
8
|
-
__export
|
|
9
|
-
} from "./chunk-PZ5AY32C.js";
|
|
10
|
-
|
|
11
|
-
// tools/browser/vercel.ts
|
|
12
|
-
var vercel_exports = {};
|
|
13
|
-
__export(vercel_exports, {
|
|
14
|
-
browserTool: () => browserTool,
|
|
15
|
-
createBrowserTool: () => createBrowserTool
|
|
16
|
-
});
|
|
17
|
-
import { tool as createTool } from "ai";
|
|
18
|
-
import { z } from "zod";
|
|
19
|
-
function createBrowserTool(config) {
|
|
20
|
-
const schema = z.object({
|
|
21
|
-
task: z.string().describe('Natural language description of what to do (e.g., "Test checkout flow for buying a pineapple")'),
|
|
22
|
-
url: z.string().optional().describe("Starting URL (e.g., https://3000-xyz.e2b.dev)"),
|
|
23
|
-
maxSteps: z.number().min(1).max(50).default(10).describe("Maximum number of browser actions to take"),
|
|
24
|
-
region: z.enum(["sfo", "lon"]).default("sfo").describe("Browserless region: sfo (US West) or lon (Europe)")
|
|
25
|
-
});
|
|
26
|
-
return createTool({
|
|
27
|
-
description: BROWSER_TOOL_DESCRIPTION,
|
|
28
|
-
inputSchema: schema,
|
|
29
|
-
execute: async (params) => {
|
|
30
|
-
const { task, url, maxSteps, region } = params;
|
|
31
|
-
const result = await executeBrowserTask(
|
|
32
|
-
{ task, url, maxSteps, region },
|
|
33
|
-
config
|
|
34
|
-
);
|
|
35
|
-
if (result.success) {
|
|
36
|
-
return {
|
|
37
|
-
success: true,
|
|
38
|
-
result: result.result,
|
|
39
|
-
stepsTaken: result.stepsTaken,
|
|
40
|
-
executionTimeMs: result.executionTimeMs
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
return {
|
|
44
|
-
success: false,
|
|
45
|
-
error: result.error
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
var browserTool = createBrowserTool();
|
|
51
|
-
|
|
52
|
-
export {
|
|
53
|
-
createBrowserTool,
|
|
54
|
-
browserTool,
|
|
55
|
-
vercel_exports
|
|
56
|
-
};
|
|
57
|
-
//# sourceMappingURL=chunk-GJ42MYUU.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../tools/browser/vercel.ts"],"sourcesContent":["/**\n * Vercel AI SDK adapter for browser automation tool\n */\n\nimport { tool as createTool } from 'ai';\nimport { z } from 'zod';\nimport { executeBrowserTask } from './core.js';\nimport type { BrowserConfig } from './types.js';\nimport { BROWSER_TOOL_DESCRIPTION } from './prompts.js';\n\n/**\n * Create Vercel AI SDK tool for browser automation\n * \n * @param config - Optional browser worker configuration\n * @returns Vercel AI SDK tool\n * \n * @example\n * ```typescript\n * import { generateText } from 'ai';\n * import { anthropic } from '@ai-sdk/anthropic';\n * import { createBrowserTool } from 'morphsdk/tools/browser/vercel';\n * \n * const browserTool = createBrowserTool({\n * apiUrl: 'https://browser-worker.example.com'\n * });\n * \n * const result = await generateText({\n * model: anthropic('claude-sonnet-4-5-20250929'),\n * tools: { browserTask: browserTool },\n * prompt: 'Test the checkout flow at https://3000-abc.e2b.dev',\n * maxSteps: 5\n * });\n * ```\n */\nexport function createBrowserTool(config?: BrowserConfig) {\n const schema = z.object({\n task: z.string().describe('Natural language description of what to do (e.g., \"Test checkout flow for buying a pineapple\")'),\n url: z.string().optional().describe('Starting URL (e.g., https://3000-xyz.e2b.dev)'),\n maxSteps: z.number().min(1).max(50).default(10).describe('Maximum number of browser actions to take'),\n region: z.enum(['sfo', 'lon']).default('sfo').describe('Browserless region: sfo (US West) or lon (Europe)'),\n });\n\n return createTool({\n description: BROWSER_TOOL_DESCRIPTION,\n inputSchema: schema,\n execute: async (params) => {\n const { task, url, maxSteps, region } = params;\n const result = await executeBrowserTask(\n { task, url, maxSteps, region },\n config\n );\n\n // Return minimal summary for agent context (to save tokens)\n // Full result with urls, errors, action_history, judgement, etc. is available\n // when calling executeBrowserTask() directly outside of agent tools\n if (result.success) {\n return {\n success: true,\n result: result.result,\n stepsTaken: result.stepsTaken,\n executionTimeMs: result.executionTimeMs,\n };\n }\n\n return {\n success: false,\n error: result.error,\n };\n },\n });\n}\n\n/**\n * Default browser tool for Vercel AI SDK\n */\nexport const browserTool = createBrowserTool();\n"],"mappings":";;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,SAAS,QAAQ,kBAAkB;AACnC,SAAS,SAAS;AA6BX,SAAS,kBAAkB,QAAwB;AACxD,QAAM,SAAS,EAAE,OAAO;AAAA,IACtB,MAAM,EAAE,OAAO,EAAE,SAAS,gGAAgG;AAAA,IAC1H,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,+CAA+C;AAAA,IACnF,UAAU,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,IAAI,EAAE,EAAE,QAAQ,EAAE,EAAE,SAAS,2CAA2C;AAAA,IACpG,QAAQ,EAAE,KAAK,CAAC,OAAO,KAAK,CAAC,EAAE,QAAQ,KAAK,EAAE,SAAS,mDAAmD;AAAA,EAC5G,CAAC;AAED,SAAO,WAAW;AAAA,IAChB,aAAa;AAAA,IACb,aAAa;AAAA,IACb,SAAS,OAAO,WAAW;AACzB,YAAM,EAAE,MAAM,KAAK,UAAU,OAAO,IAAI;AACxC,YAAM,SAAS,MAAM;AAAA,QACnB,EAAE,MAAM,KAAK,UAAU,OAAO;AAAA,QAC9B;AAAA,MACF;AAKA,UAAI,OAAO,SAAS;AAClB,eAAO;AAAA,UACL,SAAS;AAAA,UACT,QAAQ,OAAO;AAAA,UACf,YAAY,OAAO;AAAA,UACnB,iBAAiB,OAAO;AAAA,QAC1B;AAAA,MACF;AAEA,aAAO;AAAA,QACL,SAAS;AAAA,QACT,OAAO,OAAO;AAAA,MAChB;AAAA,IACF;AAAA,EACF,CAAC;AACH;AAKO,IAAM,cAAc,kBAAkB;","names":[]}
|
package/dist/chunk-KQKLQHJF.js
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
BROWSER_SYSTEM_PROMPT,
|
|
3
|
-
BROWSER_TOOL_DESCRIPTION
|
|
4
|
-
} from "./chunk-2HMEZZKK.js";
|
|
5
|
-
import {
|
|
6
|
-
executeBrowserTask
|
|
7
|
-
} from "./chunk-YD6TNDR4.js";
|
|
8
|
-
import {
|
|
9
|
-
__export
|
|
10
|
-
} from "./chunk-PZ5AY32C.js";
|
|
11
|
-
|
|
12
|
-
// tools/browser/openai.ts
|
|
13
|
-
var openai_exports = {};
|
|
14
|
-
__export(openai_exports, {
|
|
15
|
-
browserTool: () => browserTool,
|
|
16
|
-
createBrowserTool: () => createBrowserTool,
|
|
17
|
-
execute: () => execute,
|
|
18
|
-
formatResult: () => formatResult,
|
|
19
|
-
getSystemPrompt: () => getSystemPrompt
|
|
20
|
-
});
|
|
21
|
-
var browserTool = {
|
|
22
|
-
type: "function",
|
|
23
|
-
function: {
|
|
24
|
-
name: "browser_task",
|
|
25
|
-
description: BROWSER_TOOL_DESCRIPTION,
|
|
26
|
-
parameters: {
|
|
27
|
-
type: "object",
|
|
28
|
-
properties: {
|
|
29
|
-
task: {
|
|
30
|
-
type: "string",
|
|
31
|
-
description: 'Natural language description of what to do (e.g., "Test checkout flow for buying a pineapple")'
|
|
32
|
-
},
|
|
33
|
-
url: {
|
|
34
|
-
type: "string",
|
|
35
|
-
description: "Starting URL (e.g., https://3000-xyz.e2b.dev). Required if navigating to a specific page."
|
|
36
|
-
},
|
|
37
|
-
maxSteps: {
|
|
38
|
-
type: "number",
|
|
39
|
-
description: "Maximum number of browser actions to take (1-50). Default: 10. Use 15-30 for complex flows.",
|
|
40
|
-
default: 10
|
|
41
|
-
},
|
|
42
|
-
region: {
|
|
43
|
-
type: "string",
|
|
44
|
-
enum: ["sfo", "lon"],
|
|
45
|
-
description: "Browserless region: sfo (US West Coast) or lon (Europe). Default: sfo.",
|
|
46
|
-
default: "sfo"
|
|
47
|
-
}
|
|
48
|
-
},
|
|
49
|
-
required: ["task"]
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
async function execute(input, config) {
|
|
54
|
-
const parsedInput = typeof input === "string" ? JSON.parse(input) : input;
|
|
55
|
-
return executeBrowserTask(parsedInput, config);
|
|
56
|
-
}
|
|
57
|
-
function formatResult(result) {
|
|
58
|
-
if (result.success) {
|
|
59
|
-
const parts = [
|
|
60
|
-
"\u2705 Browser task completed successfully",
|
|
61
|
-
`Steps taken: ${result.stepsTaken ?? 0}`,
|
|
62
|
-
result.executionTimeMs ? `Execution time: ${result.executionTimeMs}ms` : null,
|
|
63
|
-
"",
|
|
64
|
-
"Result:",
|
|
65
|
-
result.result || "Task completed"
|
|
66
|
-
];
|
|
67
|
-
return parts.filter(Boolean).join("\n");
|
|
68
|
-
}
|
|
69
|
-
return `\u274C Browser task failed: ${result.error || "Unknown error"}`;
|
|
70
|
-
}
|
|
71
|
-
function getSystemPrompt() {
|
|
72
|
-
return BROWSER_SYSTEM_PROMPT;
|
|
73
|
-
}
|
|
74
|
-
function createBrowserTool(config) {
|
|
75
|
-
return Object.assign({}, browserTool, {
|
|
76
|
-
execute: async (input) => {
|
|
77
|
-
return execute(input, config);
|
|
78
|
-
},
|
|
79
|
-
formatResult: (result) => {
|
|
80
|
-
return formatResult(result);
|
|
81
|
-
},
|
|
82
|
-
getSystemPrompt: () => {
|
|
83
|
-
return getSystemPrompt();
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export {
|
|
89
|
-
browserTool,
|
|
90
|
-
execute,
|
|
91
|
-
formatResult,
|
|
92
|
-
getSystemPrompt,
|
|
93
|
-
createBrowserTool,
|
|
94
|
-
openai_exports
|
|
95
|
-
};
|
|
96
|
-
//# sourceMappingURL=chunk-KQKLQHJF.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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":[]}
|
package/dist/chunk-PIIXU2H3.js
DELETED
|
@@ -1,389 +0,0 @@
|
|
|
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-FESO6TDQ.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-PIIXU2H3.js.map
|