@granular-software/sdk 0.4.74 → 0.4.75
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/agent-evals.d.mts +2 -2
- package/dist/agent-evals.d.ts +2 -2
- package/dist/agent-evals.js +11208 -11210
- package/dist/agent-evals.js.map +1 -1
- package/dist/agent-evals.mjs +11208 -11210
- package/dist/agent-evals.mjs.map +1 -1
- package/dist/cli/index.js +4694 -4696
- package/dist/{spend-DBRQOSaj.d.ts → client-CljnHfK3.d.mts} +3810 -2564
- package/dist/{spend-DBRQOSaj.d.mts → client-Dbam34Zn.d.ts} +3810 -2564
- package/dist/index.d.mts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +12303 -12305
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +12303 -12305
- package/dist/index.mjs.map +1 -1
- package/dist/spend-ZMtzJoMN.d.mts +145 -0
- package/dist/spend-ZMtzJoMN.d.ts +145 -0
- package/dist/spend.d.mts +1 -1
- package/dist/spend.d.ts +1 -1
- package/package.json +1 -1
- package/dist/client-6d1OsWJf.d.mts +0 -1381
- package/dist/client-DdEXINlv.d.ts +0 -1381
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
type SpendLineItemType = "llm_tokens" | "granular_session_time" | string;
|
|
2
|
+
type QuotaScopeType = "tenant" | "sandbox" | "permission_profile" | "subject";
|
|
3
|
+
type QuotaPeriod = "hour" | "day" | "week" | "month";
|
|
4
|
+
type QuotaStatus = "active" | "paused" | "archived";
|
|
5
|
+
interface SpendSummary {
|
|
6
|
+
amountMicros: number;
|
|
7
|
+
inputTokens: number;
|
|
8
|
+
outputTokens: number;
|
|
9
|
+
cachedInputTokens: number;
|
|
10
|
+
reasoningTokens: number;
|
|
11
|
+
quantity: number;
|
|
12
|
+
eventCount: number;
|
|
13
|
+
}
|
|
14
|
+
interface QuotaLineItemFilter {
|
|
15
|
+
lineItemTypes?: string[];
|
|
16
|
+
sources?: string[];
|
|
17
|
+
providers?: string[];
|
|
18
|
+
models?: string[];
|
|
19
|
+
}
|
|
20
|
+
interface GranularQuotaPolicy {
|
|
21
|
+
quotaId: string;
|
|
22
|
+
tenantId: string;
|
|
23
|
+
scopeType: QuotaScopeType;
|
|
24
|
+
sandboxId: string | null;
|
|
25
|
+
permissionProfileId: string | null;
|
|
26
|
+
subjectId: string | null;
|
|
27
|
+
period: QuotaPeriod;
|
|
28
|
+
limitAmountMicros: number;
|
|
29
|
+
currency: string;
|
|
30
|
+
lineItemFilter: QuotaLineItemFilter | null;
|
|
31
|
+
status: QuotaStatus;
|
|
32
|
+
description: string | null;
|
|
33
|
+
createdBy: string | null;
|
|
34
|
+
startsAt: number | null;
|
|
35
|
+
endsAt: number | null;
|
|
36
|
+
createdAt: number;
|
|
37
|
+
updatedAt: number;
|
|
38
|
+
}
|
|
39
|
+
interface GranularQuotaProgress {
|
|
40
|
+
unlimited: boolean;
|
|
41
|
+
allowed: boolean;
|
|
42
|
+
blocked: boolean;
|
|
43
|
+
policy: GranularQuotaPolicy | null;
|
|
44
|
+
period: QuotaPeriod | null;
|
|
45
|
+
periodStart: number | null;
|
|
46
|
+
periodEnd: number | null;
|
|
47
|
+
usedAmountMicros: number;
|
|
48
|
+
limitAmountMicros: number | null;
|
|
49
|
+
remainingAmountMicros: number | null;
|
|
50
|
+
percentUsed: number | null;
|
|
51
|
+
currency: string;
|
|
52
|
+
summary: SpendSummary;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
interface OpenAIModelPricing {
|
|
56
|
+
provider: "openai";
|
|
57
|
+
model: string;
|
|
58
|
+
currency: "USD";
|
|
59
|
+
inputUsdPerMillion: number;
|
|
60
|
+
cachedInputUsdPerMillion: number;
|
|
61
|
+
cacheWriteUsdPerMillion?: number | null;
|
|
62
|
+
outputUsdPerMillion: number;
|
|
63
|
+
contextTier?: "short" | "long";
|
|
64
|
+
longContextThresholdTokens?: number | null;
|
|
65
|
+
longContextPricing?: {
|
|
66
|
+
inputUsdPerMillion: number;
|
|
67
|
+
cachedInputUsdPerMillion: number;
|
|
68
|
+
cacheWriteUsdPerMillion?: number | null;
|
|
69
|
+
outputUsdPerMillion: number;
|
|
70
|
+
};
|
|
71
|
+
sourceUrl: string;
|
|
72
|
+
effectiveDate: string;
|
|
73
|
+
}
|
|
74
|
+
interface NormalizedOpenAIUsage {
|
|
75
|
+
inputTokens: number;
|
|
76
|
+
cachedInputTokens: number;
|
|
77
|
+
cacheWriteTokens: number;
|
|
78
|
+
uncachedInputTokens: number;
|
|
79
|
+
outputTokens: number;
|
|
80
|
+
reasoningTokens: number;
|
|
81
|
+
totalTokens: number;
|
|
82
|
+
}
|
|
83
|
+
interface OpenAITokenSpend {
|
|
84
|
+
provider: "openai";
|
|
85
|
+
model: string;
|
|
86
|
+
inputTokens: number;
|
|
87
|
+
cachedInputTokens: number;
|
|
88
|
+
cacheWriteTokens: number;
|
|
89
|
+
uncachedInputTokens: number;
|
|
90
|
+
outputTokens: number;
|
|
91
|
+
reasoningTokens: number;
|
|
92
|
+
totalTokens: number;
|
|
93
|
+
amountMicros: number;
|
|
94
|
+
currency: "USD";
|
|
95
|
+
inputPricePerMillionMicros: number;
|
|
96
|
+
cachedInputPricePerMillionMicros: number;
|
|
97
|
+
cacheWritePricePerMillionMicros: number | null;
|
|
98
|
+
cacheWriteCostMicros: number;
|
|
99
|
+
outputPricePerMillionMicros: number;
|
|
100
|
+
pricingContextTier: "short" | "long";
|
|
101
|
+
longContextThresholdTokens: number | null;
|
|
102
|
+
pricingSource: string;
|
|
103
|
+
pricingEffectiveAt: string;
|
|
104
|
+
usage: NormalizedOpenAIUsage;
|
|
105
|
+
}
|
|
106
|
+
declare const OPENAI_MODEL_PRICING_USD_PER_MILLION: Record<string, OpenAIModelPricing>;
|
|
107
|
+
declare function getOpenAIModelPricing(model: string, inputTokens?: number): OpenAIModelPricing | null;
|
|
108
|
+
declare function normalizeOpenAIUsage(rawUsage: unknown): NormalizedOpenAIUsage;
|
|
109
|
+
declare function calculateOpenAITokenSpend(model: string, rawUsage: unknown): OpenAITokenSpend | null;
|
|
110
|
+
|
|
111
|
+
interface GranularSpendContext {
|
|
112
|
+
tenantId?: string | null;
|
|
113
|
+
sandboxId?: string | null;
|
|
114
|
+
environmentId?: string | null;
|
|
115
|
+
sessionId?: string | null;
|
|
116
|
+
subjectId?: string | null;
|
|
117
|
+
permissionProfileId?: string | null;
|
|
118
|
+
[key: string]: string | null | undefined;
|
|
119
|
+
}
|
|
120
|
+
interface OpenAIUsageSpendEvent extends OpenAITokenSpend {
|
|
121
|
+
spendEventId?: string;
|
|
122
|
+
source?: "openai";
|
|
123
|
+
lineItemType?: "llm_tokens";
|
|
124
|
+
operation?: string;
|
|
125
|
+
requestId?: string | null;
|
|
126
|
+
usageContext?: GranularSpendContext;
|
|
127
|
+
rawUsage?: unknown;
|
|
128
|
+
}
|
|
129
|
+
interface RecordOpenAIUsageSpendOptions {
|
|
130
|
+
apiUrl: string;
|
|
131
|
+
token: string;
|
|
132
|
+
usage: OpenAIUsageSpendEvent;
|
|
133
|
+
context?: GranularSpendContext | null;
|
|
134
|
+
metadata?: Record<string, unknown> | null;
|
|
135
|
+
}
|
|
136
|
+
interface RecordOpenAIUsageSpendResult {
|
|
137
|
+
spendEventId: string;
|
|
138
|
+
inserted: boolean;
|
|
139
|
+
quota: GranularQuotaProgress | null;
|
|
140
|
+
}
|
|
141
|
+
declare function toGranularHttpBase(apiUrl: string): string;
|
|
142
|
+
declare function buildOpenAISpendEventId(usage: Pick<OpenAIUsageSpendEvent, "requestId">, context?: GranularSpendContext): string | undefined;
|
|
143
|
+
declare function recordOpenAIUsageSpend(options: RecordOpenAIUsageSpendOptions): Promise<RecordOpenAIUsageSpendResult>;
|
|
144
|
+
|
|
145
|
+
export { type GranularSpendContext as G, type NormalizedOpenAIUsage as N, type OpenAIModelPricing as O, type QuotaLineItemFilter as Q, type RecordOpenAIUsageSpendOptions as R, type SpendLineItemType as S, type OpenAITokenSpend as a, OPENAI_MODEL_PRICING_USD_PER_MILLION as b, calculateOpenAITokenSpend as c, type OpenAIUsageSpendEvent as d, type RecordOpenAIUsageSpendResult as e, buildOpenAISpendEventId as f, getOpenAIModelPricing as g, type GranularQuotaPolicy as h, type GranularQuotaProgress as i, type QuotaPeriod as j, type QuotaScopeType as k, type QuotaStatus as l, type SpendSummary as m, normalizeOpenAIUsage as n, recordOpenAIUsageSpend as r, toGranularHttpBase as t };
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
type SpendLineItemType = "llm_tokens" | "granular_session_time" | string;
|
|
2
|
+
type QuotaScopeType = "tenant" | "sandbox" | "permission_profile" | "subject";
|
|
3
|
+
type QuotaPeriod = "hour" | "day" | "week" | "month";
|
|
4
|
+
type QuotaStatus = "active" | "paused" | "archived";
|
|
5
|
+
interface SpendSummary {
|
|
6
|
+
amountMicros: number;
|
|
7
|
+
inputTokens: number;
|
|
8
|
+
outputTokens: number;
|
|
9
|
+
cachedInputTokens: number;
|
|
10
|
+
reasoningTokens: number;
|
|
11
|
+
quantity: number;
|
|
12
|
+
eventCount: number;
|
|
13
|
+
}
|
|
14
|
+
interface QuotaLineItemFilter {
|
|
15
|
+
lineItemTypes?: string[];
|
|
16
|
+
sources?: string[];
|
|
17
|
+
providers?: string[];
|
|
18
|
+
models?: string[];
|
|
19
|
+
}
|
|
20
|
+
interface GranularQuotaPolicy {
|
|
21
|
+
quotaId: string;
|
|
22
|
+
tenantId: string;
|
|
23
|
+
scopeType: QuotaScopeType;
|
|
24
|
+
sandboxId: string | null;
|
|
25
|
+
permissionProfileId: string | null;
|
|
26
|
+
subjectId: string | null;
|
|
27
|
+
period: QuotaPeriod;
|
|
28
|
+
limitAmountMicros: number;
|
|
29
|
+
currency: string;
|
|
30
|
+
lineItemFilter: QuotaLineItemFilter | null;
|
|
31
|
+
status: QuotaStatus;
|
|
32
|
+
description: string | null;
|
|
33
|
+
createdBy: string | null;
|
|
34
|
+
startsAt: number | null;
|
|
35
|
+
endsAt: number | null;
|
|
36
|
+
createdAt: number;
|
|
37
|
+
updatedAt: number;
|
|
38
|
+
}
|
|
39
|
+
interface GranularQuotaProgress {
|
|
40
|
+
unlimited: boolean;
|
|
41
|
+
allowed: boolean;
|
|
42
|
+
blocked: boolean;
|
|
43
|
+
policy: GranularQuotaPolicy | null;
|
|
44
|
+
period: QuotaPeriod | null;
|
|
45
|
+
periodStart: number | null;
|
|
46
|
+
periodEnd: number | null;
|
|
47
|
+
usedAmountMicros: number;
|
|
48
|
+
limitAmountMicros: number | null;
|
|
49
|
+
remainingAmountMicros: number | null;
|
|
50
|
+
percentUsed: number | null;
|
|
51
|
+
currency: string;
|
|
52
|
+
summary: SpendSummary;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
interface OpenAIModelPricing {
|
|
56
|
+
provider: "openai";
|
|
57
|
+
model: string;
|
|
58
|
+
currency: "USD";
|
|
59
|
+
inputUsdPerMillion: number;
|
|
60
|
+
cachedInputUsdPerMillion: number;
|
|
61
|
+
cacheWriteUsdPerMillion?: number | null;
|
|
62
|
+
outputUsdPerMillion: number;
|
|
63
|
+
contextTier?: "short" | "long";
|
|
64
|
+
longContextThresholdTokens?: number | null;
|
|
65
|
+
longContextPricing?: {
|
|
66
|
+
inputUsdPerMillion: number;
|
|
67
|
+
cachedInputUsdPerMillion: number;
|
|
68
|
+
cacheWriteUsdPerMillion?: number | null;
|
|
69
|
+
outputUsdPerMillion: number;
|
|
70
|
+
};
|
|
71
|
+
sourceUrl: string;
|
|
72
|
+
effectiveDate: string;
|
|
73
|
+
}
|
|
74
|
+
interface NormalizedOpenAIUsage {
|
|
75
|
+
inputTokens: number;
|
|
76
|
+
cachedInputTokens: number;
|
|
77
|
+
cacheWriteTokens: number;
|
|
78
|
+
uncachedInputTokens: number;
|
|
79
|
+
outputTokens: number;
|
|
80
|
+
reasoningTokens: number;
|
|
81
|
+
totalTokens: number;
|
|
82
|
+
}
|
|
83
|
+
interface OpenAITokenSpend {
|
|
84
|
+
provider: "openai";
|
|
85
|
+
model: string;
|
|
86
|
+
inputTokens: number;
|
|
87
|
+
cachedInputTokens: number;
|
|
88
|
+
cacheWriteTokens: number;
|
|
89
|
+
uncachedInputTokens: number;
|
|
90
|
+
outputTokens: number;
|
|
91
|
+
reasoningTokens: number;
|
|
92
|
+
totalTokens: number;
|
|
93
|
+
amountMicros: number;
|
|
94
|
+
currency: "USD";
|
|
95
|
+
inputPricePerMillionMicros: number;
|
|
96
|
+
cachedInputPricePerMillionMicros: number;
|
|
97
|
+
cacheWritePricePerMillionMicros: number | null;
|
|
98
|
+
cacheWriteCostMicros: number;
|
|
99
|
+
outputPricePerMillionMicros: number;
|
|
100
|
+
pricingContextTier: "short" | "long";
|
|
101
|
+
longContextThresholdTokens: number | null;
|
|
102
|
+
pricingSource: string;
|
|
103
|
+
pricingEffectiveAt: string;
|
|
104
|
+
usage: NormalizedOpenAIUsage;
|
|
105
|
+
}
|
|
106
|
+
declare const OPENAI_MODEL_PRICING_USD_PER_MILLION: Record<string, OpenAIModelPricing>;
|
|
107
|
+
declare function getOpenAIModelPricing(model: string, inputTokens?: number): OpenAIModelPricing | null;
|
|
108
|
+
declare function normalizeOpenAIUsage(rawUsage: unknown): NormalizedOpenAIUsage;
|
|
109
|
+
declare function calculateOpenAITokenSpend(model: string, rawUsage: unknown): OpenAITokenSpend | null;
|
|
110
|
+
|
|
111
|
+
interface GranularSpendContext {
|
|
112
|
+
tenantId?: string | null;
|
|
113
|
+
sandboxId?: string | null;
|
|
114
|
+
environmentId?: string | null;
|
|
115
|
+
sessionId?: string | null;
|
|
116
|
+
subjectId?: string | null;
|
|
117
|
+
permissionProfileId?: string | null;
|
|
118
|
+
[key: string]: string | null | undefined;
|
|
119
|
+
}
|
|
120
|
+
interface OpenAIUsageSpendEvent extends OpenAITokenSpend {
|
|
121
|
+
spendEventId?: string;
|
|
122
|
+
source?: "openai";
|
|
123
|
+
lineItemType?: "llm_tokens";
|
|
124
|
+
operation?: string;
|
|
125
|
+
requestId?: string | null;
|
|
126
|
+
usageContext?: GranularSpendContext;
|
|
127
|
+
rawUsage?: unknown;
|
|
128
|
+
}
|
|
129
|
+
interface RecordOpenAIUsageSpendOptions {
|
|
130
|
+
apiUrl: string;
|
|
131
|
+
token: string;
|
|
132
|
+
usage: OpenAIUsageSpendEvent;
|
|
133
|
+
context?: GranularSpendContext | null;
|
|
134
|
+
metadata?: Record<string, unknown> | null;
|
|
135
|
+
}
|
|
136
|
+
interface RecordOpenAIUsageSpendResult {
|
|
137
|
+
spendEventId: string;
|
|
138
|
+
inserted: boolean;
|
|
139
|
+
quota: GranularQuotaProgress | null;
|
|
140
|
+
}
|
|
141
|
+
declare function toGranularHttpBase(apiUrl: string): string;
|
|
142
|
+
declare function buildOpenAISpendEventId(usage: Pick<OpenAIUsageSpendEvent, "requestId">, context?: GranularSpendContext): string | undefined;
|
|
143
|
+
declare function recordOpenAIUsageSpend(options: RecordOpenAIUsageSpendOptions): Promise<RecordOpenAIUsageSpendResult>;
|
|
144
|
+
|
|
145
|
+
export { type GranularSpendContext as G, type NormalizedOpenAIUsage as N, type OpenAIModelPricing as O, type QuotaLineItemFilter as Q, type RecordOpenAIUsageSpendOptions as R, type SpendLineItemType as S, type OpenAITokenSpend as a, OPENAI_MODEL_PRICING_USD_PER_MILLION as b, calculateOpenAITokenSpend as c, type OpenAIUsageSpendEvent as d, type RecordOpenAIUsageSpendResult as e, buildOpenAISpendEventId as f, getOpenAIModelPricing as g, type GranularQuotaPolicy as h, type GranularQuotaProgress as i, type QuotaPeriod as j, type QuotaScopeType as k, type QuotaStatus as l, type SpendSummary as m, normalizeOpenAIUsage as n, recordOpenAIUsageSpend as r, toGranularHttpBase as t };
|
package/dist/spend.d.mts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { G as GranularSpendContext, d as OpenAIUsageSpendEvent, R as RecordOpenAIUsageSpendOptions, e as RecordOpenAIUsageSpendResult, f as buildOpenAISpendEventId, r as recordOpenAIUsageSpend, t as toGranularHttpBase } from './spend-ZMtzJoMN.mjs';
|
package/dist/spend.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { G as GranularSpendContext, d as OpenAIUsageSpendEvent, R as RecordOpenAIUsageSpendOptions, e as RecordOpenAIUsageSpendResult, f as buildOpenAISpendEventId, r as recordOpenAIUsageSpend, t as toGranularHttpBase } from './spend-ZMtzJoMN.js';
|
package/package.json
CHANGED