@morphllm/morphsdk 0.2.198 → 0.2.200
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -147
- package/dist/{chunk-ZQNTXHBQ.js → chunk-3CCWSLQW.js} +2 -2
- package/dist/{chunk-FESO6TDQ.js → chunk-7I2A7GGJ.js} +2 -2
- package/dist/{chunk-4JUIEYAH.js → chunk-AKSXZBPT.js} +3 -3
- package/dist/chunk-B4X5RWLR.js +271 -0
- package/dist/chunk-B4X5RWLR.js.map +1 -0
- package/dist/{chunk-QKNGVBE2.js → chunk-L6YOMTFU.js} +3 -3
- package/dist/{chunk-YQ2G5YLI.js → chunk-MLROWLS6.js} +4 -4
- package/dist/{chunk-4DNEBVGV.js → chunk-MPL6BDR6.js} +2 -2
- package/dist/{chunk-3XS5P5XH.js → chunk-PD3EDFQD.js} +2 -2
- package/dist/{chunk-CAFREMIT.js → chunk-PJNL35DC.js} +2 -2
- package/dist/{chunk-PEFXG5M6.js → chunk-Q65LL6UM.js} +2 -2
- package/dist/{chunk-YUH3MTP3.js → chunk-QTBFL4DG.js} +2 -2
- package/dist/{chunk-XTFRHVCW.js → chunk-SNYHVDE4.js} +4 -4
- package/dist/{chunk-ZGERT23F.js → chunk-TIMDDHYB.js} +4 -4
- package/dist/{chunk-PV6EF6NG.js → chunk-UHIANNKC.js} +4 -4
- package/dist/{chunk-FUYX2MNM.js → chunk-UKAAT6KT.js} +4 -10
- package/dist/chunk-UKAAT6KT.js.map +1 -0
- package/dist/{chunk-ZU5YYGBJ.js → chunk-UZ42MHTR.js} +3 -63
- package/dist/chunk-UZ42MHTR.js.map +1 -0
- package/dist/{chunk-XK3PQZW6.js → chunk-WTENYKJP.js} +2 -2
- package/dist/{chunk-6XFL2NER.js → chunk-XTLPA7ZP.js} +2 -2
- package/dist/{chunk-D2RFP6R2.js → chunk-Z57GJLCG.js} +3 -3
- package/dist/{chunk-SKN2L5CE.js → chunk-ZE64EWUV.js} +2 -2
- package/dist/client-BWhi-vSj.d.ts +341 -0
- package/dist/client.cjs +88 -2086
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.ts +4 -10
- package/dist/client.js +20 -30
- package/dist/core/client.cjs +2 -68
- package/dist/core/client.cjs.map +1 -1
- package/dist/core/client.d.ts +0 -8
- package/dist/core/client.js +4 -4
- package/dist/core/error.cjs +2 -62
- package/dist/core/error.cjs.map +1 -1
- package/dist/core/error.js +3 -3
- package/dist/core/index.cjs +2 -68
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.js +4 -4
- package/dist/edge.cjs +2 -68
- package/dist/edge.cjs.map +1 -1
- package/dist/edge.js +7 -7
- package/dist/index.cjs +89 -2101
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -8
- package/dist/index.js +21 -47
- package/dist/modelrouter/core.cjs +2 -68
- package/dist/modelrouter/core.cjs.map +1 -1
- package/dist/modelrouter/core.js +5 -5
- package/dist/modelrouter/index.cjs +2 -68
- package/dist/modelrouter/index.cjs.map +1 -1
- package/dist/modelrouter/index.js +5 -5
- package/dist/subagents/anthropic.cjs +2 -68
- package/dist/subagents/anthropic.cjs.map +1 -1
- package/dist/subagents/anthropic.d.ts +1 -1
- package/dist/subagents/anthropic.js +9 -9
- package/dist/subagents/index.d.ts +1 -1
- package/dist/subagents/prompts.d.ts +1 -1
- package/dist/subagents/types.d.ts +1 -1
- package/dist/subagents/vercel.cjs +2 -68
- package/dist/subagents/vercel.cjs.map +1 -1
- package/dist/subagents/vercel.d.ts +1 -1
- package/dist/subagents/vercel.js +9 -9
- package/dist/tools/compact/core.cjs +2 -68
- package/dist/tools/compact/core.cjs.map +1 -1
- package/dist/tools/compact/core.js +5 -5
- package/dist/tools/compact/index.cjs +2 -68
- package/dist/tools/compact/index.cjs.map +1 -1
- package/dist/tools/compact/index.js +6 -6
- package/dist/tools/fastapply/anthropic.cjs +2 -62
- package/dist/tools/fastapply/anthropic.cjs.map +1 -1
- package/dist/tools/fastapply/anthropic.js +7 -7
- package/dist/tools/fastapply/apply.cjs +2 -62
- package/dist/tools/fastapply/apply.cjs.map +1 -1
- package/dist/tools/fastapply/apply.js +2 -2
- package/dist/tools/fastapply/core.cjs +2 -68
- package/dist/tools/fastapply/core.cjs.map +1 -1
- package/dist/tools/fastapply/core.js +6 -6
- package/dist/tools/fastapply/index.cjs +2 -62
- package/dist/tools/fastapply/index.cjs.map +1 -1
- package/dist/tools/fastapply/index.js +13 -13
- package/dist/tools/fastapply/openai.cjs +2 -62
- package/dist/tools/fastapply/openai.cjs.map +1 -1
- package/dist/tools/fastapply/openai.js +7 -7
- package/dist/tools/fastapply/vercel.cjs +2 -62
- package/dist/tools/fastapply/vercel.cjs.map +1 -1
- package/dist/tools/fastapply/vercel.js +7 -7
- package/dist/tools/index.cjs +2 -62
- package/dist/tools/index.cjs.map +1 -1
- package/dist/tools/index.js +13 -13
- package/dist/tools/utils/resilience.cjs +2 -62
- package/dist/tools/utils/resilience.cjs.map +1 -1
- package/dist/tools/utils/resilience.js +2 -2
- package/dist/tools/warp_grep/agent/runner.cjs +2 -62
- package/dist/tools/warp_grep/agent/runner.cjs.map +1 -1
- package/dist/tools/warp_grep/agent/runner.js +2 -2
- package/dist/tools/warp_grep/anthropic.cjs +2 -68
- package/dist/tools/warp_grep/anthropic.cjs.map +1 -1
- package/dist/tools/warp_grep/anthropic.d.ts +1 -1
- package/dist/tools/warp_grep/anthropic.js +9 -9
- package/dist/tools/warp_grep/client.cjs +2 -68
- package/dist/tools/warp_grep/client.cjs.map +1 -1
- package/dist/tools/warp_grep/client.d.ts +1 -1
- package/dist/tools/warp_grep/client.js +8 -8
- package/dist/tools/warp_grep/gemini.cjs +2 -68
- package/dist/tools/warp_grep/gemini.cjs.map +1 -1
- package/dist/tools/warp_grep/gemini.d.ts +1 -1
- package/dist/tools/warp_grep/gemini.js +8 -8
- package/dist/tools/warp_grep/index.cjs +2 -68
- package/dist/tools/warp_grep/index.cjs.map +1 -1
- package/dist/tools/warp_grep/index.d.ts +1 -1
- package/dist/tools/warp_grep/index.js +8 -8
- package/dist/tools/warp_grep/openai.cjs +2 -68
- package/dist/tools/warp_grep/openai.cjs.map +1 -1
- package/dist/tools/warp_grep/openai.d.ts +1 -1
- package/dist/tools/warp_grep/openai.js +9 -9
- package/dist/tools/warp_grep/providers/code_storage_http.d.ts +1 -1
- package/dist/tools/warp_grep/providers/remote.d.ts +1 -1
- package/dist/tools/warp_grep/vercel.cjs +2 -68
- package/dist/tools/warp_grep/vercel.cjs.map +1 -1
- package/dist/tools/warp_grep/vercel.d.ts +1 -1
- package/dist/tools/warp_grep/vercel.js +9 -9
- package/dist/{types-qwD753FR.d.ts → types-DxZLPogx.d.ts} +1 -1
- package/dist/version.cjs +2 -62
- package/dist/version.cjs.map +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -62
- package/dist/anthropic-B6my2oBx.d.ts +0 -56
- package/dist/chunk-2AMEQAO2.js +0 -46
- package/dist/chunk-2AMEQAO2.js.map +0 -1
- package/dist/chunk-2HMEZZKK.js +0 -44
- package/dist/chunk-2HMEZZKK.js.map +0 -1
- package/dist/chunk-2VERUKO2.js +0 -177
- package/dist/chunk-2VERUKO2.js.map +0 -1
- package/dist/chunk-EMURAU6J.js +0 -148
- package/dist/chunk-EMURAU6J.js.map +0 -1
- package/dist/chunk-FUYX2MNM.js.map +0 -1
- package/dist/chunk-GJ42MYUU.js +0 -57
- package/dist/chunk-GJ42MYUU.js.map +0 -1
- package/dist/chunk-IDMKQWQG.js +0 -214
- package/dist/chunk-IDMKQWQG.js.map +0 -1
- package/dist/chunk-KQKLQHJF.js +0 -96
- package/dist/chunk-KQKLQHJF.js.map +0 -1
- package/dist/chunk-O5264GI4.js +0 -58
- package/dist/chunk-O5264GI4.js.map +0 -1
- package/dist/chunk-PIIXU2H3.js +0 -389
- package/dist/chunk-PIIXU2H3.js.map +0 -1
- package/dist/chunk-T6TXYTKH.js +0 -83
- package/dist/chunk-T6TXYTKH.js.map +0 -1
- package/dist/chunk-TLXVGE4R.js +0 -42
- package/dist/chunk-TLXVGE4R.js.map +0 -1
- package/dist/chunk-VBZ7BG47.js +0 -97
- package/dist/chunk-VBZ7BG47.js.map +0 -1
- package/dist/chunk-WLMPQFER.js +0 -128
- package/dist/chunk-WLMPQFER.js.map +0 -1
- package/dist/chunk-XH6KJJDI.js +0 -80
- package/dist/chunk-XH6KJJDI.js.map +0 -1
- package/dist/chunk-YD6TNDR4.js +0 -622
- package/dist/chunk-YD6TNDR4.js.map +0 -1
- package/dist/chunk-YHZJYCOU.js +0 -680
- package/dist/chunk-YHZJYCOU.js.map +0 -1
- package/dist/chunk-YQMPVJ2L.js +0 -32
- package/dist/chunk-YQMPVJ2L.js.map +0 -1
- package/dist/chunk-YTYCHRQ2.js +0 -106
- package/dist/chunk-YTYCHRQ2.js.map +0 -1
- package/dist/chunk-ZU5YYGBJ.js.map +0 -1
- package/dist/client-DCeydotn.d.ts +0 -1015
- package/dist/openai-BQMeDFef.d.ts +0 -81
- package/dist/otel-CG0uqXjp.d.ts +0 -42
- package/dist/tools/browser/anthropic.cjs +0 -645
- package/dist/tools/browser/anthropic.cjs.map +0 -1
- package/dist/tools/browser/anthropic.d.ts +0 -4
- package/dist/tools/browser/anthropic.js +0 -22
- package/dist/tools/browser/anthropic.js.map +0 -1
- package/dist/tools/browser/core.cjs +0 -1821
- package/dist/tools/browser/core.cjs.map +0 -1
- package/dist/tools/browser/core.d.ts +0 -245
- package/dist/tools/browser/core.js +0 -32
- package/dist/tools/browser/core.js.map +0 -1
- package/dist/tools/browser/errors.cjs +0 -208
- package/dist/tools/browser/errors.cjs.map +0 -1
- package/dist/tools/browser/errors.d.ts +0 -158
- package/dist/tools/browser/errors.js +0 -22
- package/dist/tools/browser/errors.js.map +0 -1
- package/dist/tools/browser/index.cjs +0 -2159
- package/dist/tools/browser/index.cjs.map +0 -1
- package/dist/tools/browser/index.d.ts +0 -134
- package/dist/tools/browser/index.js +0 -163
- package/dist/tools/browser/index.js.map +0 -1
- package/dist/tools/browser/live.cjs +0 -134
- package/dist/tools/browser/live.cjs.map +0 -1
- package/dist/tools/browser/live.d.ts +0 -75
- package/dist/tools/browser/live.js +0 -16
- package/dist/tools/browser/live.js.map +0 -1
- package/dist/tools/browser/openai.cjs +0 -661
- package/dist/tools/browser/openai.cjs.map +0 -1
- package/dist/tools/browser/openai.d.ts +0 -4
- package/dist/tools/browser/openai.js +0 -28
- package/dist/tools/browser/openai.js.map +0 -1
- package/dist/tools/browser/profiles/core.cjs +0 -932
- package/dist/tools/browser/profiles/core.cjs.map +0 -1
- package/dist/tools/browser/profiles/core.d.ts +0 -187
- package/dist/tools/browser/profiles/core.js +0 -30
- package/dist/tools/browser/profiles/core.js.map +0 -1
- package/dist/tools/browser/profiles/index.cjs +0 -932
- package/dist/tools/browser/profiles/index.cjs.map +0 -1
- package/dist/tools/browser/profiles/index.d.ts +0 -4
- package/dist/tools/browser/profiles/index.js +0 -30
- package/dist/tools/browser/profiles/index.js.map +0 -1
- package/dist/tools/browser/profiles/types.cjs +0 -74
- package/dist/tools/browser/profiles/types.cjs.map +0 -1
- package/dist/tools/browser/profiles/types.d.ts +0 -195
- package/dist/tools/browser/profiles/types.js +0 -16
- package/dist/tools/browser/profiles/types.js.map +0 -1
- package/dist/tools/browser/prompts.cjs +0 -69
- package/dist/tools/browser/prompts.cjs.map +0 -1
- package/dist/tools/browser/prompts.d.ts +0 -7
- package/dist/tools/browser/prompts.js +0 -10
- package/dist/tools/browser/prompts.js.map +0 -1
- package/dist/tools/browser/types.cjs +0 -19
- package/dist/tools/browser/types.cjs.map +0 -1
- package/dist/tools/browser/types.d.ts +0 -338
- package/dist/tools/browser/types.js +0 -1
- package/dist/tools/browser/types.js.map +0 -1
- package/dist/tools/browser/vercel.cjs +0 -622
- package/dist/tools/browser/vercel.cjs.map +0 -1
- package/dist/tools/browser/vercel.d.ts +0 -4
- package/dist/tools/browser/vercel.js +0 -22
- package/dist/tools/browser/vercel.js.map +0 -1
- package/dist/tools/codebase_search/anthropic.cjs +0 -696
- package/dist/tools/codebase_search/anthropic.cjs.map +0 -1
- package/dist/tools/codebase_search/anthropic.d.ts +0 -40
- package/dist/tools/codebase_search/anthropic.js +0 -16
- package/dist/tools/codebase_search/anthropic.js.map +0 -1
- package/dist/tools/codebase_search/core.cjs +0 -638
- package/dist/tools/codebase_search/core.cjs.map +0 -1
- package/dist/tools/codebase_search/core.d.ts +0 -51
- package/dist/tools/codebase_search/core.js +0 -16
- package/dist/tools/codebase_search/core.js.map +0 -1
- package/dist/tools/codebase_search/index.cjs +0 -821
- package/dist/tools/codebase_search/index.cjs.map +0 -1
- package/dist/tools/codebase_search/index.d.ts +0 -12
- package/dist/tools/codebase_search/index.js +0 -32
- package/dist/tools/codebase_search/index.js.map +0 -1
- package/dist/tools/codebase_search/openai.cjs +0 -745
- package/dist/tools/codebase_search/openai.cjs.map +0 -1
- package/dist/tools/codebase_search/openai.d.ts +0 -87
- package/dist/tools/codebase_search/openai.js +0 -26
- package/dist/tools/codebase_search/openai.js.map +0 -1
- package/dist/tools/codebase_search/prompts.cjs +0 -57
- package/dist/tools/codebase_search/prompts.cjs.map +0 -1
- package/dist/tools/codebase_search/prompts.d.ts +0 -7
- package/dist/tools/codebase_search/prompts.js +0 -10
- package/dist/tools/codebase_search/prompts.js.map +0 -1
- package/dist/tools/codebase_search/types.cjs +0 -19
- package/dist/tools/codebase_search/types.cjs.map +0 -1
- package/dist/tools/codebase_search/types.d.ts +0 -50
- package/dist/tools/codebase_search/types.js +0 -1
- package/dist/tools/codebase_search/types.js.map +0 -1
- package/dist/tools/codebase_search/vercel.cjs +0 -658
- package/dist/tools/codebase_search/vercel.cjs.map +0 -1
- package/dist/tools/codebase_search/vercel.d.ts +0 -65
- package/dist/tools/codebase_search/vercel.js +0 -20
- package/dist/tools/codebase_search/vercel.js.map +0 -1
- package/dist/tracing/core.cjs +0 -410
- package/dist/tracing/core.cjs.map +0 -1
- package/dist/tracing/core.d.ts +0 -58
- package/dist/tracing/core.js +0 -12
- package/dist/tracing/core.js.map +0 -1
- package/dist/tracing/index.cjs +0 -422
- package/dist/tracing/index.cjs.map +0 -1
- package/dist/tracing/index.d.ts +0 -5
- package/dist/tracing/index.js +0 -17
- package/dist/tracing/index.js.map +0 -1
- package/dist/tracing/interaction.cjs +0 -273
- package/dist/tracing/interaction.cjs.map +0 -1
- package/dist/tracing/interaction.d.ts +0 -41
- package/dist/tracing/interaction.js +0 -11
- package/dist/tracing/interaction.js.map +0 -1
- package/dist/tracing/otel.cjs +0 -56
- package/dist/tracing/otel.cjs.map +0 -1
- package/dist/tracing/otel.d.ts +0 -2
- package/dist/tracing/otel.js +0 -10
- package/dist/tracing/otel.js.map +0 -1
- package/dist/tracing/types.cjs +0 -19
- package/dist/tracing/types.cjs.map +0 -1
- package/dist/tracing/types.d.ts +0 -124
- package/dist/tracing/types.js +0 -1
- package/dist/tracing/types.js.map +0 -1
- package/dist/vercel-CVF27qFK.d.ts +0 -74
- /package/dist/{chunk-ZQNTXHBQ.js.map → chunk-3CCWSLQW.js.map} +0 -0
- /package/dist/{chunk-FESO6TDQ.js.map → chunk-7I2A7GGJ.js.map} +0 -0
- /package/dist/{chunk-4JUIEYAH.js.map → chunk-AKSXZBPT.js.map} +0 -0
- /package/dist/{chunk-QKNGVBE2.js.map → chunk-L6YOMTFU.js.map} +0 -0
- /package/dist/{chunk-YQ2G5YLI.js.map → chunk-MLROWLS6.js.map} +0 -0
- /package/dist/{chunk-4DNEBVGV.js.map → chunk-MPL6BDR6.js.map} +0 -0
- /package/dist/{chunk-3XS5P5XH.js.map → chunk-PD3EDFQD.js.map} +0 -0
- /package/dist/{chunk-CAFREMIT.js.map → chunk-PJNL35DC.js.map} +0 -0
- /package/dist/{chunk-PEFXG5M6.js.map → chunk-Q65LL6UM.js.map} +0 -0
- /package/dist/{chunk-YUH3MTP3.js.map → chunk-QTBFL4DG.js.map} +0 -0
- /package/dist/{chunk-XTFRHVCW.js.map → chunk-SNYHVDE4.js.map} +0 -0
- /package/dist/{chunk-ZGERT23F.js.map → chunk-TIMDDHYB.js.map} +0 -0
- /package/dist/{chunk-PV6EF6NG.js.map → chunk-UHIANNKC.js.map} +0 -0
- /package/dist/{chunk-XK3PQZW6.js.map → chunk-WTENYKJP.js.map} +0 -0
- /package/dist/{chunk-6XFL2NER.js.map → chunk-XTLPA7ZP.js.map} +0 -0
- /package/dist/{chunk-D2RFP6R2.js.map → chunk-Z57GJLCG.js.map} +0 -0
- /package/dist/{chunk-SKN2L5CE.js.map → chunk-ZE64EWUV.js.map} +0 -0
package/dist/chunk-T6TXYTKH.js
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
executeCodebaseSearch
|
|
3
|
-
} from "./chunk-VBZ7BG47.js";
|
|
4
|
-
import {
|
|
5
|
-
CODEBASE_SEARCH_DESCRIPTION,
|
|
6
|
-
CODEBASE_SEARCH_SYSTEM_PROMPT
|
|
7
|
-
} from "./chunk-YQMPVJ2L.js";
|
|
8
|
-
|
|
9
|
-
// tools/codebase_search/anthropic.ts
|
|
10
|
-
function createCodebaseSearchTool(config) {
|
|
11
|
-
const toolDefinition = {
|
|
12
|
-
name: "codebase_search",
|
|
13
|
-
description: CODEBASE_SEARCH_DESCRIPTION,
|
|
14
|
-
input_schema: {
|
|
15
|
-
type: "object",
|
|
16
|
-
properties: {
|
|
17
|
-
explanation: {
|
|
18
|
-
type: "string",
|
|
19
|
-
description: "One sentence explanation as to why this tool is being used, and how it contributes to the goal."
|
|
20
|
-
},
|
|
21
|
-
query: {
|
|
22
|
-
type: "string",
|
|
23
|
-
description: '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?"'
|
|
24
|
-
},
|
|
25
|
-
target_directories: {
|
|
26
|
-
type: "array",
|
|
27
|
-
items: { type: "string" },
|
|
28
|
-
description: "Prefix directory paths to limit search scope (single directory only, no glob patterns). Use [] to search entire repo."
|
|
29
|
-
},
|
|
30
|
-
limit: {
|
|
31
|
-
type: "number",
|
|
32
|
-
description: "Maximum results to return (default: 10)"
|
|
33
|
-
}
|
|
34
|
-
},
|
|
35
|
-
required: ["query", "target_directories", "explanation"]
|
|
36
|
-
},
|
|
37
|
-
cache_control: { type: "ephemeral" }
|
|
38
|
-
};
|
|
39
|
-
return Object.assign(toolDefinition, {
|
|
40
|
-
execute: async (input) => {
|
|
41
|
-
return executeCodebaseSearch(input, config);
|
|
42
|
-
},
|
|
43
|
-
formatResult: (result) => {
|
|
44
|
-
return formatResult(result);
|
|
45
|
-
},
|
|
46
|
-
getSystemPrompt: () => {
|
|
47
|
-
return CODEBASE_SEARCH_SYSTEM_PROMPT;
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
function formatResult(result) {
|
|
52
|
-
if (!result.success) {
|
|
53
|
-
return `Search failed: ${result.error}`;
|
|
54
|
-
}
|
|
55
|
-
if (result.results.length === 0) {
|
|
56
|
-
return "No matching code found. Try rephrasing your query or broadening the search scope.";
|
|
57
|
-
}
|
|
58
|
-
const lines = [];
|
|
59
|
-
lines.push(`Found ${result.results.length} relevant code sections (searched ${result.stats.candidatesRetrieved} candidates in ${result.stats.searchTimeMs}ms):
|
|
60
|
-
`);
|
|
61
|
-
result.results.forEach((r, i) => {
|
|
62
|
-
const relevance = (r.rerankScore * 100).toFixed(1);
|
|
63
|
-
lines.push(`${i + 1}. ${r.filepath} (${relevance}% relevant)`);
|
|
64
|
-
lines.push(` Symbol: ${r.symbolPath}`);
|
|
65
|
-
lines.push(` Language: ${r.language}`);
|
|
66
|
-
lines.push(` Lines: ${r.startLine}-${r.endLine}`);
|
|
67
|
-
lines.push(` Code:`);
|
|
68
|
-
const codeLines = r.content.split("\n");
|
|
69
|
-
codeLines.slice(0, Math.min(codeLines.length, 20)).forEach((line) => {
|
|
70
|
-
lines.push(` ${line}`);
|
|
71
|
-
});
|
|
72
|
-
if (codeLines.length > 20) {
|
|
73
|
-
lines.push(` ... (${codeLines.length - 20} more lines)`);
|
|
74
|
-
}
|
|
75
|
-
lines.push("");
|
|
76
|
-
});
|
|
77
|
-
return lines.join("\n");
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export {
|
|
81
|
-
createCodebaseSearchTool
|
|
82
|
-
};
|
|
83
|
-
//# sourceMappingURL=chunk-T6TXYTKH.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../tools/codebase_search/anthropic.ts"],"sourcesContent":["/**\n * Anthropic SDK adapter for codebase_search tool\n */\n\nimport type { Tool } from '@anthropic-ai/sdk/resources/messages';\nimport { executeCodebaseSearch } from './core.js';\nimport { CODEBASE_SEARCH_DESCRIPTION, CODEBASE_SEARCH_SYSTEM_PROMPT } from './prompts.js';\nimport type { CodebaseSearchConfig, CodebaseSearchInput, CodebaseSearchResult } from './types.js';\n\n\n/**\n * Create Anthropic-native codebase_search tool with execute and formatResult methods\n * \n * @param config - Configuration with repoId\n * @returns Anthropic Tool definition with execute and formatResult methods\n * \n * @example\n * ```ts\n * import Anthropic from '@anthropic-ai/sdk';\n * import { createCodebaseSearchTool } from 'morphsdk/tools/anthropic';\n * \n * const client = new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY });\n * const tool = createCodebaseSearchTool({ repoId: 'my-project' });\n * \n * const response = await client.messages.create({\n * model: \"claude-sonnet-4-5-20250929\",\n * tools: [tool], // tool itself is the Tool definition\n * messages: [{ role: \"user\", content: \"Find authentication code\" }]\n * });\n * \n * // Execute tool and format result\n * const result = await tool.execute(toolUseBlock.input);\n * const formatted = tool.formatResult(result);\n * ```\n */\nexport function createCodebaseSearchTool(config: CodebaseSearchConfig) {\n const toolDefinition: Tool = {\n name: 'codebase_search',\n description: CODEBASE_SEARCH_DESCRIPTION,\n input_schema: {\n type: 'object',\n properties: {\n explanation: {\n type: 'string',\n description: 'One sentence explanation as to why this tool is being used, and how it contributes to the goal.',\n },\n query: {\n type: 'string',\n description: '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 },\n target_directories: {\n type: 'array',\n items: { type: 'string' },\n description: 'Prefix directory paths to limit search scope (single directory only, no glob patterns). Use [] to search entire repo.',\n },\n limit: {\n type: 'number',\n description: 'Maximum results to return (default: 10)',\n },\n },\n required: ['query', 'target_directories', 'explanation'],\n },\n cache_control: { type: 'ephemeral' } as any,\n } as any;\n\n return Object.assign(toolDefinition, {\n execute: async (input: CodebaseSearchInput): Promise<CodebaseSearchResult> => {\n return executeCodebaseSearch(input, config);\n },\n formatResult: (result: CodebaseSearchResult): string => {\n return formatResult(result);\n },\n getSystemPrompt: (): string => {\n return CODEBASE_SEARCH_SYSTEM_PROMPT;\n },\n });\n}\n\n/**\n * Format search results for Claude\n * \n * @param result - Search result from endpoint\n * @returns Formatted string for tool_result\n */\nfunction formatResult(result: CodebaseSearchResult): string {\n if (!result.success) {\n return `Search failed: ${result.error}`;\n }\n\n if (result.results.length === 0) {\n return 'No matching code found. Try rephrasing your query or broadening the search scope.';\n }\n\n const lines: string[] = [];\n \n lines.push(`Found ${result.results.length} relevant code sections (searched ${result.stats.candidatesRetrieved} candidates in ${result.stats.searchTimeMs}ms):\\n`);\n\n result.results.forEach((r, i) => {\n const relevance = (r.rerankScore * 100).toFixed(1);\n lines.push(`${i + 1}. ${r.filepath} (${relevance}% relevant)`);\n lines.push(` Symbol: ${r.symbolPath}`);\n lines.push(` Language: ${r.language}`);\n lines.push(` Lines: ${r.startLine}-${r.endLine}`);\n lines.push(` Code:`);\n \n // Show code content with indentation\n const codeLines = r.content.split('\\n');\n codeLines.slice(0, Math.min(codeLines.length, 20)).forEach(line => {\n lines.push(` ${line}`);\n });\n \n if (codeLines.length > 20) {\n lines.push(` ... (${codeLines.length - 20} more lines)`);\n }\n \n lines.push('');\n });\n\n return lines.join('\\n');\n}\n\n"],"mappings":";;;;;;;;;AAmCO,SAAS,yBAAyB,QAA8B;AACrE,QAAM,iBAAuB;AAAA,IAC3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EAAE;AACvC,UAAM,KAAK,gBAAgB,EAAE,QAAQ,EAAE;AACvC,UAAM,KAAK,aAAa,EAAE,SAAS,IAAI,EAAE,OAAO,EAAE;AAClD,UAAM,KAAK,UAAU;AAGrB,UAAM,YAAY,EAAE,QAAQ,MAAM,IAAI;AACtC,cAAU,MAAM,GAAG,KAAK,IAAI,UAAU,QAAQ,EAAE,CAAC,EAAE,QAAQ,UAAQ;AACjE,YAAM,KAAK,QAAQ,IAAI,EAAE;AAAA,IAC3B,CAAC;AAED,QAAI,UAAU,SAAS,IAAI;AACzB,YAAM,KAAK,aAAa,UAAU,SAAS,EAAE,cAAc;AAAA,IAC7D;AAEA,UAAM,KAAK,EAAE;AAAA,EACf,CAAC;AAED,SAAO,MAAM,KAAK,IAAI;AACxB;","names":[]}
|
package/dist/chunk-TLXVGE4R.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
__export
|
|
3
|
-
} from "./chunk-PZ5AY32C.js";
|
|
4
|
-
|
|
5
|
-
// tracing/otel.ts
|
|
6
|
-
var otel_exports = {};
|
|
7
|
-
__export(otel_exports, {
|
|
8
|
-
default: () => otel_default,
|
|
9
|
-
metadata: () => metadata
|
|
10
|
-
});
|
|
11
|
-
var RESERVED_KEYS = /* @__PURE__ */ new Set(["user_id", "convo_id", "event_id", "event_name"]);
|
|
12
|
-
function uuid() {
|
|
13
|
-
const c = globalThis.crypto;
|
|
14
|
-
if (c?.randomUUID) return c.randomUUID();
|
|
15
|
-
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (ch) => {
|
|
16
|
-
const r = Math.random() * 16 | 0;
|
|
17
|
-
const v = ch === "x" ? r : r & 3 | 8;
|
|
18
|
-
return v.toString(16);
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
function metadata(opts) {
|
|
22
|
-
const result = {
|
|
23
|
-
user_id: opts.userId,
|
|
24
|
-
event_id: opts.eventId ?? uuid()
|
|
25
|
-
};
|
|
26
|
-
if (opts.convoId) result.convo_id = opts.convoId;
|
|
27
|
-
if (opts.eventName) result.event_name = opts.eventName;
|
|
28
|
-
if (opts.properties) {
|
|
29
|
-
for (const [key, value] of Object.entries(opts.properties)) {
|
|
30
|
-
if (!RESERVED_KEYS.has(key)) result[key] = value;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
return result;
|
|
34
|
-
}
|
|
35
|
-
var otel_default = { metadata };
|
|
36
|
-
|
|
37
|
-
export {
|
|
38
|
-
metadata,
|
|
39
|
-
otel_default,
|
|
40
|
-
otel_exports
|
|
41
|
-
};
|
|
42
|
-
//# sourceMappingURL=chunk-TLXVGE4R.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../tracing/otel.ts"],"sourcesContent":["/**\n * Morph Tracing — Vercel AI SDK helper.\n *\n * The Vercel AI SDK emits its own OpenTelemetry spans when you pass\n * `experimental_telemetry`. There is nothing to monkey-patch; instead you tag\n * each call with `metadata()` so Morph can attribute the resulting spans to a\n * user/conversation/event.\n *\n * @example\n * ```ts\n * import { generateText } from \"ai\";\n * import { metadata } from \"@morphllm/morphsdk/tracing/otel\";\n *\n * const res = await generateText({\n * model: openai(\"gpt-4o\"),\n * prompt: \"Hello!\",\n * experimental_telemetry: {\n * isEnabled: true,\n * metadata: metadata({ userId: \"user-123\", convoId: \"convo-456\" }),\n * },\n * });\n * ```\n */\nimport type { MetadataOptions } from './types.js';\n\n/**\n * Reserved metadata keys Morph owns. Custom `properties` can't overwrite these,\n * so attribution (user_id / convo_id / event_id) stays intact.\n *\n * The AI SDK stores metadata as `ai.telemetry.metadata.<key>`; Traceloop's span\n * processor copies them to `traceloop.association.properties.<key>`, which is\n * what ClickHouse views read. Use snake_case names (user_id, convo_id, …).\n */\nconst RESERVED_KEYS = new Set(['user_id', 'convo_id', 'event_id', 'event_name']);\n\nfunction uuid(): string {\n // Node 18+ and modern runtimes expose globalThis.crypto.randomUUID.\n const c = (globalThis as { crypto?: { randomUUID?: () => string } }).crypto;\n if (c?.randomUUID) return c.randomUUID();\n // Fallback: RFC4122-ish without crypto.\n return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (ch) => {\n const r = (Math.random() * 16) | 0;\n const v = ch === 'x' ? r : (r & 0x3) | 0x8;\n return v.toString(16);\n });\n}\n\n/**\n * Build the metadata object for the Vercel AI SDK's\n * `experimental_telemetry.metadata`. The values are propagated to every span the\n * AI SDK creates for that call. Generate a fresh `eventId` per call for grouping.\n */\nexport function metadata(opts: MetadataOptions): Record<string, string> {\n const result: Record<string, string> = {\n user_id: opts.userId,\n event_id: opts.eventId ?? uuid(),\n };\n if (opts.convoId) result.convo_id = opts.convoId;\n if (opts.eventName) result.event_name = opts.eventName;\n if (opts.properties) {\n for (const [key, value] of Object.entries(opts.properties)) {\n if (!RESERVED_KEYS.has(key)) result[key] = value;\n }\n }\n return result;\n}\n\nexport default { metadata };\n"],"mappings":";;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAiCA,IAAM,gBAAgB,oBAAI,IAAI,CAAC,WAAW,YAAY,YAAY,YAAY,CAAC;AAE/E,SAAS,OAAe;AAEtB,QAAM,IAAK,WAA0D;AACrE,MAAI,GAAG,WAAY,QAAO,EAAE,WAAW;AAEvC,SAAO,uCAAuC,QAAQ,SAAS,CAAC,OAAO;AACrE,UAAM,IAAK,KAAK,OAAO,IAAI,KAAM;AACjC,UAAM,IAAI,OAAO,MAAM,IAAK,IAAI,IAAO;AACvC,WAAO,EAAE,SAAS,EAAE;AAAA,EACtB,CAAC;AACH;AAOO,SAAS,SAAS,MAA+C;AACtE,QAAM,SAAiC;AAAA,IACrC,SAAS,KAAK;AAAA,IACd,UAAU,KAAK,WAAW,KAAK;AAAA,EACjC;AACA,MAAI,KAAK,QAAS,QAAO,WAAW,KAAK;AACzC,MAAI,KAAK,UAAW,QAAO,aAAa,KAAK;AAC7C,MAAI,KAAK,YAAY;AACnB,eAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,KAAK,UAAU,GAAG;AAC1D,UAAI,CAAC,cAAc,IAAI,GAAG,EAAG,QAAO,GAAG,IAAI;AAAA,IAC7C;AAAA,EACF;AACA,SAAO;AACT;AAEA,IAAO,eAAQ,EAAE,SAAS;","names":[]}
|
package/dist/chunk-VBZ7BG47.js
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
MorphAPIClient
|
|
3
|
-
} from "./chunk-FUYX2MNM.js";
|
|
4
|
-
import {
|
|
5
|
-
logger
|
|
6
|
-
} from "./chunk-F3NCFNUX.js";
|
|
7
|
-
import {
|
|
8
|
-
MorphError
|
|
9
|
-
} from "./chunk-FESO6TDQ.js";
|
|
10
|
-
import {
|
|
11
|
-
APIResource
|
|
12
|
-
} from "./chunk-5TOJD2C5.js";
|
|
13
|
-
|
|
14
|
-
// tools/codebase_search/core.ts
|
|
15
|
-
var DEFAULT_TIMEOUT = 3e4;
|
|
16
|
-
var emptyStats = { totalResults: 0, candidatesRetrieved: 0, searchTimeMs: 0 };
|
|
17
|
-
async function runSearch(client, input, repoId, timeout, baseURL) {
|
|
18
|
-
const startTime = Date.now();
|
|
19
|
-
logger.debug("CodebaseSearch", "request", { query: input.query.slice(0, 100), repo_id: repoId });
|
|
20
|
-
try {
|
|
21
|
-
const data = await client.post(
|
|
22
|
-
"/v1/codebase_search",
|
|
23
|
-
{
|
|
24
|
-
baseURL: baseURL ?? client.reposURL,
|
|
25
|
-
timeout,
|
|
26
|
-
body: {
|
|
27
|
-
query: input.query,
|
|
28
|
-
repoId,
|
|
29
|
-
targetDirectories: input.target_directories || [],
|
|
30
|
-
limit: input.limit || 10,
|
|
31
|
-
candidateLimit: 50
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
);
|
|
35
|
-
const elapsed = Date.now() - startTime;
|
|
36
|
-
logger.debug("CodebaseSearch", "response", { results_count: data.results?.length || 0, latency_ms: elapsed });
|
|
37
|
-
return {
|
|
38
|
-
success: true,
|
|
39
|
-
results: data.results || [],
|
|
40
|
-
stats: data.stats || { totalResults: 0, candidatesRetrieved: 0, searchTimeMs: elapsed }
|
|
41
|
-
};
|
|
42
|
-
} catch (error) {
|
|
43
|
-
const message = error instanceof MorphError && error.statusCode ? `Search failed (${error.statusCode}): ${error.message}` : error instanceof Error ? error.message : "Unknown error";
|
|
44
|
-
logger.error("CodebaseSearch", "error", { error: message, latency_ms: Date.now() - startTime });
|
|
45
|
-
return { success: false, results: [], stats: { ...emptyStats }, error: message };
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
var CodebaseSearchClient = class extends APIResource {
|
|
49
|
-
timeout;
|
|
50
|
-
constructor(clientOrConfig = {}) {
|
|
51
|
-
super(
|
|
52
|
-
clientOrConfig instanceof MorphAPIClient ? clientOrConfig : new MorphAPIClient({
|
|
53
|
-
apiKey: clientOrConfig.apiKey,
|
|
54
|
-
timeout: clientOrConfig.timeout ?? DEFAULT_TIMEOUT,
|
|
55
|
-
retryConfig: clientOrConfig.retryConfig,
|
|
56
|
-
debug: clientOrConfig.debug
|
|
57
|
-
})
|
|
58
|
-
);
|
|
59
|
-
this.timeout = (clientOrConfig instanceof MorphAPIClient ? void 0 : clientOrConfig.timeout) ?? DEFAULT_TIMEOUT;
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Execute a semantic code search
|
|
63
|
-
*
|
|
64
|
-
* @param input - Search parameters including query, repoId, and target directories
|
|
65
|
-
* @param overrides - Optional config overrides for this operation
|
|
66
|
-
* @returns Search results with ranked code matches
|
|
67
|
-
*/
|
|
68
|
-
async search(input, overrides) {
|
|
69
|
-
return runSearch(
|
|
70
|
-
this._client,
|
|
71
|
-
{ query: input.query, target_directories: input.target_directories, explanation: input.explanation, limit: input.limit },
|
|
72
|
-
input.repoId,
|
|
73
|
-
overrides?.timeout ?? this.timeout,
|
|
74
|
-
overrides?.searchUrl
|
|
75
|
-
);
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
async function executeCodebaseSearch(input, config) {
|
|
79
|
-
const apiKey = config.apiKey || process.env.MORPH_API_KEY;
|
|
80
|
-
if (!apiKey) {
|
|
81
|
-
throw new Error("MORPH_API_KEY not found. Set environment variable or pass in config");
|
|
82
|
-
}
|
|
83
|
-
const client = new MorphAPIClient({
|
|
84
|
-
apiKey,
|
|
85
|
-
reposURL: config.searchUrl,
|
|
86
|
-
timeout: config.timeout ?? DEFAULT_TIMEOUT,
|
|
87
|
-
retryConfig: config.retryConfig,
|
|
88
|
-
debug: config.debug
|
|
89
|
-
});
|
|
90
|
-
return runSearch(client, input, config.repoId, config.timeout ?? DEFAULT_TIMEOUT, config.searchUrl);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export {
|
|
94
|
-
CodebaseSearchClient,
|
|
95
|
-
executeCodebaseSearch
|
|
96
|
-
};
|
|
97
|
-
//# sourceMappingURL=chunk-VBZ7BG47.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../tools/codebase_search/core.ts"],"sourcesContent":["/**\n * Core implementation for codebase search.\n * Calls the Morph rerank service for two-stage semantic search over the\n * code-storage host, through the shared `MorphAPIClient` transport.\n */\nimport { MorphAPIClient } from '../../core/client.js';\nimport { APIResource } from '../../core/resource.js';\nimport { MorphError } from '../utils/resilience.js';\nimport { logger } from '../../logger.js';\nimport type { CodebaseSearchConfig, CodebaseSearchInput, CodebaseSearchResult } from './types.js';\n\nconst DEFAULT_TIMEOUT = 30000;\n\nconst emptyStats = { totalResults: 0, candidatesRetrieved: 0, searchTimeMs: 0 };\n\n/**\n * Run a search against `/v1/codebase_search` on the repos host. HTTP failures\n * are returned in-band as `{ success: false, error }` (never thrown), matching\n * the long-standing contract callers rely on.\n */\nasync function runSearch(\n client: MorphAPIClient,\n input: CodebaseSearchInput,\n repoId: string,\n timeout: number,\n baseURL?: string,\n): Promise<CodebaseSearchResult> {\n const startTime = Date.now();\n logger.debug('CodebaseSearch', 'request', { query: input.query.slice(0, 100), repo_id: repoId });\n\n try {\n const data = await client.post<{ results?: unknown[]; stats?: CodebaseSearchResult['stats'] }>(\n '/v1/codebase_search',\n {\n baseURL: baseURL ?? client.reposURL,\n timeout,\n body: {\n query: input.query,\n repoId,\n targetDirectories: input.target_directories || [],\n limit: input.limit || 10,\n candidateLimit: 50,\n },\n },\n );\n\n const elapsed = Date.now() - startTime;\n logger.debug('CodebaseSearch', 'response', { results_count: data.results?.length || 0, latency_ms: elapsed });\n return {\n success: true,\n results: (data.results as CodebaseSearchResult['results']) || [],\n stats: data.stats || { totalResults: 0, candidatesRetrieved: 0, searchTimeMs: elapsed },\n };\n } catch (error) {\n const message =\n error instanceof MorphError && error.statusCode\n ? `Search failed (${error.statusCode}): ${error.message}`\n : error instanceof Error\n ? error.message\n : 'Unknown error';\n logger.error('CodebaseSearch', 'error', { error: message, latency_ms: Date.now() - startTime });\n return { success: false, results: [], stats: { ...emptyStats }, error: message };\n }\n}\n\n/**\n * CodebaseSearch client for programmatic semantic search\n *\n * @deprecated Prefer the unified `MorphClient` (`new MorphClient({ apiKey }).codebaseSearch`).\n * Standalone clients remain only for backwards compatibility and may be removed in a future\n * major version — do not use them in new code.\n */\nexport class CodebaseSearchClient extends APIResource {\n private readonly timeout: number;\n\n constructor(\n clientOrConfig: MorphAPIClient | { apiKey?: string; debug?: boolean; timeout?: number; retryConfig?: any } = {},\n ) {\n super(\n clientOrConfig instanceof MorphAPIClient\n ? clientOrConfig\n : new MorphAPIClient({\n apiKey: clientOrConfig.apiKey,\n timeout: clientOrConfig.timeout ?? DEFAULT_TIMEOUT,\n retryConfig: clientOrConfig.retryConfig,\n debug: clientOrConfig.debug,\n }),\n );\n this.timeout = (clientOrConfig instanceof MorphAPIClient ? undefined : clientOrConfig.timeout) ?? DEFAULT_TIMEOUT;\n }\n\n /**\n * Execute a semantic code search\n *\n * @param input - Search parameters including query, repoId, and target directories\n * @param overrides - Optional config overrides for this operation\n * @returns Search results with ranked code matches\n */\n async search(\n input: { query: string; repoId: string; target_directories?: string[]; explanation?: string; limit?: number },\n overrides?: { searchUrl?: string; timeout?: number },\n ): Promise<CodebaseSearchResult> {\n return runSearch(\n this._client,\n { query: input.query, target_directories: input.target_directories, explanation: input.explanation, limit: input.limit },\n input.repoId,\n overrides?.timeout ?? this.timeout,\n overrides?.searchUrl,\n );\n }\n}\n\n/**\n * Execute semantic code search (standalone — builds its own transport).\n * Throws on a missing API key; returns `{ success: false, error }` on HTTP failure.\n */\nexport async function executeCodebaseSearch(\n input: CodebaseSearchInput,\n config: CodebaseSearchConfig,\n): Promise<CodebaseSearchResult> {\n const apiKey = config.apiKey || process.env.MORPH_API_KEY;\n if (!apiKey) {\n throw new Error('MORPH_API_KEY not found. Set environment variable or pass in config');\n }\n\n const client = new MorphAPIClient({\n apiKey,\n reposURL: config.searchUrl,\n timeout: config.timeout ?? DEFAULT_TIMEOUT,\n retryConfig: config.retryConfig,\n debug: config.debug,\n });\n\n return runSearch(client, input, config.repoId, config.timeout ?? DEFAULT_TIMEOUT, config.searchUrl);\n}\n"],"mappings":";;;;;;;;;;;;;;AAWA,IAAM,kBAAkB;AAExB,IAAM,aAAa,EAAE,cAAc,GAAG,qBAAqB,GAAG,cAAc,EAAE;AAO9E,eAAe,UACb,QACA,OACA,QACA,SACA,SAC+B;AAC/B,QAAM,YAAY,KAAK,IAAI;AAC3B,SAAO,MAAM,kBAAkB,WAAW,EAAE,OAAO,MAAM,MAAM,MAAM,GAAG,GAAG,GAAG,SAAS,OAAO,CAAC;AAE/F,MAAI;AACF,UAAM,OAAO,MAAM,OAAO;AAAA,MACxB;AAAA,MACA;AAAA,QACE,SAAS,WAAW,OAAO;AAAA,QAC3B;AAAA,QACA,MAAM;AAAA,UACJ,OAAO,MAAM;AAAA,UACb;AAAA,UACA,mBAAmB,MAAM,sBAAsB,CAAC;AAAA,UAChD,OAAO,MAAM,SAAS;AAAA,UACtB,gBAAgB;AAAA,QAClB;AAAA,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;AAAA,EACF;AACF;AAMA,eAAsB,sBACpB,OACA,QAC+B;AAC/B,QAAM,SAAS,OAAO,UAAU,QAAQ,IAAI;AAC5C,MAAI,CAAC,QAAQ;AACX,UAAM,IAAI,MAAM,qEAAqE;AAAA,EACvF;AAEA,QAAM,SAAS,IAAI,eAAe;AAAA,IAChC;AAAA,IACA,UAAU,OAAO;AAAA,IACjB,SAAS,OAAO,WAAW;AAAA,IAC3B,aAAa,OAAO;AAAA,IACpB,OAAO,OAAO;AAAA,EAChB,CAAC;AAED,SAAO,UAAU,QAAQ,OAAO,OAAO,QAAQ,OAAO,WAAW,iBAAiB,OAAO,SAAS;AACpG;","names":[]}
|
package/dist/chunk-WLMPQFER.js
DELETED
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
executeCodebaseSearch
|
|
3
|
-
} from "./chunk-VBZ7BG47.js";
|
|
4
|
-
import {
|
|
5
|
-
CODEBASE_SEARCH_DESCRIPTION,
|
|
6
|
-
CODEBASE_SEARCH_SYSTEM_PROMPT
|
|
7
|
-
} from "./chunk-YQMPVJ2L.js";
|
|
8
|
-
|
|
9
|
-
// tools/codebase_search/openai.ts
|
|
10
|
-
var codebaseSearchTool = {
|
|
11
|
-
type: "function",
|
|
12
|
-
function: {
|
|
13
|
-
name: "codebase_search",
|
|
14
|
-
description: CODEBASE_SEARCH_DESCRIPTION,
|
|
15
|
-
parameters: {
|
|
16
|
-
type: "object",
|
|
17
|
-
properties: {
|
|
18
|
-
query: {
|
|
19
|
-
type: "string",
|
|
20
|
-
description: 'A complete question or description 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?"'
|
|
21
|
-
},
|
|
22
|
-
target_directories: {
|
|
23
|
-
type: "array",
|
|
24
|
-
items: { type: "string" },
|
|
25
|
-
description: "Prefix directory paths to limit search scope (single directory only, no glob patterns). Use [] to search entire repo."
|
|
26
|
-
},
|
|
27
|
-
explanation: {
|
|
28
|
-
type: "string",
|
|
29
|
-
description: "One sentence explanation as to why this tool is being used, and how it contributes to the goal."
|
|
30
|
-
},
|
|
31
|
-
limit: {
|
|
32
|
-
type: "number",
|
|
33
|
-
description: "Maximum results to return (default: 10)"
|
|
34
|
-
}
|
|
35
|
-
},
|
|
36
|
-
required: ["query", "target_directories", "explanation"]
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
function createCodebaseSearchTool(config) {
|
|
41
|
-
const toolDefinition = {
|
|
42
|
-
type: "function",
|
|
43
|
-
function: {
|
|
44
|
-
name: "codebase_search",
|
|
45
|
-
description: CODEBASE_SEARCH_DESCRIPTION,
|
|
46
|
-
parameters: {
|
|
47
|
-
type: "object",
|
|
48
|
-
properties: {
|
|
49
|
-
query: {
|
|
50
|
-
type: "string",
|
|
51
|
-
description: '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?"'
|
|
52
|
-
},
|
|
53
|
-
target_directories: {
|
|
54
|
-
type: "array",
|
|
55
|
-
items: { type: "string" },
|
|
56
|
-
description: "Prefix directory paths to limit search scope (single directory only, no glob patterns). Use [] to search entire repo."
|
|
57
|
-
},
|
|
58
|
-
explanation: {
|
|
59
|
-
type: "string",
|
|
60
|
-
description: "One sentence explanation as to why this tool is being used, and how it contributes to the goal."
|
|
61
|
-
},
|
|
62
|
-
limit: {
|
|
63
|
-
type: "number",
|
|
64
|
-
description: "Maximum results to return (default: 10)"
|
|
65
|
-
}
|
|
66
|
-
},
|
|
67
|
-
required: ["query", "target_directories", "explanation"]
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
return Object.assign(toolDefinition, {
|
|
72
|
-
execute: async (input) => {
|
|
73
|
-
const parsedInput = typeof input === "string" ? JSON.parse(input) : input;
|
|
74
|
-
return executeCodebaseSearch(parsedInput, config);
|
|
75
|
-
},
|
|
76
|
-
formatResult: (result) => {
|
|
77
|
-
return formatResult(result);
|
|
78
|
-
},
|
|
79
|
-
getSystemPrompt: () => {
|
|
80
|
-
return CODEBASE_SEARCH_SYSTEM_PROMPT;
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
async function execute(input, config) {
|
|
85
|
-
return executeCodebaseSearch(input, config);
|
|
86
|
-
}
|
|
87
|
-
function formatResult(result) {
|
|
88
|
-
if (!result.success) {
|
|
89
|
-
return `Search failed: ${result.error}`;
|
|
90
|
-
}
|
|
91
|
-
if (result.results.length === 0) {
|
|
92
|
-
return "No matching code found. Try rephrasing your query or removing directory filters.";
|
|
93
|
-
}
|
|
94
|
-
const lines = [];
|
|
95
|
-
lines.push(`Found ${result.results.length} relevant code sections (${result.stats.searchTimeMs}ms):
|
|
96
|
-
`);
|
|
97
|
-
result.results.forEach((r, i) => {
|
|
98
|
-
const relevance = (r.rerankScore * 100).toFixed(1);
|
|
99
|
-
lines.push(`${i + 1}. ${r.filepath} (${relevance}% relevant)`);
|
|
100
|
-
lines.push(` Symbol: ${r.symbolPath}`);
|
|
101
|
-
lines.push(` Language: ${r.language}`);
|
|
102
|
-
lines.push(` Lines: ${r.startLine}-${r.endLine}`);
|
|
103
|
-
lines.push(` Code:`);
|
|
104
|
-
const codeLines = r.content.split("\n");
|
|
105
|
-
codeLines.slice(0, Math.min(codeLines.length, 20)).forEach((line) => {
|
|
106
|
-
lines.push(` ${line}`);
|
|
107
|
-
});
|
|
108
|
-
if (codeLines.length > 20) {
|
|
109
|
-
lines.push(` ... (${codeLines.length - 20} more lines)`);
|
|
110
|
-
}
|
|
111
|
-
lines.push("");
|
|
112
|
-
});
|
|
113
|
-
return lines.join("\n");
|
|
114
|
-
}
|
|
115
|
-
function getSystemPrompt() {
|
|
116
|
-
return CODEBASE_SEARCH_SYSTEM_PROMPT;
|
|
117
|
-
}
|
|
118
|
-
var openai_default = { createCodebaseSearchTool, execute, formatResult, getSystemPrompt };
|
|
119
|
-
|
|
120
|
-
export {
|
|
121
|
-
codebaseSearchTool,
|
|
122
|
-
createCodebaseSearchTool,
|
|
123
|
-
execute,
|
|
124
|
-
formatResult,
|
|
125
|
-
getSystemPrompt,
|
|
126
|
-
openai_default
|
|
127
|
-
};
|
|
128
|
-
//# sourceMappingURL=chunk-WLMPQFER.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../tools/codebase_search/openai.ts"],"sourcesContent":["/**\n * OpenAI SDK adapter for codebase_search tool\n */\n\nimport type { ChatCompletionTool } from 'openai/resources/chat/completions';\nimport { executeCodebaseSearch } from './core.js';\nimport { CODEBASE_SEARCH_DESCRIPTION, CODEBASE_SEARCH_SYSTEM_PROMPT } from './prompts.js';\nimport type { CodebaseSearchConfig, CodebaseSearchInput, CodebaseSearchResult } from './types.js';\n\n/**\n * Direct codebase_search tool definition\n * Use this when you want to pass config at execute time\n */\nexport const codebaseSearchTool: ChatCompletionTool = {\n type: 'function',\n function: {\n name: 'codebase_search',\n description: CODEBASE_SEARCH_DESCRIPTION,\n parameters: {\n type: 'object',\n properties: {\n query: {\n type: 'string',\n description: 'A complete question or description 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 },\n target_directories: {\n type: 'array',\n items: { type: 'string' },\n description: 'Prefix directory paths to limit search scope (single directory only, no glob patterns). Use [] to search entire repo.',\n },\n explanation: {\n type: 'string',\n description: 'One sentence explanation as to why this tool is being used, and how it contributes to the goal.',\n },\n limit: {\n type: 'number',\n description: 'Maximum results to return (default: 10)',\n },\n },\n required: ['query', 'target_directories', 'explanation'],\n },\n },\n};\n\n/**\n * Create OpenAI-native codebase_search tool with execute and formatResult methods\n * \n * @param config - Configuration with repoId\n * @returns OpenAI ChatCompletionTool definition with methods\n * \n * @example\n * ```ts\n * import OpenAI from 'openai';\n * import { createCodebaseSearchTool } from 'morphsdk/tools/openai';\n * \n * const client = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });\n * const tool = createCodebaseSearchTool({ repoId: 'my-project' });\n * \n * const response = await client.chat.completions.create({\n * model: \"gpt-4o\",\n * tools: [tool], // tool itself is the ChatCompletionTool\n * messages: [{ role: \"user\", content: \"Find authentication code\" }]\n * });\n * \n * // Execute and format\n * const result = await tool.execute(toolCallArgs);\n * const formatted = tool.formatResult(result);\n * ```\n */\nexport function createCodebaseSearchTool(config: CodebaseSearchConfig) {\n const toolDefinition: ChatCompletionTool = {\n type: 'function',\n function: {\n name: 'codebase_search',\n description: CODEBASE_SEARCH_DESCRIPTION,\n parameters: {\n type: 'object',\n properties: {\n query: {\n type: 'string',\n description: '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 },\n target_directories: {\n type: 'array',\n items: { type: 'string' },\n description: 'Prefix directory paths to limit search scope (single directory only, no glob patterns). Use [] to search entire repo.',\n },\n explanation: {\n type: 'string',\n description: 'One sentence explanation as to why this tool is being used, and how it contributes to the goal.',\n },\n limit: {\n type: 'number',\n description: 'Maximum results to return (default: 10)',\n },\n },\n required: ['query', 'target_directories', 'explanation'],\n },\n },\n };\n\n return Object.assign(toolDefinition, {\n execute: async (input: CodebaseSearchInput | string): Promise<CodebaseSearchResult> => {\n const parsedInput = typeof input === 'string' ? JSON.parse(input) : input;\n return executeCodebaseSearch(parsedInput, config);\n },\n formatResult: (result: CodebaseSearchResult): string => {\n return formatResult(result);\n },\n getSystemPrompt: (): string => {\n return CODEBASE_SEARCH_SYSTEM_PROMPT;\n },\n });\n}\n\n/**\n * Execute codebase_search tool call\n * \n * @param input - Tool input from GPT (parsed from tool_calls)\n * @param config - Configuration with repoId (REQUIRED)\n * @returns Search results\n * \n * @example\n * ```ts\n * // Handle tool calls from GPT:\n * if (response.choices[0].message.tool_calls) {\n * for (const toolCall of response.choices[0].message.tool_calls) {\n * const args = JSON.parse(toolCall.function.arguments);\n * const result = await execute(args, { repoId: 'my-project' });\n * console.log(`Found ${result.results.length} matches`);\n * }\n * }\n * ```\n */\nexport async function execute(\n input: CodebaseSearchInput,\n config: CodebaseSearchConfig\n): Promise<CodebaseSearchResult> {\n return executeCodebaseSearch(input, config);\n}\n\n/**\n * Format search results for GPT\n * \n * @param result - Search result from endpoint\n * @returns Formatted string for tool message\n */\nexport function formatResult(result: CodebaseSearchResult): string {\n if (!result.success) {\n return `Search failed: ${result.error}`;\n }\n\n if (result.results.length === 0) {\n return 'No matching code found. Try rephrasing your query or removing directory filters.';\n }\n\n const lines: string[] = [];\n \n lines.push(`Found ${result.results.length} relevant code sections (${result.stats.searchTimeMs}ms):\\n`);\n\n result.results.forEach((r, i) => {\n const relevance = (r.rerankScore * 100).toFixed(1);\n lines.push(`${i + 1}. ${r.filepath} (${relevance}% relevant)`);\n lines.push(` Symbol: ${r.symbolPath}`);\n lines.push(` Language: ${r.language}`);\n lines.push(` Lines: ${r.startLine}-${r.endLine}`);\n lines.push(` Code:`);\n \n // Show code content\n const codeLines = r.content.split('\\n');\n codeLines.slice(0, Math.min(codeLines.length, 20)).forEach(line => {\n lines.push(` ${line}`);\n });\n \n if (codeLines.length > 20) {\n lines.push(` ... (${codeLines.length - 20} more lines)`);\n }\n \n lines.push('');\n });\n\n return lines.join('\\n');\n}\n\n/**\n * Get the system prompt for codebase_search usage\n * \n * @returns System prompt to guide GPT\n */\nexport function getSystemPrompt(): string {\n return CODEBASE_SEARCH_SYSTEM_PROMPT;\n}\n\n/**\n * Default export for convenience\n */\nexport default { createCodebaseSearchTool, execute, formatResult, getSystemPrompt };\n\n"],"mappings":";;;;;;;;;AAaO,IAAM,qBAAyC;AAAA,EACpD,MAAM;AAAA,EACN,UAAU;AAAA,IACR,MAAM;AAAA,IACN,aAAa;AAAA,IACb,YAAY;AAAA,MACV,MAAM;AAAA,MACN,YAAY;AAAA,QACV,OAAO;AAAA,UACL,MAAM;AAAA,UACN,aAAa;AAAA,QACf;AAAA,QACA,oBAAoB;AAAA,UAClB,MAAM;AAAA,UACN,OAAO,EAAE,MAAM,SAAS;AAAA,UACxB,aAAa;AAAA,QACf;AAAA,QACA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export
|
|
10
|
-
} from "./chunk-PZ5AY32C.js";
|
|
11
|
-
|
|
12
|
-
// tools/browser/anthropic.ts
|
|
13
|
-
var anthropic_exports = {};
|
|
14
|
-
__export(anthropic_exports, {
|
|
15
|
-
browserTool: () => browserTool,
|
|
16
|
-
createBrowserTool: () => createBrowserTool
|
|
17
|
-
});
|
|
18
|
-
var browserTool = {
|
|
19
|
-
name: "browser_task",
|
|
20
|
-
description: BROWSER_TOOL_DESCRIPTION,
|
|
21
|
-
input_schema: {
|
|
22
|
-
type: "object",
|
|
23
|
-
properties: {
|
|
24
|
-
task: {
|
|
25
|
-
type: "string",
|
|
26
|
-
description: 'Natural language description of what to do (e.g., "Test checkout flow for buying a pineapple")'
|
|
27
|
-
},
|
|
28
|
-
url: {
|
|
29
|
-
type: "string",
|
|
30
|
-
description: "Starting URL (e.g., https://3000-xyz.e2b.dev). Required if navigating to a specific page."
|
|
31
|
-
},
|
|
32
|
-
maxSteps: {
|
|
33
|
-
type: "number",
|
|
34
|
-
description: "Maximum number of browser actions to take (1-50). Default: 10. Use 15-30 for complex flows.",
|
|
35
|
-
default: 10
|
|
36
|
-
},
|
|
37
|
-
region: {
|
|
38
|
-
type: "string",
|
|
39
|
-
enum: ["sfo", "lon"],
|
|
40
|
-
description: "Browserless region: sfo (US West Coast) or lon (Europe). Default: sfo.",
|
|
41
|
-
default: "sfo"
|
|
42
|
-
}
|
|
43
|
-
},
|
|
44
|
-
required: ["task"]
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
function formatResult(result) {
|
|
48
|
-
if (result.success) {
|
|
49
|
-
const parts = [
|
|
50
|
-
"\u2705 Browser task completed successfully",
|
|
51
|
-
`Steps taken: ${result.stepsTaken ?? 0}`,
|
|
52
|
-
result.executionTimeMs ? `Execution time: ${result.executionTimeMs}ms` : null,
|
|
53
|
-
"",
|
|
54
|
-
"Result:",
|
|
55
|
-
result.result || "Task completed"
|
|
56
|
-
];
|
|
57
|
-
return parts.filter(Boolean).join("\n");
|
|
58
|
-
}
|
|
59
|
-
return `\u274C Browser task failed: ${result.error || "Unknown error"}`;
|
|
60
|
-
}
|
|
61
|
-
function createBrowserTool(config) {
|
|
62
|
-
return Object.assign({}, browserTool, {
|
|
63
|
-
execute: async (input) => {
|
|
64
|
-
return executeBrowserTask(input, config);
|
|
65
|
-
},
|
|
66
|
-
formatResult: (result) => {
|
|
67
|
-
return formatResult(result);
|
|
68
|
-
},
|
|
69
|
-
getSystemPrompt: () => {
|
|
70
|
-
return BROWSER_SYSTEM_PROMPT;
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export {
|
|
76
|
-
browserTool,
|
|
77
|
-
createBrowserTool,
|
|
78
|
-
anthropic_exports
|
|
79
|
-
};
|
|
80
|
-
//# sourceMappingURL=chunk-XH6KJJDI.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../tools/browser/anthropic.ts"],"sourcesContent":["/**\n * Anthropic SDK adapter for browser automation tool\n */\n\nimport type { Tool } from '@anthropic-ai/sdk/resources/messages.mjs';\nimport { executeBrowserTask } from './core.js';\nimport type {\n BrowserConfig,\n BrowserTaskInput,\n BrowserTaskResult,\n} from './types.js';\nimport { BROWSER_TOOL_DESCRIPTION, BROWSER_SYSTEM_PROMPT } from './prompts.js';\n\n/**\n * Anthropic tool definition for browser automation\n */\nexport const browserTool: Tool = {\n name: 'browser_task',\n description: BROWSER_TOOL_DESCRIPTION,\n input_schema: {\n type: 'object',\n properties: {\n task: {\n type: 'string',\n description: 'Natural language description of what to do (e.g., \"Test checkout flow for buying a pineapple\")',\n },\n url: {\n type: 'string',\n description: 'Starting URL (e.g., https://3000-xyz.e2b.dev). Required if navigating to a specific page.',\n },\n maxSteps: {\n type: 'number',\n description: 'Maximum number of browser actions to take (1-50). Default: 10. Use 15-30 for complex flows.',\n default: 10,\n },\n region: {\n type: 'string',\n enum: ['sfo', 'lon'],\n description: 'Browserless region: sfo (US West Coast) or lon (Europe). Default: sfo.',\n default: 'sfo',\n },\n },\n required: ['task'],\n },\n};\n\n/**\n * Format browser task result for Anthropic tool result\n * \n * Returns a concise summary suitable for agent context. The full result object\n * (with urls, errors, action_history, judgement, etc.) is available when calling\n * execute() directly, but this formatted string omits those details to save tokens.\n * \n * @param result - Browser task result with full history data\n * @returns Formatted string summary for tool result\n */\nfunction formatResult(result: BrowserTaskResult): string {\n if (result.success) {\n const parts = [\n '✅ Browser task completed successfully',\n `Steps taken: ${result.stepsTaken ?? 0}`,\n result.executionTimeMs ? `Execution time: ${result.executionTimeMs}ms` : null,\n '',\n 'Result:',\n result.result || 'Task completed',\n ];\n return parts.filter(Boolean).join('\\n');\n }\n\n return `❌ Browser task failed: ${result.error || 'Unknown error'}`;\n}\n\n/**\n * Create a configured browser tool with execute and formatResult methods\n * \n * @param config - Browser worker configuration\n * @returns Tool definition with execute and formatResult methods\n * \n * @example\n * ```typescript\n * import Anthropic from '@anthropic-ai/sdk';\n * import { createBrowserTool } from 'morphsdk/tools/browser/anthropic';\n * \n * const tool = createBrowserTool({\n * apiKey: process.env.MORPH_API_KEY,\n * timeout: 180000\n * });\n * \n * const client = new Anthropic();\n * \n * const response = await client.messages.create({\n * model: 'claude-sonnet-4-5-20250929',\n * tools: [tool], // tool itself is the Tool definition\n * messages: [{\n * role: 'user',\n * content: 'Test the checkout flow at https://3000-abc.e2b.dev'\n * }]\n * });\n * \n * // Execute and format\n * const result = await tool.execute(toolUseBlock.input);\n * const formatted = tool.formatResult(result);\n * ```\n */\nexport function createBrowserTool(config?: BrowserConfig) {\n return Object.assign({}, browserTool, {\n execute: async (input: BrowserTaskInput): Promise<BrowserTaskResult> => {\n return executeBrowserTask(input, config);\n },\n formatResult: (result: BrowserTaskResult): string => {\n return formatResult(result);\n },\n getSystemPrompt: (): string => {\n return BROWSER_SYSTEM_PROMPT;\n },\n });\n}\n"],"mappings":";;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAgBO,IAAM,cAAoB;AAAA,EAC/B,MAAM;AAAA,EACN,aAAa;AAAA,EACb,cAAc;AAAA,IACZ,MAAM;AAAA,IACN,YAAY;AAAA,MACV,MAAM;AAAA,QACJ,MAAM;AAAA,QACN,aAAa;AAAA,MACf;AAAA,MACA,KAAK;AAAA,QACH,MAAM;AAAA,QACN,aAAa;AAAA,MACf;AAAA,MACA,UAAU;AAAA,QACR,MAAM;AAAA,QACN,aAAa;AAAA,QACb,SAAS;AAAA,MACX;AAAA,MACA,QAAQ;AAAA,QACN,MAAM;AAAA,QACN,MAAM,CAAC,OAAO,KAAK;AAAA,QACnB,aAAa;AAAA,QACb,SAAS;AAAA,MACX;AAAA,IACF;AAAA,IACA,UAAU,CAAC,MAAM;AAAA,EACnB;AACF;AAYA,SAAS,aAAa,QAAmC;AACvD,MAAI,OAAO,SAAS;AAClB,UAAM,QAAQ;AAAA,MACZ;AAAA,MACA,gBAAgB,OAAO,cAAc,CAAC;AAAA,MACtC,OAAO,kBAAkB,mBAAmB,OAAO,eAAe,OAAO;AAAA,MACzE;AAAA,MACA;AAAA,MACA,OAAO,UAAU;AAAA,IACnB;AACA,WAAO,MAAM,OAAO,OAAO,EAAE,KAAK,IAAI;AAAA,EACxC;AAEA,SAAO,+BAA0B,OAAO,SAAS,eAAe;AAClE;AAkCO,SAAS,kBAAkB,QAAwB;AACxD,SAAO,OAAO,OAAO,CAAC,GAAG,aAAa;AAAA,IACpC,SAAS,OAAO,UAAwD;AACtE,aAAO,mBAAmB,OAAO,MAAM;AAAA,IACzC;AAAA,IACA,cAAc,CAAC,WAAsC;AACnD,aAAO,aAAa,MAAM;AAAA,IAC5B;AAAA,IACA,iBAAiB,MAAc;AAC7B,aAAO;AAAA,IACT;AAAA,EACF,CAAC;AACH;","names":[]}
|