@arizeai/openinference-genai 0.1.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.
Files changed (34) hide show
  1. package/README.md +137 -0
  2. package/dist/esm/__generated__/opentelemetryInputMessages.d.ts +103 -0
  3. package/dist/esm/__generated__/opentelemetryInputMessages.d.ts.map +1 -0
  4. package/dist/esm/__generated__/opentelemetryInputMessages.js +7 -0
  5. package/dist/esm/__generated__/opentelemetryInputMessages.js.map +1 -0
  6. package/dist/esm/__generated__/opentelemetryOutputMessages.d.ts +116 -0
  7. package/dist/esm/__generated__/opentelemetryOutputMessages.d.ts.map +1 -0
  8. package/dist/esm/__generated__/opentelemetryOutputMessages.js +7 -0
  9. package/dist/esm/__generated__/opentelemetryOutputMessages.js.map +1 -0
  10. package/dist/esm/attributes.d.ts +79 -0
  11. package/dist/esm/attributes.d.ts.map +1 -0
  12. package/dist/esm/attributes.js +306 -0
  13. package/dist/esm/attributes.js.map +1 -0
  14. package/dist/esm/index.d.ts +2 -0
  15. package/dist/esm/index.d.ts.map +1 -0
  16. package/dist/esm/index.js +10 -0
  17. package/dist/esm/index.js.map +1 -0
  18. package/dist/esm/package.json +1 -0
  19. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -0
  20. package/dist/esm/types.d.ts +9 -0
  21. package/dist/esm/types.d.ts.map +1 -0
  22. package/dist/esm/types.js +2 -0
  23. package/dist/esm/types.js.map +1 -0
  24. package/dist/esm/utils.d.ts +42 -0
  25. package/dist/esm/utils.d.ts.map +1 -0
  26. package/dist/esm/utils.js +94 -0
  27. package/dist/esm/utils.js.map +1 -0
  28. package/package.json +68 -0
  29. package/src/__generated__/opentelemetryInputMessages.ts +104 -0
  30. package/src/__generated__/opentelemetryOutputMessages.ts +122 -0
  31. package/src/attributes.ts +467 -0
  32. package/src/index.ts +14 -0
  33. package/src/types.ts +14 -0
  34. package/src/utils.ts +106 -0
