@agentmark-ai/shared-utils 0.3.2 → 0.3.3
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/index.js +22 -41
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +22 -41
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -228,27 +228,26 @@ async function generateTypeDefinitionsV1_0(prompts) {
|
|
|
228
228
|
for (const prompt of prompts) {
|
|
229
229
|
const { path: promptPath, input_schema } = prompt;
|
|
230
230
|
const name = getInterfaceName(promptPath);
|
|
231
|
-
let tools = {};
|
|
232
231
|
try {
|
|
233
232
|
let kind = "text";
|
|
234
233
|
let output_schema = null;
|
|
234
|
+
let hasTools = false;
|
|
235
235
|
if ("text_config" in prompt) {
|
|
236
236
|
kind = "text";
|
|
237
|
-
|
|
237
|
+
hasTools = Array.isArray(prompt.text_config.tools) ? prompt.text_config.tools.length > 0 : !!prompt.text_config.tools;
|
|
238
238
|
} else if ("object_config" in prompt) {
|
|
239
239
|
kind = "object";
|
|
240
|
-
|
|
240
|
+
hasTools = Array.isArray(prompt.object_config.tools) ? prompt.object_config.tools.length > 0 : !!prompt.object_config.tools;
|
|
241
241
|
output_schema = prompt.object_config.schema;
|
|
242
242
|
} else if ("image_config" in prompt) {
|
|
243
243
|
kind = "image";
|
|
244
|
-
|
|
244
|
+
hasTools = Array.isArray(prompt.image_config.tools) ? prompt.image_config.tools.length > 0 : !!prompt.image_config.tools;
|
|
245
245
|
}
|
|
246
246
|
const compile = await getCompile();
|
|
247
247
|
const inputInterface = input_schema ? await compile(input_schema, `${name}In`, {
|
|
248
248
|
bannerComment: "",
|
|
249
249
|
additionalProperties: false
|
|
250
250
|
}) : `interface ${name}In { [key: string]: any }`;
|
|
251
|
-
const toolTypes = await generateToolTypes(tools);
|
|
252
251
|
const outputInterface = output_schema ? await compile(output_schema, `${name}Out`, {
|
|
253
252
|
bannerComment: "",
|
|
254
253
|
additionalProperties: false
|
|
@@ -257,12 +256,11 @@ async function generateTypeDefinitionsV1_0(prompts) {
|
|
|
257
256
|
inputInterface.replace("export interface", "interface"),
|
|
258
257
|
outputInterface.replace("export type", "type").replace("export interface", "interface")
|
|
259
258
|
);
|
|
260
|
-
output += toolTypes || "";
|
|
261
259
|
output += `type ${name} = {
|
|
262
260
|
kind: '${kind}';
|
|
263
261
|
input: ${name}In;
|
|
264
|
-
output: ${name}Out;${
|
|
265
|
-
tools?:
|
|
262
|
+
output: ${name}Out;${hasTools ? `
|
|
263
|
+
tools?: string[];` : ""}
|
|
266
264
|
};
|
|
267
265
|
|
|
268
266
|
`;
|
|
@@ -689,6 +687,7 @@ async function generateTypeDefinitions(prompts, language = "typescript") {
|
|
|
689
687
|
return generateTypeDefinitionsV0(prompts);
|
|
690
688
|
}
|
|
691
689
|
async function fetchPromptsFrontmatter(options) {
|
|
690
|
+
var _a, _b, _c;
|
|
692
691
|
if (options.local) {
|
|
693
692
|
const baseUrl = `http://localhost:${options.local}`;
|
|
694
693
|
try {
|
|
@@ -698,7 +697,8 @@ async function fetchPromptsFrontmatter(options) {
|
|
|
698
697
|
`Failed to fetch prompt paths: ${pathsResponse.statusText}`
|
|
699
698
|
);
|
|
700
699
|
}
|
|
701
|
-
const
|
|
700
|
+
const body = await pathsResponse.json();
|
|
701
|
+
const paths = (_c = (_b = (_a = body == null ? void 0 : body.data) == null ? void 0 : _a.paths) != null ? _b : body == null ? void 0 : body.paths) != null ? _c : [];
|
|
702
702
|
return Promise.all(
|
|
703
703
|
paths.map(async (promptPath) => {
|
|
704
704
|
const templateResponse = await fetch(
|
|
@@ -764,34 +764,6 @@ async function fetchPromptsFrontmatter(options) {
|
|
|
764
764
|
}
|
|
765
765
|
throw new Error("Either --local or --root-dir must be specified");
|
|
766
766
|
}
|
|
767
|
-
async function generateToolTypes(tools) {
|
|
768
|
-
const toolArgTypes = [];
|
|
769
|
-
for (const [toolName, schema] of Object.entries(tools)) {
|
|
770
|
-
const typeName = `${getToolInterfaceName(toolName)}Args`;
|
|
771
|
-
try {
|
|
772
|
-
const compile = await getCompile();
|
|
773
|
-
const argInterface = schema.parameters ? await compile(schema.parameters, typeName, {
|
|
774
|
-
bannerComment: "",
|
|
775
|
-
additionalProperties: false
|
|
776
|
-
}) : `type ${typeName} = { ${Object.entries(schema.parameters || {}).map(([key]) => `${key}: any`).join("; ")} };`;
|
|
777
|
-
toolArgTypes.push(
|
|
778
|
-
argInterface.replace("export type", "type").replace("export interface", "interface")
|
|
779
|
-
);
|
|
780
|
-
} catch (error) {
|
|
781
|
-
console.error(`Error processing tool ${toolName}:`, error);
|
|
782
|
-
toolArgTypes.push(`type ${typeName} = { [key: string]: any };`);
|
|
783
|
-
}
|
|
784
|
-
}
|
|
785
|
-
if (Object.keys(tools).length > 0) {
|
|
786
|
-
const toolsInterface = `export interface Tools {
|
|
787
|
-
${Object.keys(tools).map(
|
|
788
|
-
(toolName) => ` ${toolName}: { args: ${getToolInterfaceName(toolName)}Args };`
|
|
789
|
-
).join("\n")}
|
|
790
|
-
}`;
|
|
791
|
-
return toolArgTypes.join("\n\n") + "\n\n" + toolsInterface + "\n\n";
|
|
792
|
-
}
|
|
793
|
-
return null;
|
|
794
|
-
}
|
|
795
767
|
|
|
796
768
|
// src/normalizer/types.ts
|
|
797
769
|
var SpanType = /* @__PURE__ */ ((SpanType2) => {
|
|
@@ -1778,6 +1750,7 @@ var AgentMarkTransformer = class {
|
|
|
1778
1750
|
* Transform the span and extract normalized fields from GenAI attributes.
|
|
1779
1751
|
*/
|
|
1780
1752
|
transform(_span, attributes) {
|
|
1753
|
+
var _a;
|
|
1781
1754
|
const result = {};
|
|
1782
1755
|
const responseModel = attributes[GenAIAttributes.RESPONSE_MODEL];
|
|
1783
1756
|
const requestModel = attributes[GenAIAttributes.REQUEST_MODEL];
|
|
@@ -1851,7 +1824,7 @@ var AgentMarkTransformer = class {
|
|
|
1851
1824
|
} catch {
|
|
1852
1825
|
}
|
|
1853
1826
|
}
|
|
1854
|
-
const amInput = attributes["agentmark.input"];
|
|
1827
|
+
const amInput = (_a = attributes["agentmark.input"]) != null ? _a : attributes["agentmark.props"];
|
|
1855
1828
|
if (amInput && typeof amInput === "string" && !result.input) {
|
|
1856
1829
|
result.input = [{ role: "user", content: amInput }];
|
|
1857
1830
|
}
|
|
@@ -1917,9 +1890,16 @@ var Attrs = {
|
|
|
1917
1890
|
RESPONSE_FINISH_REASONS: "gen_ai.response.finish_reasons",
|
|
1918
1891
|
USAGE_INPUT_TOKENS: "gen_ai.usage.input_tokens",
|
|
1919
1892
|
USAGE_OUTPUT_TOKENS: "gen_ai.usage.output_tokens",
|
|
1920
|
-
// v1.37.0+ content attributes
|
|
1893
|
+
// v1.37.0+ content attributes (canonical OTel GenAI semantic conventions).
|
|
1894
|
+
// SDKs that emit the AgentMark-scoped equivalents (`gen_ai.request.input`
|
|
1895
|
+
// / `gen_ai.response.output` — used by `claude-agent-sdk-v0-adapter`) are
|
|
1896
|
+
// also accepted here as fallbacks so an SDK picking either key set
|
|
1897
|
+
// doesn't silently lose IO data on ingest. The canonical pair always wins
|
|
1898
|
+
// when both are present.
|
|
1921
1899
|
INPUT_MESSAGES: "gen_ai.input.messages",
|
|
1922
1900
|
OUTPUT_MESSAGES: "gen_ai.output.messages",
|
|
1901
|
+
REQUEST_INPUT_FALLBACK: "gen_ai.request.input",
|
|
1902
|
+
RESPONSE_OUTPUT_FALLBACK: "gen_ai.response.output",
|
|
1923
1903
|
SYSTEM_INSTRUCTIONS: "gen_ai.system_instructions",
|
|
1924
1904
|
TOOL_DEFINITIONS: "gen_ai.tool.definitions",
|
|
1925
1905
|
// Tool call attributes (v1.37.0+)
|
|
@@ -1984,6 +1964,7 @@ var OtelGenAiTransformer = class {
|
|
|
1984
1964
|
return "SPAN" /* SPAN */;
|
|
1985
1965
|
}
|
|
1986
1966
|
transform(span, attributes) {
|
|
1967
|
+
var _a, _b;
|
|
1987
1968
|
const result = {};
|
|
1988
1969
|
const model = attributes[Attrs.RESPONSE_MODEL] || attributes[Attrs.REQUEST_MODEL];
|
|
1989
1970
|
if (model && typeof model === "string") {
|
|
@@ -2004,12 +1985,12 @@ var OtelGenAiTransformer = class {
|
|
|
2004
1985
|
if (typeof temperature === "number") {
|
|
2005
1986
|
result.settings = { ...result.settings, temperature };
|
|
2006
1987
|
}
|
|
2007
|
-
const inputMessages = attributes[Attrs.INPUT_MESSAGES];
|
|
1988
|
+
const inputMessages = (_a = attributes[Attrs.INPUT_MESSAGES]) != null ? _a : attributes[Attrs.REQUEST_INPUT_FALLBACK];
|
|
2008
1989
|
if (inputMessages && typeof inputMessages === "string") {
|
|
2009
1990
|
const messages = normalizeMessages(inputMessages);
|
|
2010
1991
|
if (messages) result.input = messages;
|
|
2011
1992
|
}
|
|
2012
|
-
const outputMessages = attributes[Attrs.OUTPUT_MESSAGES];
|
|
1993
|
+
const outputMessages = (_b = attributes[Attrs.OUTPUT_MESSAGES]) != null ? _b : attributes[Attrs.RESPONSE_OUTPUT_FALLBACK];
|
|
2013
1994
|
if (outputMessages && typeof outputMessages === "string") {
|
|
2014
1995
|
const extracted = extractStructuredOutput(outputMessages);
|
|
2015
1996
|
if (extracted) {
|