langwatch 0.1.1 → 0.1.4

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.
@@ -1,5 +1,4 @@
1
1
  import { CoreMessage } from 'ai';
2
- import modelPrices from 'llm-cost/model_prices_and_context_window.json';
3
2
 
4
3
  type ChatRole = "system" | "user" | "assistant" | "function" | "tool" | "unknown";
5
4
  interface FunctionCall {
@@ -17,6 +16,7 @@ interface ChatMessage$1 {
17
16
  function_call?: FunctionCall | null;
18
17
  tool_calls?: ToolCall[] | null;
19
18
  tool_call_id?: string | null;
19
+ name?: string | null;
20
20
  }
21
21
  type ChatRichContent$1 = {
22
22
  type: "text";
@@ -49,18 +49,23 @@ type Money = {
49
49
  currency: string;
50
50
  amount: number;
51
51
  };
52
- interface GuardrailResult {
52
+ interface EvaluationResult {
53
53
  status: "processed" | "skipped" | "error";
54
- passed: boolean;
54
+ passed?: boolean | null;
55
55
  score?: number | null;
56
+ label?: string | null;
56
57
  details?: string | null;
57
58
  cost?: Money | null;
58
59
  }
59
60
  interface TypedValueGuardrailResult {
60
61
  type: "guardrail_result";
61
- value: GuardrailResult;
62
+ value: EvaluationResult;
63
+ }
64
+ interface TypedValueEvaluationResult {
65
+ type: "evaluation_result";
66
+ value: EvaluationResult;
62
67
  }
63
- type SpanInputOutput$1 = TypedValueText | TypedValueChatMessages | TypedValueGuardrailResult | TypedValueJson | TypedValueRaw | {
68
+ type SpanInputOutput$1 = TypedValueText | TypedValueChatMessages | TypedValueGuardrailResult | TypedValueEvaluationResult | TypedValueJson | TypedValueRaw | {
64
69
  type: "list";
65
70
  value: SpanInputOutput$1[];
66
71
  };
@@ -75,19 +80,32 @@ interface SpanMetrics {
75
80
  tokens_estimated?: boolean | null;
76
81
  cost?: number | null;
77
82
  }
78
- interface SpanParams {
79
- temperature?: number;
80
- stream?: boolean;
81
- functions?: Record<string, any>[];
82
- tools?: Record<string, any>[];
83
- tool_choice?: string;
84
- }
83
+ type ReservedSpanParams = {
84
+ frequency_penalty?: number | null;
85
+ logit_bias?: Record<string, number> | null;
86
+ logprobs?: boolean | null;
87
+ top_logprobs?: number | null;
88
+ max_tokens?: number | null;
89
+ n?: number | null;
90
+ presence_penalty?: number | null;
91
+ seed?: number | null;
92
+ stop?: string | string[] | null;
93
+ stream?: boolean | null;
94
+ temperature?: number | null;
95
+ top_p?: number | null;
96
+ tools?: Record<string, any>[] | null;
97
+ tool_choice?: Record<string, any> | string | null;
98
+ parallel_tool_calls?: boolean | null;
99
+ functions?: Record<string, any>[] | null;
100
+ user?: string | null;
101
+ };
102
+ type SpanParams = ReservedSpanParams & Record<string, any>;
85
103
  interface SpanTimestamps {
86
104
  started_at: number;
87
105
  first_token_at?: number | null;
88
106
  finished_at: number;
89
107
  }
90
- type SpanTypes = "span" | "llm" | "chain" | "tool" | "agent" | "rag" | "guardrail" | "unknown";
108
+ type SpanTypes = "span" | "llm" | "chain" | "tool" | "agent" | "rag" | "guardrail" | "evaluation" | "workflow" | "component" | "server" | "client" | "producer" | "consumer" | "task" | "unknown";
91
109
  interface BaseSpan$1 {
92
110
  span_id: string;
93
111
  parent_id?: string | null;
@@ -99,12 +117,12 @@ interface BaseSpan$1 {
99
117
  error?: ErrorCapture | null;
100
118
  timestamps: SpanTimestamps;
101
119
  metrics?: SpanMetrics | null;
120
+ params?: SpanParams | null;
102
121
  }
103
122
  interface LLMSpan$1 extends BaseSpan$1 {
104
123
  type: "llm";
105
124
  vendor?: string | null;
106
- model?: string;
107
- params?: SpanParams;
125
+ model?: string | null;
108
126
  }
109
127
  interface RAGChunk {
110
128
  document_id?: string | null;
@@ -131,25 +149,35 @@ type TraceOutput = {
131
149
  embeddings: number[];
132
150
  };
133
151
  };
152
+ type PrimitiveType = string | number | boolean | null | undefined;
153
+ type ReservedTraceMetadata = {
154
+ thread_id?: string | null;
155
+ user_id?: string | null;
156
+ customer_id?: string | null;
157
+ labels?: string[] | null;
158
+ topic_id?: string | null;
159
+ subtopic_id?: string | null;
160
+ sdk_version?: string | null;
161
+ sdk_language?: string | null;
162
+ };
163
+ type CustomMetadata = Record<string, PrimitiveType | PrimitiveType[] | Record<string, PrimitiveType> | Record<string, Record<string, PrimitiveType>>>;
164
+ type TraceMetadata = ReservedTraceMetadata & CustomMetadata;
134
165
  type Trace = {
135
166
  trace_id: string;
136
167
  project_id: string;
137
- metadata: {
138
- thread_id?: string;
139
- user_id?: string;
140
- customer_id?: string;
141
- labels?: string[];
142
- topic_id?: string;
143
- subtopic_id?: string;
144
- };
168
+ metadata: TraceMetadata;
145
169
  timestamps: {
146
170
  started_at: number;
147
171
  inserted_at: number;
148
172
  updated_at: number;
149
173
  };
150
- input: TraceInput;
174
+ input?: TraceInput;
151
175
  output?: TraceOutput;
152
- metrics: {
176
+ contexts?: RAGChunk[];
177
+ expected_output?: {
178
+ value: string;
179
+ };
180
+ metrics?: {
153
181
  first_token_ms?: number | null;
154
182
  total_time_ms?: number | null;
155
183
  prompt_tokens?: number | null;
@@ -159,10 +187,39 @@ type Trace = {
159
187
  };
160
188
  error?: ErrorCapture | null;
161
189
  indexing_md5s?: string[];
190
+ events?: Event[];
191
+ evaluations?: Evaluation[];
162
192
  };
163
- type Experiment = {
164
- experiment_id: string;
165
- variant: number;
193
+ type EvaluationStatus = "scheduled" | "in_progress" | "error" | "skipped" | "processed";
194
+ type Evaluation = {
195
+ evaluation_id: string;
196
+ evaluator_id: string;
197
+ span_id?: string | null;
198
+ name: string;
199
+ type?: string | null;
200
+ is_guardrail?: boolean | null;
201
+ status: EvaluationStatus;
202
+ passed?: boolean | null;
203
+ score?: number | null;
204
+ label?: string | null;
205
+ details?: string | null;
206
+ error?: ErrorCapture | null;
207
+ retries?: number | null;
208
+ timestamps: {
209
+ inserted_at?: number | null;
210
+ started_at?: number | null;
211
+ finished_at?: number | null;
212
+ updated_at?: number | null;
213
+ };
214
+ };
215
+ type RESTEvaluation$1 = Omit<Evaluation, "evaluation_id" | "evaluator_id" | "status" | "timestamps" | "retries"> & {
216
+ evaluation_id?: string | null;
217
+ evaluator_id?: string | null;
218
+ status?: "processed" | "skipped" | "error" | null;
219
+ timestamps?: {
220
+ started_at?: number | null;
221
+ finished_at?: number | null;
222
+ } | null;
166
223
  };
167
224
  type CollectorRESTParams = {
168
225
  trace_id?: string | null | undefined;
@@ -172,7 +229,23 @@ type CollectorRESTParams = {
172
229
  thread_id?: string | null | undefined;
173
230
  customer_id?: string | null | undefined;
174
231
  labels?: string[] | null | undefined;
175
- experiments?: Experiment[] | null | undefined;
232
+ sdk_version?: string | null | undefined;
233
+ sdk_language?: string | null | undefined;
234
+ } & CustomMetadata;
235
+ expected_output?: string | null;
236
+ evaluations?: RESTEvaluation$1[];
237
+ };
238
+ type Event = {
239
+ event_id: string;
240
+ event_type: string;
241
+ project_id: string;
242
+ metrics: Record<string, number>;
243
+ event_details: Record<string, string>;
244
+ trace_id: string;
245
+ timestamps: {
246
+ started_at: number;
247
+ inserted_at: number;
248
+ updated_at: number;
176
249
  };
177
250
  };
178
251
 
@@ -202,14 +275,17 @@ type PendingSpan<T extends BaseSpan> = Omit<T, "traceId" | "timestamps"> & {
202
275
  type BaseSpan = ConvertServerSpan<BaseSpan$1>;
203
276
  type PendingBaseSpan = PendingSpan<BaseSpan>;
204
277
  type LLMSpan = ConvertServerSpan<Omit<LLMSpan$1, "vendor" | "model">> & {
205
- model: keyof typeof modelPrices | (string & NonNullable<unknown>);
278
+ model: string;
206
279
  };
207
280
  type PendingLLMSpan = PendingSpan<LLMSpan>;
208
281
  type RAGSpan = ConvertServerSpan<RAGSpan$1>;
209
282
  type PendingRAGSpan = PendingSpan<RAGSpan>;
283
+ type RESTEvaluation = SnakeToCamelCaseNested<Omit<RESTEvaluation$1, "error">> & {
284
+ error?: RESTEvaluation$1["error"];
285
+ };
210
286
 
211
287
  declare function convertFromVercelAIMessages(messages: CoreMessage[]): ChatMessage[];
212
288
  declare const captureError: (error: unknown) => ErrorCapture;
213
289
  declare const autoconvertTypedValues: (value: unknown) => SpanInputOutput;
214
290
 
215
- export { type BaseSpan as B, type CollectorRESTParams as C, type LLMSpan as L, type Metadata as M, type PendingBaseSpan as P, type RAGSpan as R, type Span as S, type PendingLLMSpan as a, type PendingRAGSpan as b, type SpanTypes as c, type ChatMessage as d, type ChatRichContent as e, type SpanInputOutput as f, convertFromVercelAIMessages as g, captureError as h, autoconvertTypedValues as i };
291
+ export { type BaseSpan as B, type CollectorRESTParams as C, type LLMSpan as L, type Metadata as M, type PendingBaseSpan as P, type RAGChunk as R, type Span as S, type RESTEvaluation as a, type PendingLLMSpan as b, type PendingRAGSpan as c, type SpanTypes as d, type ChatMessage as e, type ChatRichContent as f, type RAGSpan as g, type SpanInputOutput as h, autoconvertTypedValues as i, captureError as j, convertFromVercelAIMessages as k };
@@ -1,5 +1,4 @@
1
1
  import { CoreMessage } from 'ai';
2
- import modelPrices from 'llm-cost/model_prices_and_context_window.json';
3
2
 
4
3
  type ChatRole = "system" | "user" | "assistant" | "function" | "tool" | "unknown";
5
4
  interface FunctionCall {
@@ -17,6 +16,7 @@ interface ChatMessage$1 {
17
16
  function_call?: FunctionCall | null;
18
17
  tool_calls?: ToolCall[] | null;
19
18
  tool_call_id?: string | null;
19
+ name?: string | null;
20
20
  }
21
21
  type ChatRichContent$1 = {
22
22
  type: "text";
@@ -49,18 +49,23 @@ type Money = {
49
49
  currency: string;
50
50
  amount: number;
51
51
  };
52
- interface GuardrailResult {
52
+ interface EvaluationResult {
53
53
  status: "processed" | "skipped" | "error";
54
- passed: boolean;
54
+ passed?: boolean | null;
55
55
  score?: number | null;
56
+ label?: string | null;
56
57
  details?: string | null;
57
58
  cost?: Money | null;
58
59
  }
59
60
  interface TypedValueGuardrailResult {
60
61
  type: "guardrail_result";
61
- value: GuardrailResult;
62
+ value: EvaluationResult;
63
+ }
64
+ interface TypedValueEvaluationResult {
65
+ type: "evaluation_result";
66
+ value: EvaluationResult;
62
67
  }
63
- type SpanInputOutput$1 = TypedValueText | TypedValueChatMessages | TypedValueGuardrailResult | TypedValueJson | TypedValueRaw | {
68
+ type SpanInputOutput$1 = TypedValueText | TypedValueChatMessages | TypedValueGuardrailResult | TypedValueEvaluationResult | TypedValueJson | TypedValueRaw | {
64
69
  type: "list";
65
70
  value: SpanInputOutput$1[];
66
71
  };
@@ -75,19 +80,32 @@ interface SpanMetrics {
75
80
  tokens_estimated?: boolean | null;
76
81
  cost?: number | null;
77
82
  }
78
- interface SpanParams {
79
- temperature?: number;
80
- stream?: boolean;
81
- functions?: Record<string, any>[];
82
- tools?: Record<string, any>[];
83
- tool_choice?: string;
84
- }
83
+ type ReservedSpanParams = {
84
+ frequency_penalty?: number | null;
85
+ logit_bias?: Record<string, number> | null;
86
+ logprobs?: boolean | null;
87
+ top_logprobs?: number | null;
88
+ max_tokens?: number | null;
89
+ n?: number | null;
90
+ presence_penalty?: number | null;
91
+ seed?: number | null;
92
+ stop?: string | string[] | null;
93
+ stream?: boolean | null;
94
+ temperature?: number | null;
95
+ top_p?: number | null;
96
+ tools?: Record<string, any>[] | null;
97
+ tool_choice?: Record<string, any> | string | null;
98
+ parallel_tool_calls?: boolean | null;
99
+ functions?: Record<string, any>[] | null;
100
+ user?: string | null;
101
+ };
102
+ type SpanParams = ReservedSpanParams & Record<string, any>;
85
103
  interface SpanTimestamps {
86
104
  started_at: number;
87
105
  first_token_at?: number | null;
88
106
  finished_at: number;
89
107
  }
90
- type SpanTypes = "span" | "llm" | "chain" | "tool" | "agent" | "rag" | "guardrail" | "unknown";
108
+ type SpanTypes = "span" | "llm" | "chain" | "tool" | "agent" | "rag" | "guardrail" | "evaluation" | "workflow" | "component" | "server" | "client" | "producer" | "consumer" | "task" | "unknown";
91
109
  interface BaseSpan$1 {
92
110
  span_id: string;
93
111
  parent_id?: string | null;
@@ -99,12 +117,12 @@ interface BaseSpan$1 {
99
117
  error?: ErrorCapture | null;
100
118
  timestamps: SpanTimestamps;
101
119
  metrics?: SpanMetrics | null;
120
+ params?: SpanParams | null;
102
121
  }
103
122
  interface LLMSpan$1 extends BaseSpan$1 {
104
123
  type: "llm";
105
124
  vendor?: string | null;
106
- model?: string;
107
- params?: SpanParams;
125
+ model?: string | null;
108
126
  }
109
127
  interface RAGChunk {
110
128
  document_id?: string | null;
@@ -131,25 +149,35 @@ type TraceOutput = {
131
149
  embeddings: number[];
132
150
  };
133
151
  };
152
+ type PrimitiveType = string | number | boolean | null | undefined;
153
+ type ReservedTraceMetadata = {
154
+ thread_id?: string | null;
155
+ user_id?: string | null;
156
+ customer_id?: string | null;
157
+ labels?: string[] | null;
158
+ topic_id?: string | null;
159
+ subtopic_id?: string | null;
160
+ sdk_version?: string | null;
161
+ sdk_language?: string | null;
162
+ };
163
+ type CustomMetadata = Record<string, PrimitiveType | PrimitiveType[] | Record<string, PrimitiveType> | Record<string, Record<string, PrimitiveType>>>;
164
+ type TraceMetadata = ReservedTraceMetadata & CustomMetadata;
134
165
  type Trace = {
135
166
  trace_id: string;
136
167
  project_id: string;
137
- metadata: {
138
- thread_id?: string;
139
- user_id?: string;
140
- customer_id?: string;
141
- labels?: string[];
142
- topic_id?: string;
143
- subtopic_id?: string;
144
- };
168
+ metadata: TraceMetadata;
145
169
  timestamps: {
146
170
  started_at: number;
147
171
  inserted_at: number;
148
172
  updated_at: number;
149
173
  };
150
- input: TraceInput;
174
+ input?: TraceInput;
151
175
  output?: TraceOutput;
152
- metrics: {
176
+ contexts?: RAGChunk[];
177
+ expected_output?: {
178
+ value: string;
179
+ };
180
+ metrics?: {
153
181
  first_token_ms?: number | null;
154
182
  total_time_ms?: number | null;
155
183
  prompt_tokens?: number | null;
@@ -159,10 +187,39 @@ type Trace = {
159
187
  };
160
188
  error?: ErrorCapture | null;
161
189
  indexing_md5s?: string[];
190
+ events?: Event[];
191
+ evaluations?: Evaluation[];
162
192
  };
163
- type Experiment = {
164
- experiment_id: string;
165
- variant: number;
193
+ type EvaluationStatus = "scheduled" | "in_progress" | "error" | "skipped" | "processed";
194
+ type Evaluation = {
195
+ evaluation_id: string;
196
+ evaluator_id: string;
197
+ span_id?: string | null;
198
+ name: string;
199
+ type?: string | null;
200
+ is_guardrail?: boolean | null;
201
+ status: EvaluationStatus;
202
+ passed?: boolean | null;
203
+ score?: number | null;
204
+ label?: string | null;
205
+ details?: string | null;
206
+ error?: ErrorCapture | null;
207
+ retries?: number | null;
208
+ timestamps: {
209
+ inserted_at?: number | null;
210
+ started_at?: number | null;
211
+ finished_at?: number | null;
212
+ updated_at?: number | null;
213
+ };
214
+ };
215
+ type RESTEvaluation$1 = Omit<Evaluation, "evaluation_id" | "evaluator_id" | "status" | "timestamps" | "retries"> & {
216
+ evaluation_id?: string | null;
217
+ evaluator_id?: string | null;
218
+ status?: "processed" | "skipped" | "error" | null;
219
+ timestamps?: {
220
+ started_at?: number | null;
221
+ finished_at?: number | null;
222
+ } | null;
166
223
  };
167
224
  type CollectorRESTParams = {
168
225
  trace_id?: string | null | undefined;
@@ -172,7 +229,23 @@ type CollectorRESTParams = {
172
229
  thread_id?: string | null | undefined;
173
230
  customer_id?: string | null | undefined;
174
231
  labels?: string[] | null | undefined;
175
- experiments?: Experiment[] | null | undefined;
232
+ sdk_version?: string | null | undefined;
233
+ sdk_language?: string | null | undefined;
234
+ } & CustomMetadata;
235
+ expected_output?: string | null;
236
+ evaluations?: RESTEvaluation$1[];
237
+ };
238
+ type Event = {
239
+ event_id: string;
240
+ event_type: string;
241
+ project_id: string;
242
+ metrics: Record<string, number>;
243
+ event_details: Record<string, string>;
244
+ trace_id: string;
245
+ timestamps: {
246
+ started_at: number;
247
+ inserted_at: number;
248
+ updated_at: number;
176
249
  };
177
250
  };
178
251
 
@@ -202,14 +275,17 @@ type PendingSpan<T extends BaseSpan> = Omit<T, "traceId" | "timestamps"> & {
202
275
  type BaseSpan = ConvertServerSpan<BaseSpan$1>;
203
276
  type PendingBaseSpan = PendingSpan<BaseSpan>;
204
277
  type LLMSpan = ConvertServerSpan<Omit<LLMSpan$1, "vendor" | "model">> & {
205
- model: keyof typeof modelPrices | (string & NonNullable<unknown>);
278
+ model: string;
206
279
  };
207
280
  type PendingLLMSpan = PendingSpan<LLMSpan>;
208
281
  type RAGSpan = ConvertServerSpan<RAGSpan$1>;
209
282
  type PendingRAGSpan = PendingSpan<RAGSpan>;
283
+ type RESTEvaluation = SnakeToCamelCaseNested<Omit<RESTEvaluation$1, "error">> & {
284
+ error?: RESTEvaluation$1["error"];
285
+ };
210
286
 
211
287
  declare function convertFromVercelAIMessages(messages: CoreMessage[]): ChatMessage[];
212
288
  declare const captureError: (error: unknown) => ErrorCapture;
213
289
  declare const autoconvertTypedValues: (value: unknown) => SpanInputOutput;
214
290
 
215
- export { type BaseSpan as B, type CollectorRESTParams as C, type LLMSpan as L, type Metadata as M, type PendingBaseSpan as P, type RAGSpan as R, type Span as S, type PendingLLMSpan as a, type PendingRAGSpan as b, type SpanTypes as c, type ChatMessage as d, type ChatRichContent as e, type SpanInputOutput as f, convertFromVercelAIMessages as g, captureError as h, autoconvertTypedValues as i };
291
+ export { type BaseSpan as B, type CollectorRESTParams as C, type LLMSpan as L, type Metadata as M, type PendingBaseSpan as P, type RAGChunk as R, type Span as S, type RESTEvaluation as a, type PendingLLMSpan as b, type PendingRAGSpan as c, type SpanTypes as d, type ChatMessage as e, type ChatRichContent as f, type RAGSpan as g, type SpanInputOutput as h, autoconvertTypedValues as i, captureError as j, convertFromVercelAIMessages as k };
package/dist/utils.d.mts CHANGED
@@ -1,3 +1,2 @@
1
1
  import 'ai';
2
- export { i as autoconvertTypedValues, h as captureError, g as convertFromVercelAIMessages } from './utils-K-jSEpnZ.mjs';
3
- import 'llm-cost/model_prices_and_context_window.json';
2
+ export { i as autoconvertTypedValues, j as captureError, k as convertFromVercelAIMessages } from './utils-CFtM8VVg.mjs';
package/dist/utils.d.ts CHANGED
@@ -1,3 +1,2 @@
1
1
  import 'ai';
2
- export { i as autoconvertTypedValues, h as captureError, g as convertFromVercelAIMessages } from './utils-K-jSEpnZ.js';
3
- import 'llm-cost/model_prices_and_context_window.json';
2
+ export { i as autoconvertTypedValues, j as captureError, k as convertFromVercelAIMessages } from './utils-CFtM8VVg.js';