@@ -0,0 +1,94 @@
1
+ import { MimeType } from "@arizeai/openinference-semantic-conventions";
2
+ export const safelyJSONStringify = (value) => {
3
+ try {
4
+ return JSON.stringify(value);
5
+ }
6
+ catch {
7
+ return null;
8
+ }
9
+ };
10
+ export const getNumber = (value) => {
11
+ if (typeof value === "number" && Number.isFinite(value))
12
+ return value;
13
+ return undefined;
14
+ };
15
+ export const getString = (value) => {
16
+ if (typeof value === "string" && value.length > 0)
17
+ return value;
18
+ return undefined;
19
+ };
20
+ export const getStringArray = (value) => {
21
+ if (Array.isArray(value) && value.every((v) => typeof v === "string")) {
22
+ return value;
23
+ }
24
+ return undefined;
25
+ };
26
+ export const safelyParseJSON = (value) => {
27
+ const s = getString(value);
28
+ if (!s)
29
+ return undefined;
30
+ try {
31
+ return JSON.parse(s);
32
+ }
33
+ catch {
34
+ return undefined;
35
+ }
36
+ };
37
+ export const getMimeType = (value) => {
38
+ if (safelyParseJSON(value))
39
+ return MimeType.JSON;
40
+ return MimeType.TEXT;
41
+ };
42
+ /**
43
+ * Assign attribute value to attributes object if value is not undefined or null
44
+ * This mutates the attrs object
45
+ * @param attrs - The attributes object to assign the value to
46
+ * @param key - The key to assign the value to
47
+ * @param value - The value to assign to the key
48
+ */
49
+ export const set = (attrs, key, value) => {
50
+ if (value === undefined || value === null)
51
+ return;
52
+ attrs[key] = value;
53
+ };
54
+ /**
55
+ * Merge multiple attributes objects into a single attributes object
56
+ * This mutates the first attributes object
57
+ * @param groups - The groups of attributes to merge
58
+ * @returns The merged attributes
59
+ */
60
+ export const merge = (...groups) => groups.reduce((acc, g) => Object.assign(acc, g), {});
61
+ /**
62
+ * Convert a value to a string. If the value is already a string, return it.
63
+ * If the value can be jsonified, jsonify it.
64
+ * Otherwise, return the string representation of the value.
65
+ * @param value - The value to convert to a string
66
+ * @returns The string representation of the value
67
+ */
68
+ export const toStringContent = (value) => {
69
+ if (typeof value === "string")
70
+ return value;
71
+ const json = safelyJSONStringify(value);
72
+ if (typeof json === "string")
73
+ return json;
74
+ return String(value);
75
+ };
76
+ /**
77
+ * Wraps a function with a try-catch block to catch and log any errors.
78
+ * @param fn - A function to wrap with a try-catch block.
79
+ * @returns A function that returns null if an error is thrown.
80
+ */
81
+ export function withSafety({ fn, onError, }) {
82
+ return (...args) => {
83
+ try {
84
+ return fn(...args);
85
+ }
86
+ catch (error) {
87
+ if (onError) {
88
+ onError(error);
89
+ }
90
+ return null;
91
+ }
92
+ };
93
+ }
94
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,6CAA6C,CAAC;AAIvE,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,KAAc,EAAE,EAAE;IACpD,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IAC/B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,KAAc,EAAsB,EAAE;IAC9D,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IACtE,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,KAAc,EAAsB,EAAE;IAC9D,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,KAAK,CAAC;IAChE,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,KAAc,EAAwB,EAAE;IACrE,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,CA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AmB,CAAC,KAAK,CAAC,CAAC;IACxC,IAAI,OAAO,IAAI,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC;IAC1C,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAA4B,EACpD,EAAE,EACF,OAAO,GAIR;IACC,OAAO,CAAC,GAAG,IAAI,EAAE,EAAE;QACjB,IAAI,CAAC;YACH,OAAO,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC;QACrB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,OAAO,EAAE,CAAC;gBACZ,OAAO,CAAC,KAAK,CAAC,CAAC;YACjB,CAAC;YACD,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
package/package.json ADDED
@@ -0,0 +1,68 @@
1
+ {
2
+ "name": "@arizeai/openinference-genai",
3
+ "version": "0.1.0",
4
+ "private": false,
5
+ "type": "module",
6
+ "types": "dist/esm/index.d.ts",
7
+ "description": "OpenInference utilities for converting OpenTelemetry GenAI span attributes to OpenInference span attributes",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/esm/index.js"
11
+ },
12
+ "./attributes": {
13
+ "import": "./dist/esm/attributes.js"
14
+ },
15
+ "./utils": {
16
+ "import": "./dist/esm/utils.js"
17
+ },
18
+ "./types": {
19
+ "types": "./dist/esm/types.d.ts"
20
+ }
21
+ },
22
+ "files": [
23
+ "dist",
24
+ "src"
25
+ ],
26
+ "keywords": [
27
+ "openinference",
28
+ "llm",
29
+ "opentelemetry",
30
+ "genai",
31
+ "agent"
32
+ ],
33
+ "author": "oss-devs@arize.com",
34
+ "license": "Apache-2.0",
35
+ "homepage": "https://github.com/arize-ai/openinference/tree/main/js/packages/openinference-genai",
36
+ "repository": {
37
+ "type": "git",
38
+ "url": "git+https://github.com/Arize-ai/openinference.git"
39
+ },
40
+ "bugs": {
41
+ "url": "https://github.com/Arize-ai/openinference/issues"
42
+ },
43
+ "dependencies": {
44
+ "@arizeai/openinference-semantic-conventions": "2.1.2"
45
+ },
46
+ "devDependencies": {
47
+ "@opentelemetry/api": "^1.9.0",
48
+ "@opentelemetry/core": "^2.1.0",
49
+ "@opentelemetry/exporter-trace-otlp-proto": "^0.206.0",
50
+ "@opentelemetry/resources": "^2.1.0",
51
+ "@opentelemetry/sdk-trace-base": "^2.1.0",
52
+ "@opentelemetry/sdk-trace-node": "^2.1.0",
53
+ "@opentelemetry/semantic-conventions": "^1.37.0",
54
+ "@types/node": "^20.14.11",
55
+ "vitest": "^3.1.3"
56
+ },
57
+ "peerDependencies": {
58
+ "@opentelemetry/api": ">=1.9.0",
59
+ "@opentelemetry/semantic-conventions": ">=1.37.0"
60
+ },
61
+ "scripts": {
62
+ "prebuild": "rimraf dist",
63
+ "build": "tsc --build tsconfig.esm.json && tsc-alias -p tsconfig.esm.json",
64
+ "postbuild": "echo '{\"type\": \"module\"}' > ./dist/esm/package.json && rimraf dist/test dist/examples",
65
+ "type:check": "tsc --noEmit",
66
+ "test": "vitest"
67
+ }
68
+ }
@@ -0,0 +1,104 @@
1
+ /**
2
+ * OpenTelemetry input messages schema
3
+ * As of 10/14/2025, this schema is still in draft status.
4
+ * https://opentelemetry.io/docs/specs/semconv/gen-ai/gen-ai-input-messages.json
5
+ */
6
+
7
+ /**
8
+ * Role of the entity that created the message.
9
+ */
10
+ export type Role = Role1 | string;
11
+ export type Role1 = "system" | "user" | "assistant" | "tool";
12
+ /**
13
+ * The type of the content captured in this part.
14
+ */
15
+ export type Type = "text";
16
+ /**
17
+ * Text content sent to or received from the model.
18
+ */
19
+ export type Content = string;
20
+ /**
21
+ * The type of the content captured in this part.
22
+ */
23
+ export type Type1 = "tool_call";
24
+ /**
25
+ * Unique identifier for the tool call.
26
+ */
27
+ export type Id = string | null;
28
+ /**
29
+ * Name of the tool.
30
+ */
31
+ export type Name = string;
32
+ /**
33
+ * The type of the content captured in this part.
34
+ */
35
+ export type Type2 = "tool_call_response";
36
+ /**
37
+ * Unique tool call identifier.
38
+ */
39
+ export type Id1 = string | null;
40
+ /**
41
+ * The type of the content captured in this part.
42
+ */
43
+ export type Type3 = string;
44
+ /**
45
+ * List of message parts that make up the message content.
46
+ */
47
+ export type Parts = (TextPart | ToolCallRequestPart | ToolCallResponsePart)[];
48
+ /**
49
+ * Represents the list of input messages sent to the model.
50
+ */
51
+ export type InputMessages = ChatMessage[];
52
+
53
+ export interface ChatMessage {
54
+ role: Role;
55
+ parts: Parts;
56
+ [k: string]: unknown;
57
+ }
58
+ /**
59
+ * Represents text content sent to or received from the model.
60
+ */
61
+ export interface TextPart {
62
+ type: Type;
63
+ content: Content;
64
+ [k: string]: unknown;
65
+ }
66
+ /**
67
+ * Represents a tool call requested by the model.
68
+ */
69
+ export interface ToolCallRequestPart {
70
+ type: Type1;
71
+ id?: Id;
72
+ name: Name;
73
+ arguments?: Arguments;
74
+ [k: string]: unknown;
75
+ }
76
+ /**
77
+ * Arguments for the tool call.
78
+ */
79
+ export interface Arguments {
80
+ [k: string]: unknown;
81
+ }
82
+ /**
83
+ * Represents a tool call result sent to the model or a built-in tool call outcome and details.
84
+ */
85
+ export interface ToolCallResponsePart {
86
+ type: Type2;
87
+ id?: Id1;
88
+ response: Response;
89
+ [k: string]: unknown;
90
+ }
91
+ /**
92
+ * Tool call response.
93
+ */
94
+ export interface Response {
95
+ [k: string]: unknown;
96
+ }
97
+ /**
98
+ * Represents an arbitrary message part with any type and properties.
99
+ * This allows for extensibility with custom message part types.
100
+ */
101
+ export interface GenericPart {
102
+ type: Type3;
103
+ [k: string]: unknown;
104
+ }
@@ -0,0 +1,122 @@
1
+ /**
2
+ * OpenTelemetry output messages schema
3
+ * As of 10/14/2025, this schema is still in draft status.
4
+ * https://opentelemetry.io/docs/specs/semconv/gen-ai/gen-ai-output-messages.json
5
+ */
6
+
7
+ /**
8
+ * Role of the entity that created the message.
9
+ */
10
+ export type Role = Role1 | string;
11
+ export type Role1 = "system" | "user" | "assistant" | "tool";
12
+ /**
13
+ * The type of the content captured in this part.
14
+ */
15
+ export type Type = "text";
16
+ /**
17
+ * Text content sent to or received from the model.
18
+ */
19
+ export type Content = string;
20
+ /**
21
+ * The type of the content captured in this part.
22
+ */
23
+ export type Type1 = "tool_call";
24
+ /**
25
+ * Unique identifier for the tool call.
26
+ */
27
+ export type Id = string | null;
28
+ /**
29
+ * Name of the tool.
30
+ */
31
+ export type Name = string;
32
+ /**
33
+ * The type of the content captured in this part.
34
+ */
35
+ export type Type2 = "tool_call_response";
36
+ /**
37
+ * Unique tool call identifier.
38
+ */
39
+ export type Id1 = string | null;
40
+ /**
41
+ * The type of the content captured in this part.
42
+ */
43
+ export type Type3 = string;
44
+ /**
45
+ * List of message parts that make up the message content.
46
+ */
47
+ export type Parts = (TextPart | ToolCallRequestPart | ToolCallResponsePart)[];
48
+ /**
49
+ * Reason for finishing the generation.
50
+ */
51
+ export type FinishReason = FinishReason1 | string;
52
+ /**
53
+ * Represents the reason for finishing the generation.
54
+ */
55
+ export type FinishReason1 =
56
+ | "stop"
57
+ | "length"
58
+ | "content_filter"
59
+ | "tool_call"
60
+ | "error";
61
+ /**
62
+ * Represents the list of output messages generated by the model or agent.
63
+ */
64
+ export type OutputMessages = OutputMessage[];
65
+
66
+ /**
67
+ * Represents an output message generated by the model or agent. The output message captures
68
+ * specific response (choice, candidate).
69
+ */
70
+ export interface OutputMessage {
71
+ role: Role;
72
+ parts: Parts;
73
+ finish_reason: FinishReason;
74
+ [k: string]: unknown;
75
+ }
76
+ /**
77
+ * Represents text content sent to or received from the model.
78
+ */
79
+ export interface TextPart {
80
+ type: Type;
81
+ content: Content;
82
+ [k: string]: unknown;
83
+ }
84
+ /**
85
+ * Represents a tool call requested by the model.
86
+ */
87
+ export interface ToolCallRequestPart {
88
+ type: Type1;
89
+ id?: Id;
90
+ name: Name;
91
+ arguments?: Arguments;
92
+ [k: string]: unknown;
93
+ }
94
+ /**
95
+ * Arguments for the tool call.
96
+ */
97
+ export interface Arguments {
98
+ [k: string]: unknown;
99
+ }
100
+ /**
101
+ * Represents a tool call result sent to the model or a built-in tool call outcome and details.
102
+ */
103
+ export interface ToolCallResponsePart {
104
+ type: Type2;
105
+ id?: Id1;
106
+ response: Response;
107
+ [k: string]: unknown;
108
+ }
109
+ /**
110
+ * Tool call response.
111
+ */
112
+ export interface Response {
113
+ [k: string]: unknown;
114
+ }
115
+ /**
116
+ * Represents an arbitrary message part with any type and properties.
117
+ * This allows for extensibility with custom message part types.
118
+ */
119
+ export interface GenericPart {
120
+ type: Type3;
121
+ [k: string]: unknown;
122
+ }