@morphllm/morphsdk 0.2.199 → 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/dist/{chunk-GTV27THY.js → chunk-3CCWSLQW.js} +2 -2
- package/dist/{chunk-DP2PT36G.js → chunk-7I2A7GGJ.js} +2 -2
- package/dist/{chunk-CEXBKXWU.js → chunk-AKSXZBPT.js} +3 -3
- package/dist/{chunk-GKRPR5PZ.js → chunk-B4X5RWLR.js} +18 -69
- package/dist/chunk-B4X5RWLR.js.map +1 -0
- package/dist/{chunk-PKJ7ODTG.js → chunk-L6YOMTFU.js} +3 -3
- package/dist/{chunk-OPNTDMHH.js → chunk-LN7GNFET.js} +4 -4
- package/dist/{chunk-KXEPBLVD.js → chunk-MLROWLS6.js} +10 -10
- package/dist/{chunk-PW6K6OJL.js → chunk-MPL6BDR6.js} +2 -2
- package/dist/{chunk-ZHB57ORD.js → chunk-PD3EDFQD.js} +6 -6
- package/dist/{chunk-5KQ2WRBU.js → chunk-PJNL35DC.js} +2 -2
- package/dist/{chunk-UT3NQLCF.js → chunk-Q65LL6UM.js} +2 -2
- package/dist/{chunk-W37OFBSG.js → chunk-QTBFL4DG.js} +2 -2
- package/dist/{chunk-BLCCGRKT.js → chunk-SNYHVDE4.js} +4 -4
- package/dist/{chunk-O7LJEVZO.js → chunk-TIMDDHYB.js} +4 -4
- package/dist/{chunk-Q3NH3NPD.js → chunk-UHIANNKC.js} +4 -4
- package/dist/{chunk-7UU4NF4G.js → chunk-UKAAT6KT.js} +4 -4
- package/dist/{chunk-JOC3ZI56.js → chunk-UZ42MHTR.js} +3 -37
- package/dist/chunk-UZ42MHTR.js.map +1 -0
- package/dist/{chunk-YSFEKIYQ.js → chunk-WTENYKJP.js} +2 -2
- package/dist/{chunk-BTMMUG3E.js → chunk-XTLPA7ZP.js} +2 -2
- package/dist/{chunk-ULHHMZRL.js → chunk-Z57GJLCG.js} +3 -3
- package/dist/{chunk-WDBYAXZ5.js → chunk-ZE64EWUV.js} +2 -2
- package/dist/{client-CGW0Cevz.d.ts → client-BWhi-vSj.d.ts} +4 -65
- package/dist/client.cjs +45 -411
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.ts +2 -4
- package/dist/client.js +22 -27
- package/dist/core/client.cjs +2 -36
- package/dist/core/client.cjs.map +1 -1
- package/dist/core/client.js +4 -4
- package/dist/core/error.cjs +2 -36
- package/dist/core/error.cjs.map +1 -1
- package/dist/core/error.js +3 -3
- package/dist/core/index.cjs +2 -36
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.js +4 -4
- package/dist/edge.cjs +2 -36
- package/dist/edge.cjs.map +1 -1
- package/dist/edge.js +7 -7
- package/dist/index.cjs +48 -416
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -4
- package/dist/index.js +26 -34
- package/dist/modelrouter/core.cjs +2 -36
- package/dist/modelrouter/core.cjs.map +1 -1
- package/dist/modelrouter/core.js +5 -5
- package/dist/modelrouter/index.cjs +2 -36
- package/dist/modelrouter/index.cjs.map +1 -1
- package/dist/modelrouter/index.js +5 -5
- package/dist/subagents/anthropic.cjs +2 -36
- package/dist/subagents/anthropic.cjs.map +1 -1
- package/dist/subagents/anthropic.d.ts +1 -1
- package/dist/subagents/anthropic.js +11 -11
- 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 -36
- package/dist/subagents/vercel.cjs.map +1 -1
- package/dist/subagents/vercel.d.ts +1 -1
- package/dist/subagents/vercel.js +11 -11
- package/dist/tools/compact/core.cjs +2 -36
- package/dist/tools/compact/core.cjs.map +1 -1
- package/dist/tools/compact/core.js +5 -5
- package/dist/tools/compact/index.cjs +2 -36
- package/dist/tools/compact/index.cjs.map +1 -1
- package/dist/tools/compact/index.js +6 -6
- package/dist/tools/fastapply/anthropic.cjs +2 -36
- package/dist/tools/fastapply/anthropic.cjs.map +1 -1
- package/dist/tools/fastapply/anthropic.js +7 -7
- package/dist/tools/fastapply/apply.cjs +2 -36
- package/dist/tools/fastapply/apply.cjs.map +1 -1
- package/dist/tools/fastapply/apply.js +2 -2
- package/dist/tools/fastapply/core.cjs +2 -36
- package/dist/tools/fastapply/core.cjs.map +1 -1
- package/dist/tools/fastapply/core.js +6 -6
- package/dist/tools/fastapply/index.cjs +2 -36
- package/dist/tools/fastapply/index.cjs.map +1 -1
- package/dist/tools/fastapply/index.js +12 -12
- package/dist/tools/fastapply/openai.cjs +2 -36
- package/dist/tools/fastapply/openai.cjs.map +1 -1
- package/dist/tools/fastapply/openai.js +7 -7
- package/dist/tools/fastapply/vercel.cjs +2 -36
- package/dist/tools/fastapply/vercel.cjs.map +1 -1
- package/dist/tools/fastapply/vercel.js +7 -7
- package/dist/tools/index.cjs +2 -36
- package/dist/tools/index.cjs.map +1 -1
- package/dist/tools/index.js +12 -12
- package/dist/tools/utils/resilience.cjs +2 -36
- 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 -36
- package/dist/tools/warp_grep/agent/runner.cjs.map +1 -1
- package/dist/tools/warp_grep/agent/runner.js +3 -3
- package/dist/tools/warp_grep/anthropic.cjs +2 -36
- 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 +11 -11
- package/dist/tools/warp_grep/client.cjs +2 -36
- 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 +10 -10
- package/dist/tools/warp_grep/gemini.cjs +2 -36
- 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 +10 -10
- package/dist/tools/warp_grep/harness.js +9 -9
- package/dist/tools/warp_grep/index.cjs +2 -36
- 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 +16 -16
- package/dist/tools/warp_grep/openai.cjs +2 -36
- 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 +11 -11
- package/dist/tools/warp_grep/providers/code_storage_http.d.ts +1 -1
- package/dist/tools/warp_grep/providers/local.js +2 -2
- package/dist/tools/warp_grep/providers/remote.d.ts +1 -1
- package/dist/tools/warp_grep/vercel.cjs +2 -36
- 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 +11 -11
- package/dist/{types-qwD753FR.d.ts → types-DxZLPogx.d.ts} +1 -1
- package/dist/version.cjs +2 -36
- package/dist/version.cjs.map +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -36
- package/dist/chunk-EMURAU6J.js +0 -148
- package/dist/chunk-EMURAU6J.js.map +0 -1
- package/dist/chunk-GKRPR5PZ.js.map +0 -1
- package/dist/chunk-IDMKQWQG.js +0 -214
- package/dist/chunk-IDMKQWQG.js.map +0 -1
- package/dist/chunk-JOC3ZI56.js.map +0 -1
- package/dist/chunk-K2JR2NFQ.js +0 -128
- package/dist/chunk-K2JR2NFQ.js.map +0 -1
- package/dist/chunk-MEZTHMB2.js +0 -83
- package/dist/chunk-MEZTHMB2.js.map +0 -1
- package/dist/chunk-RL3ZTXT3.js +0 -58
- package/dist/chunk-RL3ZTXT3.js.map +0 -1
- package/dist/chunk-TLXVGE4R.js +0 -42
- package/dist/chunk-TLXVGE4R.js.map +0 -1
- package/dist/chunk-VS5F2ORN.js +0 -97
- package/dist/chunk-VS5F2ORN.js.map +0 -1
- package/dist/chunk-YQMPVJ2L.js +0 -32
- package/dist/chunk-YQMPVJ2L.js.map +0 -1
- package/dist/otel-CG0uqXjp.d.ts +0 -42
- package/dist/tools/codebase_search/anthropic.cjs +0 -664
- 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 -606
- 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 -789
- 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 -713
- 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 -626
- 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/{chunk-GTV27THY.js.map → chunk-3CCWSLQW.js.map} +0 -0
- /package/dist/{chunk-DP2PT36G.js.map → chunk-7I2A7GGJ.js.map} +0 -0
- /package/dist/{chunk-CEXBKXWU.js.map → chunk-AKSXZBPT.js.map} +0 -0
- /package/dist/{chunk-PKJ7ODTG.js.map → chunk-L6YOMTFU.js.map} +0 -0
- /package/dist/{chunk-OPNTDMHH.js.map → chunk-LN7GNFET.js.map} +0 -0
- /package/dist/{chunk-KXEPBLVD.js.map → chunk-MLROWLS6.js.map} +0 -0
- /package/dist/{chunk-PW6K6OJL.js.map → chunk-MPL6BDR6.js.map} +0 -0
- /package/dist/{chunk-ZHB57ORD.js.map → chunk-PD3EDFQD.js.map} +0 -0
- /package/dist/{chunk-5KQ2WRBU.js.map → chunk-PJNL35DC.js.map} +0 -0
- /package/dist/{chunk-UT3NQLCF.js.map → chunk-Q65LL6UM.js.map} +0 -0
- /package/dist/{chunk-W37OFBSG.js.map → chunk-QTBFL4DG.js.map} +0 -0
- /package/dist/{chunk-BLCCGRKT.js.map → chunk-SNYHVDE4.js.map} +0 -0
- /package/dist/{chunk-O7LJEVZO.js.map → chunk-TIMDDHYB.js.map} +0 -0
- /package/dist/{chunk-Q3NH3NPD.js.map → chunk-UHIANNKC.js.map} +0 -0
- /package/dist/{chunk-7UU4NF4G.js.map → chunk-UKAAT6KT.js.map} +0 -0
- /package/dist/{chunk-YSFEKIYQ.js.map → chunk-WTENYKJP.js.map} +0 -0
- /package/dist/{chunk-BTMMUG3E.js.map → chunk-XTLPA7ZP.js.map} +0 -0
- /package/dist/{chunk-ULHHMZRL.js.map → chunk-Z57GJLCG.js.map} +0 -0
- /package/dist/{chunk-WDBYAXZ5.js.map → chunk-ZE64EWUV.js.map} +0 -0
package/dist/chunk-IDMKQWQG.js
DELETED
|
@@ -1,214 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
metadata
|
|
3
|
-
} from "./chunk-TLXVGE4R.js";
|
|
4
|
-
|
|
5
|
-
// tracing/interaction.ts
|
|
6
|
-
import { context, SpanStatusCode, trace } from "@opentelemetry/api";
|
|
7
|
-
import * as traceloop from "@traceloop/node-server-sdk";
|
|
8
|
-
var ASSOC = "traceloop.association.properties.";
|
|
9
|
-
var ENTITY_INPUT = "traceloop.entity.input";
|
|
10
|
-
var ENTITY_OUTPUT = "traceloop.entity.output";
|
|
11
|
-
var ENTITY_NAME = "traceloop.entity.name";
|
|
12
|
-
var SPAN_KIND = "traceloop.span.kind";
|
|
13
|
-
function uuid() {
|
|
14
|
-
const c = globalThis.crypto;
|
|
15
|
-
if (c?.randomUUID) return c.randomUUID();
|
|
16
|
-
return "xxxxxxxxxxxx4xxxyxxx".replace(/[xy]/g, (ch) => {
|
|
17
|
-
const r = Math.random() * 16 | 0;
|
|
18
|
-
return (ch === "x" ? r : r & 3 | 8).toString(16);
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
function asString(v) {
|
|
22
|
-
if (v == null) return "";
|
|
23
|
-
return typeof v === "string" ? v : JSON.stringify(v);
|
|
24
|
-
}
|
|
25
|
-
function associationProps(ctx, extra) {
|
|
26
|
-
const props = { ...extra };
|
|
27
|
-
if (ctx.userId) props.user_id = ctx.userId;
|
|
28
|
-
if (ctx.convoId) props.convo_id = ctx.convoId;
|
|
29
|
-
if (ctx.eventId) props.event_id = ctx.eventId;
|
|
30
|
-
if (ctx.event) props.event_name = ctx.event;
|
|
31
|
-
return props;
|
|
32
|
-
}
|
|
33
|
-
function createInteractionApi(initial, traceContent, onClose) {
|
|
34
|
-
const ctx = {
|
|
35
|
-
...initial,
|
|
36
|
-
eventId: initial.eventId ?? uuid()
|
|
37
|
-
};
|
|
38
|
-
const properties = { ...initial.properties ?? {} };
|
|
39
|
-
let input = initial.input;
|
|
40
|
-
let workflowSpan = null;
|
|
41
|
-
let finished = false;
|
|
42
|
-
const withAssoc = (fn) => traceloop.withAssociationProperties(associationProps(ctx, properties), fn);
|
|
43
|
-
const workflowName = () => ctx.event ?? "interaction";
|
|
44
|
-
function ensureWorkflowSpan() {
|
|
45
|
-
if (workflowSpan) return workflowSpan;
|
|
46
|
-
const span = traceloop.getTraceloopTracer().startSpan(workflowName());
|
|
47
|
-
span.setAttribute(SPAN_KIND, "workflow");
|
|
48
|
-
for (const [k, v] of Object.entries(associationProps(ctx, properties))) {
|
|
49
|
-
span.setAttribute(ASSOC + k, v);
|
|
50
|
-
}
|
|
51
|
-
if (traceContent && input) span.setAttribute(ENTITY_INPUT, input);
|
|
52
|
-
workflowSpan = span;
|
|
53
|
-
return span;
|
|
54
|
-
}
|
|
55
|
-
function withWorkflowContext(fn) {
|
|
56
|
-
return withAssoc(() => {
|
|
57
|
-
const span = ensureWorkflowSpan();
|
|
58
|
-
return context.with(trace.setSpan(context.active(), span), fn);
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
function closeWorkflowSpan(apply) {
|
|
62
|
-
if (finished) return;
|
|
63
|
-
withAssoc(() => {
|
|
64
|
-
const span = ensureWorkflowSpan();
|
|
65
|
-
apply(span);
|
|
66
|
-
span.end();
|
|
67
|
-
});
|
|
68
|
-
workflowSpan = null;
|
|
69
|
-
finished = true;
|
|
70
|
-
onClose?.(ctx.eventId);
|
|
71
|
-
}
|
|
72
|
-
function failWorkflowSpan(err) {
|
|
73
|
-
const e = err instanceof Error ? err : new Error(String(err));
|
|
74
|
-
closeWorkflowSpan((span) => {
|
|
75
|
-
span.recordException(e);
|
|
76
|
-
span.setStatus({ code: SpanStatusCode.ERROR, message: e.message });
|
|
77
|
-
if (traceContent) span.setAttribute(ENTITY_OUTPUT, `ERROR: ${e.message}`);
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
const toolName = (p) => typeof p === "string" ? p : p.name;
|
|
81
|
-
function startToolSpan(params) {
|
|
82
|
-
const name = toolName(params);
|
|
83
|
-
const span = traceloop.getTraceloopTracer().startSpan(name);
|
|
84
|
-
span.setAttribute(SPAN_KIND, "tool");
|
|
85
|
-
span.setAttribute(ENTITY_NAME, name);
|
|
86
|
-
for (const [k, v] of Object.entries(associationProps(ctx, properties))) {
|
|
87
|
-
span.setAttribute(ASSOC + k, v);
|
|
88
|
-
}
|
|
89
|
-
if (typeof params !== "string" && params.properties) {
|
|
90
|
-
for (const [k, v] of Object.entries(params.properties)) span.setAttribute(k, v);
|
|
91
|
-
}
|
|
92
|
-
return {
|
|
93
|
-
setInput(value) {
|
|
94
|
-
if (traceContent) span.setAttribute(ENTITY_INPUT, asString(value));
|
|
95
|
-
},
|
|
96
|
-
setOutput(value) {
|
|
97
|
-
if (traceContent) span.setAttribute(ENTITY_OUTPUT, asString(value));
|
|
98
|
-
},
|
|
99
|
-
setError(error) {
|
|
100
|
-
const e = typeof error === "string" ? new Error(error) : error;
|
|
101
|
-
span.recordException(e);
|
|
102
|
-
span.setStatus({ code: SpanStatusCode.ERROR, message: e.message });
|
|
103
|
-
},
|
|
104
|
-
end() {
|
|
105
|
-
span.end();
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
return {
|
|
110
|
-
getEventId: () => ctx.eventId,
|
|
111
|
-
setInput(value) {
|
|
112
|
-
input = value;
|
|
113
|
-
},
|
|
114
|
-
setProperty(key, value) {
|
|
115
|
-
properties[key] = value;
|
|
116
|
-
},
|
|
117
|
-
setProperties(props) {
|
|
118
|
-
Object.assign(properties, props);
|
|
119
|
-
},
|
|
120
|
-
vercelAiSdkMetadata() {
|
|
121
|
-
return metadata({
|
|
122
|
-
userId: ctx.userId ?? "unknown",
|
|
123
|
-
convoId: ctx.convoId,
|
|
124
|
-
eventName: ctx.event,
|
|
125
|
-
eventId: ctx.eventId,
|
|
126
|
-
properties
|
|
127
|
-
});
|
|
128
|
-
},
|
|
129
|
-
async run(fn) {
|
|
130
|
-
try {
|
|
131
|
-
return await Promise.resolve(withWorkflowContext(fn));
|
|
132
|
-
} catch (err) {
|
|
133
|
-
failWorkflowSpan(err);
|
|
134
|
-
throw err;
|
|
135
|
-
}
|
|
136
|
-
},
|
|
137
|
-
withSpan(params, fn) {
|
|
138
|
-
const name = typeof params === "string" ? params : params.name;
|
|
139
|
-
return Promise.resolve(withWorkflowContext(() => traceloop.withTask({ name }, fn)));
|
|
140
|
-
},
|
|
141
|
-
withTool(params, fn) {
|
|
142
|
-
const name = toolName(params);
|
|
143
|
-
const version = typeof params === "string" ? void 0 : params.version;
|
|
144
|
-
return Promise.resolve(withWorkflowContext(() => traceloop.withTool({ name, version }, fn)));
|
|
145
|
-
},
|
|
146
|
-
startToolSpan,
|
|
147
|
-
trackTool(params) {
|
|
148
|
-
const span = startToolSpan({ name: params.name, properties: params.properties });
|
|
149
|
-
if (params.input !== void 0) span.setInput(params.input);
|
|
150
|
-
if (params.output !== void 0) span.setOutput(params.output);
|
|
151
|
-
if (params.error) span.setError(params.error);
|
|
152
|
-
span.end();
|
|
153
|
-
},
|
|
154
|
-
async finish(opts) {
|
|
155
|
-
const output = typeof opts === "string" ? opts : opts.output;
|
|
156
|
-
if (typeof opts !== "string" && opts.properties) Object.assign(properties, opts.properties);
|
|
157
|
-
closeWorkflowSpan((span) => {
|
|
158
|
-
if (traceContent) span.setAttribute(ENTITY_OUTPUT, output);
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
};
|
|
162
|
-
}
|
|
163
|
-
function createNoopInteraction(initial) {
|
|
164
|
-
const ctx = {
|
|
165
|
-
...initial,
|
|
166
|
-
eventId: initial.eventId ?? uuid()
|
|
167
|
-
};
|
|
168
|
-
const properties = { ...initial.properties ?? {} };
|
|
169
|
-
const noopToolSpan = { setInput() {
|
|
170
|
-
}, setOutput() {
|
|
171
|
-
}, setError() {
|
|
172
|
-
}, end() {
|
|
173
|
-
} };
|
|
174
|
-
return {
|
|
175
|
-
getEventId: () => ctx.eventId,
|
|
176
|
-
setInput() {
|
|
177
|
-
},
|
|
178
|
-
setProperty(key, value) {
|
|
179
|
-
properties[key] = value;
|
|
180
|
-
},
|
|
181
|
-
setProperties(props) {
|
|
182
|
-
Object.assign(properties, props);
|
|
183
|
-
},
|
|
184
|
-
vercelAiSdkMetadata() {
|
|
185
|
-
return metadata({
|
|
186
|
-
userId: ctx.userId ?? "unknown",
|
|
187
|
-
convoId: ctx.convoId,
|
|
188
|
-
eventName: ctx.event,
|
|
189
|
-
eventId: ctx.eventId,
|
|
190
|
-
properties
|
|
191
|
-
});
|
|
192
|
-
},
|
|
193
|
-
async run(fn) {
|
|
194
|
-
return await fn();
|
|
195
|
-
},
|
|
196
|
-
async withSpan(_params, fn) {
|
|
197
|
-
return await fn();
|
|
198
|
-
},
|
|
199
|
-
async withTool(_params, fn) {
|
|
200
|
-
return await fn();
|
|
201
|
-
},
|
|
202
|
-
startToolSpan: () => noopToolSpan,
|
|
203
|
-
trackTool() {
|
|
204
|
-
},
|
|
205
|
-
async finish() {
|
|
206
|
-
}
|
|
207
|
-
};
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
export {
|
|
211
|
-
createInteractionApi,
|
|
212
|
-
createNoopInteraction
|
|
213
|
-
};
|
|
214
|
-
//# sourceMappingURL=chunk-IDMKQWQG.js.map
|
|
@@ -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,GAAG,MAAM;AACjD,MAAI,IAAI,OAAQ,OAAM,UAAU,IAAI;AACpC,MAAI,IAAI,QAAS,OAAM,WAAW,IAAI;AACtC,MAAI,IAAI,QAAS,OAAM,WAAW,IAAI;AACtC,MAAI,IAAI,MAAO,OAAM,aAAa,IAAI;AACtC,SAAO;AACT;AAEO,SAAS,qBACd,SACA,cACA,SACa;AACb,QAAM,MAA0C;AAAA,IAC9C,GAAG;AAAA,IACH,SAAS,QAAQ,WAAW,KAAK;AAAA,EACnC;AACA,QAAM,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3D,CAAC;AAAA,IACH;AAAA,EACF;AACF;AASO,SAAS,sBAAsB,SAA0D;AAC9F,QAAM,MAA0C;AAAA,IAC9C,GAAG;AAAA,IACH,SAAS,QAAQ,WAAW,KAAK;AAAA,EACnC;AACA,QAAM,aAAqC,EAAE,GAAI,QAAQ,cAAc,CAAC,EAAG;AAC3E,QAAM,eAAyB,EAAE,WAAW;AAAA,EAAC,GAAG,YAAY;AAAA,EAAC,GAAG,WAAW;AAAA,EAAC,GAAG,MAAM;AAAA,EAAC,EAAE;AAExF,SAAO;AAAA,IACL,YAAY,MAAM,IAAI;AAAA,IACtB,WAAW;AAAA,IAAC;AAAA,IACZ,YAAY,KAAa,OAAe;AACtC,iBAAW,GAAG,IAAI;AAAA,IACpB;AAAA,IACA,cAAc,OAA+B;AAC3C,aAAO,OAAO,YAAY,KAAK;AAAA,IACjC;AAAA,IACA,sBAAsB;AACpB,aAAO,SAAc;AAAA,QACnB,QAAQ,IAAI,UAAU;AAAA,QACtB,SAAS,IAAI;AAAA,QACb,WAAW,IAAI;AAAA,QACf,SAAS,IAAI;AAAA,QACb;AAAA,MACF,CAAC;AAAA,IACH;AAAA,IACA,MAAM,IAAI,IAAI;AACZ,aAAO,MAAM,GAAG;AAAA,IAClB;AAAA,IACA,MAAM,SAAS,SAAS,IAAI;AAC1B,aAAO,MAAM,GAAG;AAAA,IAClB;AAAA,IACA,MAAM,SAAS,SAAS,IAAI;AAC1B,aAAO,MAAM,GAAG;AAAA,IAClB;AAAA,IACA,eAAe,MAAM;AAAA,IACrB,YAAY;AAAA,IAAC;AAAA,IACb,MAAM,SAAS;AAAA,IAAC;AAAA,EAClB;AACF;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../package.json","../version.ts"],"sourcesContent":["{\n \"name\": \"@morphllm/morphsdk\",\n \"version\": \"0.2.199\",\n \"description\": \"TypeScript SDK and CLI for Morph Fast Apply integration\",\n \"type\": \"module\",\n \"main\": \"./dist/index.cjs\",\n \"module\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"exports\": {\n \".\": {\n \"types\": \"./dist/index.d.ts\",\n \"import\": \"./dist/index.js\",\n \"require\": \"./dist/index.cjs\"\n },\n \"./logger\": {\n \"types\": \"./dist/logger.d.ts\",\n \"import\": \"./dist/logger.js\",\n \"require\": \"./dist/logger.cjs\"\n },\n \"./edge\": {\n \"types\": \"./dist/edge.d.ts\",\n \"import\": \"./dist/edge.js\",\n \"require\": \"./dist/edge.cjs\"\n },\n \"./tools/warp-grep\": {\n \"types\": \"./dist/tools/warp_grep/index.d.ts\",\n \"import\": \"./dist/tools/warp_grep/index.js\",\n \"require\": \"./dist/tools/warp_grep/index.cjs\"\n },\n \"./tools/warp-grep/openai\": {\n \"types\": \"./dist/tools/warp_grep/openai.d.ts\",\n \"import\": \"./dist/tools/warp_grep/openai.js\",\n \"require\": \"./dist/tools/warp_grep/openai.cjs\"\n },\n \"./tools/warp-grep/anthropic\": {\n \"types\": \"./dist/tools/warp_grep/anthropic.d.ts\",\n \"import\": \"./dist/tools/warp_grep/anthropic.js\",\n \"require\": \"./dist/tools/warp_grep/anthropic.cjs\"\n },\n \"./tools/warp-grep/vercel\": {\n \"types\": \"./dist/tools/warp_grep/vercel.d.ts\",\n \"import\": \"./dist/tools/warp_grep/vercel.js\",\n \"require\": \"./dist/tools/warp_grep/vercel.cjs\"\n },\n \"./tools/warp-grep/client\": {\n \"types\": \"./dist/tools/warp_grep/client.d.ts\",\n \"import\": \"./dist/tools/warp_grep/client.js\",\n \"require\": \"./dist/tools/warp_grep/client.cjs\"\n },\n \"./tools/warp-grep/gemini\": {\n \"types\": \"./dist/tools/warp_grep/gemini.d.ts\",\n \"import\": \"./dist/tools/warp_grep/gemini.js\",\n \"require\": \"./dist/tools/warp_grep/gemini.cjs\"\n },\n \"./tools/warp-grep/harness\": {\n \"types\": \"./dist/tools/warp_grep/harness.d.ts\",\n \"import\": \"./dist/tools/warp_grep/harness.js\",\n \"require\": \"./dist/tools/warp_grep/harness.cjs\"\n },\n \"./tracing\": {\n \"types\": \"./dist/tracing/index.d.ts\",\n \"import\": \"./dist/tracing/index.js\",\n \"require\": \"./dist/tracing/index.cjs\"\n },\n \"./tracing/otel\": {\n \"types\": \"./dist/tracing/otel.d.ts\",\n \"import\": \"./dist/tracing/otel.js\",\n \"require\": \"./dist/tracing/otel.cjs\"\n },\n \"./tools/fastapply\": {\n \"types\": \"./dist/tools/fastapply/index.d.ts\",\n \"import\": \"./dist/tools/fastapply/index.js\",\n \"require\": \"./dist/tools/fastapply/index.cjs\"\n },\n \"./tools/fastapply/anthropic\": {\n \"types\": \"./dist/tools/fastapply/anthropic.d.ts\",\n \"import\": \"./dist/tools/fastapply/anthropic.js\",\n \"require\": \"./dist/tools/fastapply/anthropic.cjs\"\n },\n \"./tools/fastapply/openai\": {\n \"types\": \"./dist/tools/fastapply/openai.d.ts\",\n \"import\": \"./dist/tools/fastapply/openai.js\",\n \"require\": \"./dist/tools/fastapply/openai.cjs\"\n },\n \"./tools/fastapply/vercel\": {\n \"types\": \"./dist/tools/fastapply/vercel.d.ts\",\n \"import\": \"./dist/tools/fastapply/vercel.js\",\n \"require\": \"./dist/tools/fastapply/vercel.cjs\"\n },\n \"./tools/codebase-search\": {\n \"types\": \"./dist/tools/codebase_search/index.d.ts\",\n \"import\": \"./dist/tools/codebase_search/index.js\",\n \"require\": \"./dist/tools/codebase_search/index.cjs\"\n },\n \"./tools/codebase-search/anthropic\": {\n \"types\": \"./dist/tools/codebase_search/anthropic.d.ts\",\n \"import\": \"./dist/tools/codebase_search/anthropic.js\",\n \"require\": \"./dist/tools/codebase_search/anthropic.cjs\"\n },\n \"./tools/codebase-search/openai\": {\n \"types\": \"./dist/tools/codebase_search/openai.d.ts\",\n \"import\": \"./dist/tools/codebase_search/openai.js\",\n \"require\": \"./dist/tools/codebase_search/openai.cjs\"\n },\n \"./tools/codebase-search/vercel\": {\n \"types\": \"./dist/tools/codebase_search/vercel.d.ts\",\n \"import\": \"./dist/tools/codebase_search/vercel.js\",\n \"require\": \"./dist/tools/codebase_search/vercel.cjs\"\n },\n \"./modelrouter\": {\n \"types\": \"./dist/modelrouter/index.d.ts\",\n \"import\": \"./dist/modelrouter/index.js\",\n \"require\": \"./dist/modelrouter/index.cjs\"\n },\n \"./tools/compact\": {\n \"types\": \"./dist/tools/compact/index.d.ts\",\n \"import\": \"./dist/tools/compact/index.js\",\n \"require\": \"./dist/tools/compact/index.cjs\"\n },\n \"./subagents\": {\n \"types\": \"./dist/subagents/index.d.ts\",\n \"import\": \"./dist/subagents/index.js\",\n \"require\": \"./dist/subagents/index.cjs\"\n },\n \"./subagents/vercel\": {\n \"types\": \"./dist/subagents/vercel.d.ts\",\n \"import\": \"./dist/subagents/vercel.js\",\n \"require\": \"./dist/subagents/vercel.cjs\"\n },\n \"./subagents/anthropic\": {\n \"types\": \"./dist/subagents/anthropic.d.ts\",\n \"import\": \"./dist/subagents/anthropic.js\",\n \"require\": \"./dist/subagents/anthropic.cjs\"\n },\n \"./ai-sdk\": {\n \"types\": \"./dist/ai-sdk/index.d.ts\",\n \"import\": \"./dist/ai-sdk/index.js\",\n \"require\": \"./dist/ai-sdk/index.cjs\"\n }\n },\n \"files\": [\n \"dist/**/*.js\",\n \"dist/**/*.cjs\",\n \"dist/**/*.d.ts\",\n \"dist/**/*.map\",\n \"!dist/**/__tests__/**\",\n \"!dist/**/*.test.*\"\n ],\n \"scripts\": {\n \"build\": \"tsup version.ts index.ts edge.ts client.ts core/index.ts core/client.ts core/resource.ts core/error.ts tools/index.ts tools/fastapply/index.ts tools/fastapply/core.ts tools/fastapply/apply.ts tools/fastapply/types.ts tools/fastapply/prompts.ts tools/fastapply/anthropic.ts tools/fastapply/openai.ts tools/fastapply/vercel.ts tools/codebase_search/index.ts tools/codebase_search/core.ts tools/codebase_search/types.ts tools/codebase_search/prompts.ts tools/codebase_search/anthropic.ts tools/codebase_search/openai.ts tools/codebase_search/vercel.ts tools/warp_grep/index.ts tools/warp_grep/client.ts tools/warp_grep/openai.ts tools/warp_grep/anthropic.ts tools/warp_grep/vercel.ts tools/warp_grep/gemini.ts tools/warp_grep/harness.ts tools/warp_grep/agent/config.ts tools/warp_grep/agent/parser.ts tools/warp_grep/agent/runner.ts tools/warp_grep/agent/types.ts tools/warp_grep/agent/formatter.ts tools/warp_grep/providers/types.ts tools/warp_grep/providers/local.ts tools/warp_grep/providers/remote.ts tools/warp_grep/providers/code_storage_http.ts tools/warp_grep/tools/grep.ts tools/warp_grep/tools/analyse.ts tools/warp_grep/tools/read.ts tools/warp_grep/tools/finish.ts tools/warp_grep/utils/paths.ts tools/warp_grep/utils/github.ts tools/warp_grep/utils/ripgrep.ts tools/warp_grep/utils/format.ts tools/warp_grep/utils/files.ts modelrouter/index.ts modelrouter/core.ts modelrouter/types.ts tools/compact/index.ts tools/compact/core.ts tools/compact/types.ts tools/utils/resilience.ts subagents/index.ts subagents/types.ts subagents/prompts.ts subagents/vercel.ts subagents/anthropic.ts tracing/index.ts tracing/core.ts tracing/interaction.ts tracing/otel.ts tracing/types.ts --format esm,cjs --sourcemap --clean --dts --dts-resolve && tsup ai-sdk/index.ts --format esm,cjs --sourcemap --dts --no-clean --out-dir dist/ai-sdk\",\n \"prepare\": \"npm run build\",\n \"typecheck\": \"tsc --noEmit && tsc --noEmit -p ai-sdk/tsconfig.json\",\n \"lint\": \"eslint .\",\n \"test\": \"vitest run\",\n \"test:watch\": \"vitest watch\",\n \"test:anthropic\": \"vitest run anthropic\",\n \"test:openai\": \"vitest run openai\",\n \"test:vercel\": \"vitest run vercel\",\n \"test:git\": \"vitest run git\",\n \"test:agent\": \"npx tsx tests/fullAgentTest.ts\",\n \"test:integration\": \"npx tsx tests/fullIntegrationTest.ts\",\n \"test:e2e\": \"vitest run --config vitest.e2e.config.ts\",\n \"release:patch\": \"npm version patch && npm publish\",\n \"release:minor\": \"npm version minor && npm publish\",\n \"release:major\": \"npm version major && npm publish\"\n },\n \"keywords\": [\n \"morph\",\n \"fast-apply\",\n \"cli\",\n \"sdk\",\n \"edit-file\"\n ],\n \"engines\": {\n \"node\": \">=18\"\n },\n \"license\": \"MIT\",\n \"dependencies\": {\n \"@opentelemetry/api\": \"^1.9.0\",\n \"@opentelemetry/exporter-trace-otlp-http\": \"^0.203.0\",\n \"@opentelemetry/sdk-trace-base\": \"^2.7.1\",\n \"@traceloop/node-server-sdk\": \"^0.27.0\",\n \"@vscode/ripgrep\": \"^1.17.0\",\n \"ai\": \">=5.0.0\",\n \"diff\": \"^7.0.0\",\n \"openai\": \"^4.52.7\",\n \"zod\": \">=3.23.0\"\n },\n \"devDependencies\": {\n \"@ai-sdk/anthropic\": \"^2.0.70\",\n \"@ai-sdk/openai\": \"^2.0.35\",\n \"@anthropic-ai/sdk\": \"^0.30.1\",\n \"@google/generative-ai\": \"^0.24.1\",\n \"@types/diff\": \"^7.0.2\",\n \"@types/node\": \"^20.14.10\",\n \"@typescript-eslint/eslint-plugin\": \"^7.18.0\",\n \"@typescript-eslint/parser\": \"^7.18.0\",\n \"dotenv\": \"^16.4.5\",\n \"eslint\": \"^8.57.0\",\n \"shx\": \"^0.3.4\",\n \"tsup\": \"^8.5.0\",\n \"tsx\": \"^4.16.2\",\n \"typescript\": \"^5.5.4\",\n \"vitest\": \"^2.1.6\"\n },\n \"peerDependencies\": {\n \"@ai-sdk/openai-compatible\": \">=2.0.74 <4\",\n \"@anthropic-ai/sdk\": \">=0.25.0\",\n \"@google/generative-ai\": \">=0.21.0\",\n \"ai\": \">=5.0.0\",\n \"zod\": \">=3.23.0\"\n },\n \"peerDependenciesMeta\": {\n \"@anthropic-ai/sdk\": {\n \"optional\": true\n },\n \"@google/generative-ai\": {\n \"optional\": true\n },\n \"ai\": {\n \"optional\": true\n },\n \"zod\": {\n \"optional\": true\n }\n },\n \"publishConfig\": {\n \"access\": \"public\"\n }\n}\n","import pkg from './package.json' with { type: 'json' };\nexport const SDK_VERSION: string = pkg.version;\n"],"mappings":";AAAA;AAAA,EAC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f,QAAU;AAAA,EACZ;AACF;;;ACpOO,IAAM,cAAsB,gBAAI;","names":[]}
|
package/dist/chunk-K2JR2NFQ.js
DELETED
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
CODEBASE_SEARCH_DESCRIPTION,
|
|
3
|
-
CODEBASE_SEARCH_SYSTEM_PROMPT
|
|
4
|
-
} from "./chunk-YQMPVJ2L.js";
|
|
5
|
-
import {
|
|
6
|
-
executeCodebaseSearch
|
|
7
|
-
} from "./chunk-VS5F2ORN.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-K2JR2NFQ.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,aAAa;AAAA,UACX,MAAM;AAAA,UACN,aAAa;AAAA,QACf;AAAA,QACA,OAAO;AAAA,UACL,MAAM;AAAA,UACN,aAAa;AAAA,QACf;AAAA,MACF;AAAA,MACA,UAAU,CAAC,SAAS,sBAAsB,aAAa;AAAA,IACzD;AAAA,EACF;AACF;AA2BO,SAAS,yBAAyB,QAA8B;AACrE,QAAM,iBAAqC;AAAA,IACzC,MAAM;AAAA,IACN,UAAU;AAAA,MACR,MAAM;AAAA,MACN,aAAa;AAAA,MACb,YAAY;AAAA,QACV,MAAM;A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c,EAAE,UAAU,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;AAOO,SAAS,kBAA0B;AACxC,SAAO;AACT;AAKA,IAAO,iBAAQ,EAAE,0BAA0B,SAAS,cAAc,gBAAgB;","names":[]}
|
package/dist/chunk-MEZTHMB2.js
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
CODEBASE_SEARCH_DESCRIPTION,
|
|
3
|
-
CODEBASE_SEARCH_SYSTEM_PROMPT
|
|
4
|
-
} from "./chunk-YQMPVJ2L.js";
|
|
5
|
-
import {
|
|
6
|
-
executeCodebaseSearch
|
|
7
|
-
} from "./chunk-VS5F2ORN.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-MEZTHMB2.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,IAC3B,MAAM;AAAA,IACN,aAAa;AAAA,IACb,cAAc;AAAA,MACZ,MAAM;AAAA,MACN,YAAY;AAAA,QACV,aAAa;AAAA,UACX,MAAM;AAAA,UACN,aAAa;AAAA,QACf;AAAA,QACA,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,OAAO;AAAA,UACL,MAAM;AAAA,UACN,aAAa;AAAA,QACf;AAAA,MACF;AAAA,MACA,UAAU,CAAC,SAAS,sBAAsB,aAAa;AAAA,IACzD;AAAA,IACA,eAAe,EAAE,MAAM,YAAY;AAAA,EACrC;AAEA,SAAO,OAAO,OAAO,gBAAgB;AAAA,IACnC,SAAS,OAAO,UAA8D;AAC5E,aAAO,sBAAsB,OAAO,MAAM;AAAA,IAC5C;AAAA,IACA,cAAc,CAAC,WAAyC;AACtD,aAAO,aAAa,MAAM;AAAA,IAC5B;AAAA,IACA,iBAAiB,MAAc;AAC7B,aAAO;AAAA,IACT;AAAA,EACF,CAAC;AACH;AAQA,SAAS,aAAa,QAAsC;AAC1D,MAAI,CAAC,OAAO,SAAS;AACnB,WAAO,kBAAkB,OAAO,KAAK;AAAA,EACvC;AAEA,MAAI,OAAO,QAAQ,WAAW,GAAG;AAC/B,WAAO;AAAA,EACT;AAEA,QAAM,QAAkB,CAAC;AAEzB,QAAM,KAAK,SAAS,OAAO,QAAQ,MAAM,qCAAqC,OAAO,MAAM,mBAAmB,kBAAkB,OAAO,MAAM,YAAY;AAAA,CAAQ;AAEjK,SAAO,QAAQ,QAAQ,CAAC,GAAG,MAAM;AAC/B,UAAM,aAAa,EAAE,cAAc,KAAK,QAAQ,CAAC;AACjD,UAAM,KAAK,GAAG,IAAI,CAAC,KAAK,EAAE,QAAQ,KAAK,SAAS,aAAa;AAC7D,UAAM,KAAK,cAAc,EAAE,UAAU,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-RL3ZTXT3.js
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
CODEBASE_SEARCH_DESCRIPTION
|
|
3
|
-
} from "./chunk-YQMPVJ2L.js";
|
|
4
|
-
import {
|
|
5
|
-
executeCodebaseSearch
|
|
6
|
-
} from "./chunk-VS5F2ORN.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-RL3ZTXT3.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-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
|