@llmops/sdk 1.0.0-beta.5 → 1.0.0-beta.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/dist/agents.cjs +1 -1
  2. package/dist/agents.d.cts +1 -1
  3. package/dist/agents.d.mts +1 -1
  4. package/dist/agents.mjs +1 -1
  5. package/dist/d1-store-D664VLg0.d.cts +52 -0
  6. package/dist/d1-store-DBf99oU8.d.mts +52 -0
  7. package/dist/express.cjs +1 -1
  8. package/dist/express.d.cts +3 -3
  9. package/dist/express.d.mts +3 -3
  10. package/dist/express.mjs +1 -1
  11. package/dist/hono.d.cts +2 -2
  12. package/dist/hono.d.mts +2 -2
  13. package/dist/{index-DnWGper4.d.cts → index-BHO7MEJx.d.cts} +1 -1
  14. package/dist/{index-05byZKeu.d.mts → index-C0CDqR9v.d.mts} +1 -1
  15. package/dist/{index-Dvz-L2Hf.d.mts → index-DVkfeg2W.d.mts} +1 -1
  16. package/dist/{index-Beb26ZNG.d.cts → index-sjRozlIk.d.cts} +1 -1
  17. package/dist/index.cjs +6 -3
  18. package/dist/index.d.cts +5 -4
  19. package/dist/index.d.mts +5 -4
  20. package/dist/index.mjs +4 -3
  21. package/dist/interface-BrJMazBg.d.mts +240 -0
  22. package/dist/interface-DMuF7YgM.d.cts +240 -0
  23. package/dist/nextjs.d.cts +2 -2
  24. package/dist/nextjs.d.mts +2 -2
  25. package/dist/pg-store-sIMdF_Pc.mjs +13598 -0
  26. package/dist/pg-store-uawkO2hJ.cjs +13607 -0
  27. package/dist/store/d1.cjs +491 -0
  28. package/dist/store/d1.d.cts +12 -0
  29. package/dist/store/d1.d.mts +12 -0
  30. package/dist/store/d1.mjs +490 -0
  31. package/dist/store/pg.cjs +2 -7
  32. package/dist/store/pg.d.cts +2 -2
  33. package/dist/store/pg.d.mts +2 -2
  34. package/dist/store/pg.mjs +2 -2
  35. package/dist/types.d.cts +3 -2
  36. package/dist/types.d.mts +3 -2
  37. package/package.json +15 -5
  38. /package/dist/{agents-exporter-BZHCcFSd.d.mts → agents-exporter-Bn3NtzMO.d.mts} +0 -0
  39. /package/dist/{agents-exporter-BuTq2n2y.cjs → agents-exporter-CEbQkds8.cjs} +0 -0
  40. /package/dist/{agents-exporter-vcpgCF69.mjs → agents-exporter-CGxTzDeQ.mjs} +0 -0
  41. /package/dist/{agents-exporter-uzN3bkth.d.cts → agents-exporter-vuQine9v.d.cts} +0 -0
  42. /package/dist/{express-DMtc0d_Y.mjs → express-ClNV0OG9.mjs} +0 -0
  43. /package/dist/{express-B-wbCza5.cjs → express-D-Nfc61h.cjs} +0 -0
