langwatch 0.3.2 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{add-LBBS4I3H.js → add-35QACTIV.js} +34 -28
- package/dist/add-35QACTIV.js.map +1 -0
- package/dist/{add-RD3ZKFAT.mjs → add-TRJAXM4D.mjs} +22 -16
- package/dist/add-TRJAXM4D.mjs.map +1 -0
- package/dist/chunk-4ZSSHX6F.js +636 -0
- package/dist/chunk-4ZSSHX6F.js.map +1 -0
- package/dist/chunk-5EVBOHJY.js +155 -0
- package/dist/chunk-5EVBOHJY.js.map +1 -0
- package/dist/{chunk-YN4436PK.mjs → chunk-CU3443HD.mjs} +14 -9
- package/dist/{chunk-2JU376G7.js → chunk-D2CSG4SJ.js} +4 -4
- package/dist/chunk-D2CSG4SJ.js.map +1 -0
- package/dist/chunk-DISMHYXC.js +184 -0
- package/dist/chunk-DISMHYXC.js.map +1 -0
- package/dist/{chunk-E7UE2MPD.mjs → chunk-ECUXLXFT.mjs} +2 -2
- package/dist/chunk-EJWJXTPU.mjs +626 -0
- package/dist/chunk-EJWJXTPU.mjs.map +1 -0
- package/dist/chunk-GQMDZ4GY.mjs +155 -0
- package/dist/chunk-GQMDZ4GY.mjs.map +1 -0
- package/dist/{chunk-3GKPQB4R.mjs → chunk-HUI45ULC.mjs} +4 -4
- package/dist/chunk-HUI45ULC.mjs.map +1 -0
- package/dist/{chunk-HJU67C7H.js → chunk-K64Y6YUG.js} +10 -10
- package/dist/{chunk-HJU67C7H.js.map → chunk-K64Y6YUG.js.map} +1 -1
- package/dist/chunk-LP76VXI3.mjs +636 -0
- package/dist/chunk-LP76VXI3.mjs.map +1 -0
- package/dist/chunk-M4VUHTT2.js +626 -0
- package/dist/chunk-M4VUHTT2.js.map +1 -0
- package/dist/{chunk-PR3JDWC3.mjs → chunk-N2V6J3U2.mjs} +28 -3
- package/dist/chunk-N2V6J3U2.mjs.map +1 -0
- package/dist/chunk-OUCVXP4G.js +258 -0
- package/dist/chunk-OUCVXP4G.js.map +1 -0
- package/dist/{chunk-FJLK5CFL.js → chunk-OXBO24RB.js} +13 -8
- package/dist/chunk-OXBO24RB.js.map +1 -0
- package/dist/chunk-PGWR3OQY.mjs +258 -0
- package/dist/chunk-PGWR3OQY.mjs.map +1 -0
- package/dist/{chunk-SMXXAVMB.js → chunk-SGNJDRCT.js} +2 -2
- package/dist/chunk-SGNJDRCT.js.map +1 -0
- package/dist/{chunk-W5ZEP3CI.mjs → chunk-SYMZPWZE.mjs} +2 -2
- package/dist/chunk-SYMZPWZE.mjs.map +1 -0
- package/dist/{chunk-KGDAENGD.js → chunk-YH5TIVK2.js} +28 -3
- package/dist/chunk-YH5TIVK2.js.map +1 -0
- package/dist/chunk-YNQ44U6D.mjs +184 -0
- package/dist/chunk-YNQ44U6D.mjs.map +1 -0
- package/dist/cli/index.js +8 -8
- package/dist/cli/index.mjs +8 -8
- package/dist/{create-G5MTGOOH.js → create-7K2CC4KQ.js} +11 -11
- package/dist/{create-G5MTGOOH.js.map → create-7K2CC4KQ.js.map} +1 -1
- package/dist/{create-QUZYBMQB.mjs → create-MK7NEGCM.mjs} +8 -8
- package/dist/implementation-C4lvooSg.d.mts +576 -0
- package/dist/implementation-CzemP9jY.d.ts +576 -0
- package/dist/index-DTEZr0Jn.d.mts +34 -0
- package/dist/index-DTEZr0Jn.d.ts +34 -0
- package/dist/index.d.mts +121 -47
- package/dist/index.d.ts +121 -47
- package/dist/index.js +16 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +27 -23
- package/dist/index.mjs.map +1 -1
- package/dist/init-GDKJICSS.js +16 -0
- package/dist/{init-XU2JFY6N.js.map → init-GDKJICSS.js.map} +1 -1
- package/dist/{init-H67RW22E.mjs → init-RINSTP4L.mjs} +5 -5
- package/dist/{list-7NPSX2E4.mjs → list-7L23G5DY.mjs} +28 -16
- package/dist/list-7L23G5DY.mjs.map +1 -0
- package/dist/{list-ZXFLAF52.js → list-OLLQ7XKZ.js} +29 -17
- package/dist/list-OLLQ7XKZ.js.map +1 -0
- package/dist/{login-EK4WVOI2.mjs → login-RCNKL5AM.mjs} +6 -5
- package/dist/login-RCNKL5AM.mjs.map +1 -0
- package/dist/{login-76NQIHKR.js → login-XF3BQQPV.js} +7 -6
- package/dist/login-XF3BQQPV.js.map +1 -0
- package/dist/observability-sdk/index.d.mts +134 -0
- package/dist/observability-sdk/index.d.ts +134 -0
- package/dist/observability-sdk/index.js +41 -0
- package/dist/observability-sdk/index.js.map +1 -0
- package/dist/observability-sdk/index.mjs +41 -0
- package/dist/observability-sdk/instrumentation/langchain/index.d.mts +69 -0
- package/dist/observability-sdk/instrumentation/langchain/index.d.ts +69 -0
- package/dist/observability-sdk/instrumentation/langchain/index.js +518 -0
- package/dist/observability-sdk/instrumentation/langchain/index.js.map +1 -0
- package/dist/observability-sdk/instrumentation/langchain/index.mjs +518 -0
- package/dist/observability-sdk/instrumentation/langchain/index.mjs.map +1 -0
- package/dist/observability-sdk/setup/node/index.d.mts +368 -0
- package/dist/observability-sdk/setup/node/index.d.ts +368 -0
- package/dist/observability-sdk/setup/node/index.js +276 -0
- package/dist/observability-sdk/setup/node/index.js.map +1 -0
- package/dist/observability-sdk/setup/node/index.mjs +276 -0
- package/dist/observability-sdk/setup/node/index.mjs.map +1 -0
- package/dist/{remove-SDJYEPAY.mjs → remove-3VLQNVHN.mjs} +11 -8
- package/dist/remove-3VLQNVHN.mjs.map +1 -0
- package/dist/{remove-XBNGIVMR.js → remove-L6JVJBWY.js} +18 -15
- package/dist/remove-L6JVJBWY.js.map +1 -0
- package/dist/{sync-ST2IWXSB.mjs → sync-DPMTUTVL.mjs} +39 -33
- package/dist/sync-DPMTUTVL.mjs.map +1 -0
- package/dist/{sync-EISKGPTL.js → sync-PSU3F5Z4.js} +52 -46
- package/dist/sync-PSU3F5Z4.js.map +1 -0
- package/dist/{prompt-D-jpMrLS.d.mts → types-1q5wIYP5.d.mts} +628 -14
- package/dist/{prompt-D-jpMrLS.d.ts → types-C9k5gGhU.d.ts} +628 -14
- package/dist/types-DRiQaKFG.d.mts +254 -0
- package/dist/types-DRiQaKFG.d.ts +254 -0
- package/dist/types-Dmazk5Bk.d.mts +44 -0
- package/dist/types-Dmazk5Bk.d.ts +44 -0
- package/package.json +39 -39
- package/dist/add-LBBS4I3H.js.map +0 -1
- package/dist/add-RD3ZKFAT.mjs.map +0 -1
- package/dist/chunk-2JU376G7.js.map +0 -1
- package/dist/chunk-2ODBGSBI.js +0 -4
- package/dist/chunk-2ODBGSBI.js.map +0 -1
- package/dist/chunk-3GKPQB4R.mjs.map +0 -1
- package/dist/chunk-52GXX3MA.js +0 -426
- package/dist/chunk-52GXX3MA.js.map +0 -1
- package/dist/chunk-5NC5ILKA.js +0 -94
- package/dist/chunk-5NC5ILKA.js.map +0 -1
- package/dist/chunk-AAROJADR.mjs +0 -49
- package/dist/chunk-AAROJADR.mjs.map +0 -1
- package/dist/chunk-DTEKFQ4U.js +0 -159
- package/dist/chunk-DTEKFQ4U.js.map +0 -1
- package/dist/chunk-F63YKTXA.mjs +0 -47
- package/dist/chunk-F63YKTXA.mjs.map +0 -1
- package/dist/chunk-FJLK5CFL.js.map +0 -1
- package/dist/chunk-GJSEBQXF.mjs +0 -392
- package/dist/chunk-GJSEBQXF.mjs.map +0 -1
- package/dist/chunk-IGHXIIIK.js +0 -49
- package/dist/chunk-IGHXIIIK.js.map +0 -1
- package/dist/chunk-J7ICRUU4.mjs +0 -426
- package/dist/chunk-J7ICRUU4.mjs.map +0 -1
- package/dist/chunk-KGDAENGD.js.map +0 -1
- package/dist/chunk-LD74LVRU.js +0 -47
- package/dist/chunk-LD74LVRU.js.map +0 -1
- package/dist/chunk-PCQVQ7SB.js +0 -45
- package/dist/chunk-PCQVQ7SB.js.map +0 -1
- package/dist/chunk-PR3JDWC3.mjs.map +0 -1
- package/dist/chunk-PWZBLTHR.js +0 -118
- package/dist/chunk-PWZBLTHR.js.map +0 -1
- package/dist/chunk-QEWDG5QE.mjs +0 -45
- package/dist/chunk-QEWDG5QE.mjs.map +0 -1
- package/dist/chunk-SMXXAVMB.js.map +0 -1
- package/dist/chunk-STV4ZVNA.mjs +0 -118
- package/dist/chunk-STV4ZVNA.mjs.map +0 -1
- package/dist/chunk-T5AZMMVS.mjs +0 -94
- package/dist/chunk-T5AZMMVS.mjs.map +0 -1
- package/dist/chunk-UU33HCCZ.mjs +0 -159
- package/dist/chunk-UU33HCCZ.mjs.map +0 -1
- package/dist/chunk-VGHLQXKB.js +0 -392
- package/dist/chunk-VGHLQXKB.js.map +0 -1
- package/dist/chunk-W5ZEP3CI.mjs.map +0 -1
- package/dist/chunk-Y666BJA5.mjs +0 -4
- package/dist/chunk-YN4436PK.mjs.map +0 -1
- package/dist/client-B2HqIKg6.d.ts +0 -51
- package/dist/client-XyCqclCi.d.mts +0 -51
- package/dist/client-browser.d.mts +0 -8
- package/dist/client-browser.d.ts +0 -8
- package/dist/client-browser.js +0 -88
- package/dist/client-browser.js.map +0 -1
- package/dist/client-browser.mjs +0 -88
- package/dist/client-browser.mjs.map +0 -1
- package/dist/client-node.d.mts +0 -8
- package/dist/client-node.d.ts +0 -8
- package/dist/client-node.js +0 -95
- package/dist/client-node.js.map +0 -1
- package/dist/client-node.mjs +0 -95
- package/dist/client-node.mjs.map +0 -1
- package/dist/evaluation/index.d.mts +0 -897
- package/dist/evaluation/index.d.ts +0 -897
- package/dist/evaluation/index.js +0 -14
- package/dist/evaluation/index.js.map +0 -1
- package/dist/evaluation/index.mjs +0 -14
- package/dist/filterable-batch-span-processor-zO5kcjBY.d.mts +0 -64
- package/dist/filterable-batch-span-processor-zO5kcjBY.d.ts +0 -64
- package/dist/init-XU2JFY6N.js +0 -16
- package/dist/list-7NPSX2E4.mjs.map +0 -1
- package/dist/list-ZXFLAF52.js.map +0 -1
- package/dist/login-76NQIHKR.js.map +0 -1
- package/dist/login-EK4WVOI2.mjs.map +0 -1
- package/dist/observability/index.d.mts +0 -260
- package/dist/observability/index.d.ts +0 -260
- package/dist/observability/index.js +0 -21
- package/dist/observability/index.js.map +0 -1
- package/dist/observability/index.mjs +0 -21
- package/dist/observability/index.mjs.map +0 -1
- package/dist/observability/instrumentation/langchain/index.d.mts +0 -40
- package/dist/observability/instrumentation/langchain/index.d.ts +0 -40
- package/dist/observability/instrumentation/langchain/index.js +0 -668
- package/dist/observability/instrumentation/langchain/index.js.map +0 -1
- package/dist/observability/instrumentation/langchain/index.mjs +0 -668
- package/dist/observability/instrumentation/langchain/index.mjs.map +0 -1
- package/dist/prompt/index.d.mts +0 -10
- package/dist/prompt/index.d.ts +0 -10
- package/dist/prompt/index.js +0 -22
- package/dist/prompt/index.js.map +0 -1
- package/dist/prompt/index.mjs +0 -22
- package/dist/prompt/index.mjs.map +0 -1
- package/dist/record-evaluation-CmxMXa-3.d.mts +0 -25
- package/dist/record-evaluation-CmxMXa-3.d.ts +0 -25
- package/dist/remove-SDJYEPAY.mjs.map +0 -1
- package/dist/remove-XBNGIVMR.js.map +0 -1
- package/dist/sync-EISKGPTL.js.map +0 -1
- package/dist/sync-ST2IWXSB.mjs.map +0 -1
- package/dist/trace-CqaKo0kZ.d.ts +0 -622
- package/dist/trace-DtVc5GhF.d.mts +0 -622
- /package/dist/{chunk-Y666BJA5.mjs.map → chunk-CU3443HD.mjs.map} +0 -0
- /package/dist/{chunk-E7UE2MPD.mjs.map → chunk-ECUXLXFT.mjs.map} +0 -0
- /package/dist/{create-QUZYBMQB.mjs.map → create-MK7NEGCM.mjs.map} +0 -0
- /package/dist/{init-H67RW22E.mjs.map → init-RINSTP4L.mjs.map} +0 -0
- /package/dist/{evaluation → observability-sdk}/index.mjs.map +0 -0
|
@@ -1,668 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
canAutomaticallyCaptureInput,
|
|
3
|
-
canAutomaticallyCaptureOutput
|
|
4
|
-
} from "../../../chunk-QEWDG5QE.mjs";
|
|
5
|
-
import {
|
|
6
|
-
getLangWatchTracer
|
|
7
|
-
} from "../../../chunk-J7ICRUU4.mjs";
|
|
8
|
-
import {
|
|
9
|
-
ATTR_LANGWATCH_LANGCHAIN_EVENT_NAME,
|
|
10
|
-
ATTR_LANGWATCH_LANGCHAIN_RUN_EXTRA_PARAMS,
|
|
11
|
-
ATTR_LANGWATCH_LANGCHAIN_RUN_ID,
|
|
12
|
-
ATTR_LANGWATCH_LANGCHAIN_RUN_METADATA,
|
|
13
|
-
ATTR_LANGWATCH_LANGCHAIN_RUN_PARENT_ID,
|
|
14
|
-
ATTR_LANGWATCH_LANGCHAIN_RUN_TAGS,
|
|
15
|
-
ATTR_LANGWATCH_LANGCHAIN_RUN_TYPE,
|
|
16
|
-
ATTR_LANGWATCH_LANGCHAIN_TAGS,
|
|
17
|
-
EVNT_LANGWATCH_LANGCHAIN_CALLBACK
|
|
18
|
-
} from "../../../chunk-UU33HCCZ.mjs";
|
|
19
|
-
import {
|
|
20
|
-
__spreadValues
|
|
21
|
-
} from "../../../chunk-YN4436PK.mjs";
|
|
22
|
-
|
|
23
|
-
// src/observability/instrumentation/langchain/index.ts
|
|
24
|
-
import { BaseCallbackHandler } from "@langchain/core/callbacks/base";
|
|
25
|
-
import {
|
|
26
|
-
AIMessage,
|
|
27
|
-
AIMessageChunk,
|
|
28
|
-
FunctionMessage,
|
|
29
|
-
FunctionMessageChunk,
|
|
30
|
-
HumanMessage,
|
|
31
|
-
HumanMessageChunk,
|
|
32
|
-
SystemMessage,
|
|
33
|
-
SystemMessageChunk,
|
|
34
|
-
ToolMessage,
|
|
35
|
-
ToolMessageChunk,
|
|
36
|
-
mapChatMessagesToStoredMessages
|
|
37
|
-
} from "@langchain/core/messages";
|
|
38
|
-
import { context, trace, SpanStatusCode } from "@opentelemetry/api";
|
|
39
|
-
|
|
40
|
-
// src/internal/generated/types/tracer.generated.ts
|
|
41
|
-
import { z } from "zod";
|
|
42
|
-
var chatRoleSchema = z.union([
|
|
43
|
-
z.literal("system"),
|
|
44
|
-
z.literal("user"),
|
|
45
|
-
z.literal("assistant"),
|
|
46
|
-
z.literal("function"),
|
|
47
|
-
z.literal("tool"),
|
|
48
|
-
z.literal("unknown")
|
|
49
|
-
]);
|
|
50
|
-
var functionCallSchema = z.object({
|
|
51
|
-
name: z.string().optional(),
|
|
52
|
-
arguments: z.string().optional()
|
|
53
|
-
});
|
|
54
|
-
var toolCallSchema = z.object({
|
|
55
|
-
id: z.string(),
|
|
56
|
-
type: z.string(),
|
|
57
|
-
function: functionCallSchema
|
|
58
|
-
});
|
|
59
|
-
var rAGChunkSchema = z.object({
|
|
60
|
-
document_id: z.string().optional().nullable(),
|
|
61
|
-
chunk_id: z.string().optional().nullable(),
|
|
62
|
-
content: z.union([z.string(), z.record(z.string(), z.any()), z.array(z.any())])
|
|
63
|
-
});
|
|
64
|
-
var chatRichContentSchema = z.union([
|
|
65
|
-
z.object({
|
|
66
|
-
type: z.literal("text"),
|
|
67
|
-
text: z.string().optional()
|
|
68
|
-
}),
|
|
69
|
-
z.object({
|
|
70
|
-
text: z.string()
|
|
71
|
-
}),
|
|
72
|
-
z.object({
|
|
73
|
-
type: z.literal("image_url"),
|
|
74
|
-
image_url: z.object({
|
|
75
|
-
url: z.string(),
|
|
76
|
-
detail: z.union([z.literal("auto"), z.literal("low"), z.literal("high")]).optional()
|
|
77
|
-
}).optional()
|
|
78
|
-
}),
|
|
79
|
-
z.object({
|
|
80
|
-
type: z.literal("tool_call"),
|
|
81
|
-
toolName: z.string().optional(),
|
|
82
|
-
toolCallId: z.string().optional(),
|
|
83
|
-
args: z.string().optional()
|
|
84
|
-
}),
|
|
85
|
-
z.object({
|
|
86
|
-
type: z.literal("tool_result"),
|
|
87
|
-
toolName: z.string().optional(),
|
|
88
|
-
toolCallId: z.string().optional(),
|
|
89
|
-
result: z.any().optional()
|
|
90
|
-
})
|
|
91
|
-
]);
|
|
92
|
-
var chatMessageSchema = z.object({
|
|
93
|
-
role: chatRoleSchema.optional(),
|
|
94
|
-
content: z.union([z.string(), z.array(chatRichContentSchema)]).optional().nullable(),
|
|
95
|
-
function_call: functionCallSchema.optional().nullable(),
|
|
96
|
-
tool_calls: z.array(toolCallSchema).optional().nullable(),
|
|
97
|
-
tool_call_id: z.string().optional().nullable(),
|
|
98
|
-
name: z.string().optional().nullable()
|
|
99
|
-
});
|
|
100
|
-
var typedValueTextSchema = z.object({
|
|
101
|
-
type: z.literal("text"),
|
|
102
|
-
value: z.string()
|
|
103
|
-
});
|
|
104
|
-
var typedValueRawSchema = z.object({
|
|
105
|
-
type: z.literal("raw"),
|
|
106
|
-
value: z.string()
|
|
107
|
-
});
|
|
108
|
-
var jSONSerializableSchema = z.union([
|
|
109
|
-
z.string(),
|
|
110
|
-
z.number(),
|
|
111
|
-
z.boolean(),
|
|
112
|
-
z.record(z.string(), z.any()),
|
|
113
|
-
z.array(z.any())
|
|
114
|
-
]).nullable();
|
|
115
|
-
var typedValueJsonSchema = z.object({
|
|
116
|
-
type: z.literal("json"),
|
|
117
|
-
value: jSONSerializableSchema
|
|
118
|
-
});
|
|
119
|
-
var moneySchema = z.object({
|
|
120
|
-
currency: z.string(),
|
|
121
|
-
amount: z.number()
|
|
122
|
-
});
|
|
123
|
-
var evaluationResultSchema = z.object({
|
|
124
|
-
status: z.union([
|
|
125
|
-
z.literal("processed"),
|
|
126
|
-
z.literal("skipped"),
|
|
127
|
-
z.literal("error")
|
|
128
|
-
]),
|
|
129
|
-
passed: z.boolean().optional().nullable(),
|
|
130
|
-
score: z.number().optional().nullable(),
|
|
131
|
-
label: z.string().optional().nullable(),
|
|
132
|
-
details: z.string().optional().nullable(),
|
|
133
|
-
cost: moneySchema.optional().nullable()
|
|
134
|
-
});
|
|
135
|
-
var typedValueGuardrailResultSchema = z.object({
|
|
136
|
-
type: z.literal("guardrail_result"),
|
|
137
|
-
value: evaluationResultSchema
|
|
138
|
-
});
|
|
139
|
-
var typedValueEvaluationResultSchema = z.object({
|
|
140
|
-
type: z.literal("evaluation_result"),
|
|
141
|
-
value: evaluationResultSchema
|
|
142
|
-
});
|
|
143
|
-
var typedValueChatMessagesSchema = z.object({
|
|
144
|
-
type: z.literal("chat_messages"),
|
|
145
|
-
value: z.array(chatMessageSchema)
|
|
146
|
-
});
|
|
147
|
-
var spanInputOutputSchema = z.lazy(
|
|
148
|
-
() => z.union([
|
|
149
|
-
typedValueTextSchema,
|
|
150
|
-
typedValueChatMessagesSchema,
|
|
151
|
-
typedValueGuardrailResultSchema,
|
|
152
|
-
typedValueEvaluationResultSchema,
|
|
153
|
-
typedValueJsonSchema,
|
|
154
|
-
typedValueRawSchema,
|
|
155
|
-
z.object({
|
|
156
|
-
type: z.literal("list"),
|
|
157
|
-
value: z.array(spanInputOutputSchema)
|
|
158
|
-
})
|
|
159
|
-
])
|
|
160
|
-
);
|
|
161
|
-
var errorCaptureSchema = z.object({
|
|
162
|
-
has_error: z.literal(true),
|
|
163
|
-
message: z.string(),
|
|
164
|
-
stacktrace: z.array(z.string())
|
|
165
|
-
});
|
|
166
|
-
var spanMetricsSchema = z.object({
|
|
167
|
-
prompt_tokens: z.number().optional().nullable(),
|
|
168
|
-
completion_tokens: z.number().optional().nullable(),
|
|
169
|
-
tokens_estimated: z.boolean().optional().nullable(),
|
|
170
|
-
cost: z.number().optional().nullable()
|
|
171
|
-
});
|
|
172
|
-
var spanTimestampsSchema = z.object({
|
|
173
|
-
ignore_timestamps_on_write: z.boolean().optional().nullable(),
|
|
174
|
-
started_at: z.number(),
|
|
175
|
-
first_token_at: z.number().optional().nullable(),
|
|
176
|
-
finished_at: z.number()
|
|
177
|
-
});
|
|
178
|
-
var spanTypesSchema = z.union([
|
|
179
|
-
z.literal("span"),
|
|
180
|
-
z.literal("llm"),
|
|
181
|
-
z.literal("chain"),
|
|
182
|
-
z.literal("tool"),
|
|
183
|
-
z.literal("agent"),
|
|
184
|
-
z.literal("rag"),
|
|
185
|
-
z.literal("guardrail"),
|
|
186
|
-
z.literal("evaluation"),
|
|
187
|
-
z.literal("workflow"),
|
|
188
|
-
z.literal("component"),
|
|
189
|
-
z.literal("module"),
|
|
190
|
-
z.literal("server"),
|
|
191
|
-
z.literal("client"),
|
|
192
|
-
z.literal("producer"),
|
|
193
|
-
z.literal("consumer"),
|
|
194
|
-
z.literal("task"),
|
|
195
|
-
z.literal("unknown")
|
|
196
|
-
]);
|
|
197
|
-
var spanInputOutputValidatorSchema = spanInputOutputSchema.and(
|
|
198
|
-
z.object({
|
|
199
|
-
value: z.any()
|
|
200
|
-
})
|
|
201
|
-
);
|
|
202
|
-
var traceInputSchema = z.object({
|
|
203
|
-
value: z.string(),
|
|
204
|
-
satisfaction_score: z.number().optional()
|
|
205
|
-
});
|
|
206
|
-
var traceOutputSchema = z.object({
|
|
207
|
-
value: z.string()
|
|
208
|
-
});
|
|
209
|
-
var primitiveTypeSchema = z.union([z.string(), z.number(), z.boolean(), z.undefined()]).nullable();
|
|
210
|
-
var reservedTraceMetadataSchema = z.object({
|
|
211
|
-
thread_id: z.string().optional().nullable(),
|
|
212
|
-
user_id: z.string().optional().nullable(),
|
|
213
|
-
customer_id: z.string().optional().nullable(),
|
|
214
|
-
labels: z.array(z.string()).optional().nullable(),
|
|
215
|
-
topic_id: z.string().optional().nullable(),
|
|
216
|
-
subtopic_id: z.string().optional().nullable(),
|
|
217
|
-
sdk_name: z.string().optional().nullable(),
|
|
218
|
-
sdk_version: z.string().optional().nullable(),
|
|
219
|
-
sdk_language: z.string().optional().nullable(),
|
|
220
|
-
telemetry_sdk_language: z.string().optional().nullable(),
|
|
221
|
-
telemetry_sdk_name: z.string().optional().nullable(),
|
|
222
|
-
telemetry_sdk_version: z.string().optional().nullable(),
|
|
223
|
-
prompt_ids: z.array(z.string()).optional().nullable(),
|
|
224
|
-
prompt_version_ids: z.array(z.string()).optional().nullable()
|
|
225
|
-
});
|
|
226
|
-
var evaluationStatusSchema = z.union([
|
|
227
|
-
z.literal("scheduled"),
|
|
228
|
-
z.literal("in_progress"),
|
|
229
|
-
z.literal("error"),
|
|
230
|
-
z.literal("skipped"),
|
|
231
|
-
z.literal("processed")
|
|
232
|
-
]);
|
|
233
|
-
var evaluationSchema = z.object({
|
|
234
|
-
evaluation_id: z.string(),
|
|
235
|
-
evaluator_id: z.string(),
|
|
236
|
-
span_id: z.string().optional().nullable(),
|
|
237
|
-
name: z.string(),
|
|
238
|
-
type: z.string().optional().nullable(),
|
|
239
|
-
is_guardrail: z.boolean().optional().nullable(),
|
|
240
|
-
status: evaluationStatusSchema,
|
|
241
|
-
passed: z.boolean().optional().nullable(),
|
|
242
|
-
score: z.number().optional().nullable(),
|
|
243
|
-
label: z.string().optional().nullable(),
|
|
244
|
-
details: z.string().optional().nullable(),
|
|
245
|
-
error: errorCaptureSchema.optional().nullable(),
|
|
246
|
-
retries: z.number().optional().nullable(),
|
|
247
|
-
timestamps: z.object({
|
|
248
|
-
ignore_timestamps_on_write: z.boolean().optional().nullable(),
|
|
249
|
-
inserted_at: z.number().optional().nullable(),
|
|
250
|
-
started_at: z.number().optional().nullable(),
|
|
251
|
-
finished_at: z.number().optional().nullable(),
|
|
252
|
-
updated_at: z.number().optional().nullable()
|
|
253
|
-
})
|
|
254
|
-
});
|
|
255
|
-
var rESTEvaluationSchema = evaluationSchema.omit({
|
|
256
|
-
evaluation_id: true,
|
|
257
|
-
evaluator_id: true,
|
|
258
|
-
status: true,
|
|
259
|
-
timestamps: true,
|
|
260
|
-
retries: true
|
|
261
|
-
}).and(
|
|
262
|
-
z.object({
|
|
263
|
-
evaluation_id: z.string().optional().nullable(),
|
|
264
|
-
evaluator_id: z.string().optional().nullable(),
|
|
265
|
-
status: z.union([
|
|
266
|
-
z.literal("processed"),
|
|
267
|
-
z.literal("skipped"),
|
|
268
|
-
z.literal("error")
|
|
269
|
-
]).optional().nullable(),
|
|
270
|
-
timestamps: z.object({
|
|
271
|
-
started_at: z.number().optional().nullable(),
|
|
272
|
-
finished_at: z.number().optional().nullable()
|
|
273
|
-
}).optional().nullable()
|
|
274
|
-
})
|
|
275
|
-
);
|
|
276
|
-
var contextsSchema = z.object({
|
|
277
|
-
traceId: z.string(),
|
|
278
|
-
contexts: z.array(rAGChunkSchema)
|
|
279
|
-
});
|
|
280
|
-
|
|
281
|
-
// src/observability/instrumentation/langchain/index.ts
|
|
282
|
-
import { z as z2 } from "zod";
|
|
283
|
-
var LangWatchCallbackHandler = class extends BaseCallbackHandler {
|
|
284
|
-
constructor() {
|
|
285
|
-
super();
|
|
286
|
-
this.name = "LangWatchCallbackHandler";
|
|
287
|
-
this.tracer = getLangWatchTracer("langwatch.instrumentation.langchain");
|
|
288
|
-
this.spans = {};
|
|
289
|
-
}
|
|
290
|
-
getParentContext(parentRunId) {
|
|
291
|
-
if (parentRunId && this.spans[parentRunId]) {
|
|
292
|
-
return trace.setSpan(context.active(), this.spans[parentRunId]);
|
|
293
|
-
}
|
|
294
|
-
return context.active();
|
|
295
|
-
}
|
|
296
|
-
getSpan(runId) {
|
|
297
|
-
return this.spans[runId];
|
|
298
|
-
}
|
|
299
|
-
async handleLLMStart(llm, prompts, runId, parentRunId, extraParams, _tags, metadata, name) {
|
|
300
|
-
var _a, _b, _c;
|
|
301
|
-
const parentContext = this.getParentContext(parentRunId);
|
|
302
|
-
const span = this.tracer.startSpan(
|
|
303
|
-
(_c = name != null ? name : (_b = (_a = llm.id) == null ? void 0 : _a[llm.id.length - 1]) == null ? void 0 : _b.toString()) != null ? _c : "llm",
|
|
304
|
-
{},
|
|
305
|
-
parentContext
|
|
306
|
-
);
|
|
307
|
-
span.setType("llm");
|
|
308
|
-
if (canAutomaticallyCaptureInput()) {
|
|
309
|
-
span.setInput(prompts);
|
|
310
|
-
}
|
|
311
|
-
if (_tags) {
|
|
312
|
-
span.setAttribute(ATTR_LANGWATCH_LANGCHAIN_RUN_TAGS, _tags);
|
|
313
|
-
}
|
|
314
|
-
if (extraParams) {
|
|
315
|
-
span.setAttributes(
|
|
316
|
-
Object.fromEntries(
|
|
317
|
-
Object.entries(extraParams).map(([key, value]) => [
|
|
318
|
-
[`${ATTR_LANGWATCH_LANGCHAIN_RUN_EXTRA_PARAMS}.${key}`],
|
|
319
|
-
wrapNonScalarValues(value)
|
|
320
|
-
])
|
|
321
|
-
)
|
|
322
|
-
);
|
|
323
|
-
}
|
|
324
|
-
if (metadata) {
|
|
325
|
-
if (metadata.ls_model_name) {
|
|
326
|
-
span.setRequestModel(metadata.ls_model_name);
|
|
327
|
-
metadata.ls_model_name = void 0;
|
|
328
|
-
}
|
|
329
|
-
span.setAttributes(
|
|
330
|
-
Object.fromEntries(
|
|
331
|
-
Object.entries(metadata).map(([key, value]) => [
|
|
332
|
-
[`${ATTR_LANGWATCH_LANGCHAIN_RUN_METADATA}.${key}`],
|
|
333
|
-
wrapNonScalarValues(value)
|
|
334
|
-
])
|
|
335
|
-
)
|
|
336
|
-
);
|
|
337
|
-
}
|
|
338
|
-
this.spans[runId] = span;
|
|
339
|
-
}
|
|
340
|
-
async handleChatModelStart(llm, messages, runId, parentRunId, extraParams, _tags, metadata, name) {
|
|
341
|
-
var _a, _b, _c;
|
|
342
|
-
const parentContext = this.getParentContext(parentRunId);
|
|
343
|
-
const span = this.tracer.startSpan(
|
|
344
|
-
(_c = name != null ? name : (_b = (_a = llm.id) == null ? void 0 : _a[llm.id.length - 1]) == null ? void 0 : _b.toString()) != null ? _c : "chat_model",
|
|
345
|
-
{},
|
|
346
|
-
parentContext
|
|
347
|
-
);
|
|
348
|
-
span.setType("llm");
|
|
349
|
-
if (canAutomaticallyCaptureInput()) {
|
|
350
|
-
span.setInput(messages.flatMap(convertFromLangChainMessages));
|
|
351
|
-
}
|
|
352
|
-
if (_tags) {
|
|
353
|
-
span.setAttribute(ATTR_LANGWATCH_LANGCHAIN_RUN_TAGS, _tags);
|
|
354
|
-
}
|
|
355
|
-
if (extraParams) {
|
|
356
|
-
span.setAttributes(
|
|
357
|
-
Object.fromEntries(
|
|
358
|
-
Object.entries(extraParams).map(([key, value]) => [
|
|
359
|
-
[`${ATTR_LANGWATCH_LANGCHAIN_RUN_EXTRA_PARAMS}.${key}`],
|
|
360
|
-
wrapNonScalarValues(value)
|
|
361
|
-
])
|
|
362
|
-
)
|
|
363
|
-
);
|
|
364
|
-
}
|
|
365
|
-
if (metadata) {
|
|
366
|
-
if (metadata.ls_model_name) {
|
|
367
|
-
span.setRequestModel(metadata.ls_model_name);
|
|
368
|
-
metadata.ls_model_name = void 0;
|
|
369
|
-
}
|
|
370
|
-
span.setAttributes(
|
|
371
|
-
Object.fromEntries(
|
|
372
|
-
Object.entries(metadata).map(([key, value]) => [
|
|
373
|
-
[`${ATTR_LANGWATCH_LANGCHAIN_RUN_METADATA}.${key}`],
|
|
374
|
-
wrapNonScalarValues(value)
|
|
375
|
-
])
|
|
376
|
-
)
|
|
377
|
-
);
|
|
378
|
-
}
|
|
379
|
-
this.spans[runId] = span;
|
|
380
|
-
}
|
|
381
|
-
async handleLLMEnd(response, runId, _parentRunId) {
|
|
382
|
-
const span = this.getSpan(runId);
|
|
383
|
-
if (!span) return;
|
|
384
|
-
const outputs = [];
|
|
385
|
-
for (const generation of response.generations) {
|
|
386
|
-
for (const generation_ of generation) {
|
|
387
|
-
if ("message" in generation_ && generation_.message) {
|
|
388
|
-
outputs.push(
|
|
389
|
-
convertFromLangChainMessages([
|
|
390
|
-
generation_.message
|
|
391
|
-
])
|
|
392
|
-
);
|
|
393
|
-
} else if ("text" in generation_) {
|
|
394
|
-
outputs.push(generation_.text);
|
|
395
|
-
} else {
|
|
396
|
-
outputs.push(JSON.stringify(generation_));
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
const output = outputs.length === 1 ? outputs[0] : outputs;
|
|
401
|
-
if (canAutomaticallyCaptureOutput()) {
|
|
402
|
-
span.setOutput(output);
|
|
403
|
-
}
|
|
404
|
-
addLangChainEvent(span, "handleLLMEnd", runId, _parentRunId);
|
|
405
|
-
span.end();
|
|
406
|
-
this.spans[runId] = void 0;
|
|
407
|
-
}
|
|
408
|
-
async handleLLMError(err, runId, _parentRunId) {
|
|
409
|
-
const span = this.getSpan(runId);
|
|
410
|
-
if (!span) return;
|
|
411
|
-
addLangChainEvent(span, "handleLLMError", runId, _parentRunId);
|
|
412
|
-
span.recordException(err);
|
|
413
|
-
span.setStatus({ code: SpanStatusCode.ERROR, message: err.message });
|
|
414
|
-
span.end();
|
|
415
|
-
this.spans[runId] = void 0;
|
|
416
|
-
}
|
|
417
|
-
async handleChainStart(chain, inputs, runId, parentRunId, _tags, _metadata, _runType, name) {
|
|
418
|
-
var _a, _b, _c;
|
|
419
|
-
const parentContext = this.getParentContext(parentRunId);
|
|
420
|
-
const span = this.tracer.startSpan(
|
|
421
|
-
(_c = name != null ? name : (_b = (_a = chain.id) == null ? void 0 : _a[chain.id.length - 1]) == null ? void 0 : _b.toString()) != null ? _c : "chain",
|
|
422
|
-
{},
|
|
423
|
-
parentContext
|
|
424
|
-
);
|
|
425
|
-
span.setType("chain");
|
|
426
|
-
if (canAutomaticallyCaptureInput()) {
|
|
427
|
-
span.setInput(inputs);
|
|
428
|
-
}
|
|
429
|
-
if (_tags) {
|
|
430
|
-
span.setAttribute(ATTR_LANGWATCH_LANGCHAIN_RUN_TAGS, _tags);
|
|
431
|
-
}
|
|
432
|
-
if (_metadata) {
|
|
433
|
-
span.setAttributes(
|
|
434
|
-
Object.fromEntries(
|
|
435
|
-
Object.entries(_metadata).map(([key, value]) => [
|
|
436
|
-
[`${ATTR_LANGWATCH_LANGCHAIN_RUN_METADATA}.${key}`],
|
|
437
|
-
wrapNonScalarValues(value)
|
|
438
|
-
])
|
|
439
|
-
)
|
|
440
|
-
);
|
|
441
|
-
}
|
|
442
|
-
if (_runType) {
|
|
443
|
-
span.setAttribute(ATTR_LANGWATCH_LANGCHAIN_RUN_TYPE, _runType);
|
|
444
|
-
}
|
|
445
|
-
this.spans[runId] = span;
|
|
446
|
-
}
|
|
447
|
-
async handleChainEnd(output, runId, _parentRunId) {
|
|
448
|
-
const span = this.getSpan(runId);
|
|
449
|
-
if (!span) return;
|
|
450
|
-
addLangChainEvent(span, "handleChainEnd", runId, _parentRunId);
|
|
451
|
-
span.setOutput(output);
|
|
452
|
-
span.end();
|
|
453
|
-
this.spans[runId] = void 0;
|
|
454
|
-
}
|
|
455
|
-
async handleChainError(err, runId, _parentRunId, _tags, _kwargs) {
|
|
456
|
-
const span = this.getSpan(runId);
|
|
457
|
-
if (!span) return;
|
|
458
|
-
addLangChainEvent(span, "handleChainError", runId, _parentRunId);
|
|
459
|
-
span.recordException(err);
|
|
460
|
-
span.setStatus({ code: SpanStatusCode.ERROR, message: err.message });
|
|
461
|
-
span.end();
|
|
462
|
-
this.spans[runId] = void 0;
|
|
463
|
-
}
|
|
464
|
-
async handleToolStart(tool, input, runId, parentRunId, _tags, _metadata, name) {
|
|
465
|
-
var _a, _b, _c;
|
|
466
|
-
const parentContext = this.getParentContext(parentRunId);
|
|
467
|
-
const span = this.tracer.startSpan(
|
|
468
|
-
(_c = name != null ? name : (_b = (_a = tool.id) == null ? void 0 : _a[tool.id.length - 1]) == null ? void 0 : _b.toString()) != null ? _c : "tool",
|
|
469
|
-
{},
|
|
470
|
-
parentContext
|
|
471
|
-
);
|
|
472
|
-
span.setType("tool");
|
|
473
|
-
if (canAutomaticallyCaptureInput()) {
|
|
474
|
-
span.setInputString(input);
|
|
475
|
-
}
|
|
476
|
-
span.setAttributes({
|
|
477
|
-
[ATTR_LANGWATCH_LANGCHAIN_RUN_ID]: runId,
|
|
478
|
-
[ATTR_LANGWATCH_LANGCHAIN_RUN_PARENT_ID]: parentRunId
|
|
479
|
-
});
|
|
480
|
-
if (_tags) {
|
|
481
|
-
span.setAttribute(ATTR_LANGWATCH_LANGCHAIN_RUN_TAGS, _tags);
|
|
482
|
-
}
|
|
483
|
-
if (_metadata) {
|
|
484
|
-
span.setAttributes(
|
|
485
|
-
Object.fromEntries(
|
|
486
|
-
Object.entries(_metadata).map(([key, value]) => [
|
|
487
|
-
[`${ATTR_LANGWATCH_LANGCHAIN_RUN_METADATA}.${key}`],
|
|
488
|
-
wrapNonScalarValues(value)
|
|
489
|
-
])
|
|
490
|
-
)
|
|
491
|
-
);
|
|
492
|
-
}
|
|
493
|
-
this.spans[runId] = span;
|
|
494
|
-
}
|
|
495
|
-
async handleToolEnd(output, runId, _parentRunId) {
|
|
496
|
-
const span = this.getSpan(runId);
|
|
497
|
-
if (!span) return;
|
|
498
|
-
if (canAutomaticallyCaptureOutput()) {
|
|
499
|
-
span.setOutputString(output);
|
|
500
|
-
}
|
|
501
|
-
addLangChainEvent(span, "handleToolEnd", runId, _parentRunId);
|
|
502
|
-
span.end();
|
|
503
|
-
this.spans[runId] = void 0;
|
|
504
|
-
}
|
|
505
|
-
async handleToolError(err, runId, _parentRunId, _tags) {
|
|
506
|
-
const span = this.getSpan(runId);
|
|
507
|
-
if (!span) return;
|
|
508
|
-
addLangChainEvent(span, "handleToolError", runId, _parentRunId, _tags);
|
|
509
|
-
span.recordException(err);
|
|
510
|
-
span.setStatus({ code: SpanStatusCode.ERROR, message: err.message });
|
|
511
|
-
span.end();
|
|
512
|
-
this.spans[runId] = void 0;
|
|
513
|
-
}
|
|
514
|
-
async handleRetrieverStart(retriever, query, runId, parentRunId, _tags, _metadata, name) {
|
|
515
|
-
var _a, _b, _c;
|
|
516
|
-
const parentContext = this.getParentContext(parentRunId);
|
|
517
|
-
const span = this.tracer.startSpan(
|
|
518
|
-
(_c = name != null ? name : (_b = (_a = retriever.id) == null ? void 0 : _a[retriever.id.length - 1]) == null ? void 0 : _b.toString()) != null ? _c : "retriever",
|
|
519
|
-
{},
|
|
520
|
-
parentContext
|
|
521
|
-
);
|
|
522
|
-
span.setType("rag");
|
|
523
|
-
if (canAutomaticallyCaptureInput()) {
|
|
524
|
-
span.setInputString(query);
|
|
525
|
-
}
|
|
526
|
-
if (_tags) {
|
|
527
|
-
span.setAttribute(ATTR_LANGWATCH_LANGCHAIN_RUN_TAGS, _tags);
|
|
528
|
-
}
|
|
529
|
-
if (_metadata) {
|
|
530
|
-
span.setAttributes(
|
|
531
|
-
Object.fromEntries(
|
|
532
|
-
Object.entries(_metadata).map(([key, value]) => [
|
|
533
|
-
[`${ATTR_LANGWATCH_LANGCHAIN_RUN_METADATA}.${key}`],
|
|
534
|
-
wrapNonScalarValues(value)
|
|
535
|
-
])
|
|
536
|
-
)
|
|
537
|
-
);
|
|
538
|
-
}
|
|
539
|
-
span.setAttributes({
|
|
540
|
-
[ATTR_LANGWATCH_LANGCHAIN_RUN_ID]: runId,
|
|
541
|
-
[ATTR_LANGWATCH_LANGCHAIN_RUN_PARENT_ID]: parentRunId
|
|
542
|
-
});
|
|
543
|
-
this.spans[runId] = span;
|
|
544
|
-
}
|
|
545
|
-
async handleRetrieverEnd(documents, runId, _parentRunId, _tags) {
|
|
546
|
-
const span = this.getSpan(runId);
|
|
547
|
-
if (!span) return;
|
|
548
|
-
if (canAutomaticallyCaptureOutput()) {
|
|
549
|
-
span.setOutput(documents);
|
|
550
|
-
}
|
|
551
|
-
addLangChainEvent(span, "handleRetrieverEnd", runId, _parentRunId, _tags);
|
|
552
|
-
span.setRAGContexts(
|
|
553
|
-
documents.map((document) => ({
|
|
554
|
-
document_id: document.metadata.id,
|
|
555
|
-
chunk_id: document.metadata.chunk_id,
|
|
556
|
-
content: canAutomaticallyCaptureInput() ? document.pageContent : ""
|
|
557
|
-
}))
|
|
558
|
-
);
|
|
559
|
-
span.end();
|
|
560
|
-
this.spans[runId] = void 0;
|
|
561
|
-
}
|
|
562
|
-
async handleRetrieverError(err, runId, _parentRunId, _tags) {
|
|
563
|
-
const span = this.getSpan(runId);
|
|
564
|
-
if (!span) return;
|
|
565
|
-
addLangChainEvent(span, "handleRetrieverError", runId, _parentRunId, _tags);
|
|
566
|
-
span.recordException(err);
|
|
567
|
-
span.setStatus({ code: SpanStatusCode.ERROR, message: err.message });
|
|
568
|
-
span.end();
|
|
569
|
-
this.spans[runId] = void 0;
|
|
570
|
-
}
|
|
571
|
-
async handleAgentAction(_action, runId, _parentRunId, _tags) {
|
|
572
|
-
const span = this.getSpan(runId);
|
|
573
|
-
if (!span) return;
|
|
574
|
-
addLangChainEvent(span, "handleAgentAction", runId, _parentRunId, _tags);
|
|
575
|
-
span.setType("agent");
|
|
576
|
-
}
|
|
577
|
-
async handleAgentEnd(action, runId, _parentRunId, _tags) {
|
|
578
|
-
const span = this.getSpan(runId);
|
|
579
|
-
if (!span) return;
|
|
580
|
-
addLangChainEvent(span, "handleAgentEnd", runId, _parentRunId, _tags);
|
|
581
|
-
if (canAutomaticallyCaptureOutput()) {
|
|
582
|
-
span.setOutput(action.returnValues);
|
|
583
|
-
}
|
|
584
|
-
span.end();
|
|
585
|
-
this.spans[runId] = void 0;
|
|
586
|
-
}
|
|
587
|
-
};
|
|
588
|
-
var convertFromLangChainMessages = (messages) => {
|
|
589
|
-
const chatMessages = [];
|
|
590
|
-
for (const message of messages) {
|
|
591
|
-
chatMessages.push(
|
|
592
|
-
convertFromLangChainMessage(message)
|
|
593
|
-
);
|
|
594
|
-
}
|
|
595
|
-
return chatMessages;
|
|
596
|
-
};
|
|
597
|
-
var convertFromLangChainMessage = (message) => {
|
|
598
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
599
|
-
let role = "user";
|
|
600
|
-
const message_ = message.lc_serializable ? mapChatMessagesToStoredMessages([message])[0] : message;
|
|
601
|
-
if (message_ instanceof HumanMessage || message_ instanceof HumanMessageChunk || ((_a = message_.id) == null ? void 0 : _a[message_.id.length - 1]) === "HumanMessage" || ((_b = message_.id) == null ? void 0 : _b[message_.id.length - 1]) === "HumanMessageChunk" || message_.type === "human") {
|
|
602
|
-
role = "user";
|
|
603
|
-
} else if (message instanceof AIMessage || message instanceof AIMessageChunk || ((_c = message.id) == null ? void 0 : _c[message.id.length - 1]) === "AIMessage" || ((_d = message.id) == null ? void 0 : _d[message.id.length - 1]) === "AIMessageChunk" || message_.type === "ai") {
|
|
604
|
-
role = "assistant";
|
|
605
|
-
} else if (message instanceof SystemMessage || message instanceof SystemMessageChunk || ((_e = message.id) == null ? void 0 : _e[message.id.length - 1]) === "SystemMessage" || ((_f = message.id) == null ? void 0 : _f[message.id.length - 1]) === "SystemMessageChunk" || message_.type === "system") {
|
|
606
|
-
role = "system";
|
|
607
|
-
} else if (message instanceof FunctionMessage || message instanceof FunctionMessageChunk || ((_g = message.id) == null ? void 0 : _g[message.id.length - 1]) === "FunctionMessage" || ((_h = message.id) == null ? void 0 : _h[message.id.length - 1]) === "FunctionMessageChunk" || message_.type === "function") {
|
|
608
|
-
role = "function";
|
|
609
|
-
} else if (message instanceof ToolMessage || message instanceof ToolMessageChunk || ((_i = message.id) == null ? void 0 : _i[message.id.length - 1]) === "ToolMessage" || ((_j = message.id) == null ? void 0 : _j[message.id.length - 1]) === "ToolMessageChunk" || message_.type === "tool") {
|
|
610
|
-
role = "tool";
|
|
611
|
-
}
|
|
612
|
-
const content = typeof message.content === "string" ? message.content : message.content.map(
|
|
613
|
-
(content2) => content2.type === "text" ? { type: "text", text: content2.text } : content2.type == "image_url" ? { type: "image_url", image_url: content2.image_url } : { type: "text", text: JSON.stringify(content2) }
|
|
614
|
-
);
|
|
615
|
-
const functionCall = message.additional_kwargs;
|
|
616
|
-
return __spreadValues({
|
|
617
|
-
role,
|
|
618
|
-
content
|
|
619
|
-
}, functionCall && typeof functionCall === "object" && Object.keys(functionCall).length > 0 ? { function_call: functionCall } : {});
|
|
620
|
-
};
|
|
621
|
-
function wrapNonScalarValues(value) {
|
|
622
|
-
if (value === void 0) {
|
|
623
|
-
return void 0;
|
|
624
|
-
}
|
|
625
|
-
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
626
|
-
return value;
|
|
627
|
-
}
|
|
628
|
-
const chatMessages = z2.array(chatMessageSchema).safeParse(value);
|
|
629
|
-
if (Array.isArray(value) && chatMessages.success) {
|
|
630
|
-
return JSON.stringify({
|
|
631
|
-
type: "chat_messages",
|
|
632
|
-
value: chatMessages.data
|
|
633
|
-
});
|
|
634
|
-
}
|
|
635
|
-
try {
|
|
636
|
-
JSON.stringify(value);
|
|
637
|
-
return JSON.stringify({
|
|
638
|
-
type: "json",
|
|
639
|
-
value
|
|
640
|
-
});
|
|
641
|
-
} catch (e) {
|
|
642
|
-
return JSON.stringify({
|
|
643
|
-
type: "raw",
|
|
644
|
-
value
|
|
645
|
-
});
|
|
646
|
-
}
|
|
647
|
-
}
|
|
648
|
-
function addLangChainEvent(span, eventName, runId, parentRunId, tags, metadata, attributes) {
|
|
649
|
-
const attrs = __spreadValues({
|
|
650
|
-
[ATTR_LANGWATCH_LANGCHAIN_RUN_ID]: runId,
|
|
651
|
-
[ATTR_LANGWATCH_LANGCHAIN_RUN_PARENT_ID]: parentRunId,
|
|
652
|
-
[ATTR_LANGWATCH_LANGCHAIN_EVENT_NAME]: eventName
|
|
653
|
-
}, attributes);
|
|
654
|
-
if (tags) {
|
|
655
|
-
attrs[ATTR_LANGWATCH_LANGCHAIN_TAGS] = tags;
|
|
656
|
-
}
|
|
657
|
-
if (metadata) {
|
|
658
|
-
Object.entries(metadata).forEach(([key, value]) => {
|
|
659
|
-
attrs[key] = wrapNonScalarValues(value);
|
|
660
|
-
});
|
|
661
|
-
}
|
|
662
|
-
span.addEvent(EVNT_LANGWATCH_LANGCHAIN_CALLBACK, attrs);
|
|
663
|
-
}
|
|
664
|
-
export {
|
|
665
|
-
LangWatchCallbackHandler,
|
|
666
|
-
convertFromLangChainMessages
|
|
667
|
-
};
|
|
668
|
-
//# sourceMappingURL=index.mjs.map
|