@introspection-sdk/introspection-node 0.4.0 → 0.4.1
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/.turbo/turbo-build.log +1 -1
- package/LICENSE +191 -0
- package/dist/converters/ai-sdk.d.ts +1 -1
- package/dist/converters/ai-sdk.d.ts.map +1 -1
- package/dist/converters/ai-sdk.js +24 -1
- package/dist/converters/claude.d.ts +1 -1
- package/dist/converters/claude.d.ts.map +1 -1
- package/dist/converters/claude.js +1 -1
- package/dist/converters/openai.d.ts +1 -1
- package/dist/converters/openai.d.ts.map +1 -1
- package/dist/converters/openinference.d.ts +1 -1
- package/dist/converters/openinference.d.ts.map +1 -1
- package/dist/converters/openinference.js +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/langchain-handler.d.ts +7 -5
- package/dist/langchain-handler.d.ts.map +1 -1
- package/dist/langchain-handler.js +55 -26
- package/dist/span-processor.d.ts.map +1 -1
- package/dist/span-processor.js +3 -0
- package/package.json +4 -2
- package/src/ai-sdk-integration.ts +1 -1
- package/src/anthropic.ts +1 -1
- package/src/converters/ai-sdk.ts +27 -2
- package/src/converters/claude.ts +2 -2
- package/src/converters/openai.ts +1 -1
- package/src/converters/openinference.ts +2 -2
- package/src/index.ts +2 -2
- package/src/langchain-handler.ts +64 -33
- package/src/mastra-exporter.ts +1 -1
- package/src/span-processor.ts +3 -0
- package/.turbo/turbo-check-types.log +0 -5
- package/.turbo/turbo-lint.log +0 -5
- package/dist/converters/openclaw.d.ts +0 -16
- package/dist/converters/openclaw.d.ts.map +0 -1
- package/dist/converters/openclaw.js +0 -49
- package/dist/types/genai.d.ts +0 -165
- package/dist/types/genai.d.ts.map +0 -1
- package/dist/types/genai.js +0 -82
- package/src/types/genai.ts +0 -264
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
|
|
2
|
-
> @introspection-sdk/introspection-node@0.1
|
|
2
|
+
> @introspection-sdk/introspection-node@0.4.1 build /home/runner/work/introspection-js-sdk/introspection-js-sdk/packages/introspection-node
|
|
3
3
|
> tsc
|
|
4
4
|
|
package/LICENSE
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to the Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by the Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding any notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
Copyright 2026 Introspection AI Inc.
|
|
180
|
+
|
|
181
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
182
|
+
you may not use this file except in compliance with the License.
|
|
183
|
+
You may obtain a copy of the License at
|
|
184
|
+
|
|
185
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
186
|
+
|
|
187
|
+
Unless required by applicable law or agreed to in writing, software
|
|
188
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
189
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
190
|
+
See the License for the specific language governing permissions and
|
|
191
|
+
limitations under the License.
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*
|
|
8
8
|
* Used by {@link IntrospectionAISDKIntegration}.
|
|
9
9
|
*/
|
|
10
|
-
import type { InputMessage, OutputMessage, SystemInstruction, ToolDefinition } from "
|
|
10
|
+
import type { InputMessage, OutputMessage, SystemInstruction, ToolDefinition } from "@introspection-sdk/types";
|
|
11
11
|
/**
|
|
12
12
|
* Convert AI SDK messages (ModelMessage[]) to gen_ai InputMessage[].
|
|
13
13
|
* System messages are excluded — they're handled separately via
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-sdk.d.ts","sourceRoot":"","sources":["../../src/converters/ai-sdk.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EACV,YAAY,EACZ,aAAa,EACb,iBAAiB,EACjB,cAAc,EAEf,MAAM,
|
|
1
|
+
{"version":3,"file":"ai-sdk.d.ts","sourceRoot":"","sources":["../../src/converters/ai-sdk.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EACV,YAAY,EACZ,aAAa,EACb,iBAAiB,EACjB,cAAc,EAEf,MAAM,0BAA0B,CAAC;AAuBlC;;;;;;;GAOG;AACH,wBAAgB,8BAA8B,CAC5C,QAAQ,EAAE,SAAS,OAAO,EAAE,GAC3B,YAAY,EAAE,CAQhB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,OAAO,EACf,QAAQ,EAAE,SAAS,OAAO,EAAE,GAC3B,iBAAiB,EAAE,GAAG,SAAS,CAoCjC;AAED;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE;IAC3C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,SAAS,CAAC,EAAE,SAAS;QAAE,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IACzC,SAAS,CAAC,EAAE,SAAS;QACnB,UAAU,EAAE,MAAM,CAAC;QACnB,QAAQ,EAAE,MAAM,CAAC;QACjB,KAAK,EAAE,OAAO,CAAC;KAChB,EAAE,CAAC;IACJ,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,GAAG,aAAa,EAAE,CAuClB;AAED;;;;;;;;;GASG;AACH,wBAAgB,6BAA6B,CAC3C,KAAK,EAAE,OAAO,GACb,cAAc,EAAE,GAAG,SAAS,CAgB9B"}
|
|
@@ -146,7 +146,7 @@ export function convertToolsToToolDefinitions(tools) {
|
|
|
146
146
|
defs.push({
|
|
147
147
|
name,
|
|
148
148
|
description: typeof t.description === "string" ? t.description : undefined,
|
|
149
|
-
parameters: extractToolParameters(t.parameters),
|
|
149
|
+
parameters: extractToolParameters(t.inputSchema ?? t.parameters),
|
|
150
150
|
});
|
|
151
151
|
}
|
|
152
152
|
return defs.length > 0 ? defs : undefined;
|
|
@@ -226,6 +226,29 @@ function extractToolParameters(parameters) {
|
|
|
226
226
|
if (!parameters || typeof parameters !== "object")
|
|
227
227
|
return undefined;
|
|
228
228
|
const p = parameters;
|
|
229
|
+
// Zod 4 schema — exposes a toJSONSchema() method.
|
|
230
|
+
if (typeof p.toJSONSchema === "function") {
|
|
231
|
+
const jsonSchema = p.toJSONSchema();
|
|
232
|
+
if (jsonSchema && typeof jsonSchema === "object") {
|
|
233
|
+
return jsonSchema;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
// AI SDK v6 tools expose inputSchema instead of parameters. Zod-backed
|
|
237
|
+
// schemas usually carry a JSON Schema factory on this property.
|
|
238
|
+
if (p["~standard"] && typeof p["~standard"] === "object") {
|
|
239
|
+
const standard = p["~standard"];
|
|
240
|
+
const standardJsonSchema = standard.jsonSchema;
|
|
241
|
+
if (standardJsonSchema && typeof standardJsonSchema === "object") {
|
|
242
|
+
const input = standardJsonSchema.input;
|
|
243
|
+
if (typeof input === "function") {
|
|
244
|
+
const jsonSchema = input();
|
|
245
|
+
if (jsonSchema && typeof jsonSchema === "object") {
|
|
246
|
+
return jsonSchema;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
return standardJsonSchema;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
229
252
|
// jsonSchema() wrapper — has a jsonSchema property
|
|
230
253
|
if (p.jsonSchema && typeof p.jsonSchema === "object") {
|
|
231
254
|
return p.jsonSchema;
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* These functions convert Claude Agent SDK message formats to the standardized
|
|
5
5
|
* OTel Gen AI Semantic Convention format for gen_ai.input.messages and gen_ai.output.messages.
|
|
6
6
|
*/
|
|
7
|
-
import type { InputMessage, OutputMessage, GenAiAttributes } from "
|
|
7
|
+
import type { InputMessage, OutputMessage, GenAiAttributes } from "@introspection-sdk/types";
|
|
8
8
|
/** A plain-text content block from the Claude API. */
|
|
9
9
|
export interface ClaudeTextBlock {
|
|
10
10
|
type: "text";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"claude.d.ts","sourceRoot":"","sources":["../../src/converters/claude.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,YAAY,EACZ,aAAa,EAGb,eAAe,EAEhB,MAAM,
|
|
1
|
+
{"version":3,"file":"claude.d.ts","sourceRoot":"","sources":["../../src/converters/claude.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,YAAY,EACZ,aAAa,EAGb,eAAe,EAEhB,MAAM,0BAA0B,CAAC;AAGlC,sDAAsD;AACtD,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd;AAED,oEAAoE;AACpE,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,UAAU,CAAC;IACjB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EAAE,CAKhB;AAED;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IAChC,mBAAmB;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,gEAAgE;IAChE,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,kDAAkD;IAClD,cAAc,CAAC,EAAE,kBAAkB,EAAE,CAAC;IACtC,iBAAiB;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,iBAAiB;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,wBAAwB;IACxB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,yBAAyB;IACzB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,kBAAkB;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,yBAAyB;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,kBAAkB;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,mCAAmC;IACnC,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,0CAA0C;IAC1C,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,2BAA2B,CACzC,IAAI,EAAE,iBAAiB,GACtB,eAAe,CAyDjB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,oCAAoC,CAClD,IAAI,EAAE,iBAAiB,GACtB,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAajC"}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* These functions convert Claude Agent SDK message formats to the standardized
|
|
5
5
|
* OTel Gen AI Semantic Convention format for gen_ai.input.messages and gen_ai.output.messages.
|
|
6
6
|
*/
|
|
7
|
-
import { toAttributes } from "
|
|
7
|
+
import { toAttributes } from "@introspection-sdk/types";
|
|
8
8
|
/**
|
|
9
9
|
* Convert a user prompt string to OTel Gen AI input message format.
|
|
10
10
|
*
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* and gen_ai.output.messages attributes.
|
|
7
7
|
*/
|
|
8
8
|
import type { Responses } from "openai/resources/responses/responses";
|
|
9
|
-
import type { InputMessage, OutputMessage, ToolDefinition, SystemInstruction } from "
|
|
9
|
+
import type { InputMessage, OutputMessage, ToolDefinition, SystemInstruction } from "@introspection-sdk/types";
|
|
10
10
|
/** Re-export OpenAI types used by callers (e.g. tracing-processor). */
|
|
11
11
|
export type ResponseInputItem = Responses.ResponseInputItem;
|
|
12
12
|
export type ResponseOutputItem = Responses.ResponseOutputItem;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../../src/converters/openai.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sCAAsC,CAAC;AACtE,OAAO,KAAK,EACV,YAAY,EACZ,aAAa,EAGb,cAAc,EACd,iBAAiB,EAClB,MAAM,
|
|
1
|
+
{"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../../src/converters/openai.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sCAAsC,CAAC;AACtE,OAAO,KAAK,EACV,YAAY,EACZ,aAAa,EAGb,cAAc,EACd,iBAAiB,EAClB,MAAM,0BAA0B,CAAC;AAElC,uEAAuE;AACvE,MAAM,MAAM,iBAAiB,GAAG,SAAS,CAAC,iBAAiB,CAAC;AAC5D,MAAM,MAAM,kBAAkB,GAAG,SAAS,CAAC,kBAAkB,CAAC;AAC9D,MAAM,MAAM,YAAY,GAAG,SAAS,CAAC,IAAI,CAAC;AAC1C,MAAM,MAAM,aAAa,GAAG,SAAS,CAAC,aAAa,CAAC;AACpD,MAAM,MAAM,QAAQ,GAAG,SAAS,CAAC,QAAQ,CAAC;AAgC1C;;;;;;;;;;GAUG;AACH,wBAAgB,+BAA+B,CAC7C,MAAM,EAAE,iBAAiB,EAAE,GAAG,SAAS,EACvC,YAAY,EAAE,MAAM,GAAG,SAAS,GAC/B,CAAC,YAAY,EAAE,EAAE,YAAY,EAAE,CAAC,CAqDlC;AAED;;;;;;;GAOG;AACH,wBAAgB,gCAAgC,CAC9C,OAAO,EAAE,kBAAkB,EAAE,GAC5B,aAAa,EAAE,CAsHjB;AAED;;;;;GAKG;AACH,wBAAgB,8BAA8B,CAC5C,KAAK,EAAE,YAAY,EAAE,GACpB,cAAc,EAAE,CAelB;AAED;;;;;GAKG;AACH,wBAAgB,qCAAqC,CACnD,YAAY,EAAE,MAAM,GAAG,iBAAiB,EAAE,GAAG,IAAI,GAAG,SAAS,GAC5D,iBAAiB,EAAE,GAAG,SAAS,CAcjC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Attributes } from "@opentelemetry/api";
|
|
2
2
|
import type { ReadableSpan, SpanExporter } from "@opentelemetry/sdk-trace-base";
|
|
3
|
-
import type { GenAiAttributes } from "
|
|
3
|
+
import type { GenAiAttributes } from "@introspection-sdk/types";
|
|
4
4
|
/**
|
|
5
5
|
* Check whether an OTel scope name belongs to an OpenInference instrumentor.
|
|
6
6
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openinference.d.ts","sourceRoot":"","sources":["../../src/converters/openinference.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAChF,OAAO,KAAK,EACV,eAAe,EAMhB,MAAM,
|
|
1
|
+
{"version":3,"file":"openinference.d.ts","sourceRoot":"","sources":["../../src/converters/openinference.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAChF,OAAO,KAAK,EACV,eAAe,EAMhB,MAAM,0BAA0B,CAAC;AAwBlC;;;;;;;;;;;;GAYG;AACH,wBAAgB,mBAAmB,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAM/D;AAwTD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,2BAA2B,CACzC,KAAK,CAAC,EAAE,UAAU,GACjB,eAAe,CAyCjB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,6BAA6B,CAAC,KAAK,CAAC,EAAE,UAAU,GAAG,UAAU,CAsB5E;AAoED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,YAAY,GAAG,YAAY,CA6E3E;AAED;;;;;;;;;;;;GAYG;AACH,qBAAa,yBAA0B,YAAW,YAAY;IAIhD,OAAO,CAAC,KAAK;IAHzB;;OAEG;gBACiB,KAAK,EAAE,YAAY;IAEvC;;;;;OAKG;IACH,MAAM,CACJ,KAAK,EAAE,YAAY,EAAE,EACrB,cAAc,EAAE,CAAC,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,GACjD,IAAI;IAIP;;;;OAIG;IACG,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAI/B;;;;OAIG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;CAGlC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -27,8 +27,8 @@ export { IntrospectionClaudeHooks } from "./claude-hooks.js";
|
|
|
27
27
|
export type { IntrospectionClaudeHooksOptions, ClaudeHooksAdvancedOptions, ClaudeHooksConfig, ClaudeHookCallbackMatcher, ClaudeHookEvent, ClaudeHookInput, ClaudeHookOutput, ClaudeHookCallback, ClaudeUsage, ClaudeModelUsage, ClaudeResultMessage, ClaudeAssistantMessage, ClaudeSDKMessage, } from "./claude-hooks.js";
|
|
28
28
|
export { withIntrospection } from "./claude-wrapper.js";
|
|
29
29
|
export type { WithIntrospectionOptions, InstrumentedClaudeAgentSDK, ClaudeAgentSDKModule, } from "./claude-wrapper.js";
|
|
30
|
-
export type { GenAiAttributes, InputMessage, OutputMessage, SystemInstruction, ToolDefinition, TextPart, ToolCallRequestPart, ToolCallResponsePart, MessagePart, } from "
|
|
31
|
-
export { toAttributes } from "
|
|
30
|
+
export type { GenAiAttributes, InputMessage, OutputMessage, SystemInstruction, ToolDefinition, TextPart, ToolCallRequestPart, ToolCallResponsePart, MessagePart, } from "@introspection-sdk/types";
|
|
31
|
+
export { toAttributes } from "@introspection-sdk/types";
|
|
32
32
|
export { convertResponsesInputsToSemconv, convertResponsesOutputsToSemconv, convertResponsesToolsToSemconv, convertResponsesInstructionsToSemconv, } from "./converters/openai.js";
|
|
33
33
|
export type { ResponseInputItem, ResponseOutputItem, ResponseTool, ResponseUsage, Response as OpenAIResponse, } from "./converters/openai.js";
|
|
34
34
|
export { IntrospectionAISDKIntegration } from "./ai-sdk-integration.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,MAAM,qBAAqB,CAAC;AACjE,OAAO,KAAK,EAAE,iCAAiC,EAAE,MAAM,qBAAqB,CAAC;AAE7E;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,OAAO,UAAU,0BAA0B,CAChD,OAAO,CAAC,EAAE,iCAAiC,GAC1C,0BAA0B,CAE5B;AAGD,OAAO,EAAE,0BAA0B,EAAE,MAAM,qBAAqB,CAAC;AACjE,YAAY,EAAE,iCAAiC,EAAE,MAAM,qBAAqB,CAAC;AAG7E,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAGlD,YAAY,EACV,eAAe,EACf,0BAA0B,EAC1B,eAAe,EACf,UAAU,GACX,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,6BAA6B,EAAE,MAAM,wBAAwB,CAAC;AACvE,YAAY,EACV,oCAAoC,EACpC,+BAA+B,GAChC,MAAM,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hC,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAC7D,YAAY,EACV,+BAA+B,EAC/B,0BAA0B,EAC1B,iBAAiB,EACjB,yBAAyB,EACzB,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,kBAAkB,EAClB,WAAW,EACX,gBAAgB,EAChB,mBAAmB,EACnB,sBAAsB,EACtB,gBAAgB,GACjB,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,YAAY,EACV,wBAAwB,EACxB,0BAA0B,EAC1B,oBAAoB,GACrB,MAAM,qBAAqB,CAAC;AAG7B,YAAY,EACV,eAAe,EACf,YAAY,EACZ,aAAa,EACb,iBAAiB,EACjB,cAAc,EACd,QAAQ,EACR,mBAAmB,EACnB,oBAAoB,EACpB,WAAW,GACZ,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAGxD,OAAO,EACL,+BAA+B,EAC/B,gCAAgC,EAChC,8BAA8B,EAC9B,qCAAqC,GACtC,MAAM,wBAAwB,CAAC;AAChC,YAAY,EACV,iBAAiB,EACjB,kBAAkB,EAClB,YAAY,EACZ,aAAa,EACb,QAAQ,IAAI,cAAc,GAC3B,MAAM,wBAAwB,CAAC;AAGhC,OAAO,EAAE,6BAA6B,EAAE,MAAM,yBAAyB,CAAC;AACxE,YAAY,EACV,oCAAoC,EACpC,+BAA+B,GAChC,MAAM,yBAAyB,CAAC;AAGjC,OAAO,EACL,0BAA0B,EAC1B,yBAAyB,GAC1B,MAAM,+BAA+B,CAAC;AAGvC,OAAO,EACL,qBAAqB,EACrB,oBAAoB,EACpB,yBAAyB,GAC1B,MAAM,gBAAgB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -28,7 +28,7 @@ export { IntrospectionTracingProcessor } from "./tracing-processor.js";
|
|
|
28
28
|
export { IntrospectionClaudeHooks } from "./claude-hooks.js";
|
|
29
29
|
// Claude Agent SDK wrapper exports
|
|
30
30
|
export { withIntrospection } from "./claude-wrapper.js";
|
|
31
|
-
export { toAttributes } from "
|
|
31
|
+
export { toAttributes } from "@introspection-sdk/types";
|
|
32
32
|
// OpenAI converter exports
|
|
33
33
|
export { convertResponsesInputsToSemconv, convertResponsesOutputsToSemconv, convertResponsesToolsToSemconv, convertResponsesInstructionsToSemconv, } from "./converters/openai.js";
|
|
34
34
|
// AI SDK integration exports (for Vercel AI SDK)
|
|
@@ -65,16 +65,18 @@ export declare class IntrospectionCallbackHandler extends BaseCallbackHandler {
|
|
|
65
65
|
private _tracerProvider;
|
|
66
66
|
private _tracer;
|
|
67
67
|
private _spans;
|
|
68
|
-
private _rootSpan;
|
|
69
68
|
private _conversationId;
|
|
70
69
|
private _spanNames;
|
|
71
70
|
private _spanParents;
|
|
71
|
+
private _runRoots;
|
|
72
72
|
private static _wrapperNames;
|
|
73
73
|
private _llmInputs;
|
|
74
74
|
constructor(options?: IntrospectionCallbackHandlerOptions);
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
75
|
+
private _rootRunId;
|
|
76
|
+
/** Keep the top-level run span aligned with child conversation IDs. */
|
|
77
|
+
private _setRootConversationId;
|
|
78
|
+
private _endRootIfComplete;
|
|
79
|
+
/** Create a span under a LangChain parent when one exists.
|
|
78
80
|
* Sets gen_ai.agent.name to the parent span's name for hierarchy. */
|
|
79
81
|
private _createChildSpan;
|
|
80
82
|
handleChatModelStart(llm: Serialized, messages: BaseMessage[][], runId: string, parentRunId?: string, extraParams?: Record<string, unknown>, _tags?: string[], metadata?: Record<string, unknown>, runName?: string): void;
|
|
@@ -84,7 +86,7 @@ export declare class IntrospectionCallbackHandler extends BaseCallbackHandler {
|
|
|
84
86
|
handleChainStart(chain: Serialized, _inputs: ChainValues, runId: string, _runType?: string, _tags?: string[], metadata?: Record<string, unknown>, runName?: string, parentRunId?: string): void;
|
|
85
87
|
handleChainEnd(_outputs: ChainValues, runId: string): void;
|
|
86
88
|
handleChainError(err: Error, runId: string): void;
|
|
87
|
-
handleToolStart(tool: Serialized, input: string, runId: string, parentRunId?: string, _tags?: string[],
|
|
89
|
+
handleToolStart(tool: Serialized, input: string, runId: string, parentRunId?: string, _tags?: string[], metadata?: Record<string, unknown>, runName?: string): void;
|
|
88
90
|
handleToolEnd(output: unknown, runId: string): void;
|
|
89
91
|
handleToolError(err: Error, runId: string): void;
|
|
90
92
|
shutdown(): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"langchain-handler.d.ts","sourceRoot":"","sources":["../src/langchain-handler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAC;AACpE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"langchain-handler.d.ts","sourceRoot":"","sources":["../src/langchain-handler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAC;AACpE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAS/D,OAAO,EAIL,KAAK,YAAY,EACjB,KAAK,WAAW,EACjB,MAAM,+BAA+B,CAAC;AAkBvC,sDAAsD;AACtD,MAAM,WAAW,+B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AAM,EAAE,OAAO,CAAC,EAClC,OAAO,CAAC,EAAE,MAAM,GACf,IAAI;IAgBP,aAAa,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAgBnD,eAAe,CAAC,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAe1C,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IASzB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAQjC,OAAO,CAAC,iBAAiB;IA2BzB,OAAO,CAAC,gBAAgB;IAQxB,qEAAqE;IACrE,OAAO,CAAC,cAAc;IAYtB,OAAO,CAAC,kBAAkB;IAY1B,OAAO,CAAC,gBAAgB;IA6DxB,OAAO,CAAC,QAAQ;IAehB,OAAO,CAAC,eAAe;CAcxB"}
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
* ```
|
|
27
27
|
*/
|
|
28
28
|
import { BaseCallbackHandler } from "@langchain/core/callbacks/base";
|
|
29
|
-
import { context as otelContext, trace as otelTrace, } from "@opentelemetry/api";
|
|
29
|
+
import { context as otelContext, ROOT_CONTEXT, SpanStatusCode, trace as otelTrace, } from "@opentelemetry/api";
|
|
30
30
|
import { BasicTracerProvider, BatchSpanProcessor, SimpleSpanProcessor, } from "@opentelemetry/sdk-trace-base";
|
|
31
31
|
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-proto";
|
|
32
32
|
import { resourceFromAttributes } from "@opentelemetry/resources";
|
|
@@ -49,11 +49,11 @@ export class IntrospectionCallbackHandler extends BaseCallbackHandler {
|
|
|
49
49
|
_tracerProvider;
|
|
50
50
|
_tracer;
|
|
51
51
|
_spans = new Map();
|
|
52
|
-
_rootSpan = null;
|
|
53
52
|
_conversationId;
|
|
54
53
|
// Track span names and parents so children can resolve gen_ai.agent.name
|
|
55
54
|
_spanNames = new Map();
|
|
56
55
|
_spanParents = new Map();
|
|
56
|
+
_runRoots = new Map();
|
|
57
57
|
// LangChain wrapper names to skip when resolving agent names
|
|
58
58
|
static _wrapperNames = new Set([
|
|
59
59
|
"RunnableSequence",
|
|
@@ -128,20 +128,29 @@ export class IntrospectionCallbackHandler extends BaseCallbackHandler {
|
|
|
128
128
|
this._tracer = this._tracerProvider.getTracer("langchain", VERSION);
|
|
129
129
|
this._conversationId = `intro_conv_${randomUUID().replace(/-/g, "")}`;
|
|
130
130
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
131
|
+
_rootRunId(runId, parentRunId) {
|
|
132
|
+
if (!parentRunId)
|
|
133
|
+
return runId;
|
|
134
|
+
return this._runRoots.get(parentRunId) || parentRunId;
|
|
135
|
+
}
|
|
136
|
+
/** Keep the top-level run span aligned with child conversation IDs. */
|
|
137
|
+
_setRootConversationId(conversationId, runId, parentRunId) {
|
|
138
|
+
const root = this._spans.get(this._rootRunId(runId, parentRunId));
|
|
139
|
+
root?.setAttribute("gen_ai.conversation.id", conversationId);
|
|
138
140
|
}
|
|
139
|
-
|
|
141
|
+
_endRootIfComplete(runId) {
|
|
142
|
+
this._runRoots.delete(runId);
|
|
143
|
+
this._spanNames.delete(runId);
|
|
144
|
+
this._spanParents.delete(runId);
|
|
145
|
+
}
|
|
146
|
+
/** Create a span under a LangChain parent when one exists.
|
|
140
147
|
* Sets gen_ai.agent.name to the parent span's name for hierarchy. */
|
|
141
148
|
_createChildSpan(name, runId, parentRunId) {
|
|
142
|
-
const parent =
|
|
143
|
-
|
|
144
|
-
const ctx =
|
|
149
|
+
const parent = parentRunId ? this._spans.get(parentRunId) : undefined;
|
|
150
|
+
this._runRoots.set(runId, this._rootRunId(runId, parentRunId));
|
|
151
|
+
const ctx = parent
|
|
152
|
+
? otelTrace.setSpan(otelContext.active(), parent)
|
|
153
|
+
: ROOT_CONTEXT;
|
|
145
154
|
const span = this._tracer.startSpan(name, {}, ctx);
|
|
146
155
|
this._spanNames.set(runId, name);
|
|
147
156
|
if (parentRunId) {
|
|
@@ -163,6 +172,7 @@ export class IntrospectionCallbackHandler extends BaseCallbackHandler {
|
|
|
163
172
|
const otelSpan = this._createChildSpan(spanName, runId, parentRunId);
|
|
164
173
|
this._spans.set(runId, otelSpan);
|
|
165
174
|
const conversationId = this._getConversationId(metadata);
|
|
175
|
+
this._setRootConversationId(conversationId, runId, parentRunId);
|
|
166
176
|
otelSpan.setAttribute("gen_ai.operation.name", "chat");
|
|
167
177
|
otelSpan.setAttribute("gen_ai.conversation.id", conversationId);
|
|
168
178
|
otelSpan.setAttribute("openinference.span.kind", "LLM");
|
|
@@ -205,6 +215,7 @@ export class IntrospectionCallbackHandler extends BaseCallbackHandler {
|
|
|
205
215
|
const otelSpan = this._createChildSpan(spanName, runId, parentRunId);
|
|
206
216
|
this._spans.set(runId, otelSpan);
|
|
207
217
|
const conversationId = this._getConversationId(metadata);
|
|
218
|
+
this._setRootConversationId(conversationId, runId, parentRunId);
|
|
208
219
|
otelSpan.setAttribute("gen_ai.operation.name", "chat");
|
|
209
220
|
otelSpan.setAttribute("gen_ai.conversation.id", conversationId);
|
|
210
221
|
otelSpan.setAttribute("openinference.span.kind", "LLM");
|
|
@@ -227,6 +238,7 @@ export class IntrospectionCallbackHandler extends BaseCallbackHandler {
|
|
|
227
238
|
this._spans.delete(runId);
|
|
228
239
|
this._spanNames.delete(runId);
|
|
229
240
|
this._llmInputs.delete(runId);
|
|
241
|
+
this._endRootIfComplete(runId);
|
|
230
242
|
const generations = output.generations?.[0];
|
|
231
243
|
if (generations && generations.length > 0) {
|
|
232
244
|
const parts = [];
|
|
@@ -290,8 +302,10 @@ export class IntrospectionCallbackHandler extends BaseCallbackHandler {
|
|
|
290
302
|
this._spans.delete(runId);
|
|
291
303
|
this._spanNames.delete(runId);
|
|
292
304
|
this._llmInputs.delete(runId);
|
|
293
|
-
|
|
294
|
-
otelSpan.
|
|
305
|
+
this._endRootIfComplete(runId);
|
|
306
|
+
otelSpan.recordException(err);
|
|
307
|
+
otelSpan.setStatus({ code: SpanStatusCode.ERROR, message: err.message });
|
|
308
|
+
otelSpan.setAttribute("exception.message", err.message);
|
|
295
309
|
otelSpan.end();
|
|
296
310
|
}
|
|
297
311
|
// -------------------------------------------------------------------------
|
|
@@ -302,6 +316,7 @@ export class IntrospectionCallbackHandler extends BaseCallbackHandler {
|
|
|
302
316
|
const otelSpan = this._createChildSpan(name, runId, parentRunId);
|
|
303
317
|
this._spans.set(runId, otelSpan);
|
|
304
318
|
const conversationId = this._getConversationId(metadata);
|
|
319
|
+
this._setRootConversationId(conversationId, runId, parentRunId);
|
|
305
320
|
otelSpan.setAttribute("gen_ai.conversation.id", conversationId);
|
|
306
321
|
}
|
|
307
322
|
handleChainEnd(_outputs, runId) {
|
|
@@ -309,6 +324,7 @@ export class IntrospectionCallbackHandler extends BaseCallbackHandler {
|
|
|
309
324
|
if (!otelSpan)
|
|
310
325
|
return;
|
|
311
326
|
this._spans.delete(runId);
|
|
327
|
+
this._endRootIfComplete(runId);
|
|
312
328
|
otelSpan.end();
|
|
313
329
|
}
|
|
314
330
|
handleChainError(err, runId) {
|
|
@@ -316,27 +332,32 @@ export class IntrospectionCallbackHandler extends BaseCallbackHandler {
|
|
|
316
332
|
if (!otelSpan)
|
|
317
333
|
return;
|
|
318
334
|
this._spans.delete(runId);
|
|
319
|
-
|
|
320
|
-
otelSpan.
|
|
335
|
+
this._endRootIfComplete(runId);
|
|
336
|
+
otelSpan.recordException(err);
|
|
337
|
+
otelSpan.setStatus({ code: SpanStatusCode.ERROR, message: err.message });
|
|
338
|
+
otelSpan.setAttribute("exception.message", err.message);
|
|
321
339
|
otelSpan.end();
|
|
322
340
|
}
|
|
323
341
|
// -------------------------------------------------------------------------
|
|
324
342
|
// Tool callbacks
|
|
325
343
|
// -------------------------------------------------------------------------
|
|
326
|
-
handleToolStart(tool, input, runId, parentRunId, _tags,
|
|
344
|
+
handleToolStart(tool, input, runId, parentRunId, _tags, metadata, runName) {
|
|
327
345
|
const toolName = runName || tool?.name || tool?.id?.[tool.id.length - 1] || "tool";
|
|
328
346
|
const otelSpan = this._createChildSpan(toolName, runId, parentRunId);
|
|
329
347
|
this._spans.set(runId, otelSpan);
|
|
348
|
+
const conversationId = this._getConversationId(metadata);
|
|
349
|
+
this._setRootConversationId(conversationId, runId, parentRunId);
|
|
330
350
|
otelSpan.setAttribute("gen_ai.tool.name", toolName);
|
|
331
351
|
otelSpan.setAttribute("openinference.span.kind", "TOOL");
|
|
332
352
|
otelSpan.setAttribute("gen_ai.tool.input", input);
|
|
333
|
-
otelSpan.setAttribute("gen_ai.conversation.id",
|
|
353
|
+
otelSpan.setAttribute("gen_ai.conversation.id", conversationId);
|
|
334
354
|
}
|
|
335
355
|
handleToolEnd(output, runId) {
|
|
336
356
|
const otelSpan = this._spans.get(runId);
|
|
337
357
|
if (!otelSpan)
|
|
338
358
|
return;
|
|
339
359
|
this._spans.delete(runId);
|
|
360
|
+
this._endRootIfComplete(runId);
|
|
340
361
|
if (output != null) {
|
|
341
362
|
otelSpan.setAttribute("gen_ai.tool.output", typeof output === "string" ? output : JSON.stringify(output));
|
|
342
363
|
}
|
|
@@ -347,8 +368,10 @@ export class IntrospectionCallbackHandler extends BaseCallbackHandler {
|
|
|
347
368
|
if (!otelSpan)
|
|
348
369
|
return;
|
|
349
370
|
this._spans.delete(runId);
|
|
350
|
-
|
|
351
|
-
otelSpan.
|
|
371
|
+
this._endRootIfComplete(runId);
|
|
372
|
+
otelSpan.recordException(err);
|
|
373
|
+
otelSpan.setStatus({ code: SpanStatusCode.ERROR, message: err.message });
|
|
374
|
+
otelSpan.setAttribute("exception.message", err.message);
|
|
352
375
|
otelSpan.end();
|
|
353
376
|
}
|
|
354
377
|
// -------------------------------------------------------------------------
|
|
@@ -358,10 +381,9 @@ export class IntrospectionCallbackHandler extends BaseCallbackHandler {
|
|
|
358
381
|
for (const span of this._spans.values())
|
|
359
382
|
span.end();
|
|
360
383
|
this._spans.clear();
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
}
|
|
384
|
+
this._spanNames.clear();
|
|
385
|
+
this._spanParents.clear();
|
|
386
|
+
this._runRoots.clear();
|
|
365
387
|
await this._tracerProvider.shutdown();
|
|
366
388
|
}
|
|
367
389
|
async forceFlush() {
|
|
@@ -408,7 +430,14 @@ export class IntrospectionCallbackHandler extends BaseCallbackHandler {
|
|
|
408
430
|
}
|
|
409
431
|
_getConversationId(metadata) {
|
|
410
432
|
const metaConvId = metadata?.["gen_ai.conversation.id"];
|
|
411
|
-
|
|
433
|
+
if (metaConvId !== undefined && metaConvId !== null) {
|
|
434
|
+
return String(metaConvId);
|
|
435
|
+
}
|
|
436
|
+
const threadId = metadata?.["thread_id"];
|
|
437
|
+
if (threadId !== undefined && threadId !== null) {
|
|
438
|
+
return String(threadId);
|
|
439
|
+
}
|
|
440
|
+
return this._conversationId;
|
|
412
441
|
}
|
|
413
442
|
_convertMessages(messages) {
|
|
414
443
|
const inputMessages = [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"span-processor.d.ts","sourceRoot":"","sources":["../src/span-processor.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EAIR,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,aAAa,EACb,YAAY,EACZ,IAAI,EAGL,MAAM,+BAA+B,CAAC;AAMvC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"span-processor.d.ts","sourceRoot":"","sources":["../src/span-processor.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EAIR,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,aAAa,EACb,YAAY,EACZ,IAAI,EAGL,MAAM,+BAA+B,CAAC;AAMvC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AA8FlD,MAAM,WAAW,iCAAiC;IAChD,sDAAsD;IACtD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,qDAAqD;IACrD,QAAQ,CAAC,EAAE,eAAe,CAAC;CAC5B;AAED;;;;;;;;;;;;GAYG;AACH,qBAAa,0BAA2B,YAAW,aAAa;IAC9D,OAAO,CAAC,cAAc,CAAgB;IACtC,OAAO,CAAC,YAAY,CAAC,CAAS;IAC9B,OAAO,CAAC,gBAAgB,CAAkC;gBAE9C,OAAO,GAAE,iCAAsC;IAwH3D;;;;;OAKG;IACH,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,aAAa,EAAE,OAAO,GAAG,IAAI;IAIjD;;;;;;OAMG;IACH,KAAK,CAAC,IAAI,EAAE,YAAY,GAAG,IAAI;IA2H/B;;;;OAIG;IACG,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAI/B;;;;OAIG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;CAGlC"}
|
package/dist/span-processor.js
CHANGED