@cloudbase/agent-observability 1.0.1-alpha.9
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/README.md +231 -0
- package/dist/chunk-NFEGQTCC.mjs +27 -0
- package/dist/chunk-NFEGQTCC.mjs.map +1 -0
- package/dist/chunk-ZGEMAYS4.mjs +716 -0
- package/dist/chunk-ZGEMAYS4.mjs.map +1 -0
- package/dist/esm-PGEDANAI.mjs +1030 -0
- package/dist/esm-PGEDANAI.mjs.map +1 -0
- package/dist/index.d.mts +728 -0
- package/dist/index.d.ts +728 -0
- package/dist/index.js +732 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +52 -0
- package/dist/index.mjs.map +1 -0
- package/dist/langchain.d.mts +108 -0
- package/dist/langchain.d.ts +108 -0
- package/dist/langchain.js +1237 -0
- package/dist/langchain.js.map +1 -0
- package/dist/langchain.mjs +535 -0
- package/dist/langchain.mjs.map +1 -0
- package/dist/server.d.mts +163 -0
- package/dist/server.d.ts +163 -0
- package/dist/server.js +1528 -0
- package/dist/server.js.map +1 -0
- package/dist/server.mjs +175 -0
- package/dist/server.mjs.map +1 -0
- package/package.json +91 -0
- package/src/core/attributes.ts +233 -0
- package/src/core/constants.ts +75 -0
- package/src/core/spanWrapper.ts +417 -0
- package/src/core/tracerProvider.ts +136 -0
- package/src/index.ts +775 -0
- package/src/langchain/CallbackHandler.ts +893 -0
- package/src/langchain/index.ts +7 -0
- package/src/server/config.ts +160 -0
- package/src/server/index.ts +21 -0
- package/src/server/setup.ts +344 -0
- package/src/types.ts +254 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types of observations (spans) supported by AG-Kit observability.
|
|
3
|
+
*
|
|
4
|
+
* These types align with OpenInference semantic conventions:
|
|
5
|
+
* https://github.com/Arize-ai/openinference/tree/main/spec
|
|
6
|
+
*
|
|
7
|
+
* - `span`: General-purpose operations (OpenInference: internal/span)
|
|
8
|
+
* - `llm`: Language model calls (OpenInference: LLM)
|
|
9
|
+
* - `embedding`: Text embedding operations (OpenInference: EMBEDDING)
|
|
10
|
+
* - `agent`: AI agent workflows (OpenInference: AGENT)
|
|
11
|
+
* - `tool`: Tool/function calls (OpenInference: TOOL)
|
|
12
|
+
* - `chain`: Multi-step workflows (OpenInference: CHAIN)
|
|
13
|
+
* - `retriever`: Document retrieval (OpenInference: RETRIEVER)
|
|
14
|
+
* - `reranker`: Result reranking (OpenInference: RERANKER)
|
|
15
|
+
* - `guardrail`: Safety checks (OpenInference: GUARDRAIL)
|
|
16
|
+
* - `evaluator`: Quality assessment (OpenInference: EVALUATOR)
|
|
17
|
+
*
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
export type ObservationType =
|
|
21
|
+
| "span"
|
|
22
|
+
| "llm"
|
|
23
|
+
| "embedding"
|
|
24
|
+
| "agent"
|
|
25
|
+
| "tool"
|
|
26
|
+
| "chain"
|
|
27
|
+
| "retriever"
|
|
28
|
+
| "reranker"
|
|
29
|
+
| "guardrail"
|
|
30
|
+
| "evaluator";
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Severity levels for observations.
|
|
34
|
+
*
|
|
35
|
+
* @public
|
|
36
|
+
*/
|
|
37
|
+
export type ObservationLevel = "DEBUG" | "DEFAULT" | "WARNING" | "ERROR";
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Token usage details for LLM calls.
|
|
41
|
+
*
|
|
42
|
+
* Follows OpenInference semantic convention:
|
|
43
|
+
* - llm.token_count.prompt
|
|
44
|
+
* - llm.token_count.completion
|
|
45
|
+
* - llm.token_count.total
|
|
46
|
+
*
|
|
47
|
+
* @public
|
|
48
|
+
*/
|
|
49
|
+
export type TokenUsage = {
|
|
50
|
+
/** Number of tokens in the prompt */
|
|
51
|
+
promptTokens?: number;
|
|
52
|
+
/** Number of tokens in the completion */
|
|
53
|
+
completionTokens?: number;
|
|
54
|
+
/** Total number of tokens */
|
|
55
|
+
totalTokens?: number;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Base attributes for all observation types.
|
|
60
|
+
*
|
|
61
|
+
* Uses OpenInference semantic conventions where applicable:
|
|
62
|
+
* - input.value: Input data
|
|
63
|
+
* - output.value: Output data
|
|
64
|
+
*
|
|
65
|
+
* @public
|
|
66
|
+
*/
|
|
67
|
+
export type BaseSpanAttributes = {
|
|
68
|
+
/** Input data for the operation */
|
|
69
|
+
input?: unknown;
|
|
70
|
+
/** Output data from the operation */
|
|
71
|
+
output?: unknown;
|
|
72
|
+
/** Additional metadata as key-value pairs */
|
|
73
|
+
metadata?: Record<string, unknown>;
|
|
74
|
+
/** Severity level of the observation */
|
|
75
|
+
level?: ObservationLevel;
|
|
76
|
+
/** Human-readable status message */
|
|
77
|
+
statusMessage?: string;
|
|
78
|
+
/** Version identifier for the code/model being tracked */
|
|
79
|
+
version?: string;
|
|
80
|
+
/** Environment where the operation is running (e.g., 'production', 'staging') */
|
|
81
|
+
environment?: string;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* LLM-specific attributes following OpenInference semantic conventions.
|
|
86
|
+
*
|
|
87
|
+
* Uses attributes like:
|
|
88
|
+
* - llm.model_name
|
|
89
|
+
* - llm.parameters.*
|
|
90
|
+
* - llm.token_count.*
|
|
91
|
+
* - llm.invocation_parameters
|
|
92
|
+
*
|
|
93
|
+
* @public
|
|
94
|
+
*/
|
|
95
|
+
export type LLMAttributes = BaseSpanAttributes & {
|
|
96
|
+
/** Timestamp when the model started generating completion */
|
|
97
|
+
completionStartTime?: Date;
|
|
98
|
+
/** Name of the language model (e.g., 'gpt-4', 'claude-3-opus') */
|
|
99
|
+
model?: string;
|
|
100
|
+
/** Parameters passed to the model (temperature, max_tokens, etc.) */
|
|
101
|
+
modelParameters?: Record<string, string | number>;
|
|
102
|
+
/** Token usage metrics */
|
|
103
|
+
usageDetails?: TokenUsage | Record<string, number>;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Embedding-specific attributes following OpenInference semantic conventions.
|
|
108
|
+
*
|
|
109
|
+
* Uses attributes like:
|
|
110
|
+
* - embedding.model_name
|
|
111
|
+
* - embedding.embeddings.*
|
|
112
|
+
*
|
|
113
|
+
* @public
|
|
114
|
+
*/
|
|
115
|
+
export type EmbeddingAttributes = LLMAttributes;
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Tool-specific attributes following OpenInference semantic conventions.
|
|
119
|
+
*
|
|
120
|
+
* Uses attributes like:
|
|
121
|
+
* - tool.name
|
|
122
|
+
* - tool.description
|
|
123
|
+
* - tool.parameters
|
|
124
|
+
*
|
|
125
|
+
* @public
|
|
126
|
+
*/
|
|
127
|
+
export type ToolAttributes = BaseSpanAttributes;
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Agent-specific attributes following OpenInference semantic conventions.
|
|
131
|
+
*
|
|
132
|
+
* Uses attributes like:
|
|
133
|
+
* - agent.name
|
|
134
|
+
* - agent.* (various agent-specific metadata)
|
|
135
|
+
*
|
|
136
|
+
* @public
|
|
137
|
+
*/
|
|
138
|
+
export type AgentAttributes = BaseSpanAttributes;
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Chain-specific attributes following OpenInference semantic conventions.
|
|
142
|
+
*
|
|
143
|
+
* Uses attributes like:
|
|
144
|
+
* - chain.name
|
|
145
|
+
* - chain.* (various chain-specific metadata)
|
|
146
|
+
*
|
|
147
|
+
* @public
|
|
148
|
+
*/
|
|
149
|
+
export type ChainAttributes = BaseSpanAttributes;
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Retriever-specific attributes following OpenInference semantic conventions.
|
|
153
|
+
*
|
|
154
|
+
* Uses attributes like:
|
|
155
|
+
* - retriever.name
|
|
156
|
+
* - retriever.query
|
|
157
|
+
* - retriever.*
|
|
158
|
+
*
|
|
159
|
+
* @public
|
|
160
|
+
*/
|
|
161
|
+
export type RetrieverAttributes = BaseSpanAttributes;
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Reranker-specific attributes following OpenInference semantic conventions.
|
|
165
|
+
*
|
|
166
|
+
* Uses attributes like:
|
|
167
|
+
* - reranker.model_name
|
|
168
|
+
* - reranker.top_k
|
|
169
|
+
* - reranker.*
|
|
170
|
+
*
|
|
171
|
+
* @public
|
|
172
|
+
*/
|
|
173
|
+
export type RerankerAttributes = BaseSpanAttributes;
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Evaluator-specific attributes.
|
|
177
|
+
*
|
|
178
|
+
* @public
|
|
179
|
+
*/
|
|
180
|
+
export type EvaluatorAttributes = BaseSpanAttributes;
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Guardrail-specific attributes following OpenInference semantic conventions.
|
|
184
|
+
*
|
|
185
|
+
* Uses attributes like:
|
|
186
|
+
* - guardrail.name
|
|
187
|
+
* - guardrail.*
|
|
188
|
+
*
|
|
189
|
+
* @public
|
|
190
|
+
*/
|
|
191
|
+
export type GuardrailAttributes = BaseSpanAttributes;
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Union type for all observation attributes.
|
|
195
|
+
*
|
|
196
|
+
* @public
|
|
197
|
+
*/
|
|
198
|
+
export type ObservationAttributes =
|
|
199
|
+
& BaseSpanAttributes
|
|
200
|
+
& LLMAttributes
|
|
201
|
+
& ToolAttributes
|
|
202
|
+
& AgentAttributes
|
|
203
|
+
& ChainAttributes
|
|
204
|
+
& RetrieverAttributes
|
|
205
|
+
& RerankerAttributes
|
|
206
|
+
& EvaluatorAttributes
|
|
207
|
+
& GuardrailAttributes;
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Attributes for traces.
|
|
211
|
+
*
|
|
212
|
+
* Traces are the top-level containers that group related observations together.
|
|
213
|
+
* Uses OpenInference semantic conventions where applicable.
|
|
214
|
+
*
|
|
215
|
+
* @public
|
|
216
|
+
*/
|
|
217
|
+
export type TraceAttributes = {
|
|
218
|
+
/** Human-readable name for the trace */
|
|
219
|
+
name?: string;
|
|
220
|
+
/** Identifier for the user associated with this trace */
|
|
221
|
+
userId?: string;
|
|
222
|
+
/** Session identifier for grouping related traces */
|
|
223
|
+
sessionId?: string;
|
|
224
|
+
/** Version identifier for the code/application */
|
|
225
|
+
version?: string;
|
|
226
|
+
/** Release identifier for deployment tracking */
|
|
227
|
+
release?: string;
|
|
228
|
+
/** Input data that initiated the trace */
|
|
229
|
+
input?: unknown;
|
|
230
|
+
/** Final output data from the trace */
|
|
231
|
+
output?: unknown;
|
|
232
|
+
/** Additional metadata for the trace */
|
|
233
|
+
metadata?: unknown;
|
|
234
|
+
/** Tags for categorizing and filtering traces */
|
|
235
|
+
tags?: string[];
|
|
236
|
+
/** Whether this trace should be publicly visible */
|
|
237
|
+
public?: boolean;
|
|
238
|
+
/** Environment where the trace was captured */
|
|
239
|
+
environment?: string;
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Context information for linking observations to traces.
|
|
244
|
+
*
|
|
245
|
+
* Used internally for maintaining parent-child relationships between observations.
|
|
246
|
+
*
|
|
247
|
+
* @public
|
|
248
|
+
*/
|
|
249
|
+
export type TraceContext = {
|
|
250
|
+
/** The trace ID that observations should be linked to */
|
|
251
|
+
traceId: string;
|
|
252
|
+
/** Optional parent observation ID for creating hierarchical relationships */
|
|
253
|
+
parentObservationId?: string;
|
|
254
|
+
};
|