@agentmark-ai/shared-utils 0.3.3 → 0.4.0

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.d.mts CHANGED
@@ -558,4 +558,43 @@ declare function normalizeSpan(resource: OtelResource, scope: OtelScope, span: O
558
558
  */
559
559
  declare function normalizeOtlpSpans(resourceSpans: OtlpResourceSpans[]): NormalizedSpan[];
560
560
 
561
- export { AGENTMARK_SCOPE_NAME, AgentMarkTransformer, type AgentmarkConfig, type AgentmarkModelConfig, type AgentmarkModelSchema, type AgentmarkModelSettingsConfig, type AgentmarkModelSettingsSchema, AiSdkTransformer, type AiSdkVersion, type AttributeExtractor, AgentMarkTransformer as ClaudeAgentTransformer, type GenerateTypesLanguage, MastraTransformer, type McpServerConfig, type McpServers, type McpStdioServerConfig, type McpUrlServerConfig, type Message, type ModelSettingsTypeAspectRatio, type ModelSettingsTypeImageSize, type ModelSettingsTypeSelect, type ModelSettingsTypeSlider, type NormalizedSpan, type OtelEvent, OtelGenAiTransformer, type OtelLink, type OtelResource, type OtelScope, type OtelSpan, type OtlpAttribute, type OtlpAttributeValue, type OtlpEvent, type OtlpLink, type OtlpResource, type OtlpResourceSpans, type OtlpScope, type OtlpScopeSpans, type OtlpSpan, SEMANTIC_KINDS, type ScopeTransformer, type SemanticKind, SpanType, type StandardMessageContent, type StandardTextContent, type StandardToolCallContent, type StandardToolResultContent, type ToolCall, TransformerRegistry, TypeClassifier, convertOtlpAttributes, createSignature, detectVersion, extractCustomMetadata, extractReasoningFromProviderMetadata, extractResourceScopeSpan, fetchPromptsFrontmatter, findPromptFiles, generateTypeDefinitions, generateUnique8CharString, normalizeOtlpSpans, normalizeSpan, parseAgentMarkAttributes, parseMetadata, parseTokens, registry, resolveSemanticKind, toFrontMatter, typeClassifier, verifySignature };
561
+ /**
562
+ * Compute a stable identifier for a dataset row, derived from its input.
563
+ *
564
+ * The identifier survives row reordering, additions, and deletions in the
565
+ * dataset — anything that doesn't change the row's *content* keeps the same
566
+ * id. This is the property regression-vs-baseline comparisons need: the
567
+ * same logical test case in two different runs must produce the same name
568
+ * so the baseline lookup can match them.
569
+ *
570
+ * Format: first 12 hex characters of the MD5 digest of the row's input,
571
+ * canonicalised with sorted keys at every level. This matches the Python
572
+ * runner's implementation byte-for-byte so cross-runtime comparisons
573
+ * (TS-emitted baseline vs. Python-emitted PR run, or vice versa) produce
574
+ * matching identifiers.
575
+ *
576
+ * Falls back to the positional index as a string when the row has no
577
+ * input — in that case there is nothing stable to hash, so positional is
578
+ * the best we can do.
579
+ *
580
+ * Note: we use MD5 here for compatibility with the existing Python
581
+ * implementation. MD5 is not used as a security primitive — it's used as a
582
+ * non-cryptographic content fingerprint, which is its appropriate role.
583
+ */
584
+ declare function computeDatasetItemName(input: unknown, fallbackIndex: number): string;
585
+ /**
586
+ * Stringify a value as canonical JSON with object keys sorted recursively.
587
+ *
588
+ * Differs from `JSON.stringify`:
589
+ * - Object keys are sorted lexicographically at every level of nesting, so
590
+ * `{a: 1, b: 2}` and `{b: 2, a: 1}` produce the same output.
591
+ * - Non-serializable values (functions, symbols, bigints, undefined) are
592
+ * coerced to strings via `String(value)`, matching Python's `default=str`
593
+ * behavior in `json.dumps`.
594
+ *
595
+ * Exported for testing and for callers that need the same canonicalisation
596
+ * for purposes other than item-name hashing.
597
+ */
598
+ declare function canonicalJsonStringify(value: unknown): string;
599
+
600
+ export { AGENTMARK_SCOPE_NAME, AgentMarkTransformer, type AgentmarkConfig, type AgentmarkModelConfig, type AgentmarkModelSchema, type AgentmarkModelSettingsConfig, type AgentmarkModelSettingsSchema, AiSdkTransformer, type AiSdkVersion, type AttributeExtractor, AgentMarkTransformer as ClaudeAgentTransformer, type GenerateTypesLanguage, MastraTransformer, type McpServerConfig, type McpServers, type McpStdioServerConfig, type McpUrlServerConfig, type Message, type ModelSettingsTypeAspectRatio, type ModelSettingsTypeImageSize, type ModelSettingsTypeSelect, type ModelSettingsTypeSlider, type NormalizedSpan, type OtelEvent, OtelGenAiTransformer, type OtelLink, type OtelResource, type OtelScope, type OtelSpan, type OtlpAttribute, type OtlpAttributeValue, type OtlpEvent, type OtlpLink, type OtlpResource, type OtlpResourceSpans, type OtlpScope, type OtlpScopeSpans, type OtlpSpan, SEMANTIC_KINDS, type ScopeTransformer, type SemanticKind, SpanType, type StandardMessageContent, type StandardTextContent, type StandardToolCallContent, type StandardToolResultContent, type ToolCall, TransformerRegistry, TypeClassifier, canonicalJsonStringify, computeDatasetItemName, convertOtlpAttributes, createSignature, detectVersion, extractCustomMetadata, extractReasoningFromProviderMetadata, extractResourceScopeSpan, fetchPromptsFrontmatter, findPromptFiles, generateTypeDefinitions, generateUnique8CharString, normalizeOtlpSpans, normalizeSpan, parseAgentMarkAttributes, parseMetadata, parseTokens, registry, resolveSemanticKind, toFrontMatter, typeClassifier, verifySignature };
package/dist/index.d.ts CHANGED
@@ -558,4 +558,43 @@ declare function normalizeSpan(resource: OtelResource, scope: OtelScope, span: O
558
558
  */
559
559
  declare function normalizeOtlpSpans(resourceSpans: OtlpResourceSpans[]): NormalizedSpan[];
560
560
 
561
- export { AGENTMARK_SCOPE_NAME, AgentMarkTransformer, type AgentmarkConfig, type AgentmarkModelConfig, type AgentmarkModelSchema, type AgentmarkModelSettingsConfig, type AgentmarkModelSettingsSchema, AiSdkTransformer, type AiSdkVersion, type AttributeExtractor, AgentMarkTransformer as ClaudeAgentTransformer, type GenerateTypesLanguage, MastraTransformer, type McpServerConfig, type McpServers, type McpStdioServerConfig, type McpUrlServerConfig, type Message, type ModelSettingsTypeAspectRatio, type ModelSettingsTypeImageSize, type ModelSettingsTypeSelect, type ModelSettingsTypeSlider, type NormalizedSpan, type OtelEvent, OtelGenAiTransformer, type OtelLink, type OtelResource, type OtelScope, type OtelSpan, type OtlpAttribute, type OtlpAttributeValue, type OtlpEvent, type OtlpLink, type OtlpResource, type OtlpResourceSpans, type OtlpScope, type OtlpScopeSpans, type OtlpSpan, SEMANTIC_KINDS, type ScopeTransformer, type SemanticKind, SpanType, type StandardMessageContent, type StandardTextContent, type StandardToolCallContent, type StandardToolResultContent, type ToolCall, TransformerRegistry, TypeClassifier, convertOtlpAttributes, createSignature, detectVersion, extractCustomMetadata, extractReasoningFromProviderMetadata, extractResourceScopeSpan, fetchPromptsFrontmatter, findPromptFiles, generateTypeDefinitions, generateUnique8CharString, normalizeOtlpSpans, normalizeSpan, parseAgentMarkAttributes, parseMetadata, parseTokens, registry, resolveSemanticKind, toFrontMatter, typeClassifier, verifySignature };
561
+ /**
562
+ * Compute a stable identifier for a dataset row, derived from its input.
563
+ *
564
+ * The identifier survives row reordering, additions, and deletions in the
565
+ * dataset — anything that doesn't change the row's *content* keeps the same
566
+ * id. This is the property regression-vs-baseline comparisons need: the
567
+ * same logical test case in two different runs must produce the same name
568
+ * so the baseline lookup can match them.
569
+ *
570
+ * Format: first 12 hex characters of the MD5 digest of the row's input,
571
+ * canonicalised with sorted keys at every level. This matches the Python
572
+ * runner's implementation byte-for-byte so cross-runtime comparisons
573
+ * (TS-emitted baseline vs. Python-emitted PR run, or vice versa) produce
574
+ * matching identifiers.
575
+ *
576
+ * Falls back to the positional index as a string when the row has no
577
+ * input — in that case there is nothing stable to hash, so positional is
578
+ * the best we can do.
579
+ *
580
+ * Note: we use MD5 here for compatibility with the existing Python
581
+ * implementation. MD5 is not used as a security primitive — it's used as a
582
+ * non-cryptographic content fingerprint, which is its appropriate role.
583
+ */
584
+ declare function computeDatasetItemName(input: unknown, fallbackIndex: number): string;
585
+ /**
586
+ * Stringify a value as canonical JSON with object keys sorted recursively.
587
+ *
588
+ * Differs from `JSON.stringify`:
589
+ * - Object keys are sorted lexicographically at every level of nesting, so
590
+ * `{a: 1, b: 2}` and `{b: 2, a: 1}` produce the same output.
591
+ * - Non-serializable values (functions, symbols, bigints, undefined) are
592
+ * coerced to strings via `String(value)`, matching Python's `default=str`
593
+ * behavior in `json.dumps`.
594
+ *
595
+ * Exported for testing and for callers that need the same canonicalisation
596
+ * for purposes other than item-name hashing.
597
+ */
598
+ declare function canonicalJsonStringify(value: unknown): string;
599
+
600
+ export { AGENTMARK_SCOPE_NAME, AgentMarkTransformer, type AgentmarkConfig, type AgentmarkModelConfig, type AgentmarkModelSchema, type AgentmarkModelSettingsConfig, type AgentmarkModelSettingsSchema, AiSdkTransformer, type AiSdkVersion, type AttributeExtractor, AgentMarkTransformer as ClaudeAgentTransformer, type GenerateTypesLanguage, MastraTransformer, type McpServerConfig, type McpServers, type McpStdioServerConfig, type McpUrlServerConfig, type Message, type ModelSettingsTypeAspectRatio, type ModelSettingsTypeImageSize, type ModelSettingsTypeSelect, type ModelSettingsTypeSlider, type NormalizedSpan, type OtelEvent, OtelGenAiTransformer, type OtelLink, type OtelResource, type OtelScope, type OtelSpan, type OtlpAttribute, type OtlpAttributeValue, type OtlpEvent, type OtlpLink, type OtlpResource, type OtlpResourceSpans, type OtlpScope, type OtlpScopeSpans, type OtlpSpan, SEMANTIC_KINDS, type ScopeTransformer, type SemanticKind, SpanType, type StandardMessageContent, type StandardTextContent, type StandardToolCallContent, type StandardToolResultContent, type ToolCall, TransformerRegistry, TypeClassifier, canonicalJsonStringify, computeDatasetItemName, convertOtlpAttributes, createSignature, detectVersion, extractCustomMetadata, extractReasoningFromProviderMetadata, extractResourceScopeSpan, fetchPromptsFrontmatter, findPromptFiles, generateTypeDefinitions, generateUnique8CharString, normalizeOtlpSpans, normalizeSpan, parseAgentMarkAttributes, parseMetadata, parseTokens, registry, resolveSemanticKind, toFrontMatter, typeClassifier, verifySignature };
package/dist/index.js CHANGED
@@ -40,6 +40,8 @@ __export(index_exports, {
40
40
  SpanType: () => SpanType,
41
41
  TransformerRegistry: () => TransformerRegistry,
42
42
  TypeClassifier: () => TypeClassifier,
43
+ canonicalJsonStringify: () => canonicalJsonStringify,
44
+ computeDatasetItemName: () => computeDatasetItemName,
43
45
  convertOtlpAttributes: () => convertOtlpAttributes,
44
46
  createSignature: () => createSignature,
45
47
  detectVersion: () => detectVersion,
@@ -2320,6 +2322,36 @@ function normalizeOtlpSpans(resourceSpans) {
2320
2322
  }
2321
2323
  return normalizedSpans;
2322
2324
  }
2325
+
2326
+ // src/dataset-item-name.ts
2327
+ var import_node_crypto = require("crypto");
2328
+ function computeDatasetItemName(input, fallbackIndex) {
2329
+ if (input === void 0 || input === null) {
2330
+ return String(fallbackIndex);
2331
+ }
2332
+ const canonical = canonicalJsonStringify(input);
2333
+ return (0, import_node_crypto.createHash)("md5").update(canonical).digest("hex").slice(0, 12);
2334
+ }
2335
+ function canonicalJsonStringify(value) {
2336
+ if (value === null) return "null";
2337
+ if (value === void 0) return JSON.stringify(String(void 0));
2338
+ const t = typeof value;
2339
+ if (t === "string" || t === "number" || t === "boolean") {
2340
+ return JSON.stringify(value);
2341
+ }
2342
+ if (t === "bigint" || t === "function" || t === "symbol") {
2343
+ return JSON.stringify(String(value));
2344
+ }
2345
+ if (Array.isArray(value)) {
2346
+ return "[" + value.map(canonicalJsonStringify).join(",") + "]";
2347
+ }
2348
+ const obj = value;
2349
+ const keys = Object.keys(obj).sort();
2350
+ const parts = keys.map((k) => {
2351
+ return JSON.stringify(k) + ":" + canonicalJsonStringify(obj[k]);
2352
+ });
2353
+ return "{" + parts.join(",") + "}";
2354
+ }
2323
2355
  // Annotate the CommonJS export names for ESM import in node:
2324
2356
  0 && (module.exports = {
2325
2357
  AGENTMARK_SCOPE_NAME,
@@ -2332,6 +2364,8 @@ function normalizeOtlpSpans(resourceSpans) {
2332
2364
  SpanType,
2333
2365
  TransformerRegistry,
2334
2366
  TypeClassifier,
2367
+ canonicalJsonStringify,
2368
+ computeDatasetItemName,
2335
2369
  convertOtlpAttributes,
2336
2370
  createSignature,
2337
2371
  detectVersion,