@morphllm/morphsdk 0.2.198 → 0.2.200
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -147
- package/dist/{chunk-ZQNTXHBQ.js → chunk-3CCWSLQW.js} +2 -2
- package/dist/{chunk-FESO6TDQ.js → chunk-7I2A7GGJ.js} +2 -2
- package/dist/{chunk-4JUIEYAH.js → chunk-AKSXZBPT.js} +3 -3
- package/dist/chunk-B4X5RWLR.js +271 -0
- package/dist/chunk-B4X5RWLR.js.map +1 -0
- package/dist/{chunk-QKNGVBE2.js → chunk-L6YOMTFU.js} +3 -3
- package/dist/{chunk-YQ2G5YLI.js → chunk-MLROWLS6.js} +4 -4
- package/dist/{chunk-4DNEBVGV.js → chunk-MPL6BDR6.js} +2 -2
- package/dist/{chunk-3XS5P5XH.js → chunk-PD3EDFQD.js} +2 -2
- package/dist/{chunk-CAFREMIT.js → chunk-PJNL35DC.js} +2 -2
- package/dist/{chunk-PEFXG5M6.js → chunk-Q65LL6UM.js} +2 -2
- package/dist/{chunk-YUH3MTP3.js → chunk-QTBFL4DG.js} +2 -2
- package/dist/{chunk-XTFRHVCW.js → chunk-SNYHVDE4.js} +4 -4
- package/dist/{chunk-ZGERT23F.js → chunk-TIMDDHYB.js} +4 -4
- package/dist/{chunk-PV6EF6NG.js → chunk-UHIANNKC.js} +4 -4
- package/dist/{chunk-FUYX2MNM.js → chunk-UKAAT6KT.js} +4 -10
- package/dist/chunk-UKAAT6KT.js.map +1 -0
- package/dist/{chunk-ZU5YYGBJ.js → chunk-UZ42MHTR.js} +3 -63
- package/dist/chunk-UZ42MHTR.js.map +1 -0
- package/dist/{chunk-XK3PQZW6.js → chunk-WTENYKJP.js} +2 -2
- package/dist/{chunk-6XFL2NER.js → chunk-XTLPA7ZP.js} +2 -2
- package/dist/{chunk-D2RFP6R2.js → chunk-Z57GJLCG.js} +3 -3
- package/dist/{chunk-SKN2L5CE.js → chunk-ZE64EWUV.js} +2 -2
- package/dist/client-BWhi-vSj.d.ts +341 -0
- package/dist/client.cjs +88 -2086
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.ts +4 -10
- package/dist/client.js +20 -30
- package/dist/core/client.cjs +2 -68
- package/dist/core/client.cjs.map +1 -1
- package/dist/core/client.d.ts +0 -8
- package/dist/core/client.js +4 -4
- package/dist/core/error.cjs +2 -62
- package/dist/core/error.cjs.map +1 -1
- package/dist/core/error.js +3 -3
- package/dist/core/index.cjs +2 -68
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.js +4 -4
- package/dist/edge.cjs +2 -68
- package/dist/edge.cjs.map +1 -1
- package/dist/edge.js +7 -7
- package/dist/index.cjs +89 -2101
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -8
- package/dist/index.js +21 -47
- package/dist/modelrouter/core.cjs +2 -68
- package/dist/modelrouter/core.cjs.map +1 -1
- package/dist/modelrouter/core.js +5 -5
- package/dist/modelrouter/index.cjs +2 -68
- package/dist/modelrouter/index.cjs.map +1 -1
- package/dist/modelrouter/index.js +5 -5
- package/dist/subagents/anthropic.cjs +2 -68
- package/dist/subagents/anthropic.cjs.map +1 -1
- package/dist/subagents/anthropic.d.ts +1 -1
- package/dist/subagents/anthropic.js +9 -9
- package/dist/subagents/index.d.ts +1 -1
- package/dist/subagents/prompts.d.ts +1 -1
- package/dist/subagents/types.d.ts +1 -1
- package/dist/subagents/vercel.cjs +2 -68
- package/dist/subagents/vercel.cjs.map +1 -1
- package/dist/subagents/vercel.d.ts +1 -1
- package/dist/subagents/vercel.js +9 -9
- package/dist/tools/compact/core.cjs +2 -68
- package/dist/tools/compact/core.cjs.map +1 -1
- package/dist/tools/compact/core.js +5 -5
- package/dist/tools/compact/index.cjs +2 -68
- package/dist/tools/compact/index.cjs.map +1 -1
- package/dist/tools/compact/index.js +6 -6
- package/dist/tools/fastapply/anthropic.cjs +2 -62
- package/dist/tools/fastapply/anthropic.cjs.map +1 -1
- package/dist/tools/fastapply/anthropic.js +7 -7
- package/dist/tools/fastapply/apply.cjs +2 -62
- package/dist/tools/fastapply/apply.cjs.map +1 -1
- package/dist/tools/fastapply/apply.js +2 -2
- package/dist/tools/fastapply/core.cjs +2 -68
- package/dist/tools/fastapply/core.cjs.map +1 -1
- package/dist/tools/fastapply/core.js +6 -6
- package/dist/tools/fastapply/index.cjs +2 -62
- package/dist/tools/fastapply/index.cjs.map +1 -1
- package/dist/tools/fastapply/index.js +13 -13
- package/dist/tools/fastapply/openai.cjs +2 -62
- package/dist/tools/fastapply/openai.cjs.map +1 -1
- package/dist/tools/fastapply/openai.js +7 -7
- package/dist/tools/fastapply/vercel.cjs +2 -62
- package/dist/tools/fastapply/vercel.cjs.map +1 -1
- package/dist/tools/fastapply/vercel.js +7 -7
- package/dist/tools/index.cjs +2 -62
- package/dist/tools/index.cjs.map +1 -1
- package/dist/tools/index.js +13 -13
- package/dist/tools/utils/resilience.cjs +2 -62
- package/dist/tools/utils/resilience.cjs.map +1 -1
- package/dist/tools/utils/resilience.js +2 -2
- package/dist/tools/warp_grep/agent/runner.cjs +2 -62
- package/dist/tools/warp_grep/agent/runner.cjs.map +1 -1
- package/dist/tools/warp_grep/agent/runner.js +2 -2
- package/dist/tools/warp_grep/anthropic.cjs +2 -68
- package/dist/tools/warp_grep/anthropic.cjs.map +1 -1
- package/dist/tools/warp_grep/anthropic.d.ts +1 -1
- package/dist/tools/warp_grep/anthropic.js +9 -9
- package/dist/tools/warp_grep/client.cjs +2 -68
- package/dist/tools/warp_grep/client.cjs.map +1 -1
- package/dist/tools/warp_grep/client.d.ts +1 -1
- package/dist/tools/warp_grep/client.js +8 -8
- package/dist/tools/warp_grep/gemini.cjs +2 -68
- package/dist/tools/warp_grep/gemini.cjs.map +1 -1
- package/dist/tools/warp_grep/gemini.d.ts +1 -1
- package/dist/tools/warp_grep/gemini.js +8 -8
- package/dist/tools/warp_grep/index.cjs +2 -68
- package/dist/tools/warp_grep/index.cjs.map +1 -1
- package/dist/tools/warp_grep/index.d.ts +1 -1
- package/dist/tools/warp_grep/index.js +8 -8
- package/dist/tools/warp_grep/openai.cjs +2 -68
- package/dist/tools/warp_grep/openai.cjs.map +1 -1
- package/dist/tools/warp_grep/openai.d.ts +1 -1
- package/dist/tools/warp_grep/openai.js +9 -9
- package/dist/tools/warp_grep/providers/code_storage_http.d.ts +1 -1
- package/dist/tools/warp_grep/providers/remote.d.ts +1 -1
- package/dist/tools/warp_grep/vercel.cjs +2 -68
- package/dist/tools/warp_grep/vercel.cjs.map +1 -1
- package/dist/tools/warp_grep/vercel.d.ts +1 -1
- package/dist/tools/warp_grep/vercel.js +9 -9
- package/dist/{types-qwD753FR.d.ts → types-DxZLPogx.d.ts} +1 -1
- package/dist/version.cjs +2 -62
- package/dist/version.cjs.map +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -62
- package/dist/anthropic-B6my2oBx.d.ts +0 -56
- package/dist/chunk-2AMEQAO2.js +0 -46
- package/dist/chunk-2AMEQAO2.js.map +0 -1
- package/dist/chunk-2HMEZZKK.js +0 -44
- package/dist/chunk-2HMEZZKK.js.map +0 -1
- package/dist/chunk-2VERUKO2.js +0 -177
- package/dist/chunk-2VERUKO2.js.map +0 -1
- package/dist/chunk-EMURAU6J.js +0 -148
- package/dist/chunk-EMURAU6J.js.map +0 -1
- package/dist/chunk-FUYX2MNM.js.map +0 -1
- package/dist/chunk-GJ42MYUU.js +0 -57
- package/dist/chunk-GJ42MYUU.js.map +0 -1
- package/dist/chunk-IDMKQWQG.js +0 -214
- package/dist/chunk-IDMKQWQG.js.map +0 -1
- package/dist/chunk-KQKLQHJF.js +0 -96
- package/dist/chunk-KQKLQHJF.js.map +0 -1
- package/dist/chunk-O5264GI4.js +0 -58
- package/dist/chunk-O5264GI4.js.map +0 -1
- package/dist/chunk-PIIXU2H3.js +0 -389
- package/dist/chunk-PIIXU2H3.js.map +0 -1
- package/dist/chunk-T6TXYTKH.js +0 -83
- package/dist/chunk-T6TXYTKH.js.map +0 -1
- package/dist/chunk-TLXVGE4R.js +0 -42
- package/dist/chunk-TLXVGE4R.js.map +0 -1
- package/dist/chunk-VBZ7BG47.js +0 -97
- package/dist/chunk-VBZ7BG47.js.map +0 -1
- package/dist/chunk-WLMPQFER.js +0 -128
- package/dist/chunk-WLMPQFER.js.map +0 -1
- package/dist/chunk-XH6KJJDI.js +0 -80
- package/dist/chunk-XH6KJJDI.js.map +0 -1
- package/dist/chunk-YD6TNDR4.js +0 -622
- package/dist/chunk-YD6TNDR4.js.map +0 -1
- package/dist/chunk-YHZJYCOU.js +0 -680
- package/dist/chunk-YHZJYCOU.js.map +0 -1
- package/dist/chunk-YQMPVJ2L.js +0 -32
- package/dist/chunk-YQMPVJ2L.js.map +0 -1
- package/dist/chunk-YTYCHRQ2.js +0 -106
- package/dist/chunk-YTYCHRQ2.js.map +0 -1
- package/dist/chunk-ZU5YYGBJ.js.map +0 -1
- package/dist/client-DCeydotn.d.ts +0 -1015
- package/dist/openai-BQMeDFef.d.ts +0 -81
- package/dist/otel-CG0uqXjp.d.ts +0 -42
- package/dist/tools/browser/anthropic.cjs +0 -645
- package/dist/tools/browser/anthropic.cjs.map +0 -1
- package/dist/tools/browser/anthropic.d.ts +0 -4
- package/dist/tools/browser/anthropic.js +0 -22
- package/dist/tools/browser/anthropic.js.map +0 -1
- package/dist/tools/browser/core.cjs +0 -1821
- package/dist/tools/browser/core.cjs.map +0 -1
- package/dist/tools/browser/core.d.ts +0 -245
- package/dist/tools/browser/core.js +0 -32
- package/dist/tools/browser/core.js.map +0 -1
- package/dist/tools/browser/errors.cjs +0 -208
- package/dist/tools/browser/errors.cjs.map +0 -1
- package/dist/tools/browser/errors.d.ts +0 -158
- package/dist/tools/browser/errors.js +0 -22
- package/dist/tools/browser/errors.js.map +0 -1
- package/dist/tools/browser/index.cjs +0 -2159
- package/dist/tools/browser/index.cjs.map +0 -1
- package/dist/tools/browser/index.d.ts +0 -134
- package/dist/tools/browser/index.js +0 -163
- package/dist/tools/browser/index.js.map +0 -1
- package/dist/tools/browser/live.cjs +0 -134
- package/dist/tools/browser/live.cjs.map +0 -1
- package/dist/tools/browser/live.d.ts +0 -75
- package/dist/tools/browser/live.js +0 -16
- package/dist/tools/browser/live.js.map +0 -1
- package/dist/tools/browser/openai.cjs +0 -661
- package/dist/tools/browser/openai.cjs.map +0 -1
- package/dist/tools/browser/openai.d.ts +0 -4
- package/dist/tools/browser/openai.js +0 -28
- package/dist/tools/browser/openai.js.map +0 -1
- package/dist/tools/browser/profiles/core.cjs +0 -932
- package/dist/tools/browser/profiles/core.cjs.map +0 -1
- package/dist/tools/browser/profiles/core.d.ts +0 -187
- package/dist/tools/browser/profiles/core.js +0 -30
- package/dist/tools/browser/profiles/core.js.map +0 -1
- package/dist/tools/browser/profiles/index.cjs +0 -932
- package/dist/tools/browser/profiles/index.cjs.map +0 -1
- package/dist/tools/browser/profiles/index.d.ts +0 -4
- package/dist/tools/browser/profiles/index.js +0 -30
- package/dist/tools/browser/profiles/index.js.map +0 -1
- package/dist/tools/browser/profiles/types.cjs +0 -74
- package/dist/tools/browser/profiles/types.cjs.map +0 -1
- package/dist/tools/browser/profiles/types.d.ts +0 -195
- package/dist/tools/browser/profiles/types.js +0 -16
- package/dist/tools/browser/profiles/types.js.map +0 -1
- package/dist/tools/browser/prompts.cjs +0 -69
- package/dist/tools/browser/prompts.cjs.map +0 -1
- package/dist/tools/browser/prompts.d.ts +0 -7
- package/dist/tools/browser/prompts.js +0 -10
- package/dist/tools/browser/prompts.js.map +0 -1
- package/dist/tools/browser/types.cjs +0 -19
- package/dist/tools/browser/types.cjs.map +0 -1
- package/dist/tools/browser/types.d.ts +0 -338
- package/dist/tools/browser/types.js +0 -1
- package/dist/tools/browser/types.js.map +0 -1
- package/dist/tools/browser/vercel.cjs +0 -622
- package/dist/tools/browser/vercel.cjs.map +0 -1
- package/dist/tools/browser/vercel.d.ts +0 -4
- package/dist/tools/browser/vercel.js +0 -22
- package/dist/tools/browser/vercel.js.map +0 -1
- package/dist/tools/codebase_search/anthropic.cjs +0 -696
- package/dist/tools/codebase_search/anthropic.cjs.map +0 -1
- package/dist/tools/codebase_search/anthropic.d.ts +0 -40
- package/dist/tools/codebase_search/anthropic.js +0 -16
- package/dist/tools/codebase_search/anthropic.js.map +0 -1
- package/dist/tools/codebase_search/core.cjs +0 -638
- package/dist/tools/codebase_search/core.cjs.map +0 -1
- package/dist/tools/codebase_search/core.d.ts +0 -51
- package/dist/tools/codebase_search/core.js +0 -16
- package/dist/tools/codebase_search/core.js.map +0 -1
- package/dist/tools/codebase_search/index.cjs +0 -821
- package/dist/tools/codebase_search/index.cjs.map +0 -1
- package/dist/tools/codebase_search/index.d.ts +0 -12
- package/dist/tools/codebase_search/index.js +0 -32
- package/dist/tools/codebase_search/index.js.map +0 -1
- package/dist/tools/codebase_search/openai.cjs +0 -745
- package/dist/tools/codebase_search/openai.cjs.map +0 -1
- package/dist/tools/codebase_search/openai.d.ts +0 -87
- package/dist/tools/codebase_search/openai.js +0 -26
- package/dist/tools/codebase_search/openai.js.map +0 -1
- package/dist/tools/codebase_search/prompts.cjs +0 -57
- package/dist/tools/codebase_search/prompts.cjs.map +0 -1
- package/dist/tools/codebase_search/prompts.d.ts +0 -7
- package/dist/tools/codebase_search/prompts.js +0 -10
- package/dist/tools/codebase_search/prompts.js.map +0 -1
- package/dist/tools/codebase_search/types.cjs +0 -19
- package/dist/tools/codebase_search/types.cjs.map +0 -1
- package/dist/tools/codebase_search/types.d.ts +0 -50
- package/dist/tools/codebase_search/types.js +0 -1
- package/dist/tools/codebase_search/types.js.map +0 -1
- package/dist/tools/codebase_search/vercel.cjs +0 -658
- package/dist/tools/codebase_search/vercel.cjs.map +0 -1
- package/dist/tools/codebase_search/vercel.d.ts +0 -65
- package/dist/tools/codebase_search/vercel.js +0 -20
- package/dist/tools/codebase_search/vercel.js.map +0 -1
- package/dist/tracing/core.cjs +0 -410
- package/dist/tracing/core.cjs.map +0 -1
- package/dist/tracing/core.d.ts +0 -58
- package/dist/tracing/core.js +0 -12
- package/dist/tracing/core.js.map +0 -1
- package/dist/tracing/index.cjs +0 -422
- package/dist/tracing/index.cjs.map +0 -1
- package/dist/tracing/index.d.ts +0 -5
- package/dist/tracing/index.js +0 -17
- package/dist/tracing/index.js.map +0 -1
- package/dist/tracing/interaction.cjs +0 -273
- package/dist/tracing/interaction.cjs.map +0 -1
- package/dist/tracing/interaction.d.ts +0 -41
- package/dist/tracing/interaction.js +0 -11
- package/dist/tracing/interaction.js.map +0 -1
- package/dist/tracing/otel.cjs +0 -56
- package/dist/tracing/otel.cjs.map +0 -1
- package/dist/tracing/otel.d.ts +0 -2
- package/dist/tracing/otel.js +0 -10
- package/dist/tracing/otel.js.map +0 -1
- package/dist/tracing/types.cjs +0 -19
- package/dist/tracing/types.cjs.map +0 -1
- package/dist/tracing/types.d.ts +0 -124
- package/dist/tracing/types.js +0 -1
- package/dist/tracing/types.js.map +0 -1
- package/dist/vercel-CVF27qFK.d.ts +0 -74
- /package/dist/{chunk-ZQNTXHBQ.js.map → chunk-3CCWSLQW.js.map} +0 -0
- /package/dist/{chunk-FESO6TDQ.js.map → chunk-7I2A7GGJ.js.map} +0 -0
- /package/dist/{chunk-4JUIEYAH.js.map → chunk-AKSXZBPT.js.map} +0 -0
- /package/dist/{chunk-QKNGVBE2.js.map → chunk-L6YOMTFU.js.map} +0 -0
- /package/dist/{chunk-YQ2G5YLI.js.map → chunk-MLROWLS6.js.map} +0 -0
- /package/dist/{chunk-4DNEBVGV.js.map → chunk-MPL6BDR6.js.map} +0 -0
- /package/dist/{chunk-3XS5P5XH.js.map → chunk-PD3EDFQD.js.map} +0 -0
- /package/dist/{chunk-CAFREMIT.js.map → chunk-PJNL35DC.js.map} +0 -0
- /package/dist/{chunk-PEFXG5M6.js.map → chunk-Q65LL6UM.js.map} +0 -0
- /package/dist/{chunk-YUH3MTP3.js.map → chunk-QTBFL4DG.js.map} +0 -0
- /package/dist/{chunk-XTFRHVCW.js.map → chunk-SNYHVDE4.js.map} +0 -0
- /package/dist/{chunk-ZGERT23F.js.map → chunk-TIMDDHYB.js.map} +0 -0
- /package/dist/{chunk-PV6EF6NG.js.map → chunk-UHIANNKC.js.map} +0 -0
- /package/dist/{chunk-XK3PQZW6.js.map → chunk-WTENYKJP.js.map} +0 -0
- /package/dist/{chunk-6XFL2NER.js.map → chunk-XTLPA7ZP.js.map} +0 -0
- /package/dist/{chunk-D2RFP6R2.js.map → chunk-Z57GJLCG.js.map} +0 -0
- /package/dist/{chunk-SKN2L5CE.js.map → chunk-ZE64EWUV.js.map} +0 -0
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../tracing/interaction.ts"],"sourcesContent":["/**\n * Morph Tracing — interactions, tools, and manual spans.\n *\n * An `Interaction` is one user turn / agent run. It threads association\n * properties (user_id / convo_id / event_id) onto every span created inside it —\n * including the auto-instrumented LLM spans — so a whole conversation stitches\n * together in the Morph UI. Built on Traceloop's `withTask` / `withTool` and a\n * manual tracer for already-completed tool spans.\n */\nimport { context, SpanStatusCode, trace, type Span } from '@opentelemetry/api';\nimport * as traceloop from '@traceloop/node-server-sdk';\n\nimport { metadata as buildMetadata } from './otel.js';\nimport type {\n FinishOptions,\n SpanParams,\n ToolParams,\n ToolSpan,\n TrackToolParams,\n TraceContext,\n} from './types.js';\n\n// Traceloop semantic-convention attribute keys.\nconst ASSOC = 'traceloop.association.properties.';\nconst ENTITY_INPUT = 'traceloop.entity.input';\nconst ENTITY_OUTPUT = 'traceloop.entity.output';\nconst ENTITY_NAME = 'traceloop.entity.name';\nconst SPAN_KIND = 'traceloop.span.kind';\n\nfunction uuid(): string {\n const c = (globalThis as { crypto?: { randomUUID?: () => string } }).crypto;\n if (c?.randomUUID) return c.randomUUID();\n return 'xxxxxxxxxxxx4xxxyxxx'.replace(/[xy]/g, (ch) => {\n const r = (Math.random() * 16) | 0;\n return (ch === 'x' ? r : (r & 0x3) | 0x8).toString(16);\n });\n}\n\nfunction asString(v: unknown): string {\n if (v == null) return '';\n return typeof v === 'string' ? v : JSON.stringify(v);\n}\n\nexport interface Interaction {\n getEventId(): string | undefined;\n setInput(input: string): void;\n setProperty(key: string, value: string): void;\n setProperties(props: Record<string, string>): void;\n /**\n * Run `fn` with this interaction's association properties active — required so\n * auto-instrumented OpenAI/Anthropic spans inherit user_id / convo_id / tags.\n */\n run<T>(fn: () => Promise<T> | T): Promise<T>;\n /** Run `fn` inside a traced task span; LLM calls within inherit attribution. */\n withSpan<T>(params: SpanParams | string, fn: () => Promise<T> | T): Promise<T>;\n /** Run `fn` inside a traced tool span. */\n withTool<T>(params: ToolParams | string, fn: () => Promise<T> | T): Promise<T>;\n /** Start a tool span you end manually. */\n startToolSpan(params: ToolParams | string): ToolSpan;\n /** Record an already-completed tool invocation. */\n trackTool(params: TrackToolParams): void;\n /** Metadata for the Vercel AI SDK `experimental_telemetry.metadata`. */\n vercelAiSdkMetadata(): Record<string, string>;\n /** End the interaction with its final output. */\n finish(opts: FinishOptions | string): Promise<void>;\n}\n\nexport type Tracer = Pick<Interaction, 'withSpan' | 'withTool' | 'startToolSpan' | 'trackTool'>;\n\n/** Build the association-property bag Traceloop propagates onto child spans. */\nfunction associationProps(\n ctx: TraceContext & { userId?: string },\n extra: Record<string, string>,\n): Record<string, string> {\n const props: Record<string, string> = { ...extra };\n if (ctx.userId) props.user_id = ctx.userId;\n if (ctx.convoId) props.convo_id = ctx.convoId;\n if (ctx.eventId) props.event_id = ctx.eventId;\n if (ctx.event) props.event_name = ctx.event;\n return props;\n}\n\nexport function createInteractionApi(\n initial: TraceContext & { userId?: string },\n traceContent: boolean,\n onClose?: (eventId: string) => void,\n): Interaction {\n const ctx: TraceContext & { userId?: string } = {\n ...initial,\n eventId: initial.eventId ?? uuid(),\n };\n const properties: Record<string, string> = { ...(initial.properties ?? {}) };\n let input = initial.input;\n let workflowSpan: Span | null = null;\n let finished = false;\n\n const withAssoc = <T>(fn: () => Promise<T> | T): Promise<T> | T =>\n traceloop.withAssociationProperties(associationProps(ctx, properties), fn);\n\n const workflowName = () => ctx.event ?? 'interaction';\n\n /** Open the interaction workflow span once; stays active until finish(). */\n function ensureWorkflowSpan(): Span {\n if (workflowSpan) return workflowSpan;\n const span = traceloop.getTraceloopTracer().startSpan(workflowName());\n span.setAttribute(SPAN_KIND, 'workflow');\n for (const [k, v] of Object.entries(associationProps(ctx, properties))) {\n span.setAttribute(ASSOC + k, v);\n }\n if (traceContent && input) span.setAttribute(ENTITY_INPUT, input);\n workflowSpan = span;\n return span;\n }\n\n /** Run fn with association props and the workflow span as the active parent. */\n function withWorkflowContext<T>(fn: () => Promise<T> | T): Promise<T> | T {\n return withAssoc(() => {\n const span = ensureWorkflowSpan();\n return context.with(trace.setSpan(context.active(), span), fn);\n });\n }\n\n /** Close the workflow span exactly once, applying final attributes. */\n function closeWorkflowSpan(apply: (span: Span) => void): void {\n if (finished) return;\n withAssoc(() => {\n const span = ensureWorkflowSpan();\n apply(span);\n span.end();\n });\n workflowSpan = null;\n finished = true;\n onClose?.(ctx.eventId!);\n }\n\n /** Record an exception + ERROR status on the workflow span, then close it. */\n function failWorkflowSpan(err: unknown): void {\n const e = err instanceof Error ? err : new Error(String(err));\n closeWorkflowSpan((span) => {\n span.recordException(e);\n span.setStatus({ code: SpanStatusCode.ERROR, message: e.message });\n if (traceContent) span.setAttribute(ENTITY_OUTPUT, `ERROR: ${e.message}`);\n });\n }\n\n const toolName = (p: ToolParams | string) => (typeof p === 'string' ? p : p.name);\n\n function startToolSpan(params: ToolParams | string): ToolSpan {\n const name = toolName(params);\n const span: Span = traceloop.getTraceloopTracer().startSpan(name);\n span.setAttribute(SPAN_KIND, 'tool');\n span.setAttribute(ENTITY_NAME, name);\n for (const [k, v] of Object.entries(associationProps(ctx, properties))) {\n span.setAttribute(ASSOC + k, v);\n }\n if (typeof params !== 'string' && params.properties) {\n for (const [k, v] of Object.entries(params.properties)) span.setAttribute(k, v);\n }\n return {\n setInput(value: unknown) {\n if (traceContent) span.setAttribute(ENTITY_INPUT, asString(value));\n },\n setOutput(value: unknown) {\n if (traceContent) span.setAttribute(ENTITY_OUTPUT, asString(value));\n },\n setError(error: Error | string) {\n const e = typeof error === 'string' ? new Error(error) : error;\n span.recordException(e);\n span.setStatus({ code: SpanStatusCode.ERROR, message: e.message });\n },\n end() {\n span.end();\n },\n };\n }\n\n return {\n getEventId: () => ctx.eventId,\n setInput(value: string) {\n input = value;\n },\n setProperty(key: string, value: string) {\n properties[key] = value;\n },\n setProperties(props: Record<string, string>) {\n Object.assign(properties, props);\n },\n vercelAiSdkMetadata() {\n return buildMetadata({\n userId: ctx.userId ?? 'unknown',\n convoId: ctx.convoId,\n eventName: ctx.event,\n eventId: ctx.eventId,\n properties,\n });\n },\n async run(fn) {\n try {\n return await Promise.resolve(withWorkflowContext(fn));\n } catch (err) {\n // Natively record the failure on the workflow span and ship it, so a\n // throwing interaction still lands in the trace as an errored span.\n failWorkflowSpan(err);\n throw err;\n }\n },\n withSpan(params, fn) {\n const name = typeof params === 'string' ? params : params.name;\n return Promise.resolve(withWorkflowContext(() => traceloop.withTask({ name }, fn)));\n },\n withTool(params, fn) {\n const name = toolName(params);\n const version = typeof params === 'string' ? undefined : params.version;\n return Promise.resolve(withWorkflowContext(() => traceloop.withTool({ name, version }, fn)));\n },\n startToolSpan,\n trackTool(params: TrackToolParams) {\n const span = startToolSpan({ name: params.name, properties: params.properties });\n if (params.input !== undefined) span.setInput(params.input);\n if (params.output !== undefined) span.setOutput(params.output);\n if (params.error) span.setError(params.error);\n span.end();\n },\n async finish(opts) {\n const output = typeof opts === 'string' ? opts : opts.output;\n if (typeof opts !== 'string' && opts.properties) Object.assign(properties, opts.properties);\n // No-op if run() already closed the span on error; otherwise end it now.\n // (Creates one if finish() is called alone, i.e. begin() → finish().)\n closeWorkflowSpan((span) => {\n if (traceContent) span.setAttribute(ENTITY_OUTPUT, output);\n });\n },\n };\n}\n\n/**\n * Inert Interaction for disabled instances. Preserves control flow — run() /\n * withTool() still execute their callback and rethrow errors — but never touches\n * the tracer. Required because the OTel provider is a process-wide singleton: a\n * disabled instance that created real spans would ship them through whichever\n * enabled instance registered the provider.\n */\nexport function createNoopInteraction(initial: TraceContext & { userId?: string }): Interaction {\n const ctx: TraceContext & { userId?: string } = {\n ...initial,\n eventId: initial.eventId ?? uuid(),\n };\n const properties: Record<string, string> = { ...(initial.properties ?? {}) };\n const noopToolSpan: ToolSpan = { setInput() {}, setOutput() {}, setError() {}, end() {} };\n\n return {\n getEventId: () => ctx.eventId,\n setInput() {},\n setProperty(key: string, value: string) {\n properties[key] = value;\n },\n setProperties(props: Record<string, string>) {\n Object.assign(properties, props);\n },\n vercelAiSdkMetadata() {\n return buildMetadata({\n userId: ctx.userId ?? 'unknown',\n convoId: ctx.convoId,\n eventName: ctx.event,\n eventId: ctx.eventId,\n properties,\n });\n },\n async run(fn) {\n return await fn();\n },\n async withSpan(_params, fn) {\n return await fn();\n },\n async withTool(_params, fn) {\n return await fn();\n },\n startToolSpan: () => noopToolSpan,\n trackTool() {},\n async finish() {},\n };\n}\n"],"mappings":";;;;;AASA,SAAS,SAAS,gBAAgB,aAAwB;AAC1D,YAAY,eAAe;AAa3B,IAAM,QAAQ;AACd,IAAM,eAAe;AACrB,IAAM,gBAAgB;AACtB,IAAM,cAAc;AACpB,IAAM,YAAY;AAElB,SAAS,OAAe;AACtB,QAAM,IAAK,WAA0D;AACrE,MAAI,GAAG,WAAY,QAAO,EAAE,WAAW;AACvC,SAAO,uBAAuB,QAAQ,SAAS,CAAC,OAAO;AACrD,UAAM,IAAK,KAAK,OAAO,IAAI,KAAM;AACjC,YAAQ,OAAO,MAAM,IAAK,IAAI,IAAO,GAAK,SAAS,EAAE;AAAA,EACvD,CAAC;AACH;AAEA,SAAS,SAAS,GAAoB;AACpC,MAAI,KAAK,KAAM,QAAO;AACtB,SAAO,OAAO,MAAM,WAAW,IAAI,KAAK,UAAU,CAAC;AACrD;AA6BA,SAAS,iBACP,KACA,OACwB;AACxB,QAAM,QAAgC,EAAE,G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G;AAAA,IAClB;AAAA,IACA,eAAe,MAAM;AAAA,IACrB,YAAY;AAAA,IAAC;AAAA,IACb,MAAM,SAAS;AAAA,IAAC;AAAA,EAClB;AACF;","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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
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
executeCodebaseSearch
|
|
3
|
-
} from "./chunk-VBZ7BG47.js";
|
|
4
|
-
import {
|
|
5
|
-
CODEBASE_SEARCH_DESCRIPTION
|
|
6
|
-
} from "./chunk-YQMPVJ2L.js";
|
|
7
|
-
|
|
8
|
-
// tools/codebase_search/vercel.ts
|
|
9
|
-
import { tool } from "ai";
|
|
10
|
-
import { z } from "zod";
|
|
11
|
-
function createCodebaseSearchTool(config) {
|
|
12
|
-
const schema = z.object({
|
|
13
|
-
query: z.string().describe('A complete question about what you want to understand. Ask as if talking to a colleague: "How does X work?", "What happens when Y?", "Where is Z handled?"'),
|
|
14
|
-
target_directories: z.array(z.string()).describe("Prefix directory paths to limit search scope (single directory only, no glob patterns). Use [] to search entire repo."),
|
|
15
|
-
explanation: z.string().describe("One sentence explanation as to why this tool is being used, and how it contributes to the goal."),
|
|
16
|
-
limit: z.number().optional().describe("Max results to return (default: 10)")
|
|
17
|
-
});
|
|
18
|
-
return tool({
|
|
19
|
-
description: CODEBASE_SEARCH_DESCRIPTION,
|
|
20
|
-
inputSchema: schema,
|
|
21
|
-
execute: async (params) => {
|
|
22
|
-
const { query, target_directories, explanation, limit } = params;
|
|
23
|
-
const result = await executeCodebaseSearch(
|
|
24
|
-
{ query, target_directories, explanation, limit },
|
|
25
|
-
config
|
|
26
|
-
);
|
|
27
|
-
if (!result.success) {
|
|
28
|
-
return {
|
|
29
|
-
error: result.error,
|
|
30
|
-
results: []
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
return {
|
|
34
|
-
found: result.results.length,
|
|
35
|
-
searchTime: `${result.stats.searchTimeMs}ms`,
|
|
36
|
-
results: result.results.map((r) => ({
|
|
37
|
-
file: r.filepath,
|
|
38
|
-
symbol: r.symbolPath,
|
|
39
|
-
lines: `${r.startLine}-${r.endLine}`,
|
|
40
|
-
language: r.language,
|
|
41
|
-
relevance: `${(r.rerankScore * 100).toFixed(1)}%`,
|
|
42
|
-
code: r.content
|
|
43
|
-
}))
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
function getSystemPrompt() {
|
|
49
|
-
return CODEBASE_SEARCH_DESCRIPTION;
|
|
50
|
-
}
|
|
51
|
-
var vercel_default = { createCodebaseSearchTool, getSystemPrompt };
|
|
52
|
-
|
|
53
|
-
export {
|
|
54
|
-
createCodebaseSearchTool,
|
|
55
|
-
getSystemPrompt,
|
|
56
|
-
vercel_default
|
|
57
|
-
};
|
|
58
|
-
//# sourceMappingURL=chunk-O5264GI4.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../tools/codebase_search/vercel.ts"],"sourcesContent":["/**\n * Vercel AI SDK adapter for codebase_search tool\n */\n\nimport { tool } from 'ai';\nimport { z } from 'zod';\nimport { executeCodebaseSearch } from './core.js';\nimport { CODEBASE_SEARCH_DESCRIPTION } from './prompts.js';\nimport type { CodebaseSearchConfig } from './types.js';\n\n/**\n * Create Vercel AI SDK codebase_search tool\n * \n * @param config - Configuration with repoId\n * @returns Vercel AI SDK tool definition (execution built-in)\n * \n * @example\n * ```ts\n * import { generateText } from 'ai';\n * import { anthropic } from '@ai-sdk/anthropic';\n * import { createCodebaseSearchTool } from 'morphsdk/tools/codebase-search/vercel';\n * \n * const tool = createCodebaseSearchTool({ repoId: 'my-project' });\n * \n * const result = await generateText({\n * model: anthropic('claude-3-5-sonnet-20241022'),\n * tools: { codebaseSearch: tool },\n * prompt: \"Find authentication code\",\n * maxSteps: 5\n * });\n * \n * // Vercel AI SDK automatically executes and handles results\n * console.log(result.text);\n * ```\n */\nexport function createCodebaseSearchTool(config: CodebaseSearchConfig) {\n const schema = z.object({\n query: z.string().describe('A complete question about what you want to understand. Ask as if talking to a colleague: \"How does X work?\", \"What happens when Y?\", \"Where is Z handled?\"'),\n target_directories: z.array(z.string()).describe('Prefix directory paths to limit search scope (single directory only, no glob patterns). Use [] to search entire repo.'),\n explanation: z.string().describe('One sentence explanation as to why this tool is being used, and how it contributes to the goal.'),\n limit: z.number().optional().describe('Max results to return (default: 10)'),\n });\n\n return tool({\n description: CODEBASE_SEARCH_DESCRIPTION,\n inputSchema: schema,\n execute: async (params) => {\n const { query, target_directories, explanation, limit } = params;\n const result = await executeCodebaseSearch(\n { query, target_directories, explanation, limit },\n config\n );\n\n if (!result.success) {\n return {\n error: result.error,\n results: [],\n };\n }\n\n // Format results for Vercel AI SDK\n return {\n found: result.results.length,\n searchTime: `${result.stats.searchTimeMs}ms`,\n results: result.results.map(r => ({\n file: r.filepath,\n symbol: r.symbolPath,\n lines: `${r.startLine}-${r.endLine}`,\n language: r.language,\n relevance: `${(r.rerankScore * 100).toFixed(1)}%`,\n code: r.content,\n })),\n };\n },\n });\n}\n\n/**\n * Get system prompt for Vercel AI SDK\n */\nexport function getSystemPrompt(): string {\n return CODEBASE_SEARCH_DESCRIPTION;\n}\n\n/**\n * Default export\n */\nexport default { createCodebaseSearchTool, getSystemPrompt };\n\n"],"mappings":";;;;;;;;AAIA,SAAS,YAAY;AACrB,SAAS,SAAS;AA8BX,SAAS,yBAAyB,QAA8B;AACrE,QAAM,SAAS,EAAE,OAAO;AAAA,IACtB,OAAO,EAAE,OAAO,EAAE,SAAS,4JAA4J;AAAA,IACvL,oBAAoB,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,SAAS,uHAAuH;AAAA,IACxK,aAAa,EAAE,OAAO,EAAE,SAAS,iGAAiG;AAAA,IAClI,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,qCAAqC;AAAA,EAC7E,CAAC;AAED,SAAO,KAAK;AAAA,IACV,aAAa;AAAA,IACb,aAAa;AAAA,IACb,SAAS,OAAO,WAAW;AACzB,YAAM,EAAE,OAAO,oBAAoB,aAAa,MAAM,IAAI;AAC1D,YAAM,SAAS,MAAM;AAAA,QACnB,EAAE,OAAO,oBAAoB,aAAa,MAAM;AAAA,QAChD;AAAA,MACF;AAEA,UAAI,CAAC,OAAO,SAAS;AACnB,eAAO;AAAA,UACL,OAAO,OAAO;AAAA,UACd,SAAS,CAAC;AAAA,QACZ;AAAA,MACF;AAGA,aAAO;AAAA,QACL,OAAO,OAAO,QAAQ;AAAA,QACtB,YAAY,GAAG,OAAO,MAAM,YAAY;AAAA,QACxC,SAAS,OAAO,QAAQ,IAAI,QAAM;AAAA,UAChC,MAAM,EAAE;AAAA,UACR,QAAQ,EAAE;AAAA,UACV,OAAO,GAAG,EAAE,SAAS,IAAI,EAAE,OAAO;AAAA,UAClC,UAAU,EAAE;AAAA,UACZ,WAAW,IAAI,EAAE,cAAc,KAAK,QAAQ,CAAC,CAAC;AAAA,UAC9C,MAAM,EAAE;AAAA,QACV,EAAE;AAAA,MACJ;AAAA,IACF;AAAA,EACF,CAAC;AACH;AAKO,SAAS,kBAA0B;AACxC,SAAO;AACT;AAKA,IAAO,iBAAQ,EAAE,0BAA0B,gBAAgB;","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
|
|
@@ -1 +0,0 @@
|
|
|
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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAiBA,MAAM,aAAa,QAAqC;AACtD,WAAO,aAAa,KAAK,QAAQ,MAAM;AAAA,EACzC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAgBA,MAAM,WAAW,IAAyC;AACxD,WAAO,WAAW,IAAI,KAAK,MAAM;AAAA,EACnC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,cAAc,IAAmC;AACrD,WAAO,cAAc,IAAI,KAAK,MAAM;AAAA,EACtC;AAAA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