@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.mjs
CHANGED
|
@@ -163,27 +163,26 @@ async function generateTypeDefinitionsV1_0(prompts) {
|
|
|
163
163
|
for (const prompt of prompts) {
|
|
164
164
|
const { path: promptPath, input_schema } = prompt;
|
|
165
165
|
const name = getInterfaceName(promptPath);
|
|
166
|
-
let tools = {};
|
|
167
166
|
try {
|
|
168
167
|
let kind = "text";
|
|
169
168
|
let output_schema = null;
|
|
169
|
+
let hasTools = false;
|
|
170
170
|
if ("text_config" in prompt) {
|
|
171
171
|
kind = "text";
|
|
172
|
-
|
|
172
|
+
hasTools = Array.isArray(prompt.text_config.tools) ? prompt.text_config.tools.length > 0 : !!prompt.text_config.tools;
|
|
173
173
|
} else if ("object_config" in prompt) {
|
|
174
174
|
kind = "object";
|
|
175
|
-
|
|
175
|
+
hasTools = Array.isArray(prompt.object_config.tools) ? prompt.object_config.tools.length > 0 : !!prompt.object_config.tools;
|
|
176
176
|
output_schema = prompt.object_config.schema;
|
|
177
177
|
} else if ("image_config" in prompt) {
|
|
178
178
|
kind = "image";
|
|
179
|
-
|
|
179
|
+
hasTools = Array.isArray(prompt.image_config.tools) ? prompt.image_config.tools.length > 0 : !!prompt.image_config.tools;
|
|
180
180
|
}
|
|
181
181
|
const compile = await getCompile();
|
|
182
182
|
const inputInterface = input_schema ? await compile(input_schema, `${name}In`, {
|
|
183
183
|
bannerComment: "",
|
|
184
184
|
additionalProperties: false
|
|
185
185
|
}) : `interface ${name}In { [key: string]: any }`;
|
|
186
|
-
const toolTypes = await generateToolTypes(tools);
|
|
187
186
|
const outputInterface = output_schema ? await compile(output_schema, `${name}Out`, {
|
|
188
187
|
bannerComment: "",
|
|
189
188
|
additionalProperties: false
|
|
@@ -192,12 +191,11 @@ async function generateTypeDefinitionsV1_0(prompts) {
|
|
|
192
191
|
inputInterface.replace("export interface", "interface"),
|
|
193
192
|
outputInterface.replace("export type", "type").replace("export interface", "interface")
|
|
194
193
|
);
|
|
195
|
-
output += toolTypes || "";
|
|
196
194
|
output += `type ${name} = {
|
|
197
195
|
kind: '${kind}';
|
|
198
196
|
input: ${name}In;
|
|
199
|
-
output: ${name}Out;${
|
|
200
|
-
tools?:
|
|
197
|
+
output: ${name}Out;${hasTools ? `
|
|
198
|
+
tools?: string[];` : ""}
|
|
201
199
|
};
|
|
202
200
|
|
|
203
201
|
`;
|
|
@@ -624,6 +622,7 @@ async function generateTypeDefinitions(prompts, language = "typescript") {
|
|
|
624
622
|
return generateTypeDefinitionsV0(prompts);
|
|
625
623
|
}
|
|
626
624
|
async function fetchPromptsFrontmatter(options) {
|
|
625
|
+
var _a, _b, _c;
|
|
627
626
|
if (options.local) {
|
|
628
627
|
const baseUrl = `http://localhost:${options.local}`;
|
|
629
628
|
try {
|
|
@@ -633,7 +632,8 @@ async function fetchPromptsFrontmatter(options) {
|
|
|
633
632
|
`Failed to fetch prompt paths: ${pathsResponse.statusText}`
|
|
634
633
|
);
|
|
635
634
|
}
|
|
636
|
-
const
|
|
635
|
+
const body = await pathsResponse.json();
|
|
636
|
+
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 : [];
|
|
637
637
|
return Promise.all(
|
|
638
638
|
paths.map(async (promptPath) => {
|
|
639
639
|
const templateResponse = await fetch(
|
|
@@ -699,34 +699,6 @@ async function fetchPromptsFrontmatter(options) {
|
|
|
699
699
|
}
|
|
700
700
|
throw new Error("Either --local or --root-dir must be specified");
|
|
701
701
|
}
|
|
702
|
-
async function generateToolTypes(tools) {
|
|
703
|
-
const toolArgTypes = [];
|
|
704
|
-
for (const [toolName, schema] of Object.entries(tools)) {
|
|
705
|
-
const typeName = `${getToolInterfaceName(toolName)}Args`;
|
|
706
|
-
try {
|
|
707
|
-
const compile = await getCompile();
|
|
708
|
-
const argInterface = schema.parameters ? await compile(schema.parameters, typeName, {
|
|
709
|
-
bannerComment: "",
|
|
710
|
-
additionalProperties: false
|
|
711
|
-
}) : `type ${typeName} = { ${Object.entries(schema.parameters || {}).map(([key]) => `${key}: any`).join("; ")} };`;
|
|
712
|
-
toolArgTypes.push(
|
|
713
|
-
argInterface.replace("export type", "type").replace("export interface", "interface")
|
|
714
|
-
);
|
|
715
|
-
} catch (error) {
|
|
716
|
-
console.error(`Error processing tool ${toolName}:`, error);
|
|
717
|
-
toolArgTypes.push(`type ${typeName} = { [key: string]: any };`);
|
|
718
|
-
}
|
|
719
|
-
}
|
|
720
|
-
if (Object.keys(tools).length > 0) {
|
|
721
|
-
const toolsInterface = `export interface Tools {
|
|
722
|
-
${Object.keys(tools).map(
|
|
723
|
-
(toolName) => ` ${toolName}: { args: ${getToolInterfaceName(toolName)}Args };`
|
|
724
|
-
).join("\n")}
|
|
725
|
-
}`;
|
|
726
|
-
return toolArgTypes.join("\n\n") + "\n\n" + toolsInterface + "\n\n";
|
|
727
|
-
}
|
|
728
|
-
return null;
|
|
729
|
-
}
|
|
730
702
|
|
|
731
703
|
// src/normalizer/types.ts
|
|
732
704
|
var SpanType = /* @__PURE__ */ ((SpanType2) => {
|
|
@@ -1713,6 +1685,7 @@ var AgentMarkTransformer = class {
|
|
|
1713
1685
|
* Transform the span and extract normalized fields from GenAI attributes.
|
|
1714
1686
|
*/
|
|
1715
1687
|
transform(_span, attributes) {
|
|
1688
|
+
var _a;
|
|
1716
1689
|
const result = {};
|
|
1717
1690
|
const responseModel = attributes[GenAIAttributes.RESPONSE_MODEL];
|
|
1718
1691
|
const requestModel = attributes[GenAIAttributes.REQUEST_MODEL];
|
|
@@ -1786,7 +1759,7 @@ var AgentMarkTransformer = class {
|
|
|
1786
1759
|
} catch {
|
|
1787
1760
|
}
|
|
1788
1761
|
}
|
|
1789
|
-
const amInput = attributes["agentmark.input"];
|
|
1762
|
+
const amInput = (_a = attributes["agentmark.input"]) != null ? _a : attributes["agentmark.props"];
|
|
1790
1763
|
if (amInput && typeof amInput === "string" && !result.input) {
|
|
1791
1764
|
result.input = [{ role: "user", content: amInput }];
|
|
1792
1765
|
}
|
|
@@ -1852,9 +1825,16 @@ var Attrs = {
|
|
|
1852
1825
|
RESPONSE_FINISH_REASONS: "gen_ai.response.finish_reasons",
|
|
1853
1826
|
USAGE_INPUT_TOKENS: "gen_ai.usage.input_tokens",
|
|
1854
1827
|
USAGE_OUTPUT_TOKENS: "gen_ai.usage.output_tokens",
|
|
1855
|
-
// v1.37.0+ content attributes
|
|
1828
|
+
// v1.37.0+ content attributes (canonical OTel GenAI semantic conventions).
|
|
1829
|
+
// SDKs that emit the AgentMark-scoped equivalents (`gen_ai.request.input`
|
|
1830
|
+
// / `gen_ai.response.output` — used by `claude-agent-sdk-v0-adapter`) are
|
|
1831
|
+
// also accepted here as fallbacks so an SDK picking either key set
|
|
1832
|
+
// doesn't silently lose IO data on ingest. The canonical pair always wins
|
|
1833
|
+
// when both are present.
|
|
1856
1834
|
INPUT_MESSAGES: "gen_ai.input.messages",
|
|
1857
1835
|
OUTPUT_MESSAGES: "gen_ai.output.messages",
|
|
1836
|
+
REQUEST_INPUT_FALLBACK: "gen_ai.request.input",
|
|
1837
|
+
RESPONSE_OUTPUT_FALLBACK: "gen_ai.response.output",
|
|
1858
1838
|
SYSTEM_INSTRUCTIONS: "gen_ai.system_instructions",
|
|
1859
1839
|
TOOL_DEFINITIONS: "gen_ai.tool.definitions",
|
|
1860
1840
|
// Tool call attributes (v1.37.0+)
|
|
@@ -1919,6 +1899,7 @@ var OtelGenAiTransformer = class {
|
|
|
1919
1899
|
return "SPAN" /* SPAN */;
|
|
1920
1900
|
}
|
|
1921
1901
|
transform(span, attributes) {
|
|
1902
|
+
var _a, _b;
|
|
1922
1903
|
const result = {};
|
|
1923
1904
|
const model = attributes[Attrs.RESPONSE_MODEL] || attributes[Attrs.REQUEST_MODEL];
|
|
1924
1905
|
if (model && typeof model === "string") {
|
|
@@ -1939,12 +1920,12 @@ var OtelGenAiTransformer = class {
|
|
|
1939
1920
|
if (typeof temperature === "number") {
|
|
1940
1921
|
result.settings = { ...result.settings, temperature };
|
|
1941
1922
|
}
|
|
1942
|
-
const inputMessages = attributes[Attrs.INPUT_MESSAGES];
|
|
1923
|
+
const inputMessages = (_a = attributes[Attrs.INPUT_MESSAGES]) != null ? _a : attributes[Attrs.REQUEST_INPUT_FALLBACK];
|
|
1943
1924
|
if (inputMessages && typeof inputMessages === "string") {
|
|
1944
1925
|
const messages = normalizeMessages(inputMessages);
|
|
1945
1926
|
if (messages) result.input = messages;
|
|
1946
1927
|
}
|
|
1947
|
-
const outputMessages = attributes[Attrs.OUTPUT_MESSAGES];
|
|
1928
|
+
const outputMessages = (_b = attributes[Attrs.OUTPUT_MESSAGES]) != null ? _b : attributes[Attrs.RESPONSE_OUTPUT_FALLBACK];
|
|
1948
1929
|
if (outputMessages && typeof outputMessages === "string") {
|
|
1949
1930
|
const extracted = extractStructuredOutput(outputMessages);
|
|
1950
1931
|
if (extracted) {
|