@llmops/core 1.0.0-beta.2 → 1.0.0-beta.3
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/index.cjs +695 -747
- package/dist/index.d.cts +832 -924
- package/dist/index.d.mts +832 -924
- package/dist/index.mjs +696 -746
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -1382,432 +1382,100 @@ declare const createDatasetsDataLayer: (db: Kysely<Database>) => {
|
|
|
1382
1382
|
}[]>;
|
|
1383
1383
|
};
|
|
1384
1384
|
//#endregion
|
|
1385
|
-
//#region src/datalayer/
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
cacheCreationTokens: z$1.ZodDefault<z$1.ZodNumber>;
|
|
1402
|
-
cost: z$1.ZodDefault<z$1.ZodNumber>;
|
|
1403
|
-
cacheSavings: z$1.ZodDefault<z$1.ZodNumber>;
|
|
1404
|
-
inputCost: z$1.ZodDefault<z$1.ZodNumber>;
|
|
1405
|
-
outputCost: z$1.ZodDefault<z$1.ZodNumber>;
|
|
1406
|
-
endpoint: z$1.ZodString;
|
|
1407
|
-
statusCode: z$1.ZodNumber;
|
|
1408
|
-
latencyMs: z$1.ZodDefault<z$1.ZodNumber>;
|
|
1409
|
-
isStreaming: z$1.ZodDefault<z$1.ZodBoolean>;
|
|
1410
|
-
userId: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodString>>;
|
|
1411
|
-
tags: z$1.ZodDefault<z$1.ZodRecord<z$1.ZodString, z$1.ZodString>>;
|
|
1412
|
-
guardrailResults: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodObject<{
|
|
1413
|
-
results: z$1.ZodArray<z$1.ZodObject<{
|
|
1414
|
-
checkId: z$1.ZodString;
|
|
1415
|
-
functionId: z$1.ZodString;
|
|
1416
|
-
hookType: z$1.ZodEnum<{
|
|
1417
|
-
beforeRequestHook: "beforeRequestHook";
|
|
1418
|
-
afterRequestHook: "afterRequestHook";
|
|
1385
|
+
//#region src/datalayer/playgrounds.d.ts
|
|
1386
|
+
declare const createNewPlayground: z$1.ZodObject<{
|
|
1387
|
+
name: z$1.ZodString;
|
|
1388
|
+
datasetId: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodString>>;
|
|
1389
|
+
columns: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodArray<z$1.ZodObject<{
|
|
1390
|
+
id: z$1.ZodString;
|
|
1391
|
+
name: z$1.ZodString;
|
|
1392
|
+
position: z$1.ZodNumber;
|
|
1393
|
+
providerConfigId: z$1.ZodOptional<z$1.ZodUnion<readonly [z$1.ZodString, z$1.ZodNull]>>;
|
|
1394
|
+
providerSlug: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodString>>;
|
|
1395
|
+
modelName: z$1.ZodString;
|
|
1396
|
+
messages: z$1.ZodArray<z$1.ZodObject<{
|
|
1397
|
+
role: z$1.ZodEnum<{
|
|
1398
|
+
system: "system";
|
|
1399
|
+
user: "user";
|
|
1400
|
+
assistant: "assistant";
|
|
1419
1401
|
}>;
|
|
1420
|
-
|
|
1421
|
-
latencyMs: z$1.ZodNumber;
|
|
1402
|
+
content: z$1.ZodString;
|
|
1422
1403
|
}, z$1.core.$strip>>;
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
}, z$1.core.$strip>>>;
|
|
1430
|
-
traceId: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodString>>;
|
|
1431
|
-
spanId: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodString>>;
|
|
1432
|
-
parentSpanId: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodString>>;
|
|
1433
|
-
sessionId: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodString>>;
|
|
1404
|
+
temperature: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodNumber>>;
|
|
1405
|
+
maxTokens: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodNumber>>;
|
|
1406
|
+
topP: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodNumber>>;
|
|
1407
|
+
frequencyPenalty: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodNumber>>;
|
|
1408
|
+
presencePenalty: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodNumber>>;
|
|
1409
|
+
}, z$1.core.$strip>>>>;
|
|
1434
1410
|
}, z$1.core.$strip>;
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1411
|
+
declare const updatePlayground: z$1.ZodObject<{
|
|
1412
|
+
playgroundId: z$1.ZodUUID;
|
|
1413
|
+
name: z$1.ZodOptional<z$1.ZodString>;
|
|
1414
|
+
datasetId: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodString>>;
|
|
1415
|
+
columns: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodArray<z$1.ZodObject<{
|
|
1416
|
+
id: z$1.ZodString;
|
|
1417
|
+
name: z$1.ZodString;
|
|
1418
|
+
position: z$1.ZodNumber;
|
|
1419
|
+
providerConfigId: z$1.ZodOptional<z$1.ZodUnion<readonly [z$1.ZodString, z$1.ZodNull]>>;
|
|
1420
|
+
providerSlug: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodString>>;
|
|
1421
|
+
modelName: z$1.ZodString;
|
|
1422
|
+
messages: z$1.ZodArray<z$1.ZodObject<{
|
|
1423
|
+
role: z$1.ZodEnum<{
|
|
1424
|
+
system: "system";
|
|
1425
|
+
user: "user";
|
|
1426
|
+
assistant: "assistant";
|
|
1427
|
+
}>;
|
|
1428
|
+
content: z$1.ZodString;
|
|
1429
|
+
}, z$1.core.$strip>>;
|
|
1430
|
+
temperature: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodNumber>>;
|
|
1431
|
+
maxTokens: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodNumber>>;
|
|
1432
|
+
topP: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodNumber>>;
|
|
1433
|
+
frequencyPenalty: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodNumber>>;
|
|
1434
|
+
presencePenalty: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodNumber>>;
|
|
1435
|
+
}, z$1.core.$strip>>>>;
|
|
1451
1436
|
}, z$1.core.$strip>;
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
*/
|
|
1455
|
-
declare const dateRangeSchema: z$1.ZodObject<{
|
|
1456
|
-
startDate: z$1.ZodDate;
|
|
1457
|
-
endDate: z$1.ZodDate;
|
|
1458
|
-
configId: z$1.ZodOptional<z$1.ZodString>;
|
|
1459
|
-
variantId: z$1.ZodOptional<z$1.ZodString>;
|
|
1460
|
-
environmentId: z$1.ZodOptional<z$1.ZodString>;
|
|
1461
|
-
tags: z$1.ZodOptional<z$1.ZodRecord<z$1.ZodString, z$1.ZodArray<z$1.ZodString>>>;
|
|
1437
|
+
declare const getPlaygroundById: z$1.ZodObject<{
|
|
1438
|
+
playgroundId: z$1.ZodUUID;
|
|
1462
1439
|
}, z$1.core.$strip>;
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
*/
|
|
1466
|
-
declare const COST_SUMMARY_GROUP_BY: readonly ["day", "hour", "model", "provider", "endpoint", "tags"];
|
|
1467
|
-
type CostSummaryGroupBy = (typeof COST_SUMMARY_GROUP_BY)[number];
|
|
1468
|
-
/**
|
|
1469
|
-
* Schema for cost summary with grouping
|
|
1470
|
-
*/
|
|
1471
|
-
declare const costSummarySchema: z$1.ZodObject<{
|
|
1472
|
-
startDate: z$1.ZodDate;
|
|
1473
|
-
endDate: z$1.ZodDate;
|
|
1474
|
-
configId: z$1.ZodOptional<z$1.ZodString>;
|
|
1475
|
-
variantId: z$1.ZodOptional<z$1.ZodString>;
|
|
1476
|
-
environmentId: z$1.ZodOptional<z$1.ZodString>;
|
|
1477
|
-
tags: z$1.ZodOptional<z$1.ZodRecord<z$1.ZodString, z$1.ZodArray<z$1.ZodString>>>;
|
|
1478
|
-
groupBy: z$1.ZodOptional<z$1.ZodEnum<{
|
|
1479
|
-
provider: "provider";
|
|
1480
|
-
model: "model";
|
|
1481
|
-
endpoint: "endpoint";
|
|
1482
|
-
tags: "tags";
|
|
1483
|
-
day: "day";
|
|
1484
|
-
hour: "hour";
|
|
1485
|
-
}>>;
|
|
1486
|
-
tagKeys: z$1.ZodOptional<z$1.ZodArray<z$1.ZodString>>;
|
|
1440
|
+
declare const deletePlayground: z$1.ZodObject<{
|
|
1441
|
+
playgroundId: z$1.ZodUUID;
|
|
1487
1442
|
}, z$1.core.$strip>;
|
|
1488
|
-
declare const
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
}>;
|
|
1496
|
-
/**
|
|
1497
|
-
* Insert a single LLM request log
|
|
1498
|
-
*/
|
|
1499
|
-
insertRequest: (request: LLMRequestInsert) => Promise<{
|
|
1443
|
+
declare const listPlaygrounds: z$1.ZodObject<{
|
|
1444
|
+
limit: z$1.ZodOptional<z$1.ZodNumber>;
|
|
1445
|
+
offset: z$1.ZodOptional<z$1.ZodNumber>;
|
|
1446
|
+
}, z$1.core.$strip>;
|
|
1447
|
+
declare const createPlaygroundDataLayer: (db: Kysely<Database>) => {
|
|
1448
|
+
createNewPlayground: (params: z$1.infer<typeof createNewPlayground>) => Promise<{
|
|
1449
|
+
name: string;
|
|
1500
1450
|
id: string;
|
|
1501
1451
|
createdAt: Date;
|
|
1502
1452
|
updatedAt: Date;
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
cost: number;
|
|
1513
|
-
requestId: string;
|
|
1514
|
-
model: string;
|
|
1515
|
-
cachedTokens: number;
|
|
1516
|
-
cacheCreationTokens: number;
|
|
1517
|
-
cacheSavings: number;
|
|
1518
|
-
inputCost: number;
|
|
1519
|
-
outputCost: number;
|
|
1520
|
-
endpoint: string;
|
|
1521
|
-
statusCode: number;
|
|
1522
|
-
isStreaming: boolean;
|
|
1523
|
-
userId: string | null;
|
|
1524
|
-
tags: Record<string, string>;
|
|
1525
|
-
guardrailResults: {
|
|
1526
|
-
results: {
|
|
1527
|
-
checkId: string;
|
|
1528
|
-
functionId: string;
|
|
1529
|
-
hookType: "beforeRequestHook" | "afterRequestHook";
|
|
1530
|
-
verdict: boolean;
|
|
1531
|
-
latencyMs: number;
|
|
1453
|
+
datasetId: string | null;
|
|
1454
|
+
columns: {
|
|
1455
|
+
id: string;
|
|
1456
|
+
name: string;
|
|
1457
|
+
position: number;
|
|
1458
|
+
modelName: string;
|
|
1459
|
+
messages: {
|
|
1460
|
+
role: "system" | "user" | "assistant";
|
|
1461
|
+
content: string;
|
|
1532
1462
|
}[];
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1463
|
+
providerConfigId?: string | null | undefined;
|
|
1464
|
+
providerSlug?: string | null | undefined;
|
|
1465
|
+
temperature?: number | null | undefined;
|
|
1466
|
+
maxTokens?: number | null | undefined;
|
|
1467
|
+
topP?: number | null | undefined;
|
|
1468
|
+
frequencyPenalty?: number | null | undefined;
|
|
1469
|
+
presencePenalty?: number | null | undefined;
|
|
1470
|
+
}[] | null;
|
|
1540
1471
|
} | undefined>;
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
createdAt: Date;
|
|
1549
|
-
updatedAt: Date;
|
|
1550
|
-
variantId: string | null;
|
|
1551
|
-
provider: string;
|
|
1552
|
-
environmentId: string | null;
|
|
1553
|
-
configId: string | null;
|
|
1554
|
-
providerConfigId: string | null;
|
|
1555
|
-
latencyMs: number;
|
|
1556
|
-
promptTokens: number;
|
|
1557
|
-
completionTokens: number;
|
|
1558
|
-
totalTokens: number;
|
|
1559
|
-
cost: number;
|
|
1560
|
-
requestId: string;
|
|
1561
|
-
model: string;
|
|
1562
|
-
cachedTokens: number;
|
|
1563
|
-
cacheCreationTokens: number;
|
|
1564
|
-
cacheSavings: number;
|
|
1565
|
-
inputCost: number;
|
|
1566
|
-
outputCost: number;
|
|
1567
|
-
endpoint: string;
|
|
1568
|
-
statusCode: number;
|
|
1569
|
-
isStreaming: boolean;
|
|
1570
|
-
userId: string | null;
|
|
1571
|
-
tags: Record<string, string>;
|
|
1572
|
-
guardrailResults: {
|
|
1573
|
-
results: {
|
|
1574
|
-
checkId: string;
|
|
1575
|
-
functionId: string;
|
|
1576
|
-
hookType: "beforeRequestHook" | "afterRequestHook";
|
|
1577
|
-
verdict: boolean;
|
|
1578
|
-
latencyMs: number;
|
|
1579
|
-
}[];
|
|
1580
|
-
action: "allowed" | "blocked" | "logged";
|
|
1581
|
-
totalLatencyMs: number;
|
|
1582
|
-
} | null;
|
|
1583
|
-
traceId: string | null;
|
|
1584
|
-
spanId: string | null;
|
|
1585
|
-
parentSpanId: string | null;
|
|
1586
|
-
sessionId: string | null;
|
|
1587
|
-
}[];
|
|
1588
|
-
total: number;
|
|
1589
|
-
limit: number;
|
|
1590
|
-
offset: number;
|
|
1591
|
-
}>;
|
|
1592
|
-
/**
|
|
1593
|
-
* Get a single request by requestId
|
|
1594
|
-
*/
|
|
1595
|
-
getRequestByRequestId: (requestId: string) => Promise<{
|
|
1596
|
-
id: string;
|
|
1597
|
-
createdAt: Date;
|
|
1598
|
-
updatedAt: Date;
|
|
1599
|
-
variantId: string | null;
|
|
1600
|
-
provider: string;
|
|
1601
|
-
environmentId: string | null;
|
|
1602
|
-
configId: string | null;
|
|
1603
|
-
providerConfigId: string | null;
|
|
1604
|
-
latencyMs: number;
|
|
1605
|
-
promptTokens: number;
|
|
1606
|
-
completionTokens: number;
|
|
1607
|
-
totalTokens: number;
|
|
1608
|
-
cost: number;
|
|
1609
|
-
requestId: string;
|
|
1610
|
-
model: string;
|
|
1611
|
-
cachedTokens: number;
|
|
1612
|
-
cacheCreationTokens: number;
|
|
1613
|
-
cacheSavings: number;
|
|
1614
|
-
inputCost: number;
|
|
1615
|
-
outputCost: number;
|
|
1616
|
-
endpoint: string;
|
|
1617
|
-
statusCode: number;
|
|
1618
|
-
isStreaming: boolean;
|
|
1619
|
-
userId: string | null;
|
|
1620
|
-
tags: Record<string, string>;
|
|
1621
|
-
guardrailResults: {
|
|
1622
|
-
results: {
|
|
1623
|
-
checkId: string;
|
|
1624
|
-
functionId: string;
|
|
1625
|
-
hookType: "beforeRequestHook" | "afterRequestHook";
|
|
1626
|
-
verdict: boolean;
|
|
1627
|
-
latencyMs: number;
|
|
1628
|
-
}[];
|
|
1629
|
-
action: "allowed" | "blocked" | "logged";
|
|
1630
|
-
totalLatencyMs: number;
|
|
1631
|
-
} | null;
|
|
1632
|
-
traceId: string | null;
|
|
1633
|
-
spanId: string | null;
|
|
1634
|
-
parentSpanId: string | null;
|
|
1635
|
-
sessionId: string | null;
|
|
1636
|
-
} | undefined>;
|
|
1637
|
-
/**
|
|
1638
|
-
* Get total cost for a date range with optional filters
|
|
1639
|
-
*/
|
|
1640
|
-
getTotalCost: (params: z$1.infer<typeof dateRangeSchema>) => Promise<{
|
|
1641
|
-
totalCost: number;
|
|
1642
|
-
totalInputCost: number;
|
|
1643
|
-
totalOutputCost: number;
|
|
1644
|
-
totalPromptTokens: number;
|
|
1645
|
-
totalCompletionTokens: number;
|
|
1646
|
-
totalTokens: number;
|
|
1647
|
-
totalCachedTokens: number;
|
|
1648
|
-
totalCacheSavings: number;
|
|
1649
|
-
requestCount: number;
|
|
1650
|
-
} | undefined>;
|
|
1651
|
-
/**
|
|
1652
|
-
* Get cost breakdown by model
|
|
1653
|
-
*/
|
|
1654
|
-
getCostByModel: (params: z$1.infer<typeof dateRangeSchema>) => Promise<{
|
|
1655
|
-
provider: string;
|
|
1656
|
-
model: string;
|
|
1657
|
-
totalCost: number;
|
|
1658
|
-
totalInputCost: number;
|
|
1659
|
-
totalOutputCost: number;
|
|
1660
|
-
totalTokens: number;
|
|
1661
|
-
requestCount: number;
|
|
1662
|
-
avgLatencyMs: number;
|
|
1663
|
-
}[]>;
|
|
1664
|
-
/**
|
|
1665
|
-
* Get cost breakdown by provider
|
|
1666
|
-
*/
|
|
1667
|
-
getCostByProvider: (params: z$1.infer<typeof dateRangeSchema>) => Promise<{
|
|
1668
|
-
provider: string;
|
|
1669
|
-
totalCost: number;
|
|
1670
|
-
totalInputCost: number;
|
|
1671
|
-
totalOutputCost: number;
|
|
1672
|
-
totalTokens: number;
|
|
1673
|
-
requestCount: number;
|
|
1674
|
-
avgLatencyMs: number;
|
|
1675
|
-
}[]>;
|
|
1676
|
-
/**
|
|
1677
|
-
* Get daily cost summary
|
|
1678
|
-
*/
|
|
1679
|
-
getDailyCosts: (params: z$1.infer<typeof dateRangeSchema>) => Promise<{
|
|
1680
|
-
totalCost: number;
|
|
1681
|
-
totalInputCost: number;
|
|
1682
|
-
totalOutputCost: number;
|
|
1683
|
-
totalTokens: number;
|
|
1684
|
-
requestCount: number;
|
|
1685
|
-
date: string;
|
|
1686
|
-
}[]>;
|
|
1687
|
-
/**
|
|
1688
|
-
* Get cost summary with flexible grouping and optional filters
|
|
1689
|
-
*/
|
|
1690
|
-
getCostSummary: (params: z$1.infer<typeof costSummarySchema>) => Promise<{
|
|
1691
|
-
totalCost: number;
|
|
1692
|
-
requestCount: number;
|
|
1693
|
-
groupKey: string;
|
|
1694
|
-
}[]>;
|
|
1695
|
-
/**
|
|
1696
|
-
* Get request count and stats for a time range with optional filters
|
|
1697
|
-
*/
|
|
1698
|
-
getRequestStats: (params: z$1.infer<typeof dateRangeSchema>) => Promise<{
|
|
1699
|
-
avgLatencyMs: number;
|
|
1700
|
-
totalRequests: number;
|
|
1701
|
-
successfulRequests: number;
|
|
1702
|
-
failedRequests: number;
|
|
1703
|
-
streamingRequests: number;
|
|
1704
|
-
maxLatencyMs: number;
|
|
1705
|
-
minLatencyMs: number;
|
|
1706
|
-
} | undefined>;
|
|
1707
|
-
/**
|
|
1708
|
-
* Get all distinct tag key-value pairs from llm_requests
|
|
1709
|
-
* Used for populating tag filter dropdowns in the UI
|
|
1710
|
-
*/
|
|
1711
|
-
getDistinctTags: () => Promise<{
|
|
1712
|
-
key: string;
|
|
1713
|
-
value: string;
|
|
1714
|
-
}[]>;
|
|
1715
|
-
};
|
|
1716
|
-
//#endregion
|
|
1717
|
-
//#region src/datalayer/playgrounds.d.ts
|
|
1718
|
-
declare const createNewPlayground: z$1.ZodObject<{
|
|
1719
|
-
name: z$1.ZodString;
|
|
1720
|
-
datasetId: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodString>>;
|
|
1721
|
-
columns: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodArray<z$1.ZodObject<{
|
|
1722
|
-
id: z$1.ZodString;
|
|
1723
|
-
name: z$1.ZodString;
|
|
1724
|
-
position: z$1.ZodNumber;
|
|
1725
|
-
providerConfigId: z$1.ZodOptional<z$1.ZodUnion<readonly [z$1.ZodString, z$1.ZodNull]>>;
|
|
1726
|
-
providerSlug: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodString>>;
|
|
1727
|
-
modelName: z$1.ZodString;
|
|
1728
|
-
messages: z$1.ZodArray<z$1.ZodObject<{
|
|
1729
|
-
role: z$1.ZodEnum<{
|
|
1730
|
-
system: "system";
|
|
1731
|
-
user: "user";
|
|
1732
|
-
assistant: "assistant";
|
|
1733
|
-
}>;
|
|
1734
|
-
content: z$1.ZodString;
|
|
1735
|
-
}, z$1.core.$strip>>;
|
|
1736
|
-
temperature: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodNumber>>;
|
|
1737
|
-
maxTokens: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodNumber>>;
|
|
1738
|
-
topP: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodNumber>>;
|
|
1739
|
-
frequencyPenalty: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodNumber>>;
|
|
1740
|
-
presencePenalty: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodNumber>>;
|
|
1741
|
-
}, z$1.core.$strip>>>>;
|
|
1742
|
-
}, z$1.core.$strip>;
|
|
1743
|
-
declare const updatePlayground: z$1.ZodObject<{
|
|
1744
|
-
playgroundId: z$1.ZodUUID;
|
|
1745
|
-
name: z$1.ZodOptional<z$1.ZodString>;
|
|
1746
|
-
datasetId: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodString>>;
|
|
1747
|
-
columns: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodArray<z$1.ZodObject<{
|
|
1748
|
-
id: z$1.ZodString;
|
|
1749
|
-
name: z$1.ZodString;
|
|
1750
|
-
position: z$1.ZodNumber;
|
|
1751
|
-
providerConfigId: z$1.ZodOptional<z$1.ZodUnion<readonly [z$1.ZodString, z$1.ZodNull]>>;
|
|
1752
|
-
providerSlug: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodString>>;
|
|
1753
|
-
modelName: z$1.ZodString;
|
|
1754
|
-
messages: z$1.ZodArray<z$1.ZodObject<{
|
|
1755
|
-
role: z$1.ZodEnum<{
|
|
1756
|
-
system: "system";
|
|
1757
|
-
user: "user";
|
|
1758
|
-
assistant: "assistant";
|
|
1759
|
-
}>;
|
|
1760
|
-
content: z$1.ZodString;
|
|
1761
|
-
}, z$1.core.$strip>>;
|
|
1762
|
-
temperature: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodNumber>>;
|
|
1763
|
-
maxTokens: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodNumber>>;
|
|
1764
|
-
topP: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodNumber>>;
|
|
1765
|
-
frequencyPenalty: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodNumber>>;
|
|
1766
|
-
presencePenalty: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodNumber>>;
|
|
1767
|
-
}, z$1.core.$strip>>>>;
|
|
1768
|
-
}, z$1.core.$strip>;
|
|
1769
|
-
declare const getPlaygroundById: z$1.ZodObject<{
|
|
1770
|
-
playgroundId: z$1.ZodUUID;
|
|
1771
|
-
}, z$1.core.$strip>;
|
|
1772
|
-
declare const deletePlayground: z$1.ZodObject<{
|
|
1773
|
-
playgroundId: z$1.ZodUUID;
|
|
1774
|
-
}, z$1.core.$strip>;
|
|
1775
|
-
declare const listPlaygrounds: z$1.ZodObject<{
|
|
1776
|
-
limit: z$1.ZodOptional<z$1.ZodNumber>;
|
|
1777
|
-
offset: z$1.ZodOptional<z$1.ZodNumber>;
|
|
1778
|
-
}, z$1.core.$strip>;
|
|
1779
|
-
declare const createPlaygroundDataLayer: (db: Kysely<Database>) => {
|
|
1780
|
-
createNewPlayground: (params: z$1.infer<typeof createNewPlayground>) => Promise<{
|
|
1781
|
-
name: string;
|
|
1782
|
-
id: string;
|
|
1783
|
-
createdAt: Date;
|
|
1784
|
-
updatedAt: Date;
|
|
1785
|
-
datasetId: string | null;
|
|
1786
|
-
columns: {
|
|
1787
|
-
id: string;
|
|
1788
|
-
name: string;
|
|
1789
|
-
position: number;
|
|
1790
|
-
modelName: string;
|
|
1791
|
-
messages: {
|
|
1792
|
-
role: "system" | "user" | "assistant";
|
|
1793
|
-
content: string;
|
|
1794
|
-
}[];
|
|
1795
|
-
providerConfigId?: string | null | undefined;
|
|
1796
|
-
providerSlug?: string | null | undefined;
|
|
1797
|
-
temperature?: number | null | undefined;
|
|
1798
|
-
maxTokens?: number | null | undefined;
|
|
1799
|
-
topP?: number | null | undefined;
|
|
1800
|
-
frequencyPenalty?: number | null | undefined;
|
|
1801
|
-
presencePenalty?: number | null | undefined;
|
|
1802
|
-
}[] | null;
|
|
1803
|
-
} | undefined>;
|
|
1804
|
-
updatePlayground: (params: z$1.infer<typeof updatePlayground>) => Promise<{
|
|
1805
|
-
name: string;
|
|
1806
|
-
id: string;
|
|
1807
|
-
createdAt: Date;
|
|
1808
|
-
updatedAt: Date;
|
|
1809
|
-
datasetId: string | null;
|
|
1810
|
-
columns: {
|
|
1472
|
+
updatePlayground: (params: z$1.infer<typeof updatePlayground>) => Promise<{
|
|
1473
|
+
name: string;
|
|
1474
|
+
id: string;
|
|
1475
|
+
createdAt: Date;
|
|
1476
|
+
updatedAt: Date;
|
|
1477
|
+
datasetId: string | null;
|
|
1478
|
+
columns: {
|
|
1811
1479
|
id: string;
|
|
1812
1480
|
name: string;
|
|
1813
1481
|
position: number;
|
|
@@ -2074,220 +1742,746 @@ declare const createPlaygroundRun: z$1.ZodObject<{
|
|
|
2074
1742
|
failed: "failed";
|
|
2075
1743
|
cancelled: "cancelled";
|
|
2076
1744
|
}>>;
|
|
2077
|
-
totalRecords: z$1.ZodDefault<z$1.ZodNumber>;
|
|
1745
|
+
totalRecords: z$1.ZodDefault<z$1.ZodNumber>;
|
|
1746
|
+
}, z$1.core.$strip>;
|
|
1747
|
+
declare const updatePlaygroundRun: z$1.ZodObject<{
|
|
1748
|
+
runId: z$1.ZodString;
|
|
1749
|
+
status: z$1.ZodOptional<z$1.ZodEnum<{
|
|
1750
|
+
pending: "pending";
|
|
1751
|
+
running: "running";
|
|
1752
|
+
completed: "completed";
|
|
1753
|
+
failed: "failed";
|
|
1754
|
+
cancelled: "cancelled";
|
|
1755
|
+
}>>;
|
|
1756
|
+
startedAt: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodDate>>;
|
|
1757
|
+
completedAt: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodDate>>;
|
|
1758
|
+
completedRecords: z$1.ZodOptional<z$1.ZodNumber>;
|
|
1759
|
+
}, z$1.core.$strip>;
|
|
1760
|
+
declare const getPlaygroundRunById: z$1.ZodObject<{
|
|
1761
|
+
runId: z$1.ZodString;
|
|
1762
|
+
}, z$1.core.$strip>;
|
|
1763
|
+
declare const listPlaygroundRuns: z$1.ZodObject<{
|
|
1764
|
+
playgroundId: z$1.ZodString;
|
|
1765
|
+
limit: z$1.ZodOptional<z$1.ZodNumber>;
|
|
1766
|
+
offset: z$1.ZodOptional<z$1.ZodNumber>;
|
|
1767
|
+
}, z$1.core.$strip>;
|
|
1768
|
+
declare const deletePlaygroundRun: z$1.ZodObject<{
|
|
1769
|
+
runId: z$1.ZodString;
|
|
1770
|
+
}, z$1.core.$strip>;
|
|
1771
|
+
declare const createPlaygroundRunsDataLayer: (db: Kysely<Database>) => {
|
|
1772
|
+
createPlaygroundRun: (params: z$1.infer<typeof createPlaygroundRun>) => Promise<{
|
|
1773
|
+
id: string;
|
|
1774
|
+
createdAt: Date;
|
|
1775
|
+
updatedAt: Date;
|
|
1776
|
+
datasetId: string | null;
|
|
1777
|
+
playgroundId: string;
|
|
1778
|
+
datasetVersionId: string | null;
|
|
1779
|
+
status: string;
|
|
1780
|
+
startedAt: Date | null;
|
|
1781
|
+
completedAt: Date | null;
|
|
1782
|
+
totalRecords: number;
|
|
1783
|
+
completedRecords: number;
|
|
1784
|
+
} | undefined>;
|
|
1785
|
+
updatePlaygroundRun: (params: z$1.infer<typeof updatePlaygroundRun>) => Promise<{
|
|
1786
|
+
id: string;
|
|
1787
|
+
createdAt: Date;
|
|
1788
|
+
updatedAt: Date;
|
|
1789
|
+
datasetId: string | null;
|
|
1790
|
+
playgroundId: string;
|
|
1791
|
+
datasetVersionId: string | null;
|
|
1792
|
+
status: string;
|
|
1793
|
+
startedAt: Date | null;
|
|
1794
|
+
completedAt: Date | null;
|
|
1795
|
+
totalRecords: number;
|
|
1796
|
+
completedRecords: number;
|
|
1797
|
+
} | undefined>;
|
|
1798
|
+
getPlaygroundRunById: (params: z$1.infer<typeof getPlaygroundRunById>) => Promise<{
|
|
1799
|
+
id: string;
|
|
1800
|
+
createdAt: Date;
|
|
1801
|
+
updatedAt: Date;
|
|
1802
|
+
datasetId: string | null;
|
|
1803
|
+
playgroundId: string;
|
|
1804
|
+
datasetVersionId: string | null;
|
|
1805
|
+
status: string;
|
|
1806
|
+
startedAt: Date | null;
|
|
1807
|
+
completedAt: Date | null;
|
|
1808
|
+
totalRecords: number;
|
|
1809
|
+
completedRecords: number;
|
|
1810
|
+
} | undefined>;
|
|
1811
|
+
listPlaygroundRuns: (params: z$1.infer<typeof listPlaygroundRuns>) => Promise<{
|
|
1812
|
+
id: string;
|
|
1813
|
+
createdAt: Date;
|
|
1814
|
+
updatedAt: Date;
|
|
1815
|
+
datasetId: string | null;
|
|
1816
|
+
playgroundId: string;
|
|
1817
|
+
datasetVersionId: string | null;
|
|
1818
|
+
status: string;
|
|
1819
|
+
startedAt: Date | null;
|
|
1820
|
+
completedAt: Date | null;
|
|
1821
|
+
totalRecords: number;
|
|
1822
|
+
completedRecords: number;
|
|
1823
|
+
}[]>;
|
|
1824
|
+
deletePlaygroundRun: (params: z$1.infer<typeof deletePlaygroundRun>) => Promise<{
|
|
1825
|
+
id: string;
|
|
1826
|
+
createdAt: Date;
|
|
1827
|
+
updatedAt: Date;
|
|
1828
|
+
datasetId: string | null;
|
|
1829
|
+
playgroundId: string;
|
|
1830
|
+
datasetVersionId: string | null;
|
|
1831
|
+
status: string;
|
|
1832
|
+
startedAt: Date | null;
|
|
1833
|
+
completedAt: Date | null;
|
|
1834
|
+
totalRecords: number;
|
|
1835
|
+
completedRecords: number;
|
|
1836
|
+
} | undefined>;
|
|
1837
|
+
countPlaygroundRuns: (playgroundId: string) => Promise<number>;
|
|
1838
|
+
};
|
|
1839
|
+
//#endregion
|
|
1840
|
+
//#region src/datalayer/workspaceSettings.d.ts
|
|
1841
|
+
declare const updateWorkspaceSettings: z$1.ZodObject<{
|
|
1842
|
+
name: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodString>>;
|
|
1843
|
+
setupComplete: z$1.ZodOptional<z$1.ZodBoolean>;
|
|
1844
|
+
superAdminId: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodString>>;
|
|
1845
|
+
}, z$1.core.$strip>;
|
|
1846
|
+
declare const createWorkspaceSettingsDataLayer: (db: Kysely<Database>) => {
|
|
1847
|
+
/**
|
|
1848
|
+
* Get workspace settings (creates default if not exists)
|
|
1849
|
+
*/
|
|
1850
|
+
getWorkspaceSettings: () => Promise<{
|
|
1851
|
+
name: string | null;
|
|
1852
|
+
id: string;
|
|
1853
|
+
createdAt: Date;
|
|
1854
|
+
updatedAt: Date;
|
|
1855
|
+
setupComplete: boolean;
|
|
1856
|
+
superAdminId: string | null;
|
|
1857
|
+
} | undefined>;
|
|
1858
|
+
/**
|
|
1859
|
+
* Update workspace settings
|
|
1860
|
+
*/
|
|
1861
|
+
updateWorkspaceSettings: (params: z$1.infer<typeof updateWorkspaceSettings>) => Promise<{
|
|
1862
|
+
name: string | null;
|
|
1863
|
+
id: string;
|
|
1864
|
+
createdAt: Date;
|
|
1865
|
+
updatedAt: Date;
|
|
1866
|
+
setupComplete: boolean;
|
|
1867
|
+
superAdminId: string | null;
|
|
1868
|
+
} | undefined>;
|
|
1869
|
+
/**
|
|
1870
|
+
* Get the super admin user ID
|
|
1871
|
+
*/
|
|
1872
|
+
getSuperAdminId: () => Promise<string | null>;
|
|
1873
|
+
/**
|
|
1874
|
+
* Set the super admin user ID (only if not already set)
|
|
1875
|
+
*/
|
|
1876
|
+
setSuperAdminId: (userId: string) => Promise<boolean>;
|
|
1877
|
+
/**
|
|
1878
|
+
* Check if initial setup has been completed
|
|
1879
|
+
*/
|
|
1880
|
+
isSetupComplete: () => Promise<boolean>;
|
|
1881
|
+
/**
|
|
1882
|
+
* Mark initial setup as complete
|
|
1883
|
+
*/
|
|
1884
|
+
markSetupComplete: () => Promise<{
|
|
1885
|
+
name: string | null;
|
|
1886
|
+
id: string;
|
|
1887
|
+
createdAt: Date;
|
|
1888
|
+
updatedAt: Date;
|
|
1889
|
+
setupComplete: boolean;
|
|
1890
|
+
superAdminId: string | null;
|
|
1891
|
+
} | undefined>;
|
|
1892
|
+
};
|
|
1893
|
+
//#endregion
|
|
1894
|
+
//#region src/datalayer/interface.d.ts
|
|
1895
|
+
type DatasetsDataLayer = ReturnType<typeof createDatasetsDataLayer>;
|
|
1896
|
+
type PlaygroundsDataLayer = ReturnType<typeof createPlaygroundDataLayer>;
|
|
1897
|
+
type PlaygroundResultsDataLayer = ReturnType<typeof createPlaygroundResultsDataLayer>;
|
|
1898
|
+
type PlaygroundRunsDataLayer = ReturnType<typeof createPlaygroundRunsDataLayer>;
|
|
1899
|
+
type WorkspaceSettingsDataLayer = ReturnType<typeof createWorkspaceSettingsDataLayer>;
|
|
1900
|
+
type DataLayer = DatasetsDataLayer & PlaygroundsDataLayer & PlaygroundResultsDataLayer & PlaygroundRunsDataLayer & WorkspaceSettingsDataLayer;
|
|
1901
|
+
//#endregion
|
|
1902
|
+
//#region src/datalayer/create.d.ts
|
|
1903
|
+
/**
|
|
1904
|
+
* Create all datalayers from a Kysely database instance.
|
|
1905
|
+
* Returns a flat object with all datalayer methods spread together.
|
|
1906
|
+
*/
|
|
1907
|
+
declare function createDataLayer(db: Kysely<Database>): DataLayer;
|
|
1908
|
+
//#endregion
|
|
1909
|
+
//#region src/pricing/types.d.ts
|
|
1910
|
+
/**
|
|
1911
|
+
* Pricing types for cost tracking
|
|
1912
|
+
*/
|
|
1913
|
+
/**
|
|
1914
|
+
* Model pricing information
|
|
1915
|
+
* All costs are in dollars per 1 million tokens
|
|
1916
|
+
*/
|
|
1917
|
+
interface ModelPricing {
|
|
1918
|
+
/** Cost per 1M input/prompt tokens in dollars */
|
|
1919
|
+
inputCostPer1M: number;
|
|
1920
|
+
/** Cost per 1M output/completion tokens in dollars */
|
|
1921
|
+
outputCostPer1M: number;
|
|
1922
|
+
/** Cost per 1M cached read tokens in dollars (optional) */
|
|
1923
|
+
cacheReadCostPer1M?: number;
|
|
1924
|
+
/** Cost per 1M cached write tokens in dollars (optional) */
|
|
1925
|
+
cacheWriteCostPer1M?: number;
|
|
1926
|
+
/** Cost per 1M reasoning tokens in dollars (optional, for models like o1) */
|
|
1927
|
+
reasoningCostPer1M?: number;
|
|
1928
|
+
}
|
|
1929
|
+
/**
|
|
1930
|
+
* Token usage data from LLM response
|
|
1931
|
+
*/
|
|
1932
|
+
interface UsageData {
|
|
1933
|
+
/** Number of tokens in the prompt/input */
|
|
1934
|
+
promptTokens: number;
|
|
1935
|
+
/** Number of tokens in the completion/output */
|
|
1936
|
+
completionTokens: number;
|
|
1937
|
+
/** Total tokens (prompt + completion) */
|
|
1938
|
+
totalTokens?: number;
|
|
1939
|
+
/** Number of cache read tokens (OpenAI cached_tokens / Anthropic cache_read_input_tokens) */
|
|
1940
|
+
cachedTokens?: number;
|
|
1941
|
+
/** Number of cache creation tokens (Anthropic cache_creation_input_tokens) */
|
|
1942
|
+
cacheCreationTokens?: number;
|
|
1943
|
+
/** Number of reasoning tokens (optional, for models like o1) */
|
|
1944
|
+
reasoningTokens?: number;
|
|
1945
|
+
}
|
|
1946
|
+
/**
|
|
1947
|
+
* Cost calculation result
|
|
1948
|
+
* All costs are in micro-dollars (1 dollar = 1,000,000 micro-dollars)
|
|
1949
|
+
* This avoids floating-point precision issues
|
|
1950
|
+
*/
|
|
1951
|
+
interface CostResult {
|
|
1952
|
+
/** Total cost in micro-dollars */
|
|
1953
|
+
totalCost: number;
|
|
1954
|
+
/** Input/prompt cost in micro-dollars */
|
|
1955
|
+
inputCost: number;
|
|
1956
|
+
/** Output/completion cost in micro-dollars */
|
|
1957
|
+
outputCost: number;
|
|
1958
|
+
/** Cost saved by cache hits in micro-dollars (negative means cache write premium exceeded savings) */
|
|
1959
|
+
cacheSavings: number;
|
|
1960
|
+
}
|
|
1961
|
+
/**
|
|
1962
|
+
* Provider for fetching model pricing data
|
|
1963
|
+
* Abstracted to allow swapping data sources (models.dev, local JSON, etc.)
|
|
1964
|
+
*/
|
|
1965
|
+
interface PricingProvider {
|
|
1966
|
+
/**
|
|
1967
|
+
* Get pricing for a specific model
|
|
1968
|
+
* @param provider - Provider name (e.g., "openai", "anthropic")
|
|
1969
|
+
* @param model - Model identifier (e.g., "gpt-4o", "claude-3-sonnet")
|
|
1970
|
+
* @returns Model pricing or null if not found
|
|
1971
|
+
*/
|
|
1972
|
+
getModelPricing(provider: string, model: string): Promise<ModelPricing | null>;
|
|
1973
|
+
/**
|
|
1974
|
+
* Force refresh the pricing cache
|
|
1975
|
+
*/
|
|
1976
|
+
refreshCache(): Promise<void>;
|
|
1977
|
+
/**
|
|
1978
|
+
* Check if the provider is ready (cache is populated)
|
|
1979
|
+
*/
|
|
1980
|
+
isReady(): boolean;
|
|
1981
|
+
}
|
|
1982
|
+
//#endregion
|
|
1983
|
+
//#region src/pricing/calculator.d.ts
|
|
1984
|
+
/**
|
|
1985
|
+
* Calculate the cost of an LLM request in micro-dollars
|
|
1986
|
+
*
|
|
1987
|
+
* Micro-dollars are used to avoid floating-point precision issues:
|
|
1988
|
+
* - 1 dollar = 1,000,000 micro-dollars
|
|
1989
|
+
* - $0.001 = 1,000 micro-dollars
|
|
1990
|
+
* - $0.000001 = 1 micro-dollar
|
|
1991
|
+
*
|
|
1992
|
+
* @param usage - Token usage data from the LLM response
|
|
1993
|
+
* @param pricing - Model pricing information
|
|
1994
|
+
* @returns Cost breakdown in micro-dollars
|
|
1995
|
+
*
|
|
1996
|
+
* @example
|
|
1997
|
+
* ```typescript
|
|
1998
|
+
* const usage = { promptTokens: 1000, completionTokens: 500 };
|
|
1999
|
+
* const pricing = { inputCostPer1M: 2.5, outputCostPer1M: 10.0 };
|
|
2000
|
+
* const cost = calculateCost(usage, pricing);
|
|
2001
|
+
* // cost = { inputCost: 2500, outputCost: 5000, totalCost: 7500 }
|
|
2002
|
+
* // In dollars: $0.0025 input + $0.005 output = $0.0075 total
|
|
2003
|
+
* ```
|
|
2004
|
+
*/
|
|
2005
|
+
declare function calculateCost(usage: UsageData, pricing: ModelPricing): CostResult;
|
|
2006
|
+
/**
|
|
2007
|
+
* Calculate cache-aware cost of an LLM request in micro-dollars.
|
|
2008
|
+
*
|
|
2009
|
+
* Splits input tokens into uncached, cache-read, and cache-creation buckets,
|
|
2010
|
+
* each priced at different rates. Falls back to provider-specific multipliers
|
|
2011
|
+
* when models.dev doesn't provide cache pricing.
|
|
2012
|
+
*
|
|
2013
|
+
* @param usage - Token usage data (with cachedTokens and cacheCreationTokens)
|
|
2014
|
+
* @param pricing - Model pricing (may include cacheReadCostPer1M / cacheWriteCostPer1M)
|
|
2015
|
+
* @param provider - Provider name for fallback rate selection
|
|
2016
|
+
* @returns Cost breakdown in micro-dollars
|
|
2017
|
+
*/
|
|
2018
|
+
declare function calculateCacheAwareCost(usage: UsageData, pricing: ModelPricing, provider?: string): CostResult;
|
|
2019
|
+
/**
|
|
2020
|
+
* Convert micro-dollars to dollars
|
|
2021
|
+
*
|
|
2022
|
+
* @param microDollars - Amount in micro-dollars
|
|
2023
|
+
* @returns Amount in dollars
|
|
2024
|
+
*
|
|
2025
|
+
* @example
|
|
2026
|
+
* ```typescript
|
|
2027
|
+
* microDollarsToDollars(7500); // 0.0075
|
|
2028
|
+
* microDollarsToDollars(1000000); // 1.0
|
|
2029
|
+
* ```
|
|
2030
|
+
*/
|
|
2031
|
+
declare function microDollarsToDollars(microDollars: number): number;
|
|
2032
|
+
/**
|
|
2033
|
+
* Convert dollars to micro-dollars
|
|
2034
|
+
*
|
|
2035
|
+
* @param dollars - Amount in dollars
|
|
2036
|
+
* @returns Amount in micro-dollars (rounded to nearest integer)
|
|
2037
|
+
*
|
|
2038
|
+
* @example
|
|
2039
|
+
* ```typescript
|
|
2040
|
+
* dollarsToMicroDollars(0.0075); // 7500
|
|
2041
|
+
* dollarsToMicroDollars(1.0); // 1000000
|
|
2042
|
+
* ```
|
|
2043
|
+
*/
|
|
2044
|
+
declare function dollarsToMicroDollars(dollars: number): number;
|
|
2045
|
+
/**
|
|
2046
|
+
* Format micro-dollars as a human-readable dollar string
|
|
2047
|
+
*
|
|
2048
|
+
* @param microDollars - Amount in micro-dollars
|
|
2049
|
+
* @param decimals - Number of decimal places (default: 6)
|
|
2050
|
+
* @returns Formatted dollar string
|
|
2051
|
+
*
|
|
2052
|
+
* @example
|
|
2053
|
+
* ```typescript
|
|
2054
|
+
* formatCost(7500); // "$0.007500"
|
|
2055
|
+
* formatCost(1234567, 2); // "$1.23"
|
|
2056
|
+
* ```
|
|
2057
|
+
*/
|
|
2058
|
+
declare function formatCost(microDollars: number, decimals?: number): string;
|
|
2059
|
+
//#endregion
|
|
2060
|
+
//#region src/pricing/provider.d.ts
|
|
2061
|
+
/**
|
|
2062
|
+
* Pricing provider that fetches per-model data from the LLMOps Models API.
|
|
2063
|
+
*
|
|
2064
|
+
* Features:
|
|
2065
|
+
* - Per-model in-memory cache with configurable TTL (default 5 minutes)
|
|
2066
|
+
* - Deduplicates concurrent fetches for the same model
|
|
2067
|
+
* - Caches null results (404s) to avoid repeated lookups
|
|
2068
|
+
* - Falls back to stale cache on fetch errors
|
|
2069
|
+
*/
|
|
2070
|
+
declare class LLMOpsPricingProvider implements PricingProvider {
|
|
2071
|
+
private cache;
|
|
2072
|
+
private pendingFetches;
|
|
2073
|
+
private cacheTTL;
|
|
2074
|
+
private baseUrl;
|
|
2075
|
+
constructor(options?: {
|
|
2076
|
+
cacheTTL?: number;
|
|
2077
|
+
baseUrl?: string;
|
|
2078
|
+
});
|
|
2079
|
+
private getCacheKey;
|
|
2080
|
+
/**
|
|
2081
|
+
* Fetch pricing for a single model from the API
|
|
2082
|
+
*/
|
|
2083
|
+
private fetchModelPricing;
|
|
2084
|
+
/**
|
|
2085
|
+
* Internal: fetch with cache and deduplication for a specific provider+model
|
|
2086
|
+
*/
|
|
2087
|
+
private getCachedPricing;
|
|
2088
|
+
/**
|
|
2089
|
+
* Get pricing for a specific model.
|
|
2090
|
+
*
|
|
2091
|
+
* When the model name contains a slash (e.g. "google/gemini-2.5-flash"),
|
|
2092
|
+
* it's likely an OpenRouter model ID. If the initial provider lookup fails,
|
|
2093
|
+
* we automatically retry with "openrouter" as the provider.
|
|
2094
|
+
*/
|
|
2095
|
+
getModelPricing(provider: string, model: string): Promise<ModelPricing | null>;
|
|
2096
|
+
/**
|
|
2097
|
+
* Force refresh the pricing cache (clears all cached entries)
|
|
2098
|
+
*/
|
|
2099
|
+
refreshCache(): Promise<void>;
|
|
2100
|
+
/**
|
|
2101
|
+
* Always ready — no bulk pre-fetch needed
|
|
2102
|
+
*/
|
|
2103
|
+
isReady(): boolean;
|
|
2104
|
+
/**
|
|
2105
|
+
* Get the number of cached models (for debugging)
|
|
2106
|
+
*/
|
|
2107
|
+
getCacheSize(): number;
|
|
2108
|
+
}
|
|
2109
|
+
/**
|
|
2110
|
+
* Get the default pricing provider instance
|
|
2111
|
+
*/
|
|
2112
|
+
declare function getDefaultPricingProvider(): LLMOpsPricingProvider;
|
|
2113
|
+
//#endregion
|
|
2114
|
+
//#region src/telemetry/postgres.d.ts
|
|
2115
|
+
declare const insertLLMRequestSchema: z$1.ZodObject<{
|
|
2116
|
+
requestId: z$1.ZodString;
|
|
2117
|
+
configId: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodString>>;
|
|
2118
|
+
variantId: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodString>>;
|
|
2119
|
+
environmentId: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodString>>;
|
|
2120
|
+
providerConfigId: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodString>>;
|
|
2121
|
+
provider: z$1.ZodString;
|
|
2122
|
+
model: z$1.ZodString;
|
|
2123
|
+
promptTokens: z$1.ZodDefault<z$1.ZodNumber>;
|
|
2124
|
+
completionTokens: z$1.ZodDefault<z$1.ZodNumber>;
|
|
2125
|
+
totalTokens: z$1.ZodDefault<z$1.ZodNumber>;
|
|
2126
|
+
cachedTokens: z$1.ZodDefault<z$1.ZodNumber>;
|
|
2127
|
+
cacheCreationTokens: z$1.ZodDefault<z$1.ZodNumber>;
|
|
2128
|
+
cost: z$1.ZodDefault<z$1.ZodNumber>;
|
|
2129
|
+
cacheSavings: z$1.ZodDefault<z$1.ZodNumber>;
|
|
2130
|
+
inputCost: z$1.ZodDefault<z$1.ZodNumber>;
|
|
2131
|
+
outputCost: z$1.ZodDefault<z$1.ZodNumber>;
|
|
2132
|
+
endpoint: z$1.ZodString;
|
|
2133
|
+
statusCode: z$1.ZodNumber;
|
|
2134
|
+
latencyMs: z$1.ZodDefault<z$1.ZodNumber>;
|
|
2135
|
+
isStreaming: z$1.ZodDefault<z$1.ZodBoolean>;
|
|
2136
|
+
userId: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodString>>;
|
|
2137
|
+
tags: z$1.ZodDefault<z$1.ZodRecord<z$1.ZodString, z$1.ZodString>>;
|
|
2138
|
+
guardrailResults: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodObject<{
|
|
2139
|
+
results: z$1.ZodArray<z$1.ZodObject<{
|
|
2140
|
+
checkId: z$1.ZodString;
|
|
2141
|
+
functionId: z$1.ZodString;
|
|
2142
|
+
hookType: z$1.ZodEnum<{
|
|
2143
|
+
beforeRequestHook: "beforeRequestHook";
|
|
2144
|
+
afterRequestHook: "afterRequestHook";
|
|
2145
|
+
}>;
|
|
2146
|
+
verdict: z$1.ZodBoolean;
|
|
2147
|
+
latencyMs: z$1.ZodNumber;
|
|
2148
|
+
}, z$1.core.$strip>>;
|
|
2149
|
+
action: z$1.ZodEnum<{
|
|
2150
|
+
allowed: "allowed";
|
|
2151
|
+
blocked: "blocked";
|
|
2152
|
+
logged: "logged";
|
|
2153
|
+
}>;
|
|
2154
|
+
totalLatencyMs: z$1.ZodNumber;
|
|
2155
|
+
}, z$1.core.$strip>>>;
|
|
2156
|
+
traceId: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodString>>;
|
|
2157
|
+
spanId: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodString>>;
|
|
2158
|
+
parentSpanId: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodString>>;
|
|
2159
|
+
sessionId: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodString>>;
|
|
2160
|
+
}, z$1.core.$strip>;
|
|
2161
|
+
type LLMRequestInsert = z$1.infer<typeof insertLLMRequestSchema>;
|
|
2162
|
+
declare const listRequestsSchema: z$1.ZodObject<{
|
|
2163
|
+
limit: z$1.ZodDefault<z$1.ZodNumber>;
|
|
2164
|
+
offset: z$1.ZodDefault<z$1.ZodNumber>;
|
|
2165
|
+
configId: z$1.ZodOptional<z$1.ZodString>;
|
|
2166
|
+
variantId: z$1.ZodOptional<z$1.ZodString>;
|
|
2167
|
+
environmentId: z$1.ZodOptional<z$1.ZodString>;
|
|
2168
|
+
providerConfigId: z$1.ZodOptional<z$1.ZodString>;
|
|
2169
|
+
provider: z$1.ZodOptional<z$1.ZodString>;
|
|
2170
|
+
model: z$1.ZodOptional<z$1.ZodString>;
|
|
2171
|
+
startDate: z$1.ZodOptional<z$1.ZodDate>;
|
|
2172
|
+
endDate: z$1.ZodOptional<z$1.ZodDate>;
|
|
2173
|
+
tags: z$1.ZodOptional<z$1.ZodRecord<z$1.ZodString, z$1.ZodArray<z$1.ZodString>>>;
|
|
2174
|
+
}, z$1.core.$strip>;
|
|
2175
|
+
declare const dateRangeSchema: z$1.ZodObject<{
|
|
2176
|
+
startDate: z$1.ZodDate;
|
|
2177
|
+
endDate: z$1.ZodDate;
|
|
2178
|
+
configId: z$1.ZodOptional<z$1.ZodString>;
|
|
2179
|
+
variantId: z$1.ZodOptional<z$1.ZodString>;
|
|
2180
|
+
environmentId: z$1.ZodOptional<z$1.ZodString>;
|
|
2181
|
+
tags: z$1.ZodOptional<z$1.ZodRecord<z$1.ZodString, z$1.ZodArray<z$1.ZodString>>>;
|
|
2182
|
+
}, z$1.core.$strip>;
|
|
2183
|
+
declare const COST_SUMMARY_GROUP_BY: readonly ["day", "hour", "model", "provider", "endpoint", "tags"];
|
|
2184
|
+
type CostSummaryGroupBy = (typeof COST_SUMMARY_GROUP_BY)[number];
|
|
2185
|
+
declare const costSummarySchema: z$1.ZodObject<{
|
|
2186
|
+
startDate: z$1.ZodDate;
|
|
2187
|
+
endDate: z$1.ZodDate;
|
|
2188
|
+
configId: z$1.ZodOptional<z$1.ZodString>;
|
|
2189
|
+
variantId: z$1.ZodOptional<z$1.ZodString>;
|
|
2190
|
+
environmentId: z$1.ZodOptional<z$1.ZodString>;
|
|
2191
|
+
tags: z$1.ZodOptional<z$1.ZodRecord<z$1.ZodString, z$1.ZodArray<z$1.ZodString>>>;
|
|
2192
|
+
groupBy: z$1.ZodOptional<z$1.ZodEnum<{
|
|
2193
|
+
provider: "provider";
|
|
2194
|
+
model: "model";
|
|
2195
|
+
endpoint: "endpoint";
|
|
2196
|
+
tags: "tags";
|
|
2197
|
+
day: "day";
|
|
2198
|
+
hour: "hour";
|
|
2199
|
+
}>>;
|
|
2200
|
+
tagKeys: z$1.ZodOptional<z$1.ZodArray<z$1.ZodString>>;
|
|
2201
|
+
}, z$1.core.$strip>;
|
|
2202
|
+
declare const upsertTraceSchema: z$1.ZodObject<{
|
|
2203
|
+
traceId: z$1.ZodString;
|
|
2204
|
+
name: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodString>>;
|
|
2205
|
+
sessionId: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodString>>;
|
|
2206
|
+
userId: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodString>>;
|
|
2207
|
+
status: z$1.ZodDefault<z$1.ZodEnum<{
|
|
2208
|
+
error: "error";
|
|
2209
|
+
unset: "unset";
|
|
2210
|
+
ok: "ok";
|
|
2211
|
+
}>>;
|
|
2212
|
+
startTime: z$1.ZodDate;
|
|
2213
|
+
endTime: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodDate>>;
|
|
2214
|
+
durationMs: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodNumber>>;
|
|
2215
|
+
spanCount: z$1.ZodDefault<z$1.ZodNumber>;
|
|
2216
|
+
totalInputTokens: z$1.ZodDefault<z$1.ZodNumber>;
|
|
2217
|
+
totalOutputTokens: z$1.ZodDefault<z$1.ZodNumber>;
|
|
2218
|
+
totalTokens: z$1.ZodDefault<z$1.ZodNumber>;
|
|
2219
|
+
totalCost: z$1.ZodDefault<z$1.ZodNumber>;
|
|
2220
|
+
tags: z$1.ZodDefault<z$1.ZodRecord<z$1.ZodString, z$1.ZodString>>;
|
|
2221
|
+
metadata: z$1.ZodDefault<z$1.ZodRecord<z$1.ZodString, z$1.ZodUnknown>>;
|
|
2078
2222
|
}, z$1.core.$strip>;
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2223
|
+
type TraceUpsert = z$1.infer<typeof upsertTraceSchema>;
|
|
2224
|
+
declare const insertSpanSchema: z$1.ZodObject<{
|
|
2225
|
+
traceId: z$1.ZodString;
|
|
2226
|
+
spanId: z$1.ZodString;
|
|
2227
|
+
parentSpanId: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodString>>;
|
|
2228
|
+
name: z$1.ZodString;
|
|
2229
|
+
kind: z$1.ZodDefault<z$1.ZodNumber>;
|
|
2230
|
+
status: z$1.ZodDefault<z$1.ZodNumber>;
|
|
2231
|
+
statusMessage: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodString>>;
|
|
2232
|
+
startTime: z$1.ZodDate;
|
|
2233
|
+
endTime: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodDate>>;
|
|
2234
|
+
durationMs: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodNumber>>;
|
|
2235
|
+
provider: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodString>>;
|
|
2236
|
+
model: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodString>>;
|
|
2237
|
+
promptTokens: z$1.ZodDefault<z$1.ZodNumber>;
|
|
2238
|
+
completionTokens: z$1.ZodDefault<z$1.ZodNumber>;
|
|
2239
|
+
totalTokens: z$1.ZodDefault<z$1.ZodNumber>;
|
|
2240
|
+
cost: z$1.ZodDefault<z$1.ZodNumber>;
|
|
2241
|
+
configId: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodString>>;
|
|
2242
|
+
variantId: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodString>>;
|
|
2243
|
+
environmentId: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodString>>;
|
|
2244
|
+
providerConfigId: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodString>>;
|
|
2245
|
+
requestId: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodString>>;
|
|
2246
|
+
source: z$1.ZodDefault<z$1.ZodEnum<{
|
|
2247
|
+
gateway: "gateway";
|
|
2248
|
+
otlp: "otlp";
|
|
2249
|
+
langsmith: "langsmith";
|
|
2087
2250
|
}>>;
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2251
|
+
input: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodUnknown>>;
|
|
2252
|
+
output: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodUnknown>>;
|
|
2253
|
+
attributes: z$1.ZodDefault<z$1.ZodRecord<z$1.ZodString, z$1.ZodUnknown>>;
|
|
2091
2254
|
}, z$1.core.$strip>;
|
|
2092
|
-
|
|
2093
|
-
|
|
2255
|
+
type SpanInsert = z$1.infer<typeof insertSpanSchema>;
|
|
2256
|
+
declare const insertSpanEventSchema: z$1.ZodObject<{
|
|
2257
|
+
traceId: z$1.ZodString;
|
|
2258
|
+
spanId: z$1.ZodString;
|
|
2259
|
+
name: z$1.ZodString;
|
|
2260
|
+
timestamp: z$1.ZodDate;
|
|
2261
|
+
attributes: z$1.ZodDefault<z$1.ZodRecord<z$1.ZodString, z$1.ZodUnknown>>;
|
|
2094
2262
|
}, z$1.core.$strip>;
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
limit: z$1.
|
|
2098
|
-
offset: z$1.
|
|
2263
|
+
type SpanEventInsert = z$1.infer<typeof insertSpanEventSchema>;
|
|
2264
|
+
declare const listTracesSchema: z$1.ZodObject<{
|
|
2265
|
+
limit: z$1.ZodDefault<z$1.ZodNumber>;
|
|
2266
|
+
offset: z$1.ZodDefault<z$1.ZodNumber>;
|
|
2267
|
+
sessionId: z$1.ZodOptional<z$1.ZodString>;
|
|
2268
|
+
userId: z$1.ZodOptional<z$1.ZodString>;
|
|
2269
|
+
status: z$1.ZodOptional<z$1.ZodEnum<{
|
|
2270
|
+
error: "error";
|
|
2271
|
+
unset: "unset";
|
|
2272
|
+
ok: "ok";
|
|
2273
|
+
}>>;
|
|
2274
|
+
name: z$1.ZodOptional<z$1.ZodString>;
|
|
2275
|
+
startDate: z$1.ZodOptional<z$1.ZodDate>;
|
|
2276
|
+
endDate: z$1.ZodOptional<z$1.ZodDate>;
|
|
2277
|
+
tags: z$1.ZodOptional<z$1.ZodRecord<z$1.ZodString, z$1.ZodArray<z$1.ZodString>>>;
|
|
2099
2278
|
}, z$1.core.$strip>;
|
|
2100
|
-
declare const
|
|
2101
|
-
|
|
2279
|
+
declare const traceStatsSchema: z$1.ZodObject<{
|
|
2280
|
+
startDate: z$1.ZodDate;
|
|
2281
|
+
endDate: z$1.ZodDate;
|
|
2282
|
+
sessionId: z$1.ZodOptional<z$1.ZodString>;
|
|
2283
|
+
userId: z$1.ZodOptional<z$1.ZodString>;
|
|
2102
2284
|
}, z$1.core.$strip>;
|
|
2103
|
-
declare
|
|
2104
|
-
|
|
2285
|
+
declare function createLLMRequestsStore(db: Kysely<Database>): {
|
|
2286
|
+
batchInsertRequests: (requests: LLMRequestInsert[]) => Promise<{
|
|
2287
|
+
count: number;
|
|
2288
|
+
}>;
|
|
2289
|
+
insertRequest: (request: LLMRequestInsert) => Promise<{
|
|
2105
2290
|
id: string;
|
|
2106
2291
|
createdAt: Date;
|
|
2107
2292
|
updatedAt: Date;
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2293
|
+
variantId: string | null;
|
|
2294
|
+
provider: string;
|
|
2295
|
+
environmentId: string | null;
|
|
2296
|
+
configId: string | null;
|
|
2297
|
+
providerConfigId: string | null;
|
|
2298
|
+
latencyMs: number;
|
|
2299
|
+
promptTokens: number;
|
|
2300
|
+
completionTokens: number;
|
|
2301
|
+
totalTokens: number;
|
|
2302
|
+
cost: number;
|
|
2303
|
+
requestId: string;
|
|
2304
|
+
model: string;
|
|
2305
|
+
cachedTokens: number;
|
|
2306
|
+
cacheCreationTokens: number;
|
|
2307
|
+
cacheSavings: number;
|
|
2308
|
+
inputCost: number;
|
|
2309
|
+
outputCost: number;
|
|
2310
|
+
endpoint: string;
|
|
2311
|
+
statusCode: number;
|
|
2312
|
+
isStreaming: boolean;
|
|
2313
|
+
userId: string | null;
|
|
2314
|
+
tags: Record<string, string>;
|
|
2315
|
+
guardrailResults: {
|
|
2316
|
+
results: {
|
|
2317
|
+
checkId: string;
|
|
2318
|
+
functionId: string;
|
|
2319
|
+
hookType: "beforeRequestHook" | "afterRequestHook";
|
|
2320
|
+
verdict: boolean;
|
|
2321
|
+
latencyMs: number;
|
|
2322
|
+
}[];
|
|
2323
|
+
action: "allowed" | "blocked" | "logged";
|
|
2324
|
+
totalLatencyMs: number;
|
|
2325
|
+
} | null;
|
|
2326
|
+
traceId: string | null;
|
|
2327
|
+
spanId: string | null;
|
|
2328
|
+
parentSpanId: string | null;
|
|
2329
|
+
sessionId: string | null;
|
|
2116
2330
|
} | undefined>;
|
|
2117
|
-
|
|
2331
|
+
listRequests: (params?: z$1.infer<typeof listRequestsSchema>) => Promise<{
|
|
2332
|
+
data: {
|
|
2333
|
+
id: string;
|
|
2334
|
+
createdAt: Date;
|
|
2335
|
+
updatedAt: Date;
|
|
2336
|
+
variantId: string | null;
|
|
2337
|
+
provider: string;
|
|
2338
|
+
environmentId: string | null;
|
|
2339
|
+
configId: string | null;
|
|
2340
|
+
providerConfigId: string | null;
|
|
2341
|
+
latencyMs: number;
|
|
2342
|
+
promptTokens: number;
|
|
2343
|
+
completionTokens: number;
|
|
2344
|
+
totalTokens: number;
|
|
2345
|
+
cost: number;
|
|
2346
|
+
requestId: string;
|
|
2347
|
+
model: string;
|
|
2348
|
+
cachedTokens: number;
|
|
2349
|
+
cacheCreationTokens: number;
|
|
2350
|
+
cacheSavings: number;
|
|
2351
|
+
inputCost: number;
|
|
2352
|
+
outputCost: number;
|
|
2353
|
+
endpoint: string;
|
|
2354
|
+
statusCode: number;
|
|
2355
|
+
isStreaming: boolean;
|
|
2356
|
+
userId: string | null;
|
|
2357
|
+
tags: Record<string, string>;
|
|
2358
|
+
guardrailResults: {
|
|
2359
|
+
results: {
|
|
2360
|
+
checkId: string;
|
|
2361
|
+
functionId: string;
|
|
2362
|
+
hookType: "beforeRequestHook" | "afterRequestHook";
|
|
2363
|
+
verdict: boolean;
|
|
2364
|
+
latencyMs: number;
|
|
2365
|
+
}[];
|
|
2366
|
+
action: "allowed" | "blocked" | "logged";
|
|
2367
|
+
totalLatencyMs: number;
|
|
2368
|
+
} | null;
|
|
2369
|
+
traceId: string | null;
|
|
2370
|
+
spanId: string | null;
|
|
2371
|
+
parentSpanId: string | null;
|
|
2372
|
+
sessionId: string | null;
|
|
2373
|
+
}[];
|
|
2374
|
+
total: number;
|
|
2375
|
+
limit: number;
|
|
2376
|
+
offset: number;
|
|
2377
|
+
}>;
|
|
2378
|
+
getRequestByRequestId: (requestId: string) => Promise<{
|
|
2118
2379
|
id: string;
|
|
2119
2380
|
createdAt: Date;
|
|
2120
2381
|
updatedAt: Date;
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2382
|
+
variantId: string | null;
|
|
2383
|
+
provider: string;
|
|
2384
|
+
environmentId: string | null;
|
|
2385
|
+
configId: string | null;
|
|
2386
|
+
providerConfigId: string | null;
|
|
2387
|
+
latencyMs: number;
|
|
2388
|
+
promptTokens: number;
|
|
2389
|
+
completionTokens: number;
|
|
2390
|
+
totalTokens: number;
|
|
2391
|
+
cost: number;
|
|
2392
|
+
requestId: string;
|
|
2393
|
+
model: string;
|
|
2394
|
+
cachedTokens: number;
|
|
2395
|
+
cacheCreationTokens: number;
|
|
2396
|
+
cacheSavings: number;
|
|
2397
|
+
inputCost: number;
|
|
2398
|
+
outputCost: number;
|
|
2399
|
+
endpoint: string;
|
|
2400
|
+
statusCode: number;
|
|
2401
|
+
isStreaming: boolean;
|
|
2402
|
+
userId: string | null;
|
|
2403
|
+
tags: Record<string, string>;
|
|
2404
|
+
guardrailResults: {
|
|
2405
|
+
results: {
|
|
2406
|
+
checkId: string;
|
|
2407
|
+
functionId: string;
|
|
2408
|
+
hookType: "beforeRequestHook" | "afterRequestHook";
|
|
2409
|
+
verdict: boolean;
|
|
2410
|
+
latencyMs: number;
|
|
2411
|
+
}[];
|
|
2412
|
+
action: "allowed" | "blocked" | "logged";
|
|
2413
|
+
totalLatencyMs: number;
|
|
2414
|
+
} | null;
|
|
2415
|
+
traceId: string | null;
|
|
2416
|
+
spanId: string | null;
|
|
2417
|
+
parentSpanId: string | null;
|
|
2418
|
+
sessionId: string | null;
|
|
2129
2419
|
} | undefined>;
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
totalRecords: number;
|
|
2141
|
-
completedRecords: number;
|
|
2420
|
+
getTotalCost: (params: z$1.infer<typeof dateRangeSchema>) => Promise<{
|
|
2421
|
+
totalCost: number;
|
|
2422
|
+
totalInputCost: number;
|
|
2423
|
+
totalOutputCost: number;
|
|
2424
|
+
totalPromptTokens: number;
|
|
2425
|
+
totalCompletionTokens: number;
|
|
2426
|
+
totalTokens: number;
|
|
2427
|
+
totalCachedTokens: number;
|
|
2428
|
+
totalCacheSavings: number;
|
|
2429
|
+
requestCount: number;
|
|
2142
2430
|
} | undefined>;
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
completedAt: Date | null;
|
|
2153
|
-
totalRecords: number;
|
|
2154
|
-
completedRecords: number;
|
|
2431
|
+
getCostByModel: (params: z$1.infer<typeof dateRangeSchema>) => Promise<{
|
|
2432
|
+
provider: string;
|
|
2433
|
+
model: string;
|
|
2434
|
+
totalCost: number;
|
|
2435
|
+
totalInputCost: number;
|
|
2436
|
+
totalOutputCost: number;
|
|
2437
|
+
totalTokens: number;
|
|
2438
|
+
requestCount: number;
|
|
2439
|
+
avgLatencyMs: number;
|
|
2155
2440
|
}[]>;
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2441
|
+
getCostByProvider: (params: z$1.infer<typeof dateRangeSchema>) => Promise<{
|
|
2442
|
+
provider: string;
|
|
2443
|
+
totalCost: number;
|
|
2444
|
+
totalInputCost: number;
|
|
2445
|
+
totalOutputCost: number;
|
|
2446
|
+
totalTokens: number;
|
|
2447
|
+
requestCount: number;
|
|
2448
|
+
avgLatencyMs: number;
|
|
2449
|
+
}[]>;
|
|
2450
|
+
getDailyCosts: (params: z$1.infer<typeof dateRangeSchema>) => Promise<{
|
|
2451
|
+
totalCost: number;
|
|
2452
|
+
totalInputCost: number;
|
|
2453
|
+
totalOutputCost: number;
|
|
2454
|
+
totalTokens: number;
|
|
2455
|
+
requestCount: number;
|
|
2456
|
+
date: string;
|
|
2457
|
+
}[]>;
|
|
2458
|
+
getCostSummary: (params: z$1.infer<typeof costSummarySchema>) => Promise<{
|
|
2459
|
+
totalCost: number;
|
|
2460
|
+
requestCount: number;
|
|
2461
|
+
groupKey: string;
|
|
2462
|
+
}[]>;
|
|
2463
|
+
getRequestStats: (params: z$1.infer<typeof dateRangeSchema>) => Promise<{
|
|
2464
|
+
avgLatencyMs: number;
|
|
2465
|
+
totalRequests: number;
|
|
2466
|
+
successfulRequests: number;
|
|
2467
|
+
failedRequests: number;
|
|
2468
|
+
streamingRequests: number;
|
|
2469
|
+
maxLatencyMs: number;
|
|
2470
|
+
minLatencyMs: number;
|
|
2168
2471
|
} | undefined>;
|
|
2169
|
-
|
|
2472
|
+
getDistinctTags: () => Promise<{
|
|
2473
|
+
key: string;
|
|
2474
|
+
value: string;
|
|
2475
|
+
}[]>;
|
|
2170
2476
|
};
|
|
2171
|
-
|
|
2172
|
-
//#region src/datalayer/traces.d.ts
|
|
2173
|
-
/**
|
|
2174
|
-
* Schema for upserting a trace
|
|
2175
|
-
*/
|
|
2176
|
-
declare const upsertTraceSchema: z$1.ZodObject<{
|
|
2177
|
-
traceId: z$1.ZodString;
|
|
2178
|
-
name: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodString>>;
|
|
2179
|
-
sessionId: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodString>>;
|
|
2180
|
-
userId: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodString>>;
|
|
2181
|
-
status: z$1.ZodDefault<z$1.ZodEnum<{
|
|
2182
|
-
error: "error";
|
|
2183
|
-
unset: "unset";
|
|
2184
|
-
ok: "ok";
|
|
2185
|
-
}>>;
|
|
2186
|
-
startTime: z$1.ZodDate;
|
|
2187
|
-
endTime: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodDate>>;
|
|
2188
|
-
durationMs: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodNumber>>;
|
|
2189
|
-
spanCount: z$1.ZodDefault<z$1.ZodNumber>;
|
|
2190
|
-
totalInputTokens: z$1.ZodDefault<z$1.ZodNumber>;
|
|
2191
|
-
totalOutputTokens: z$1.ZodDefault<z$1.ZodNumber>;
|
|
2192
|
-
totalTokens: z$1.ZodDefault<z$1.ZodNumber>;
|
|
2193
|
-
totalCost: z$1.ZodDefault<z$1.ZodNumber>;
|
|
2194
|
-
tags: z$1.ZodDefault<z$1.ZodRecord<z$1.ZodString, z$1.ZodString>>;
|
|
2195
|
-
metadata: z$1.ZodDefault<z$1.ZodRecord<z$1.ZodString, z$1.ZodUnknown>>;
|
|
2196
|
-
}, z$1.core.$strip>;
|
|
2197
|
-
type TraceUpsert = z$1.infer<typeof upsertTraceSchema>;
|
|
2198
|
-
/**
|
|
2199
|
-
* Schema for inserting spans
|
|
2200
|
-
*/
|
|
2201
|
-
declare const insertSpanSchema: z$1.ZodObject<{
|
|
2202
|
-
traceId: z$1.ZodString;
|
|
2203
|
-
spanId: z$1.ZodString;
|
|
2204
|
-
parentSpanId: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodString>>;
|
|
2205
|
-
name: z$1.ZodString;
|
|
2206
|
-
kind: z$1.ZodDefault<z$1.ZodNumber>;
|
|
2207
|
-
status: z$1.ZodDefault<z$1.ZodNumber>;
|
|
2208
|
-
statusMessage: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodString>>;
|
|
2209
|
-
startTime: z$1.ZodDate;
|
|
2210
|
-
endTime: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodDate>>;
|
|
2211
|
-
durationMs: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodNumber>>;
|
|
2212
|
-
provider: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodString>>;
|
|
2213
|
-
model: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodString>>;
|
|
2214
|
-
promptTokens: z$1.ZodDefault<z$1.ZodNumber>;
|
|
2215
|
-
completionTokens: z$1.ZodDefault<z$1.ZodNumber>;
|
|
2216
|
-
totalTokens: z$1.ZodDefault<z$1.ZodNumber>;
|
|
2217
|
-
cost: z$1.ZodDefault<z$1.ZodNumber>;
|
|
2218
|
-
configId: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodString>>;
|
|
2219
|
-
variantId: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodString>>;
|
|
2220
|
-
environmentId: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodString>>;
|
|
2221
|
-
providerConfigId: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodString>>;
|
|
2222
|
-
requestId: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodString>>;
|
|
2223
|
-
source: z$1.ZodDefault<z$1.ZodEnum<{
|
|
2224
|
-
gateway: "gateway";
|
|
2225
|
-
otlp: "otlp";
|
|
2226
|
-
langsmith: "langsmith";
|
|
2227
|
-
}>>;
|
|
2228
|
-
input: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodUnknown>>;
|
|
2229
|
-
output: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodUnknown>>;
|
|
2230
|
-
attributes: z$1.ZodDefault<z$1.ZodRecord<z$1.ZodString, z$1.ZodUnknown>>;
|
|
2231
|
-
}, z$1.core.$strip>;
|
|
2232
|
-
type SpanInsert = z$1.infer<typeof insertSpanSchema>;
|
|
2233
|
-
/**
|
|
2234
|
-
* Schema for inserting span events
|
|
2235
|
-
*/
|
|
2236
|
-
declare const insertSpanEventSchema: z$1.ZodObject<{
|
|
2237
|
-
traceId: z$1.ZodString;
|
|
2238
|
-
spanId: z$1.ZodString;
|
|
2239
|
-
name: z$1.ZodString;
|
|
2240
|
-
timestamp: z$1.ZodDate;
|
|
2241
|
-
attributes: z$1.ZodDefault<z$1.ZodRecord<z$1.ZodString, z$1.ZodUnknown>>;
|
|
2242
|
-
}, z$1.core.$strip>;
|
|
2243
|
-
type SpanEventInsert = z$1.infer<typeof insertSpanEventSchema>;
|
|
2244
|
-
/**
|
|
2245
|
-
* Schema for listing traces
|
|
2246
|
-
*/
|
|
2247
|
-
declare const listTracesSchema: z$1.ZodObject<{
|
|
2248
|
-
limit: z$1.ZodDefault<z$1.ZodNumber>;
|
|
2249
|
-
offset: z$1.ZodDefault<z$1.ZodNumber>;
|
|
2250
|
-
sessionId: z$1.ZodOptional<z$1.ZodString>;
|
|
2251
|
-
userId: z$1.ZodOptional<z$1.ZodString>;
|
|
2252
|
-
status: z$1.ZodOptional<z$1.ZodEnum<{
|
|
2253
|
-
error: "error";
|
|
2254
|
-
unset: "unset";
|
|
2255
|
-
ok: "ok";
|
|
2256
|
-
}>>;
|
|
2257
|
-
name: z$1.ZodOptional<z$1.ZodString>;
|
|
2258
|
-
startDate: z$1.ZodOptional<z$1.ZodDate>;
|
|
2259
|
-
endDate: z$1.ZodOptional<z$1.ZodDate>;
|
|
2260
|
-
tags: z$1.ZodOptional<z$1.ZodRecord<z$1.ZodString, z$1.ZodArray<z$1.ZodString>>>;
|
|
2261
|
-
}, z$1.core.$strip>;
|
|
2262
|
-
/**
|
|
2263
|
-
* Schema for trace stats query
|
|
2264
|
-
*/
|
|
2265
|
-
declare const traceStatsSchema: z$1.ZodObject<{
|
|
2266
|
-
startDate: z$1.ZodDate;
|
|
2267
|
-
endDate: z$1.ZodDate;
|
|
2268
|
-
sessionId: z$1.ZodOptional<z$1.ZodString>;
|
|
2269
|
-
userId: z$1.ZodOptional<z$1.ZodString>;
|
|
2270
|
-
}, z$1.core.$strip>;
|
|
2271
|
-
declare const createTracesDataLayer: (db: Kysely<Database>) => {
|
|
2272
|
-
/**
|
|
2273
|
-
* Upsert a trace — insert or update aggregates on conflict
|
|
2274
|
-
*/
|
|
2477
|
+
declare function createTracesStore(db: Kysely<Database>): {
|
|
2275
2478
|
upsertTrace: (data: TraceUpsert) => Promise<void>;
|
|
2276
|
-
/**
|
|
2277
|
-
* Batch insert spans
|
|
2278
|
-
*/
|
|
2279
2479
|
batchInsertSpans: (spans: SpanInsert[]) => Promise<{
|
|
2280
2480
|
count: number;
|
|
2281
2481
|
}>;
|
|
2282
|
-
/**
|
|
2283
|
-
* Batch insert span events
|
|
2284
|
-
*/
|
|
2285
2482
|
batchInsertSpanEvents: (events: SpanEventInsert[]) => Promise<{
|
|
2286
2483
|
count: number;
|
|
2287
2484
|
}>;
|
|
2288
|
-
/**
|
|
2289
|
-
* List traces with filtering and pagination
|
|
2290
|
-
*/
|
|
2291
2485
|
listTraces: (params?: z$1.infer<typeof listTracesSchema>) => Promise<{
|
|
2292
2486
|
data: {
|
|
2293
2487
|
name: string | null;
|
|
@@ -2313,9 +2507,6 @@ declare const createTracesDataLayer: (db: Kysely<Database>) => {
|
|
|
2313
2507
|
limit: number;
|
|
2314
2508
|
offset: number;
|
|
2315
2509
|
}>;
|
|
2316
|
-
/**
|
|
2317
|
-
* Get a single trace with all its spans and events
|
|
2318
|
-
*/
|
|
2319
2510
|
getTraceWithSpans: (traceId: string) => Promise<{
|
|
2320
2511
|
trace: {
|
|
2321
2512
|
name: string | null;
|
|
@@ -2361,323 +2552,32 @@ declare const createTracesDataLayer: (db: Kysely<Database>) => {
|
|
|
2361
2552
|
parentSpanId: string | null;
|
|
2362
2553
|
startTime: Date;
|
|
2363
2554
|
endTime: Date | null;
|
|
2364
|
-
durationMs: number | null;
|
|
2365
|
-
kind: number;
|
|
2366
|
-
statusMessage: string | null;
|
|
2367
|
-
source: string;
|
|
2368
|
-
attributes: Record<string, unknown>;
|
|
2369
|
-
}[];
|
|
2370
|
-
events: {
|
|
2371
|
-
name: string;
|
|
2372
|
-
id: string;
|
|
2373
|
-
createdAt: Date;
|
|
2374
|
-
traceId: string;
|
|
2375
|
-
spanId: string;
|
|
2376
|
-
attributes: Record<string, unknown>;
|
|
2377
|
-
timestamp: Date;
|
|
2378
|
-
}[];
|
|
2379
|
-
} | undefined>;
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
avgDurationMs: number;
|
|
2388
|
-
errorCount: number;
|
|
2389
|
-
totalSpans: number;
|
|
2390
|
-
} | undefined>;
|
|
2391
|
-
};
|
|
2392
|
-
//#endregion
|
|
2393
|
-
//#region src/datalayer/workspaceSettings.d.ts
|
|
2394
|
-
declare const updateWorkspaceSettings: z$1.ZodObject<{
|
|
2395
|
-
name: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodString>>;
|
|
2396
|
-
setupComplete: z$1.ZodOptional<z$1.ZodBoolean>;
|
|
2397
|
-
superAdminId: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodString>>;
|
|
2398
|
-
}, z$1.core.$strip>;
|
|
2399
|
-
declare const createWorkspaceSettingsDataLayer: (db: Kysely<Database>) => {
|
|
2400
|
-
/**
|
|
2401
|
-
* Get workspace settings (creates default if not exists)
|
|
2402
|
-
*/
|
|
2403
|
-
getWorkspaceSettings: () => Promise<{
|
|
2404
|
-
name: string | null;
|
|
2405
|
-
id: string;
|
|
2406
|
-
createdAt: Date;
|
|
2407
|
-
updatedAt: Date;
|
|
2408
|
-
setupComplete: boolean;
|
|
2409
|
-
superAdminId: string | null;
|
|
2410
|
-
} | undefined>;
|
|
2411
|
-
/**
|
|
2412
|
-
* Update workspace settings
|
|
2413
|
-
*/
|
|
2414
|
-
updateWorkspaceSettings: (params: z$1.infer<typeof updateWorkspaceSettings>) => Promise<{
|
|
2415
|
-
name: string | null;
|
|
2416
|
-
id: string;
|
|
2417
|
-
createdAt: Date;
|
|
2418
|
-
updatedAt: Date;
|
|
2419
|
-
setupComplete: boolean;
|
|
2420
|
-
superAdminId: string | null;
|
|
2421
|
-
} | undefined>;
|
|
2422
|
-
/**
|
|
2423
|
-
* Get the super admin user ID
|
|
2424
|
-
*/
|
|
2425
|
-
getSuperAdminId: () => Promise<string | null>;
|
|
2426
|
-
/**
|
|
2427
|
-
* Set the super admin user ID (only if not already set)
|
|
2428
|
-
*/
|
|
2429
|
-
setSuperAdminId: (userId: string) => Promise<boolean>;
|
|
2430
|
-
/**
|
|
2431
|
-
* Check if initial setup has been completed
|
|
2432
|
-
*/
|
|
2433
|
-
isSetupComplete: () => Promise<boolean>;
|
|
2434
|
-
/**
|
|
2435
|
-
* Mark initial setup as complete
|
|
2436
|
-
*/
|
|
2437
|
-
markSetupComplete: () => Promise<{
|
|
2438
|
-
name: string | null;
|
|
2439
|
-
id: string;
|
|
2440
|
-
createdAt: Date;
|
|
2441
|
-
updatedAt: Date;
|
|
2442
|
-
setupComplete: boolean;
|
|
2443
|
-
superAdminId: string | null;
|
|
2555
|
+
durationMs: number | null;
|
|
2556
|
+
kind: number;
|
|
2557
|
+
statusMessage: string | null;
|
|
2558
|
+
source: string;
|
|
2559
|
+
attributes: Record<string, unknown>;
|
|
2560
|
+
}[];
|
|
2561
|
+
events: {
|
|
2562
|
+
name: string;
|
|
2563
|
+
id: string;
|
|
2564
|
+
createdAt: Date;
|
|
2565
|
+
traceId: string;
|
|
2566
|
+
spanId: string;
|
|
2567
|
+
attributes: Record<string, unknown>;
|
|
2568
|
+
timestamp: Date;
|
|
2569
|
+
}[];
|
|
2570
|
+
} | undefined>;
|
|
2571
|
+
getTraceStats: (params: z$1.infer<typeof traceStatsSchema>) => Promise<{
|
|
2572
|
+
totalCost: number;
|
|
2573
|
+
totalTokens: number;
|
|
2574
|
+
totalTraces: number;
|
|
2575
|
+
avgDurationMs: number;
|
|
2576
|
+
errorCount: number;
|
|
2577
|
+
totalSpans: number;
|
|
2444
2578
|
} | undefined>;
|
|
2445
2579
|
};
|
|
2446
|
-
|
|
2447
|
-
//#region src/datalayer/interface.d.ts
|
|
2448
|
-
type DatasetsDataLayer = ReturnType<typeof createDatasetsDataLayer>;
|
|
2449
|
-
type LLMRequestsDataLayer = ReturnType<typeof createLLMRequestsDataLayer>;
|
|
2450
|
-
type PlaygroundsDataLayer = ReturnType<typeof createPlaygroundDataLayer>;
|
|
2451
|
-
type PlaygroundResultsDataLayer = ReturnType<typeof createPlaygroundResultsDataLayer>;
|
|
2452
|
-
type PlaygroundRunsDataLayer = ReturnType<typeof createPlaygroundRunsDataLayer>;
|
|
2453
|
-
type TracesDataLayer = ReturnType<typeof createTracesDataLayer>;
|
|
2454
|
-
type WorkspaceSettingsDataLayer = ReturnType<typeof createWorkspaceSettingsDataLayer>;
|
|
2455
|
-
type DataLayer = DatasetsDataLayer & LLMRequestsDataLayer & PlaygroundsDataLayer & PlaygroundResultsDataLayer & PlaygroundRunsDataLayer & TracesDataLayer & WorkspaceSettingsDataLayer;
|
|
2456
|
-
//#endregion
|
|
2457
|
-
//#region src/datalayer/create.d.ts
|
|
2458
|
-
/**
|
|
2459
|
-
* Create all datalayers from a Kysely database instance.
|
|
2460
|
-
* Returns a flat object with all datalayer methods spread together.
|
|
2461
|
-
*/
|
|
2462
|
-
declare function createDataLayer(db: Kysely<Database>): DataLayer;
|
|
2463
|
-
//#endregion
|
|
2464
|
-
//#region src/pricing/types.d.ts
|
|
2465
|
-
/**
|
|
2466
|
-
* Pricing types for cost tracking
|
|
2467
|
-
*/
|
|
2468
|
-
/**
|
|
2469
|
-
* Model pricing information
|
|
2470
|
-
* All costs are in dollars per 1 million tokens
|
|
2471
|
-
*/
|
|
2472
|
-
interface ModelPricing {
|
|
2473
|
-
/** Cost per 1M input/prompt tokens in dollars */
|
|
2474
|
-
inputCostPer1M: number;
|
|
2475
|
-
/** Cost per 1M output/completion tokens in dollars */
|
|
2476
|
-
outputCostPer1M: number;
|
|
2477
|
-
/** Cost per 1M cached read tokens in dollars (optional) */
|
|
2478
|
-
cacheReadCostPer1M?: number;
|
|
2479
|
-
/** Cost per 1M cached write tokens in dollars (optional) */
|
|
2480
|
-
cacheWriteCostPer1M?: number;
|
|
2481
|
-
/** Cost per 1M reasoning tokens in dollars (optional, for models like o1) */
|
|
2482
|
-
reasoningCostPer1M?: number;
|
|
2483
|
-
}
|
|
2484
|
-
/**
|
|
2485
|
-
* Token usage data from LLM response
|
|
2486
|
-
*/
|
|
2487
|
-
interface UsageData {
|
|
2488
|
-
/** Number of tokens in the prompt/input */
|
|
2489
|
-
promptTokens: number;
|
|
2490
|
-
/** Number of tokens in the completion/output */
|
|
2491
|
-
completionTokens: number;
|
|
2492
|
-
/** Total tokens (prompt + completion) */
|
|
2493
|
-
totalTokens?: number;
|
|
2494
|
-
/** Number of cache read tokens (OpenAI cached_tokens / Anthropic cache_read_input_tokens) */
|
|
2495
|
-
cachedTokens?: number;
|
|
2496
|
-
/** Number of cache creation tokens (Anthropic cache_creation_input_tokens) */
|
|
2497
|
-
cacheCreationTokens?: number;
|
|
2498
|
-
/** Number of reasoning tokens (optional, for models like o1) */
|
|
2499
|
-
reasoningTokens?: number;
|
|
2500
|
-
}
|
|
2501
|
-
/**
|
|
2502
|
-
* Cost calculation result
|
|
2503
|
-
* All costs are in micro-dollars (1 dollar = 1,000,000 micro-dollars)
|
|
2504
|
-
* This avoids floating-point precision issues
|
|
2505
|
-
*/
|
|
2506
|
-
interface CostResult {
|
|
2507
|
-
/** Total cost in micro-dollars */
|
|
2508
|
-
totalCost: number;
|
|
2509
|
-
/** Input/prompt cost in micro-dollars */
|
|
2510
|
-
inputCost: number;
|
|
2511
|
-
/** Output/completion cost in micro-dollars */
|
|
2512
|
-
outputCost: number;
|
|
2513
|
-
/** Cost saved by cache hits in micro-dollars (negative means cache write premium exceeded savings) */
|
|
2514
|
-
cacheSavings: number;
|
|
2515
|
-
}
|
|
2516
|
-
/**
|
|
2517
|
-
* Provider for fetching model pricing data
|
|
2518
|
-
* Abstracted to allow swapping data sources (models.dev, local JSON, etc.)
|
|
2519
|
-
*/
|
|
2520
|
-
interface PricingProvider {
|
|
2521
|
-
/**
|
|
2522
|
-
* Get pricing for a specific model
|
|
2523
|
-
* @param provider - Provider name (e.g., "openai", "anthropic")
|
|
2524
|
-
* @param model - Model identifier (e.g., "gpt-4o", "claude-3-sonnet")
|
|
2525
|
-
* @returns Model pricing or null if not found
|
|
2526
|
-
*/
|
|
2527
|
-
getModelPricing(provider: string, model: string): Promise<ModelPricing | null>;
|
|
2528
|
-
/**
|
|
2529
|
-
* Force refresh the pricing cache
|
|
2530
|
-
*/
|
|
2531
|
-
refreshCache(): Promise<void>;
|
|
2532
|
-
/**
|
|
2533
|
-
* Check if the provider is ready (cache is populated)
|
|
2534
|
-
*/
|
|
2535
|
-
isReady(): boolean;
|
|
2536
|
-
}
|
|
2537
|
-
//#endregion
|
|
2538
|
-
//#region src/pricing/calculator.d.ts
|
|
2539
|
-
/**
|
|
2540
|
-
* Calculate the cost of an LLM request in micro-dollars
|
|
2541
|
-
*
|
|
2542
|
-
* Micro-dollars are used to avoid floating-point precision issues:
|
|
2543
|
-
* - 1 dollar = 1,000,000 micro-dollars
|
|
2544
|
-
* - $0.001 = 1,000 micro-dollars
|
|
2545
|
-
* - $0.000001 = 1 micro-dollar
|
|
2546
|
-
*
|
|
2547
|
-
* @param usage - Token usage data from the LLM response
|
|
2548
|
-
* @param pricing - Model pricing information
|
|
2549
|
-
* @returns Cost breakdown in micro-dollars
|
|
2550
|
-
*
|
|
2551
|
-
* @example
|
|
2552
|
-
* ```typescript
|
|
2553
|
-
* const usage = { promptTokens: 1000, completionTokens: 500 };
|
|
2554
|
-
* const pricing = { inputCostPer1M: 2.5, outputCostPer1M: 10.0 };
|
|
2555
|
-
* const cost = calculateCost(usage, pricing);
|
|
2556
|
-
* // cost = { inputCost: 2500, outputCost: 5000, totalCost: 7500 }
|
|
2557
|
-
* // In dollars: $0.0025 input + $0.005 output = $0.0075 total
|
|
2558
|
-
* ```
|
|
2559
|
-
*/
|
|
2560
|
-
declare function calculateCost(usage: UsageData, pricing: ModelPricing): CostResult;
|
|
2561
|
-
/**
|
|
2562
|
-
* Calculate cache-aware cost of an LLM request in micro-dollars.
|
|
2563
|
-
*
|
|
2564
|
-
* Splits input tokens into uncached, cache-read, and cache-creation buckets,
|
|
2565
|
-
* each priced at different rates. Falls back to provider-specific multipliers
|
|
2566
|
-
* when models.dev doesn't provide cache pricing.
|
|
2567
|
-
*
|
|
2568
|
-
* @param usage - Token usage data (with cachedTokens and cacheCreationTokens)
|
|
2569
|
-
* @param pricing - Model pricing (may include cacheReadCostPer1M / cacheWriteCostPer1M)
|
|
2570
|
-
* @param provider - Provider name for fallback rate selection
|
|
2571
|
-
* @returns Cost breakdown in micro-dollars
|
|
2572
|
-
*/
|
|
2573
|
-
declare function calculateCacheAwareCost(usage: UsageData, pricing: ModelPricing, provider?: string): CostResult;
|
|
2574
|
-
/**
|
|
2575
|
-
* Convert micro-dollars to dollars
|
|
2576
|
-
*
|
|
2577
|
-
* @param microDollars - Amount in micro-dollars
|
|
2578
|
-
* @returns Amount in dollars
|
|
2579
|
-
*
|
|
2580
|
-
* @example
|
|
2581
|
-
* ```typescript
|
|
2582
|
-
* microDollarsToDollars(7500); // 0.0075
|
|
2583
|
-
* microDollarsToDollars(1000000); // 1.0
|
|
2584
|
-
* ```
|
|
2585
|
-
*/
|
|
2586
|
-
declare function microDollarsToDollars(microDollars: number): number;
|
|
2587
|
-
/**
|
|
2588
|
-
* Convert dollars to micro-dollars
|
|
2589
|
-
*
|
|
2590
|
-
* @param dollars - Amount in dollars
|
|
2591
|
-
* @returns Amount in micro-dollars (rounded to nearest integer)
|
|
2592
|
-
*
|
|
2593
|
-
* @example
|
|
2594
|
-
* ```typescript
|
|
2595
|
-
* dollarsToMicroDollars(0.0075); // 7500
|
|
2596
|
-
* dollarsToMicroDollars(1.0); // 1000000
|
|
2597
|
-
* ```
|
|
2598
|
-
*/
|
|
2599
|
-
declare function dollarsToMicroDollars(dollars: number): number;
|
|
2600
|
-
/**
|
|
2601
|
-
* Format micro-dollars as a human-readable dollar string
|
|
2602
|
-
*
|
|
2603
|
-
* @param microDollars - Amount in micro-dollars
|
|
2604
|
-
* @param decimals - Number of decimal places (default: 6)
|
|
2605
|
-
* @returns Formatted dollar string
|
|
2606
|
-
*
|
|
2607
|
-
* @example
|
|
2608
|
-
* ```typescript
|
|
2609
|
-
* formatCost(7500); // "$0.007500"
|
|
2610
|
-
* formatCost(1234567, 2); // "$1.23"
|
|
2611
|
-
* ```
|
|
2612
|
-
*/
|
|
2613
|
-
declare function formatCost(microDollars: number, decimals?: number): string;
|
|
2614
|
-
//#endregion
|
|
2615
|
-
//#region src/pricing/provider.d.ts
|
|
2616
|
-
/**
|
|
2617
|
-
* Pricing provider that fetches per-model data from the LLMOps Models API.
|
|
2618
|
-
*
|
|
2619
|
-
* Features:
|
|
2620
|
-
* - Per-model in-memory cache with configurable TTL (default 5 minutes)
|
|
2621
|
-
* - Deduplicates concurrent fetches for the same model
|
|
2622
|
-
* - Caches null results (404s) to avoid repeated lookups
|
|
2623
|
-
* - Falls back to stale cache on fetch errors
|
|
2624
|
-
*/
|
|
2625
|
-
declare class LLMOpsPricingProvider implements PricingProvider {
|
|
2626
|
-
private cache;
|
|
2627
|
-
private pendingFetches;
|
|
2628
|
-
private cacheTTL;
|
|
2629
|
-
private baseUrl;
|
|
2630
|
-
constructor(options?: {
|
|
2631
|
-
cacheTTL?: number;
|
|
2632
|
-
baseUrl?: string;
|
|
2633
|
-
});
|
|
2634
|
-
private getCacheKey;
|
|
2635
|
-
/**
|
|
2636
|
-
* Fetch pricing for a single model from the API
|
|
2637
|
-
*/
|
|
2638
|
-
private fetchModelPricing;
|
|
2639
|
-
/**
|
|
2640
|
-
* Internal: fetch with cache and deduplication for a specific provider+model
|
|
2641
|
-
*/
|
|
2642
|
-
private getCachedPricing;
|
|
2643
|
-
/**
|
|
2644
|
-
* Get pricing for a specific model.
|
|
2645
|
-
*
|
|
2646
|
-
* When the model name contains a slash (e.g. "google/gemini-2.5-flash"),
|
|
2647
|
-
* it's likely an OpenRouter model ID. If the initial provider lookup fails,
|
|
2648
|
-
* we automatically retry with "openrouter" as the provider.
|
|
2649
|
-
*/
|
|
2650
|
-
getModelPricing(provider: string, model: string): Promise<ModelPricing | null>;
|
|
2651
|
-
/**
|
|
2652
|
-
* Force refresh the pricing cache (clears all cached entries)
|
|
2653
|
-
*/
|
|
2654
|
-
refreshCache(): Promise<void>;
|
|
2655
|
-
/**
|
|
2656
|
-
* Always ready — no bulk pre-fetch needed
|
|
2657
|
-
*/
|
|
2658
|
-
isReady(): boolean;
|
|
2659
|
-
/**
|
|
2660
|
-
* Get the number of cached models (for debugging)
|
|
2661
|
-
*/
|
|
2662
|
-
getCacheSize(): number;
|
|
2663
|
-
}
|
|
2664
|
-
/**
|
|
2665
|
-
* Get the default pricing provider instance
|
|
2666
|
-
*/
|
|
2667
|
-
declare function getDefaultPricingProvider(): LLMOpsPricingProvider;
|
|
2668
|
-
//#endregion
|
|
2669
|
-
//#region src/telemetry/interface.d.ts
|
|
2670
|
-
type LLMRequestsStore = ReturnType<typeof createLLMRequestsDataLayer>;
|
|
2671
|
-
type TracesStore = ReturnType<typeof createTracesDataLayer>;
|
|
2672
|
-
/**
|
|
2673
|
-
* TelemetryStore provides read + write access to telemetry data.
|
|
2674
|
-
* Implemented by pgStore (and future sqliteStore, etc.)
|
|
2675
|
-
*/
|
|
2676
|
-
type TelemetryStore = LLMRequestsStore & TracesStore;
|
|
2677
|
-
//#endregion
|
|
2678
|
-
//#region src/telemetry/postgres.d.ts
|
|
2679
|
-
type PgStore = TelemetryStore & {
|
|
2680
|
-
/** Internal Kysely instance — used by the app to power remaining datalayer queries */
|
|
2580
|
+
type PgStore = ReturnType<typeof createLLMRequestsStore> & ReturnType<typeof createTracesStore> & {
|
|
2681
2581
|
_db: Kysely<Database>;
|
|
2682
2582
|
};
|
|
2683
2583
|
/**
|
|
@@ -2685,7 +2585,8 @@ type PgStore = TelemetryStore & {
|
|
|
2685
2585
|
*
|
|
2686
2586
|
* Usage:
|
|
2687
2587
|
* ```ts
|
|
2688
|
-
* import { llmops
|
|
2588
|
+
* import { llmops } from '@llmops/sdk'
|
|
2589
|
+
* import { pgStore } from '@llmops/sdk/store/pg'
|
|
2689
2590
|
*
|
|
2690
2591
|
* const ops = llmops({
|
|
2691
2592
|
* telemetry: pgStore(process.env.DATABASE_URL),
|
|
@@ -2696,4 +2597,11 @@ declare function createPgStore(connectionString: string, options?: {
|
|
|
2696
2597
|
schema?: string;
|
|
2697
2598
|
}): PgStore;
|
|
2698
2599
|
//#endregion
|
|
2699
|
-
|
|
2600
|
+
//#region src/telemetry/interface.d.ts
|
|
2601
|
+
/**
|
|
2602
|
+
* TelemetryStore provides read + write access to telemetry data.
|
|
2603
|
+
* Implemented by pgStore (and future sqliteStore, etc.)
|
|
2604
|
+
*/
|
|
2605
|
+
type TelemetryStore = Omit<PgStore, '_db'>;
|
|
2606
|
+
//#endregion
|
|
2607
|
+
export { type AnthropicProviderConfig, type AnyProviderConfig, type AzureAIProviderConfig, type AzureOpenAIProviderConfig, BaseCacheConfig, type BaseProviderConfig, type BedrockProviderConfig, COST_SUMMARY_GROUP_BY, CacheBackend, CacheBackendType, CacheConfig, CacheEntry, CacheOptions, CacheService, CacheStats, ChatCompletionCreateParamsBase, type Config, type ConfigVariant, type ConfigVariantsTable, type ConfigsTable, type CortexProviderConfig, CostResult, type CostSummaryGroupBy, DEFAULT_PROVIDER_ENV_VARS, type DataLayer, type Database, DatabaseConnection, DatabaseOptions, DatabaseType, type Dataset, type DatasetRecord, DatasetRecordsTable, type DatasetVersion, type DatasetVersionRecord, DatasetVersionRecordsTable, DatasetVersionsTable, type DatasetsDataLayer, DatasetsTable, type Environment, type EnvironmentSecret, type EnvironmentSecretsTable, type EnvironmentsTable, FileCacheBackend, FileCacheConfig, type FireworksAIProviderConfig, type GoogleProviderConfig, type GuardrailConfig, GuardrailConfigsTable, type GuardrailResult, type GuardrailResults, type HuggingFaceProviderConfig, type InlineProviderConfig, type InlineProvidersConfig, Insertable, LLMOPS_INTERNAL_HEADER, LLMOPS_REQUEST_ID_HEADER, LLMOPS_SESSION_ID_HEADER, LLMOPS_SPAN_ID_HEADER, LLMOPS_SPAN_NAME_HEADER, LLMOPS_TRACE_ID_HEADER, LLMOPS_TRACE_NAME_HEADER, LLMOPS_USER_ID_HEADER, LLMOpsClient, LLMOpsConfig, type LLMOpsConfigInput, LLMOpsPricingProvider, type LLMRequest, type LLMRequestInsert, LLMRequestsTable, MS, MemoryCacheBackend, MemoryCacheConfig, MigrationOptions, MigrationResult, type MistralAIProviderConfig, ModelPricing, type OpenAIProviderConfig, type OracleProviderConfig, type PgStore, type Playground, type PlaygroundColumn, type PlaygroundResult, type PlaygroundResultsDataLayer, PlaygroundResultsTable, type PlaygroundRun, type PlaygroundRunsDataLayer, PlaygroundRunsTable, type PlaygroundsDataLayer, PlaygroundsTable, Prettify, PricingProvider, type ProviderConfig, type ProviderConfigMap, ProviderConfigsTable, type ProviderGuardrailOverride, ProviderGuardrailOverridesTable, type ProvidersConfig, SCHEMA_METADATA, type SagemakerProviderConfig, Selectable, Span, SpanEvent, type SpanEventInsert, SpanEventsTable, type SpanInsert, SpansTable, type StabilityAIProviderConfig, SupportedProviders, type TableName, type TargetingRule, type TargetingRulesTable, type TelemetryStore, Trace, type TraceUpsert, TracesTable, Updateable, UsageData, type ValidatedLLMOpsConfig, type Variant, VariantJsonData, type VariantVersion, VariantVersionsTable, type VariantsTable, type VertexAIProviderConfig, type WorkersAIProviderConfig, type WorkspaceSettings, type WorkspaceSettingsDataLayer, WorkspaceSettingsTable, calculateCacheAwareCost, calculateCost, chatCompletionCreateParamsBaseSchema, configVariantsSchema, configsSchema, createDataLayer, createDatabase, createDatabaseFromConnection, createDatasetsDataLayer, createNeonDialect, createPgStore, createPlaygroundDataLayer, createPlaygroundResultsDataLayer, createPlaygroundRunsDataLayer, createWorkspaceSettingsDataLayer, datasetRecordsSchema, datasetVersionRecordsSchema, datasetVersionsSchema, datasetsSchema, detectDatabaseType, dollarsToMicroDollars, environmentSecretsSchema, environmentsSchema, executeWithSchema, formatCost, gateway, generateId, getDefaultPricingProvider, getDefaultProviders, getMigrations, guardrailConfigsSchema, llmRequestsSchema, llmopsConfigSchema, logger, matchType, mergeWithDefaultProviders, microDollarsToDollars, parsePartialTableData, parseTableData, playgroundColumnSchema, playgroundResultsSchema, playgroundRunsSchema, playgroundsSchema, providerConfigsSchema, providerGuardrailOverridesSchema, runAutoMigrations, schemas, spanEventsSchema, spansSchema, targetingRulesSchema, tracesSchema, validateLLMOpsConfig, validatePartialTableData, validateTableData, variantJsonDataSchema, variantVersionsSchema, variantsSchema, workspaceSettingsSchema };
|