@arizeai/openinference-genai 0.1.0 → 0.1.6
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/commonjs/__generated__/opentelemetryInputMessages.d.ts +103 -0
- package/dist/commonjs/__generated__/opentelemetryInputMessages.d.ts.map +1 -0
- package/dist/commonjs/__generated__/opentelemetryInputMessages.js +8 -0
- package/dist/commonjs/__generated__/opentelemetryInputMessages.js.map +1 -0
- package/dist/commonjs/__generated__/opentelemetryOutputMessages.d.ts +116 -0
- package/dist/commonjs/__generated__/opentelemetryOutputMessages.d.ts.map +1 -0
- package/dist/commonjs/__generated__/opentelemetryOutputMessages.js +8 -0
- package/dist/commonjs/__generated__/opentelemetryOutputMessages.js.map +1 -0
- package/dist/commonjs/attributes.d.ts +79 -0
- package/dist/commonjs/attributes.d.ts.map +1 -0
- package/dist/commonjs/attributes.js +321 -0
- package/dist/commonjs/attributes.js.map +1 -0
- package/dist/commonjs/index.d.ts +2 -0
- package/dist/commonjs/index.d.ts.map +1 -0
- package/dist/commonjs/index.js +13 -0
- package/dist/commonjs/index.js.map +1 -0
- package/dist/commonjs/tsconfig.commonjs.tsbuildinfo +1 -0
- package/dist/commonjs/types.d.ts +9 -0
- package/dist/commonjs/types.d.ts.map +1 -0
- package/dist/commonjs/types.js +3 -0
- package/dist/commonjs/types.js.map +1 -0
- package/dist/commonjs/utils.d.ts +42 -0
- package/dist/commonjs/utils.d.ts.map +1 -0
- package/dist/commonjs/utils.js +107 -0
- package/dist/commonjs/utils.js.map +1 -0
- package/dist/esm/__generated__/opentelemetryInputMessages.js +0 -1
- package/dist/esm/__generated__/opentelemetryOutputMessages.js +0 -1
- package/dist/esm/attributes.d.ts +1 -1
- package/dist/esm/attributes.d.ts.map +1 -1
- package/dist/esm/attributes.js +3 -3
- package/dist/esm/attributes.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/esm/types.js +0 -1
- package/dist/esm/utils.d.ts.map +1 -1
- package/dist/esm/utils.js.map +1 -1
- package/package.json +14 -9
- package/src/attributes.ts +27 -26
- package/src/utils.ts +2 -0
|
@@ -0,0 +1,103 @@
|
|
|
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
|
+
* Role of the entity that created the message.
|
|
8
|
+
*/
|
|
9
|
+
export type Role = Role1 | string;
|
|
10
|
+
export type Role1 = "system" | "user" | "assistant" | "tool";
|
|
11
|
+
/**
|
|
12
|
+
* The type of the content captured in this part.
|
|
13
|
+
*/
|
|
14
|
+
export type Type = "text";
|
|
15
|
+
/**
|
|
16
|
+
* Text content sent to or received from the model.
|
|
17
|
+
*/
|
|
18
|
+
export type Content = string;
|
|
19
|
+
/**
|
|
20
|
+
* The type of the content captured in this part.
|
|
21
|
+
*/
|
|
22
|
+
export type Type1 = "tool_call";
|
|
23
|
+
/**
|
|
24
|
+
* Unique identifier for the tool call.
|
|
25
|
+
*/
|
|
26
|
+
export type Id = string | null;
|
|
27
|
+
/**
|
|
28
|
+
* Name of the tool.
|
|
29
|
+
*/
|
|
30
|
+
export type Name = string;
|
|
31
|
+
/**
|
|
32
|
+
* The type of the content captured in this part.
|
|
33
|
+
*/
|
|
34
|
+
export type Type2 = "tool_call_response";
|
|
35
|
+
/**
|
|
36
|
+
* Unique tool call identifier.
|
|
37
|
+
*/
|
|
38
|
+
export type Id1 = string | null;
|
|
39
|
+
/**
|
|
40
|
+
* The type of the content captured in this part.
|
|
41
|
+
*/
|
|
42
|
+
export type Type3 = string;
|
|
43
|
+
/**
|
|
44
|
+
* List of message parts that make up the message content.
|
|
45
|
+
*/
|
|
46
|
+
export type Parts = (TextPart | ToolCallRequestPart | ToolCallResponsePart)[];
|
|
47
|
+
/**
|
|
48
|
+
* Represents the list of input messages sent to the model.
|
|
49
|
+
*/
|
|
50
|
+
export type InputMessages = ChatMessage[];
|
|
51
|
+
export interface ChatMessage {
|
|
52
|
+
role: Role;
|
|
53
|
+
parts: Parts;
|
|
54
|
+
[k: string]: unknown;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Represents text content sent to or received from the model.
|
|
58
|
+
*/
|
|
59
|
+
export interface TextPart {
|
|
60
|
+
type: Type;
|
|
61
|
+
content: Content;
|
|
62
|
+
[k: string]: unknown;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Represents a tool call requested by the model.
|
|
66
|
+
*/
|
|
67
|
+
export interface ToolCallRequestPart {
|
|
68
|
+
type: Type1;
|
|
69
|
+
id?: Id;
|
|
70
|
+
name: Name;
|
|
71
|
+
arguments?: Arguments;
|
|
72
|
+
[k: string]: unknown;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Arguments for the tool call.
|
|
76
|
+
*/
|
|
77
|
+
export interface Arguments {
|
|
78
|
+
[k: string]: unknown;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Represents a tool call result sent to the model or a built-in tool call outcome and details.
|
|
82
|
+
*/
|
|
83
|
+
export interface ToolCallResponsePart {
|
|
84
|
+
type: Type2;
|
|
85
|
+
id?: Id1;
|
|
86
|
+
response: Response;
|
|
87
|
+
[k: string]: unknown;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Tool call response.
|
|
91
|
+
*/
|
|
92
|
+
export interface Response {
|
|
93
|
+
[k: string]: unknown;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Represents an arbitrary message part with any type and properties.
|
|
97
|
+
* This allows for extensibility with custom message part types.
|
|
98
|
+
*/
|
|
99
|
+
export interface GenericPart {
|
|
100
|
+
type: Type3;
|
|
101
|
+
[k: string]: unknown;
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=opentelemetryInputMessages.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"opentelemetryInputMessages.d.ts","sourceRoot":"","sources":["../../../src/__generated__/opentelemetryInputMessages.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,MAAM,MAAM,IAAI,GAAG,KAAK,GAAG,MAAM,CAAC;AAClC,MAAM,MAAM,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,WAAW,GAAG,MAAM,CAAC;AAC7D;;GAEG;AACH,MAAM,MAAM,IAAI,GAAG,MAAM,CAAC;AAC1B;;GAEG;AACH,MAAM,MAAM,OAAO,GAAG,MAAM,CAAC;AAC7B;;GAEG;AACH,MAAM,MAAM,KAAK,GAAG,WAAW,CAAC;AAChC;;GAEG;AACH,MAAM,MAAM,EAAE,GAAG,MAAM,GAAG,IAAI,CAAC;AAC/B;;GAEG;AACH,MAAM,MAAM,IAAI,GAAG,MAAM,CAAC;AAC1B;;GAEG;AACH,MAAM,MAAM,KAAK,GAAG,oBAAoB,CAAC;AACzC;;GAEG;AACH,MAAM,MAAM,GAAG,GAAG,MAAM,GAAG,IAAI,CAAC;AAChC;;GAEG;AACH,MAAM,MAAM,KAAK,GAAG,MAAM,CAAC;AAC3B;;GAEG;AACH,MAAM,MAAM,KAAK,GAAG,CAAC,QAAQ,GAAG,mBAAmB,GAAG,oBAAoB,CAAC,EAAE,CAAC;AAC9E;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,WAAW,EAAE,CAAC;AAE1C,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,IAAI,CAAC;IACX,KAAK,EAAE,KAAK,CAAC;IACb,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CACtB;AACD;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,IAAI,CAAC;IACX,OAAO,EAAE,OAAO,CAAC;IACjB,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CACtB;AACD;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,KAAK,CAAC;IACZ,EAAE,CAAC,EAAE,EAAE,CAAC;IACR,IAAI,EAAE,IAAI,CAAC;IACX,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CACtB;AACD;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CACtB;AACD;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,KAAK,CAAC;IACZ,EAAE,CAAC,EAAE,GAAG,CAAC;IACT,QAAQ,EAAE,QAAQ,CAAC;IACnB,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CACtB;AACD;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CACtB;AACD;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,KAAK,CAAC;IACZ,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CACtB"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* OpenTelemetry input messages schema
|
|
4
|
+
* As of 10/14/2025, this schema is still in draft status.
|
|
5
|
+
* https://opentelemetry.io/docs/specs/semconv/gen-ai/gen-ai-input-messages.json
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
//# sourceMappingURL=opentelemetryInputMessages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"opentelemetryInputMessages.js","sourceRoot":"","sources":["../../../src/__generated__/opentelemetryInputMessages.ts"],"names":[],"mappings":";AAAA;;;;GAIG"}
|
|
@@ -0,0 +1,116 @@
|
|
|
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
|
+
* Role of the entity that created the message.
|
|
8
|
+
*/
|
|
9
|
+
export type Role = Role1 | string;
|
|
10
|
+
export type Role1 = "system" | "user" | "assistant" | "tool";
|
|
11
|
+
/**
|
|
12
|
+
* The type of the content captured in this part.
|
|
13
|
+
*/
|
|
14
|
+
export type Type = "text";
|
|
15
|
+
/**
|
|
16
|
+
* Text content sent to or received from the model.
|
|
17
|
+
*/
|
|
18
|
+
export type Content = string;
|
|
19
|
+
/**
|
|
20
|
+
* The type of the content captured in this part.
|
|
21
|
+
*/
|
|
22
|
+
export type Type1 = "tool_call";
|
|
23
|
+
/**
|
|
24
|
+
* Unique identifier for the tool call.
|
|
25
|
+
*/
|
|
26
|
+
export type Id = string | null;
|
|
27
|
+
/**
|
|
28
|
+
* Name of the tool.
|
|
29
|
+
*/
|
|
30
|
+
export type Name = string;
|
|
31
|
+
/**
|
|
32
|
+
* The type of the content captured in this part.
|
|
33
|
+
*/
|
|
34
|
+
export type Type2 = "tool_call_response";
|
|
35
|
+
/**
|
|
36
|
+
* Unique tool call identifier.
|
|
37
|
+
*/
|
|
38
|
+
export type Id1 = string | null;
|
|
39
|
+
/**
|
|
40
|
+
* The type of the content captured in this part.
|
|
41
|
+
*/
|
|
42
|
+
export type Type3 = string;
|
|
43
|
+
/**
|
|
44
|
+
* List of message parts that make up the message content.
|
|
45
|
+
*/
|
|
46
|
+
export type Parts = (TextPart | ToolCallRequestPart | ToolCallResponsePart)[];
|
|
47
|
+
/**
|
|
48
|
+
* Reason for finishing the generation.
|
|
49
|
+
*/
|
|
50
|
+
export type FinishReason = FinishReason1 | string;
|
|
51
|
+
/**
|
|
52
|
+
* Represents the reason for finishing the generation.
|
|
53
|
+
*/
|
|
54
|
+
export type FinishReason1 = "stop" | "length" | "content_filter" | "tool_call" | "error";
|
|
55
|
+
/**
|
|
56
|
+
* Represents the list of output messages generated by the model or agent.
|
|
57
|
+
*/
|
|
58
|
+
export type OutputMessages = OutputMessage[];
|
|
59
|
+
/**
|
|
60
|
+
* Represents an output message generated by the model or agent. The output message captures
|
|
61
|
+
* specific response (choice, candidate).
|
|
62
|
+
*/
|
|
63
|
+
export interface OutputMessage {
|
|
64
|
+
role: Role;
|
|
65
|
+
parts: Parts;
|
|
66
|
+
finish_reason: FinishReason;
|
|
67
|
+
[k: string]: unknown;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Represents text content sent to or received from the model.
|
|
71
|
+
*/
|
|
72
|
+
export interface TextPart {
|
|
73
|
+
type: Type;
|
|
74
|
+
content: Content;
|
|
75
|
+
[k: string]: unknown;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Represents a tool call requested by the model.
|
|
79
|
+
*/
|
|
80
|
+
export interface ToolCallRequestPart {
|
|
81
|
+
type: Type1;
|
|
82
|
+
id?: Id;
|
|
83
|
+
name: Name;
|
|
84
|
+
arguments?: Arguments;
|
|
85
|
+
[k: string]: unknown;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Arguments for the tool call.
|
|
89
|
+
*/
|
|
90
|
+
export interface Arguments {
|
|
91
|
+
[k: string]: unknown;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Represents a tool call result sent to the model or a built-in tool call outcome and details.
|
|
95
|
+
*/
|
|
96
|
+
export interface ToolCallResponsePart {
|
|
97
|
+
type: Type2;
|
|
98
|
+
id?: Id1;
|
|
99
|
+
response: Response;
|
|
100
|
+
[k: string]: unknown;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Tool call response.
|
|
104
|
+
*/
|
|
105
|
+
export interface Response {
|
|
106
|
+
[k: string]: unknown;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Represents an arbitrary message part with any type and properties.
|
|
110
|
+
* This allows for extensibility with custom message part types.
|
|
111
|
+
*/
|
|
112
|
+
export interface GenericPart {
|
|
113
|
+
type: Type3;
|
|
114
|
+
[k: string]: unknown;
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=opentelemetryOutputMessages.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"opentelemetryOutputMessages.d.ts","sourceRoot":"","sources":["../../../src/__generated__/opentelemetryOutputMessages.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,MAAM,MAAM,IAAI,GAAG,KAAK,GAAG,MAAM,CAAC;AAClC,MAAM,MAAM,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,WAAW,GAAG,MAAM,CAAC;AAC7D;;GAEG;AACH,MAAM,MAAM,IAAI,GAAG,MAAM,CAAC;AAC1B;;GAEG;AACH,MAAM,MAAM,OAAO,GAAG,MAAM,CAAC;AAC7B;;GAEG;AACH,MAAM,MAAM,KAAK,GAAG,WAAW,CAAC;AAChC;;GAEG;AACH,MAAM,MAAM,EAAE,GAAG,MAAM,GAAG,IAAI,CAAC;AAC/B;;GAEG;AACH,MAAM,MAAM,IAAI,GAAG,MAAM,CAAC;AAC1B;;GAEG;AACH,MAAM,MAAM,KAAK,GAAG,oBAAoB,CAAC;AACzC;;GAEG;AACH,MAAM,MAAM,GAAG,GAAG,MAAM,GAAG,IAAI,CAAC;AAChC;;GAEG;AACH,MAAM,MAAM,KAAK,GAAG,MAAM,CAAC;AAC3B;;GAEG;AACH,MAAM,MAAM,KAAK,GAAG,CAAC,QAAQ,GAAG,mBAAmB,GAAG,oBAAoB,CAAC,EAAE,CAAC;AAC9E;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,aAAa,GAAG,MAAM,CAAC;AAClD;;GAEG;AACH,MAAM,MAAM,aAAa,GACrB,MAAM,GACN,QAAQ,GACR,gBAAgB,GAChB,WAAW,GACX,OAAO,CAAC;AACZ;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,aAAa,EAAE,CAAC;AAE7C;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,IAAI,CAAC;IACX,KAAK,EAAE,KAAK,CAAC;IACb,aAAa,EAAE,YAAY,CAAC;IAC5B,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CACtB;AACD;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,IAAI,CAAC;IACX,OAAO,EAAE,OAAO,CAAC;IACjB,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CACtB;AACD;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,KAAK,CAAC;IACZ,EAAE,CAAC,EAAE,EAAE,CAAC;IACR,IAAI,EAAE,IAAI,CAAC;IACX,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CACtB;AACD;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CACtB;AACD;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,KAAK,CAAC;IACZ,EAAE,CAAC,EAAE,GAAG,CAAC;IACT,QAAQ,EAAE,QAAQ,CAAC;IACnB,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CACtB;AACD;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CACtB;AACD;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,KAAK,CAAC;IACZ,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CACtB"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* OpenTelemetry output messages schema
|
|
4
|
+
* As of 10/14/2025, this schema is still in draft status.
|
|
5
|
+
* https://opentelemetry.io/docs/specs/semconv/gen-ai/gen-ai-output-messages.json
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
//# sourceMappingURL=opentelemetryOutputMessages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"opentelemetryOutputMessages.js","sourceRoot":"","sources":["../../../src/__generated__/opentelemetryOutputMessages.ts"],"names":[],"mappings":";AAAA;;;;GAIG"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { Attributes } from "@opentelemetry/api";
|
|
2
|
+
import type { ChatMessage } from "./__generated__/opentelemetryInputMessages.js";
|
|
3
|
+
import type { OutputMessage } from "./__generated__/opentelemetryOutputMessages.js";
|
|
4
|
+
export type GenAIInputMessage = ChatMessage;
|
|
5
|
+
export type GenAIInputMessagePart = ChatMessage["parts"][number];
|
|
6
|
+
export type GenAIOutputMessage = OutputMessage & {
|
|
7
|
+
/** @deprecated use parts instead */
|
|
8
|
+
text?: string;
|
|
9
|
+
};
|
|
10
|
+
export type GenAIOutputMessagePart = OutputMessage["parts"][number];
|
|
11
|
+
/**
|
|
12
|
+
* Convert GenAI span attributes to OpenInference span attributes
|
|
13
|
+
* @param spanAttributes - The span attributes containing GenAI span attributes to convert
|
|
14
|
+
* @returns The converted OpenInference span attributes
|
|
15
|
+
*/
|
|
16
|
+
export declare const convertGenAISpanAttributesToOpenInferenceSpanAttributes: (spanAttributes: Attributes) => Attributes;
|
|
17
|
+
/**
|
|
18
|
+
* Map provider and system to openinference attributes
|
|
19
|
+
* @remarks TODO: add some heuristics that can map incoming provider names to the correct OpenInference provider name
|
|
20
|
+
* @param spanAttributes - The span attributes containing provider and system to map
|
|
21
|
+
* @returns The mapped provider and system attributes
|
|
22
|
+
*/
|
|
23
|
+
export declare const mapProviderAndSystem: (spanAttributes: Attributes) => Attributes;
|
|
24
|
+
/**
|
|
25
|
+
* Map model name to openinference attributes
|
|
26
|
+
* @param spanAttributes - The span attributes containing model name to map
|
|
27
|
+
* @returns The mapped model name attributes
|
|
28
|
+
*/
|
|
29
|
+
export declare const mapModels: (spanAttributes: Attributes) => Attributes;
|
|
30
|
+
/**
|
|
31
|
+
* Map span kind to openinference attributes
|
|
32
|
+
* @param spanAttributes - The span attributes containing span kind to map
|
|
33
|
+
* @returns The mapped span kind attributes
|
|
34
|
+
*/
|
|
35
|
+
export declare const mapSpanKind: (spanAttributes: Attributes) => Attributes;
|
|
36
|
+
/**
|
|
37
|
+
* Map invocation parameters to openinference attributes
|
|
38
|
+
* @param spanAttributes - The span attributes containing invocation parameters to map
|
|
39
|
+
* @returns The mapped invocation parameters attributes
|
|
40
|
+
*/
|
|
41
|
+
export declare const mapInvocationParameters: (spanAttributes: Attributes) => Attributes;
|
|
42
|
+
/**
|
|
43
|
+
* Map input value to openinference attributes
|
|
44
|
+
* @param spanAttributes - The span attributes containing input value to map
|
|
45
|
+
* @returns The mapped input value attributes
|
|
46
|
+
*/
|
|
47
|
+
export declare const mapInputValue: (spanAttributes: Attributes) => Attributes;
|
|
48
|
+
/**
|
|
49
|
+
* Map output value to openinference attributes
|
|
50
|
+
* @param spanAttributes - The span attributes containing output value to map
|
|
51
|
+
* @returns The mapped output value attributes
|
|
52
|
+
*/
|
|
53
|
+
export declare const mapOutputValue: (spanAttributes: Attributes) => Attributes;
|
|
54
|
+
/**
|
|
55
|
+
* Map input messages to openinference attributes
|
|
56
|
+
* @param spanAttributes - The span attributes containing input messages to map
|
|
57
|
+
* @returns The mapped input messages attributes
|
|
58
|
+
*/
|
|
59
|
+
export declare const mapInputMessages: (spanAttributes: Attributes) => Attributes;
|
|
60
|
+
/**
|
|
61
|
+
* Map output messages to openinference attributes
|
|
62
|
+
* @param spanAttributes - The span attributes containing output messages to map
|
|
63
|
+
* @returns The mapped output messages attributes
|
|
64
|
+
*/
|
|
65
|
+
export declare const mapOutputMessages: (spanAttributes: Attributes) => Attributes;
|
|
66
|
+
/**
|
|
67
|
+
* Map usage token counts to openinference attributes
|
|
68
|
+
* @param spanAttributes - The span attributes containing usage token counts to map
|
|
69
|
+
* @returns The mapped usage token counts attributes
|
|
70
|
+
*/
|
|
71
|
+
export declare const mapTokenCounts: (spanAttributes: Attributes) => Attributes;
|
|
72
|
+
/**
|
|
73
|
+
* Map tool execution to openinference attributes
|
|
74
|
+
* @see https://opentelemetry.io/docs/specs/semconv/gen-ai/gen-ai-spans/#execute-tool-span
|
|
75
|
+
* @param spanAttributes - The span attributes containing tool execution to map
|
|
76
|
+
* @returns The mapped tool execution attributes
|
|
77
|
+
*/
|
|
78
|
+
export declare const mapToolExecution: (spanAttributes: Attributes) => Attributes;
|
|
79
|
+
//# sourceMappingURL=attributes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attributes.d.ts","sourceRoot":"","sources":["../../src/attributes.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AA4BrD,OAAO,KAAK,EACV,WAAW,EAEZ,MAAM,+CAA+C,CAAC;AACvD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gDAAgD,CAAC;AAapF,MAAM,MAAM,iBAAiB,GAAG,WAAW,CAAC;AAC5C,MAAM,MAAM,qBAAqB,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC;AACjE,MAAM,MAAM,kBAAkB,GAAG,aAAa,GAAG;IAC/C,oCAAoC;IACpC,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AACF,MAAM,MAAM,sBAAsB,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC;AAoJpE;;;;GAIG;AACH,eAAO,MAAM,uDAAuD,GAClE,gBAAgB,UAAU,KACzB,UAaF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,GAC/B,gBAAgB,UAAU,KACzB,UAKF,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,SAAS,GAAI,gBAAgB,UAAU,KAAG,UAOtD,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,WAAW,GAAI,gBAAgB,UAAU,KAAG,UAgBxD,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,GAClC,gBAAgB,UAAU,KACzB,UA0CF,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,aAAa,GAAI,gBAAgB,UAAU,KAAG,UAa1D,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,cAAc,GAAI,gBAAgB,UAAU,KAAG,UAa3D,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,GAAI,gBAAgB,UAAU,KAAG,UAkB7D,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,GAAI,gBAAgB,UAAU,KAAG,UAmB9D,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,cAAc,GAAI,gBAAgB,UAAU,KAAG,UAoB3D,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,GAAI,gBAAgB,UAAU,KAAG,UAc7D,CAAC"}
|
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mapToolExecution = exports.mapTokenCounts = exports.mapOutputMessages = exports.mapInputMessages = exports.mapOutputValue = exports.mapInputValue = exports.mapInvocationParameters = exports.mapSpanKind = exports.mapModels = exports.mapProviderAndSystem = exports.convertGenAISpanAttributesToOpenInferenceSpanAttributes = void 0;
|
|
4
|
+
const openinference_semantic_conventions_1 = require("@arizeai/openinference-semantic-conventions");
|
|
5
|
+
const incubating_1 = require("@opentelemetry/semantic-conventions/incubating");
|
|
6
|
+
const utils_js_1 = require("./utils.js");
|
|
7
|
+
const AGENT_KIND_PREFIXES = [
|
|
8
|
+
incubating_1.ATTR_GEN_AI_AGENT_ID,
|
|
9
|
+
incubating_1.ATTR_GEN_AI_AGENT_NAME,
|
|
10
|
+
incubating_1.ATTR_GEN_AI_AGENT_DESCRIPTION,
|
|
11
|
+
];
|
|
12
|
+
const TOOL_EXECUTION_PREFIXES = [
|
|
13
|
+
incubating_1.ATTR_GEN_AI_TOOL_NAME,
|
|
14
|
+
incubating_1.ATTR_GEN_AI_TOOL_DESCRIPTION,
|
|
15
|
+
incubating_1.ATTR_GEN_AI_TOOL_CALL_ID,
|
|
16
|
+
incubating_1.ATTR_GEN_AI_TOOL_TYPE,
|
|
17
|
+
];
|
|
18
|
+
/**
|
|
19
|
+
* Type guard for a GenAI chat message
|
|
20
|
+
* @param value - The value to check
|
|
21
|
+
* @returns True if the value is a chat message, false otherwise
|
|
22
|
+
*/
|
|
23
|
+
const isGenAIChatMessage = (value) => {
|
|
24
|
+
if (typeof value !== "object" || value === null)
|
|
25
|
+
return false;
|
|
26
|
+
if (!("role" in value) || !("parts" in value))
|
|
27
|
+
return false;
|
|
28
|
+
if (typeof value.role !== "string" || !Array.isArray(value.parts))
|
|
29
|
+
return false;
|
|
30
|
+
if (!value.parts || !Array.isArray(value.parts))
|
|
31
|
+
return false;
|
|
32
|
+
return true;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Process genai message parts into openinference attributes
|
|
36
|
+
*
|
|
37
|
+
* @param params - The parameters to process the message parts
|
|
38
|
+
*/
|
|
39
|
+
const processMessageParts = ({ attrs, msgPrefix, parts, }) => {
|
|
40
|
+
var _a, _b, _c;
|
|
41
|
+
if (!Array.isArray(parts) || parts.length === 0)
|
|
42
|
+
return;
|
|
43
|
+
// track the index of the content and tool calls outside the loop
|
|
44
|
+
// this is just in-case we have to skip bad parts
|
|
45
|
+
let contentIndex = 0;
|
|
46
|
+
let toolIndex = 0;
|
|
47
|
+
for (const part of parts) {
|
|
48
|
+
if (!part || typeof part !== "object")
|
|
49
|
+
continue;
|
|
50
|
+
if (!part.type)
|
|
51
|
+
continue;
|
|
52
|
+
switch (part.type) {
|
|
53
|
+
case "text": {
|
|
54
|
+
const text = (0, utils_js_1.toStringContent)(part.content);
|
|
55
|
+
if (text !== undefined) {
|
|
56
|
+
// MESSAGE_CONTENTS entries
|
|
57
|
+
const contentPrefix = `${msgPrefix}${openinference_semantic_conventions_1.SemanticConventions.MESSAGE_CONTENTS}.${contentIndex}.`;
|
|
58
|
+
(0, utils_js_1.set)(attrs, `${contentPrefix}${openinference_semantic_conventions_1.SemanticConventions.MESSAGE_CONTENT_TYPE}`, "text");
|
|
59
|
+
(0, utils_js_1.set)(attrs, `${contentPrefix}${openinference_semantic_conventions_1.SemanticConventions.MESSAGE_CONTENT_TEXT}`, text);
|
|
60
|
+
contentIndex += 1;
|
|
61
|
+
}
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
case "tool_call": {
|
|
65
|
+
const id = (_a = part.id) !== null && _a !== void 0 ? _a : undefined;
|
|
66
|
+
const name = part.name;
|
|
67
|
+
const args = (_b = part.arguments) !== null && _b !== void 0 ? _b : {};
|
|
68
|
+
const toolPrefix = `${msgPrefix}${openinference_semantic_conventions_1.SemanticConventions.MESSAGE_TOOL_CALLS}.${toolIndex}.`;
|
|
69
|
+
(0, utils_js_1.set)(attrs, `${toolPrefix}${openinference_semantic_conventions_1.SemanticConventions.TOOL_CALL_ID}`, id);
|
|
70
|
+
(0, utils_js_1.set)(attrs, toolPrefix + openinference_semantic_conventions_1.SemanticConventions.TOOL_CALL_FUNCTION_NAME, name);
|
|
71
|
+
(0, utils_js_1.set)(attrs, toolPrefix + openinference_semantic_conventions_1.SemanticConventions.TOOL_CALL_FUNCTION_ARGUMENTS_JSON, (0, utils_js_1.safelyJSONStringify)(args));
|
|
72
|
+
toolIndex += 1;
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
case "tool_call_response": {
|
|
76
|
+
const id = (_c = part.id) !== null && _c !== void 0 ? _c : undefined;
|
|
77
|
+
const response = (0, utils_js_1.toStringContent)(part.response);
|
|
78
|
+
(0, utils_js_1.set)(attrs, `${msgPrefix}${openinference_semantic_conventions_1.SemanticConventions.MESSAGE_TOOL_CALL_ID}`, id);
|
|
79
|
+
const contentPrefix = `${msgPrefix}${openinference_semantic_conventions_1.SemanticConventions.MESSAGE_CONTENTS}.${contentIndex}.`;
|
|
80
|
+
(0, utils_js_1.set)(attrs, `${contentPrefix}${openinference_semantic_conventions_1.SemanticConventions.MESSAGE_CONTENT_TYPE}`, "text");
|
|
81
|
+
(0, utils_js_1.set)(attrs, `${contentPrefix}${openinference_semantic_conventions_1.SemanticConventions.MESSAGE_CONTENT_TEXT}`, response);
|
|
82
|
+
contentIndex += 1;
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
default: {
|
|
86
|
+
// Generic / unknown part type: capture as JSON text content
|
|
87
|
+
const genericPart = part;
|
|
88
|
+
const genericText = (0, utils_js_1.toStringContent)(genericPart);
|
|
89
|
+
const contentPrefix = `${msgPrefix}${openinference_semantic_conventions_1.SemanticConventions.MESSAGE_CONTENTS}.${contentIndex}.`;
|
|
90
|
+
(0, utils_js_1.set)(attrs, `${contentPrefix}${openinference_semantic_conventions_1.SemanticConventions.MESSAGE_CONTENT_TYPE}`, genericPart.type);
|
|
91
|
+
(0, utils_js_1.set)(attrs, `${contentPrefix}${openinference_semantic_conventions_1.SemanticConventions.MESSAGE_CONTENT_TEXT}`, genericText);
|
|
92
|
+
(0, utils_js_1.set)(attrs, `${msgPrefix}${openinference_semantic_conventions_1.SemanticConventions.MESSAGE_CONTENT}`, genericText);
|
|
93
|
+
contentIndex += 1;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* Convert GenAI span attributes to OpenInference span attributes
|
|
100
|
+
* @param spanAttributes - The span attributes containing GenAI span attributes to convert
|
|
101
|
+
* @returns The converted OpenInference span attributes
|
|
102
|
+
*/
|
|
103
|
+
const convertGenAISpanAttributesToOpenInferenceSpanAttributes = (spanAttributes) => {
|
|
104
|
+
return (0, utils_js_1.merge)((0, exports.mapProviderAndSystem)(spanAttributes), (0, exports.mapModels)(spanAttributes), (0, exports.mapSpanKind)(spanAttributes), (0, exports.mapInvocationParameters)(spanAttributes), (0, exports.mapInputMessages)(spanAttributes), (0, exports.mapOutputMessages)(spanAttributes), (0, exports.mapTokenCounts)(spanAttributes), (0, exports.mapToolExecution)(spanAttributes), (0, exports.mapInputValue)(spanAttributes), (0, exports.mapOutputValue)(spanAttributes));
|
|
105
|
+
};
|
|
106
|
+
exports.convertGenAISpanAttributesToOpenInferenceSpanAttributes = convertGenAISpanAttributesToOpenInferenceSpanAttributes;
|
|
107
|
+
/**
|
|
108
|
+
* Map provider and system to openinference attributes
|
|
109
|
+
* @remarks TODO: add some heuristics that can map incoming provider names to the correct OpenInference provider name
|
|
110
|
+
* @param spanAttributes - The span attributes containing provider and system to map
|
|
111
|
+
* @returns The mapped provider and system attributes
|
|
112
|
+
*/
|
|
113
|
+
const mapProviderAndSystem = (spanAttributes) => {
|
|
114
|
+
const attrs = {};
|
|
115
|
+
const provider = (0, utils_js_1.getString)(spanAttributes[incubating_1.ATTR_GEN_AI_PROVIDER_NAME]);
|
|
116
|
+
(0, utils_js_1.set)(attrs, openinference_semantic_conventions_1.SemanticConventions.LLM_PROVIDER, provider);
|
|
117
|
+
return attrs;
|
|
118
|
+
};
|
|
119
|
+
exports.mapProviderAndSystem = mapProviderAndSystem;
|
|
120
|
+
/**
|
|
121
|
+
* Map model name to openinference attributes
|
|
122
|
+
* @param spanAttributes - The span attributes containing model name to map
|
|
123
|
+
* @returns The mapped model name attributes
|
|
124
|
+
*/
|
|
125
|
+
const mapModels = (spanAttributes) => {
|
|
126
|
+
const attrs = {};
|
|
127
|
+
const requestModel = (0, utils_js_1.getString)(spanAttributes[incubating_1.ATTR_GEN_AI_REQUEST_MODEL]);
|
|
128
|
+
const responseModel = (0, utils_js_1.getString)(spanAttributes[incubating_1.ATTR_GEN_AI_RESPONSE_MODEL]);
|
|
129
|
+
const modelName = responseModel !== null && responseModel !== void 0 ? responseModel : requestModel;
|
|
130
|
+
(0, utils_js_1.set)(attrs, openinference_semantic_conventions_1.SemanticConventions.LLM_MODEL_NAME, modelName);
|
|
131
|
+
return attrs;
|
|
132
|
+
};
|
|
133
|
+
exports.mapModels = mapModels;
|
|
134
|
+
/**
|
|
135
|
+
* Map span kind to openinference attributes
|
|
136
|
+
* @param spanAttributes - The span attributes containing span kind to map
|
|
137
|
+
* @returns The mapped span kind attributes
|
|
138
|
+
*/
|
|
139
|
+
const mapSpanKind = (spanAttributes) => {
|
|
140
|
+
const attrs = {};
|
|
141
|
+
// default to LLM for now
|
|
142
|
+
let spanKind = openinference_semantic_conventions_1.OpenInferenceSpanKind.LLM;
|
|
143
|
+
// detect agent kind
|
|
144
|
+
if (AGENT_KIND_PREFIXES.some((prefix) => spanAttributes[prefix])) {
|
|
145
|
+
spanKind = openinference_semantic_conventions_1.OpenInferenceSpanKind.AGENT;
|
|
146
|
+
}
|
|
147
|
+
// detect tool execution kind
|
|
148
|
+
if (TOOL_EXECUTION_PREFIXES.some((prefix) => spanAttributes[prefix])) {
|
|
149
|
+
spanKind = openinference_semantic_conventions_1.OpenInferenceSpanKind.TOOL;
|
|
150
|
+
}
|
|
151
|
+
(0, utils_js_1.set)(attrs, openinference_semantic_conventions_1.SemanticConventions.OPENINFERENCE_SPAN_KIND, spanKind);
|
|
152
|
+
return attrs;
|
|
153
|
+
};
|
|
154
|
+
exports.mapSpanKind = mapSpanKind;
|
|
155
|
+
/**
|
|
156
|
+
* Map invocation parameters to openinference attributes
|
|
157
|
+
* @param spanAttributes - The span attributes containing invocation parameters to map
|
|
158
|
+
* @returns The mapped invocation parameters attributes
|
|
159
|
+
*/
|
|
160
|
+
const mapInvocationParameters = (spanAttributes) => {
|
|
161
|
+
const attrs = {};
|
|
162
|
+
const requestModel = (0, utils_js_1.getString)(spanAttributes[incubating_1.ATTR_GEN_AI_REQUEST_MODEL]);
|
|
163
|
+
const maxTokens = (0, utils_js_1.getNumber)(spanAttributes[incubating_1.ATTR_GEN_AI_REQUEST_MAX_TOKENS]);
|
|
164
|
+
const temperature = (0, utils_js_1.getNumber)(spanAttributes[incubating_1.ATTR_GEN_AI_REQUEST_TEMPERATURE]);
|
|
165
|
+
const topP = (0, utils_js_1.getNumber)(spanAttributes[incubating_1.ATTR_GEN_AI_REQUEST_TOP_P]);
|
|
166
|
+
const topK = (0, utils_js_1.getNumber)(spanAttributes[incubating_1.ATTR_GEN_AI_REQUEST_TOP_K]);
|
|
167
|
+
const presencePenalty = (0, utils_js_1.getNumber)(spanAttributes[incubating_1.ATTR_GEN_AI_REQUEST_PRESENCE_PENALTY]);
|
|
168
|
+
const frequencyPenalty = (0, utils_js_1.getNumber)(spanAttributes[incubating_1.ATTR_GEN_AI_REQUEST_FREQUENCY_PENALTY]);
|
|
169
|
+
const seed = (0, utils_js_1.getNumber)(spanAttributes[incubating_1.ATTR_GEN_AI_REQUEST_SEED]);
|
|
170
|
+
const stopSequences = (0, utils_js_1.getStringArray)(spanAttributes[incubating_1.ATTR_GEN_AI_REQUEST_STOP_SEQUENCES]);
|
|
171
|
+
const invocationParameters = {};
|
|
172
|
+
if (requestModel)
|
|
173
|
+
invocationParameters.model = requestModel;
|
|
174
|
+
if (typeof temperature === "number")
|
|
175
|
+
invocationParameters.temperature = temperature;
|
|
176
|
+
if (typeof topP === "number")
|
|
177
|
+
invocationParameters.top_p = topP;
|
|
178
|
+
if (typeof topK === "number")
|
|
179
|
+
invocationParameters.top_k = topK;
|
|
180
|
+
if (typeof presencePenalty === "number")
|
|
181
|
+
invocationParameters.presence_penalty = presencePenalty;
|
|
182
|
+
if (typeof frequencyPenalty === "number")
|
|
183
|
+
invocationParameters.frequency_penalty = frequencyPenalty;
|
|
184
|
+
if (typeof seed === "number")
|
|
185
|
+
invocationParameters.seed = seed;
|
|
186
|
+
if (stopSequences && stopSequences.length > 0)
|
|
187
|
+
invocationParameters.stop_sequences = stopSequences;
|
|
188
|
+
if (typeof maxTokens === "number")
|
|
189
|
+
invocationParameters.max_completion_tokens = maxTokens;
|
|
190
|
+
if (Object.keys(invocationParameters).length > 0) {
|
|
191
|
+
(0, utils_js_1.set)(attrs, openinference_semantic_conventions_1.SemanticConventions.LLM_INVOCATION_PARAMETERS, (0, utils_js_1.safelyJSONStringify)(invocationParameters));
|
|
192
|
+
}
|
|
193
|
+
return attrs;
|
|
194
|
+
};
|
|
195
|
+
exports.mapInvocationParameters = mapInvocationParameters;
|
|
196
|
+
/**
|
|
197
|
+
* Map input value to openinference attributes
|
|
198
|
+
* @param spanAttributes - The span attributes containing input value to map
|
|
199
|
+
* @returns The mapped input value attributes
|
|
200
|
+
*/
|
|
201
|
+
const mapInputValue = (spanAttributes) => {
|
|
202
|
+
const attrs = {};
|
|
203
|
+
let input = (0, utils_js_1.getString)(spanAttributes["input"]);
|
|
204
|
+
if (!input) {
|
|
205
|
+
// fallback to deprecated prompt attribute if input is not present
|
|
206
|
+
input = (0, utils_js_1.getString)(spanAttributes[incubating_1.ATTR_GEN_AI_PROMPT]);
|
|
207
|
+
}
|
|
208
|
+
// only set input value and mime type if input is present
|
|
209
|
+
if (input) {
|
|
210
|
+
(0, utils_js_1.set)(attrs, openinference_semantic_conventions_1.SemanticConventions.INPUT_VALUE, input);
|
|
211
|
+
(0, utils_js_1.set)(attrs, openinference_semantic_conventions_1.SemanticConventions.INPUT_MIME_TYPE, (0, utils_js_1.getMimeType)(input));
|
|
212
|
+
}
|
|
213
|
+
return attrs;
|
|
214
|
+
};
|
|
215
|
+
exports.mapInputValue = mapInputValue;
|
|
216
|
+
/**
|
|
217
|
+
* Map output value to openinference attributes
|
|
218
|
+
* @param spanAttributes - The span attributes containing output value to map
|
|
219
|
+
* @returns The mapped output value attributes
|
|
220
|
+
*/
|
|
221
|
+
const mapOutputValue = (spanAttributes) => {
|
|
222
|
+
const attrs = {};
|
|
223
|
+
let output = (0, utils_js_1.getString)(spanAttributes["output"]);
|
|
224
|
+
if (!output) {
|
|
225
|
+
// fallback to deprecated completion attribute if output is not present
|
|
226
|
+
output = (0, utils_js_1.getString)(spanAttributes[incubating_1.ATTR_GEN_AI_COMPLETION]);
|
|
227
|
+
}
|
|
228
|
+
// only set output value and mime type if output is present
|
|
229
|
+
if (output) {
|
|
230
|
+
(0, utils_js_1.set)(attrs, openinference_semantic_conventions_1.SemanticConventions.OUTPUT_VALUE, output);
|
|
231
|
+
(0, utils_js_1.set)(attrs, openinference_semantic_conventions_1.SemanticConventions.OUTPUT_MIME_TYPE, (0, utils_js_1.getMimeType)(output));
|
|
232
|
+
}
|
|
233
|
+
return attrs;
|
|
234
|
+
};
|
|
235
|
+
exports.mapOutputValue = mapOutputValue;
|
|
236
|
+
/**
|
|
237
|
+
* Map input messages to openinference attributes
|
|
238
|
+
* @param spanAttributes - The span attributes containing input messages to map
|
|
239
|
+
* @returns The mapped input messages attributes
|
|
240
|
+
*/
|
|
241
|
+
const mapInputMessages = (spanAttributes) => {
|
|
242
|
+
const attrs = {};
|
|
243
|
+
const genAIInputMessages = (0, utils_js_1.safelyParseJSON)(spanAttributes[incubating_1.ATTR_GEN_AI_INPUT_MESSAGES]);
|
|
244
|
+
if (Array.isArray(genAIInputMessages)) {
|
|
245
|
+
genAIInputMessages.forEach((msg, msgIndex) => {
|
|
246
|
+
if (!isGenAIChatMessage(msg))
|
|
247
|
+
return;
|
|
248
|
+
const msgPrefix = `${openinference_semantic_conventions_1.SemanticConventions.LLM_INPUT_MESSAGES}.${msgIndex}.`;
|
|
249
|
+
// set the message role
|
|
250
|
+
(0, utils_js_1.set)(attrs, `${msgPrefix}${openinference_semantic_conventions_1.SemanticConventions.MESSAGE_ROLE}`, msg.role);
|
|
251
|
+
// process and set the rest of the message parts
|
|
252
|
+
processMessageParts({ attrs, msgPrefix, parts: msg.parts });
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
return attrs;
|
|
256
|
+
};
|
|
257
|
+
exports.mapInputMessages = mapInputMessages;
|
|
258
|
+
/**
|
|
259
|
+
* Map output messages to openinference attributes
|
|
260
|
+
* @param spanAttributes - The span attributes containing output messages to map
|
|
261
|
+
* @returns The mapped output messages attributes
|
|
262
|
+
*/
|
|
263
|
+
const mapOutputMessages = (spanAttributes) => {
|
|
264
|
+
const attrs = {};
|
|
265
|
+
const genAIOutputMessages = (0, utils_js_1.safelyParseJSON)(spanAttributes[incubating_1.ATTR_GEN_AI_OUTPUT_MESSAGES]);
|
|
266
|
+
if (Array.isArray(genAIOutputMessages) && genAIOutputMessages.length > 0) {
|
|
267
|
+
// recast as unknown[] for safety, as Array.isArray() retypes to any[]
|
|
268
|
+
genAIOutputMessages.forEach((msg, msgIndex) => {
|
|
269
|
+
if (!isGenAIChatMessage(msg))
|
|
270
|
+
return;
|
|
271
|
+
const msgPrefix = `${openinference_semantic_conventions_1.SemanticConventions.LLM_OUTPUT_MESSAGES}.${msgIndex}.`;
|
|
272
|
+
// set the message role
|
|
273
|
+
(0, utils_js_1.set)(attrs, `${msgPrefix}${openinference_semantic_conventions_1.SemanticConventions.MESSAGE_ROLE}`, msg.role);
|
|
274
|
+
// process and set the rest of the message parts
|
|
275
|
+
processMessageParts({ attrs, msgPrefix, parts: msg.parts });
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
return attrs;
|
|
279
|
+
};
|
|
280
|
+
exports.mapOutputMessages = mapOutputMessages;
|
|
281
|
+
/**
|
|
282
|
+
* Map usage token counts to openinference attributes
|
|
283
|
+
* @param spanAttributes - The span attributes containing usage token counts to map
|
|
284
|
+
* @returns The mapped usage token counts attributes
|
|
285
|
+
*/
|
|
286
|
+
const mapTokenCounts = (spanAttributes) => {
|
|
287
|
+
const attrs = {};
|
|
288
|
+
const inputTokens = (0, utils_js_1.getNumber)(spanAttributes[incubating_1.ATTR_GEN_AI_USAGE_INPUT_TOKENS]);
|
|
289
|
+
const outputTokens = (0, utils_js_1.getNumber)(spanAttributes[incubating_1.ATTR_GEN_AI_USAGE_OUTPUT_TOKENS]);
|
|
290
|
+
if (typeof inputTokens === "number") {
|
|
291
|
+
(0, utils_js_1.set)(attrs, openinference_semantic_conventions_1.SemanticConventions.LLM_TOKEN_COUNT_PROMPT, inputTokens);
|
|
292
|
+
}
|
|
293
|
+
if (typeof outputTokens === "number") {
|
|
294
|
+
(0, utils_js_1.set)(attrs, openinference_semantic_conventions_1.SemanticConventions.LLM_TOKEN_COUNT_COMPLETION, outputTokens);
|
|
295
|
+
}
|
|
296
|
+
if (typeof inputTokens === "number" && typeof outputTokens === "number") {
|
|
297
|
+
(0, utils_js_1.set)(attrs, openinference_semantic_conventions_1.SemanticConventions.LLM_TOKEN_COUNT_TOTAL, inputTokens + outputTokens);
|
|
298
|
+
}
|
|
299
|
+
return attrs;
|
|
300
|
+
};
|
|
301
|
+
exports.mapTokenCounts = mapTokenCounts;
|
|
302
|
+
/**
|
|
303
|
+
* Map tool execution to openinference attributes
|
|
304
|
+
* @see https://opentelemetry.io/docs/specs/semconv/gen-ai/gen-ai-spans/#execute-tool-span
|
|
305
|
+
* @param spanAttributes - The span attributes containing tool execution to map
|
|
306
|
+
* @returns The mapped tool execution attributes
|
|
307
|
+
*/
|
|
308
|
+
const mapToolExecution = (spanAttributes) => {
|
|
309
|
+
const attrs = {};
|
|
310
|
+
const toolName = (0, utils_js_1.getString)(spanAttributes[incubating_1.ATTR_GEN_AI_TOOL_NAME]);
|
|
311
|
+
const toolDescription = (0, utils_js_1.getString)(spanAttributes[incubating_1.ATTR_GEN_AI_TOOL_DESCRIPTION]);
|
|
312
|
+
const toolCallId = (0, utils_js_1.getString)(spanAttributes[incubating_1.ATTR_GEN_AI_TOOL_CALL_ID]);
|
|
313
|
+
// parse supported tool details
|
|
314
|
+
// note: while openinference can track parameters, gen_ai does not provide this information
|
|
315
|
+
(0, utils_js_1.set)(attrs, openinference_semantic_conventions_1.SemanticConventions.TOOL_NAME, toolName);
|
|
316
|
+
(0, utils_js_1.set)(attrs, openinference_semantic_conventions_1.SemanticConventions.TOOL_DESCRIPTION, toolDescription);
|
|
317
|
+
(0, utils_js_1.set)(attrs, openinference_semantic_conventions_1.SemanticConventions.TOOL_CALL_ID, toolCallId);
|
|
318
|
+
return attrs;
|
|
319
|
+
};
|
|
320
|
+
exports.mapToolExecution = mapToolExecution;
|
|
321
|
+
//# sourceMappingURL=attributes.js.map
|