@@ -0,0 +1,240 @@
1
+ import z from "zod";
2
+
3
+ //#region src/telemetry/pg-store.d.ts
4
+ declare const insertLLMRequestSchema: z.ZodObject<{
5
+ requestId: z.ZodString;
6
+ configId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
7
+ variantId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
8
+ environmentId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
9
+ providerConfigId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
10
+ provider: z.ZodString;
11
+ model: z.ZodString;
12
+ promptTokens: z.ZodDefault<z.ZodNumber>;
13
+ completionTokens: z.ZodDefault<z.ZodNumber>;
14
+ totalTokens: z.ZodDefault<z.ZodNumber>;
15
+ cachedTokens: z.ZodDefault<z.ZodNumber>;
16
+ cacheCreationTokens: z.ZodDefault<z.ZodNumber>;
17
+ cost: z.ZodDefault<z.ZodNumber>;
18
+ cacheSavings: z.ZodDefault<z.ZodNumber>;
19
+ inputCost: z.ZodDefault<z.ZodNumber>;
20
+ outputCost: z.ZodDefault<z.ZodNumber>;
21
+ endpoint: z.ZodString;
22
+ statusCode: z.ZodNumber;
23
+ latencyMs: z.ZodDefault<z.ZodNumber>;
24
+ isStreaming: z.ZodDefault<z.ZodBoolean>;
25
+ userId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
26
+ tags: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
27
+ guardrailResults: z.ZodOptional<z.ZodNullable<z.ZodObject<{
28
+ results: z.ZodArray<z.ZodObject<{
29
+ checkId: z.ZodString;
30
+ functionId: z.ZodString;
31
+ hookType: z.ZodEnum<{
32
+ beforeRequestHook: "beforeRequestHook";
33
+ afterRequestHook: "afterRequestHook";
34
+ }>;
35
+ verdict: z.ZodBoolean;
36
+ latencyMs: z.ZodNumber;
37
+ }, z.core.$strip>>;
38
+ action: z.ZodEnum<{
39
+ allowed: "allowed";
40
+ blocked: "blocked";
41
+ logged: "logged";
42
+ }>;
43
+ totalLatencyMs: z.ZodNumber;
44
+ }, z.core.$strip>>>;
45
+ traceId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
46
+ spanId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
47
+ parentSpanId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
48
+ sessionId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
49
+ }, z.core.$strip>;
50
+ type LLMRequestInsert = z.infer<typeof insertLLMRequestSchema>;
51
+ declare const COST_SUMMARY_GROUP_BY: readonly ["day", "hour", "model", "provider", "endpoint", "tags"];
52
+ type CostSummaryGroupBy = (typeof COST_SUMMARY_GROUP_BY)[number];
53
+ declare const upsertTraceSchema: z.ZodObject<{
54
+ traceId: z.ZodString;
55
+ name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
56
+ sessionId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
57
+ userId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
58
+ status: z.ZodDefault<z.ZodEnum<{
59
+ error: "error";
60
+ unset: "unset";
61
+ ok: "ok";
62
+ }>>;
63
+ startTime: z.ZodDate;
64
+ endTime: z.ZodOptional<z.ZodNullable<z.ZodDate>>;
65
+ durationMs: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
66
+ spanCount: z.ZodDefault<z.ZodNumber>;
67
+ totalInputTokens: z.ZodDefault<z.ZodNumber>;
68
+ totalOutputTokens: z.ZodDefault<z.ZodNumber>;
69
+ totalTokens: z.ZodDefault<z.ZodNumber>;
70
+ totalCost: z.ZodDefault<z.ZodNumber>;
71
+ tags: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
72
+ metadata: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
73
+ }, z.core.$strip>;
74
+ type TraceUpsert = z.infer<typeof upsertTraceSchema>;
75
+ declare const insertSpanSchema: z.ZodObject<{
76
+ traceId: z.ZodString;
77
+ spanId: z.ZodString;
78
+ parentSpanId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
79
+ name: z.ZodString;
80
+ kind: z.ZodDefault<z.ZodNumber>;
81
+ status: z.ZodDefault<z.ZodNumber>;
82
+ statusMessage: z.ZodOptional<z.ZodNullable<z.ZodString>>;
83
+ startTime: z.ZodDate;
84
+ endTime: z.ZodOptional<z.ZodNullable<z.ZodDate>>;
85
+ durationMs: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
86
+ provider: z.ZodOptional<z.ZodNullable<z.ZodString>>;
87
+ model: z.ZodOptional<z.ZodNullable<z.ZodString>>;
88
+ promptTokens: z.ZodDefault<z.ZodNumber>;
89
+ completionTokens: z.ZodDefault<z.ZodNumber>;
90
+ totalTokens: z.ZodDefault<z.ZodNumber>;
91
+ cost: z.ZodDefault<z.ZodNumber>;
92
+ configId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
93
+ variantId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
94
+ environmentId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
95
+ providerConfigId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
96
+ requestId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
97
+ source: z.ZodDefault<z.ZodEnum<{
98
+ gateway: "gateway";
99
+ otlp: "otlp";
100
+ langsmith: "langsmith";
101
+ }>>;
102
+ input: z.ZodOptional<z.ZodNullable<z.ZodUnknown>>;
103
+ output: z.ZodOptional<z.ZodNullable<z.ZodUnknown>>;
104
+ attributes: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
105
+ }, z.core.$strip>;
106
+ type SpanInsert = z.infer<typeof insertSpanSchema>;
107
+ declare const insertSpanEventSchema: z.ZodObject<{
108
+ traceId: z.ZodString;
109
+ spanId: z.ZodString;
110
+ name: z.ZodString;
111
+ timestamp: z.ZodDate;
112
+ attributes: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
113
+ }, z.core.$strip>;
114
+ type SpanEventInsert = z.infer<typeof insertSpanEventSchema>;
115
+ type PgStore = TelemetryStore & {
116
+ _pool: unknown;
117
+ _schema: string;
118
+ };
119
+ /**
120
+ * Create a PostgreSQL-backed telemetry store.
121
+ *
122
+ * Usage:
123
+ * ```ts
124
+ * import { llmops } from '@llmops/sdk'
125
+ * import { pgStore } from '@llmops/sdk/store/pg'
126
+ *
127
+ * const ops = llmops({
128
+ * telemetry: pgStore(process.env.DATABASE_URL),
129
+ * })
130
+ * ```
131
+ */
132
+ declare function createPgStore(connectionString: string, options?: {
133
+ schema?: string;
134
+ }): PgStore;
135
+ //#endregion
136
+ //#region src/telemetry/interface.d.ts
137
+ /**
138
+ * TelemetryStore provides read + write access to telemetry data.
139
+ * Implemented by pgStore, d1Store, and future store backends.
140
+ */
141
+ interface TelemetryStore {
142
+ batchInsertRequests(requests: LLMRequestInsert[]): Promise<{
143
+ count: number;
144
+ }>;
145
+ insertRequest(request: LLMRequestInsert): Promise<unknown>;
146
+ listRequests(params?: {
147
+ limit?: number;
148
+ offset?: number;
149
+ configId?: string;
150
+ variantId?: string;
151
+ environmentId?: string;
152
+ providerConfigId?: string;
153
+ provider?: string;
154
+ model?: string;
155
+ startDate?: Date;
156
+ endDate?: Date;
157
+ tags?: Record<string, string[]>;
158
+ }): Promise<{
159
+ data: unknown[];
160
+ total: number;
161
+ limit: number;
162
+ offset: number;
163
+ }>;
164
+ getRequestByRequestId(requestId: string): Promise<unknown | undefined>;
165
+ getTotalCost(params: {
166
+ startDate: Date;
167
+ endDate: Date;
168
+ configId?: string;
169
+ variantId?: string;
170
+ environmentId?: string;
171
+ tags?: Record<string, string[]>;
172
+ }): Promise<unknown>;
173
+ getCostByModel(params: {
174
+ startDate: Date;
175
+ endDate: Date;
176
+ }): Promise<unknown[]>;
177
+ getCostByProvider(params: {
178
+ startDate: Date;
179
+ endDate: Date;
180
+ }): Promise<unknown[]>;
181
+ getDailyCosts(params: {
182
+ startDate: Date;
183
+ endDate: Date;
184
+ }): Promise<unknown[]>;
185
+ getCostSummary(params: {
186
+ startDate: Date;
187
+ endDate: Date;
188
+ configId?: string;
189
+ variantId?: string;
190
+ environmentId?: string;
191
+ groupBy?: CostSummaryGroupBy;
192
+ tags?: Record<string, string[]>;
193
+ tagKeys?: string[];
194
+ }): Promise<unknown[]>;
195
+ getRequestStats(params: {
196
+ startDate: Date;
197
+ endDate: Date;
198
+ configId?: string;
199
+ variantId?: string;
200
+ environmentId?: string;
201
+ tags?: Record<string, string[]>;
202
+ }): Promise<unknown>;
203
+ getDistinctTags(): Promise<unknown[]>;
204
+ upsertTrace(data: TraceUpsert): Promise<void>;
205
+ batchInsertSpans(spans: SpanInsert[]): Promise<{
206
+ count: number;
207
+ }>;
208
+ batchInsertSpanEvents(events: SpanEventInsert[]): Promise<{
209
+ count: number;
210
+ }>;
211
+ listTraces(params?: {
212
+ limit?: number;
213
+ offset?: number;
214
+ sessionId?: string;
215
+ userId?: string;
216
+ status?: string;
217
+ name?: string;
218
+ startDate?: Date;
219
+ endDate?: Date;
220
+ tags?: Record<string, string[]>;
221
+ }): Promise<{
222
+ data: unknown[];
223
+ total: number;
224
+ limit: number;
225
+ offset: number;
226
+ }>;
227
+ getTraceWithSpans(traceId: string): Promise<{
228
+ trace: unknown;
229
+ spans: unknown[];
230
+ events: unknown[];
231
+ } | undefined>;
232
+ getTraceStats(params: {
233
+ startDate: Date;
234
+ endDate: Date;
235
+ sessionId?: string;
236
+ userId?: string;
237
+ }): Promise<unknown>;
238
+ }
239
+ //#endregion
240
+ export { PgStore as a, TraceUpsert as c, LLMRequestInsert as i, createPgStore as l, COST_SUMMARY_GROUP_BY as n, SpanEventInsert as o, CostSummaryGroupBy as r, SpanInsert as s, TelemetryStore as t };
package/dist/nextjs.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import "./agents-exporter-uzN3bkth.cjs";
2
- import { t as LLMOpsClient } from "./index-Beb26ZNG.cjs";
1
+ import "./agents-exporter-vuQine9v.cjs";
2
+ import { t as LLMOpsClient } from "./index-sjRozlIk.cjs";
3
3
 
4
4
  //#region src/lib/nextjs/index.d.ts
5
5
  declare function toNextJsHandler(client: LLMOpsClient): {
package/dist/nextjs.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import "./agents-exporter-BZHCcFSd.mjs";
2
- import { t as LLMOpsClient } from "./index-05byZKeu.mjs";
1
+ import "./agents-exporter-Bn3NtzMO.mjs";
2
+ import { t as LLMOpsClient } from "./index-C0CDqR9v.mjs";
3
3
 
4
4
  //#region src/lib/nextjs/index.d.ts
5
5
  declare function toNextJsHandler(client: LLMOpsClient): {