@agent-finops/core 0.7.0 → 0.7.2
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/activitySnapshot.d.ts +11 -28
- package/dist/activitySnapshot.js +19 -10
- package/dist/agentEconomicsReceipt.d.ts +934 -0
- package/dist/agentEconomicsReceipt.js +1005 -0
- package/dist/contextHealth.js +3 -1
- package/dist/glance.js +16 -16
- package/dist/index.d.ts +5 -1
- package/dist/index.js +3 -1
- package/dist/localAgentFormats/registry.d.ts +8 -0
- package/dist/localAgentFormats/registry.js +219 -0
- package/dist/localAgentFormats/runtimeRegistry.d.ts +4 -0
- package/dist/localAgentFormats/runtimeRegistry.js +55 -0
- package/dist/localAgentFormats/types.d.ts +84 -0
- package/dist/localAgentFormats/types.js +2 -0
- package/dist/localAgentLogs.d.ts +19 -2
- package/dist/localAgentLogs.js +234 -172
- package/dist/sourceStatus.d.ts +2 -1
- package/dist/sourceStatus.js +7 -13
- package/package.json +1 -1
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { type LocalAgentCall, type LocalAgentSourceScan } from "./localAgentLogs.js";
|
|
3
|
+
import type { LocalAgentFormatId } from "./localAgentFormats/types.js";
|
|
3
4
|
import type { DetectedPlan } from "./planDetection.js";
|
|
4
5
|
import { type UsageRecord } from "./schema.js";
|
|
5
6
|
import { type SourceValidationCoverage } from "./sourceStatus.js";
|
|
6
|
-
export declare const activitySnapshotAgentValues: readonly [
|
|
7
|
-
export type ActivitySnapshotAgent =
|
|
7
|
+
export declare const activitySnapshotAgentValues: readonly LocalAgentFormatId[];
|
|
8
|
+
export type ActivitySnapshotAgent = LocalAgentFormatId;
|
|
8
9
|
export declare const activitySnapshotPlanIdValues: readonly ["claude-pro", "claude-max-5x", "claude-max-20x", "chatgpt-plus", "chatgpt-pro"];
|
|
9
10
|
export type ActivitySnapshotPlanId = typeof activitySnapshotPlanIdValues[number];
|
|
10
11
|
export declare const activitySnapshotProviderValues: readonly ["openai", "anthropic", "cursor", "github-copilot", "other"];
|
|
@@ -177,10 +178,7 @@ export declare const activitySnapshotLimitSchema: z.ZodObject<{
|
|
|
177
178
|
}, z.core.$strict>;
|
|
178
179
|
export type ActivitySnapshotLimit = z.infer<typeof activitySnapshotLimitSchema>;
|
|
179
180
|
export declare const activitySnapshotSubscriptionAgentSchema: z.ZodObject<{
|
|
180
|
-
agent: z.
|
|
181
|
-
"claude-code": "claude-code";
|
|
182
|
-
codex: "codex";
|
|
183
|
-
}>;
|
|
181
|
+
agent: z.ZodString & z.ZodType<LocalAgentFormatId, string, z.core.$ZodTypeInternals<LocalAgentFormatId, string>>;
|
|
184
182
|
billing: z.ZodLiteral<"subscription">;
|
|
185
183
|
planId: z.ZodNullable<z.ZodEnum<{
|
|
186
184
|
"claude-max-20x": "claude-max-20x";
|
|
@@ -260,10 +258,7 @@ export declare const activitySnapshotOverageSchema: z.ZodObject<{
|
|
|
260
258
|
export type ActivitySnapshotOverage = z.infer<typeof activitySnapshotOverageSchema>;
|
|
261
259
|
export declare const activitySnapshotCoverageSchema: z.ZodObject<{
|
|
262
260
|
agents: z.ZodArray<z.ZodObject<{
|
|
263
|
-
agent: z.
|
|
264
|
-
"claude-code": "claude-code";
|
|
265
|
-
codex: "codex";
|
|
266
|
-
}>;
|
|
261
|
+
agent: z.ZodString & z.ZodType<LocalAgentFormatId, string, z.core.$ZodTypeInternals<LocalAgentFormatId, string>>;
|
|
267
262
|
directoryStatus: z.ZodEnum<{
|
|
268
263
|
missing: "missing";
|
|
269
264
|
readable: "readable";
|
|
@@ -314,8 +309,8 @@ export declare const activitySnapshotCoverageSchema: z.ZodObject<{
|
|
|
314
309
|
recordsPriced: z.ZodNumber;
|
|
315
310
|
recordsUnpriced: z.ZodNumber;
|
|
316
311
|
validationStatus: z.ZodEnum<{
|
|
317
|
-
complete: "complete";
|
|
318
312
|
failed: "failed";
|
|
313
|
+
complete: "complete";
|
|
319
314
|
not_checked: "not_checked";
|
|
320
315
|
partial: "partial";
|
|
321
316
|
}>;
|
|
@@ -354,10 +349,7 @@ export declare const activitySnapshotSchema: z.ZodObject<{
|
|
|
354
349
|
}>;
|
|
355
350
|
subscription: z.ZodNullable<z.ZodObject<{
|
|
356
351
|
agents: z.ZodArray<z.ZodObject<{
|
|
357
|
-
agent: z.
|
|
358
|
-
"claude-code": "claude-code";
|
|
359
|
-
codex: "codex";
|
|
360
|
-
}>;
|
|
352
|
+
agent: z.ZodString & z.ZodType<LocalAgentFormatId, string, z.core.$ZodTypeInternals<LocalAgentFormatId, string>>;
|
|
361
353
|
billing: z.ZodLiteral<"subscription">;
|
|
362
354
|
planId: z.ZodNullable<z.ZodEnum<{
|
|
363
355
|
"claude-max-20x": "claude-max-20x";
|
|
@@ -428,10 +420,7 @@ export declare const activitySnapshotSchema: z.ZodObject<{
|
|
|
428
420
|
}, z.core.$strict>>;
|
|
429
421
|
metered: z.ZodNullable<z.ZodObject<{
|
|
430
422
|
agents: z.ZodArray<z.ZodObject<{
|
|
431
|
-
agent: z.
|
|
432
|
-
"claude-code": "claude-code";
|
|
433
|
-
codex: "codex";
|
|
434
|
-
}>;
|
|
423
|
+
agent: z.ZodString & z.ZodType<LocalAgentFormatId, string, z.core.$ZodTypeInternals<LocalAgentFormatId, string>>;
|
|
435
424
|
billing: z.ZodLiteral<"api_key">;
|
|
436
425
|
planId: z.ZodNullable<z.ZodEnum<{
|
|
437
426
|
"claude-max-20x": "claude-max-20x";
|
|
@@ -532,10 +521,7 @@ export declare const activitySnapshotSchema: z.ZodObject<{
|
|
|
532
521
|
}, z.core.$strict>>;
|
|
533
522
|
unresolved: z.ZodNullable<z.ZodObject<{
|
|
534
523
|
agents: z.ZodArray<z.ZodObject<{
|
|
535
|
-
agent: z.
|
|
536
|
-
"claude-code": "claude-code";
|
|
537
|
-
codex: "codex";
|
|
538
|
-
}>;
|
|
524
|
+
agent: z.ZodString & z.ZodType<LocalAgentFormatId, string, z.core.$ZodTypeInternals<LocalAgentFormatId, string>>;
|
|
539
525
|
billing: z.ZodLiteral<"unknown">;
|
|
540
526
|
planId: z.ZodNullable<z.ZodEnum<{
|
|
541
527
|
"claude-max-20x": "claude-max-20x";
|
|
@@ -600,10 +586,7 @@ export declare const activitySnapshotSchema: z.ZodObject<{
|
|
|
600
586
|
}, z.core.$strict>>;
|
|
601
587
|
coverage: z.ZodObject<{
|
|
602
588
|
agents: z.ZodArray<z.ZodObject<{
|
|
603
|
-
agent: z.
|
|
604
|
-
"claude-code": "claude-code";
|
|
605
|
-
codex: "codex";
|
|
606
|
-
}>;
|
|
589
|
+
agent: z.ZodString & z.ZodType<LocalAgentFormatId, string, z.core.$ZodTypeInternals<LocalAgentFormatId, string>>;
|
|
607
590
|
directoryStatus: z.ZodEnum<{
|
|
608
591
|
missing: "missing";
|
|
609
592
|
readable: "readable";
|
|
@@ -654,8 +637,8 @@ export declare const activitySnapshotSchema: z.ZodObject<{
|
|
|
654
637
|
recordsPriced: z.ZodNumber;
|
|
655
638
|
recordsUnpriced: z.ZodNumber;
|
|
656
639
|
validationStatus: z.ZodEnum<{
|
|
657
|
-
complete: "complete";
|
|
658
640
|
failed: "failed";
|
|
641
|
+
complete: "complete";
|
|
659
642
|
not_checked: "not_checked";
|
|
660
643
|
partial: "partial";
|
|
661
644
|
}>;
|
package/dist/activitySnapshot.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { aggregateCalls, dedupeCumulativeSessionCalls } from "./localAgentLogs.js";
|
|
3
|
+
import { localAgentFormatDescriptors } from "./localAgentFormats/registry.js";
|
|
3
4
|
import { estimateTokenCostUsd, PRICING_TABLE_AS_OF } from "./modelPricing.js";
|
|
4
5
|
import { isBundledSampleUsage } from "./schema.js";
|
|
5
6
|
import { sourceValidationCoverageValues } from "./sourceStatus.js";
|
|
6
7
|
const DAY_MS = 24 * 60 * 60 * 1_000;
|
|
7
|
-
export const activitySnapshotAgentValues =
|
|
8
|
+
export const activitySnapshotAgentValues = Object.freeze(localAgentFormatDescriptors.map((descriptor) => descriptor.id));
|
|
9
|
+
const activitySnapshotAgentValueSet = new Set(activitySnapshotAgentValues);
|
|
10
|
+
const activitySnapshotAgentLimit = activitySnapshotAgentValues.length;
|
|
8
11
|
export const activitySnapshotPlanIdValues = [
|
|
9
12
|
"claude-pro",
|
|
10
13
|
"claude-max-5x",
|
|
@@ -45,7 +48,9 @@ const isoTimestampSchema = z.string().datetime({ offset: true });
|
|
|
45
48
|
const usdSchema = z.number().finite().nonnegative();
|
|
46
49
|
const countSchema = z.number().int().nonnegative();
|
|
47
50
|
const windowCoverageSchema = z.enum(["complete", "partial", "missing"]);
|
|
48
|
-
const agentSchema = z.
|
|
51
|
+
const agentSchema = z.string().refine(isSnapshotAgent, {
|
|
52
|
+
message: "Agent must be registered as a local-agent format."
|
|
53
|
+
});
|
|
49
54
|
const planIdSchema = z.enum(activitySnapshotPlanIdValues).nullable();
|
|
50
55
|
export const activitySnapshotApiEquivalentWindowSchema = z.object({
|
|
51
56
|
amountUsd: usdSchema.nullable(),
|
|
@@ -169,14 +174,14 @@ export const activitySnapshotSubscriptionAgentSchema = z.object({
|
|
|
169
174
|
}
|
|
170
175
|
});
|
|
171
176
|
const activitySnapshotSubscriptionSchema = z.object({
|
|
172
|
-
agents: z.array(activitySnapshotSubscriptionAgentSchema).min(1).max(
|
|
177
|
+
agents: z.array(activitySnapshotSubscriptionAgentSchema).min(1).max(activitySnapshotAgentLimit)
|
|
173
178
|
}).strict().superRefine(uniqueAgentEntries);
|
|
174
179
|
const activitySnapshotMeteredSchema = z.object({
|
|
175
180
|
agents: z.array(z.object({
|
|
176
181
|
agent: agentSchema,
|
|
177
182
|
billing: z.literal("api_key"),
|
|
178
183
|
planId: planIdSchema
|
|
179
|
-
}).strict()).max(
|
|
184
|
+
}).strict()).max(activitySnapshotAgentLimit),
|
|
180
185
|
apiEquivalent: activitySnapshotApiEquivalentWindowsSchema,
|
|
181
186
|
providerBilled: activitySnapshotBilledWindowsSchema
|
|
182
187
|
}).strict().superRefine((value, context) => {
|
|
@@ -196,7 +201,7 @@ const activitySnapshotUnresolvedSchema = z.object({
|
|
|
196
201
|
agent: agentSchema,
|
|
197
202
|
billing: z.literal("unknown"),
|
|
198
203
|
planId: planIdSchema
|
|
199
|
-
}).strict()).max(
|
|
204
|
+
}).strict()).max(activitySnapshotAgentLimit),
|
|
200
205
|
apiEquivalent: activitySnapshotApiEquivalentWindowsSchema
|
|
201
206
|
}).strict().superRefine((value, context) => {
|
|
202
207
|
uniqueAgentEntries(value, context);
|
|
@@ -290,7 +295,7 @@ const activitySnapshotProviderCoverageSchema = z.object({
|
|
|
290
295
|
}
|
|
291
296
|
});
|
|
292
297
|
export const activitySnapshotCoverageSchema = z.object({
|
|
293
|
-
agents: z.array(activitySnapshotAgentCoverageSchema).max(
|
|
298
|
+
agents: z.array(activitySnapshotAgentCoverageSchema).max(activitySnapshotAgentLimit),
|
|
294
299
|
providers: z.array(activitySnapshotProviderCoverageSchema).max(5),
|
|
295
300
|
recordsParsed: countSchema,
|
|
296
301
|
recordsPriced: countSchema,
|
|
@@ -483,8 +488,10 @@ export function buildActivitySnapshot(input) {
|
|
|
483
488
|
if (isSnapshotAgent(entry.record.agentId))
|
|
484
489
|
activeAgents.add(entry.record.agentId);
|
|
485
490
|
}
|
|
486
|
-
for (const call of calls)
|
|
487
|
-
|
|
491
|
+
for (const call of calls) {
|
|
492
|
+
if (isSnapshotAgent(call.agent))
|
|
493
|
+
activeAgents.add(call.agent);
|
|
494
|
+
}
|
|
488
495
|
const meteredAgents = [...activeAgents]
|
|
489
496
|
.filter((agent) => plans.get(agent)?.billing === "api_key")
|
|
490
497
|
.sort()
|
|
@@ -529,7 +536,7 @@ export function buildActivitySnapshot(input) {
|
|
|
529
536
|
const subscription = hasSubscriptionActivity ? { agents: subscriptionAgents } : null;
|
|
530
537
|
const metered = hasMeteredActivity ? {
|
|
531
538
|
agents: meteredAgents,
|
|
532
|
-
apiEquivalent: buildApiWindows(meteredApiRecords, allCalls.filter((call) => plans.get(call.agent)?.billing === "api_key"), trustedIds, asOfMs, localCoverageForRecords(meteredApiRecords, scans, [...plans.entries()]
|
|
539
|
+
apiEquivalent: buildApiWindows(meteredApiRecords, allCalls.filter((call) => (isSnapshotAgent(call.agent) && plans.get(call.agent)?.billing === "api_key")), trustedIds, asOfMs, localCoverageForRecords(meteredApiRecords, scans, [...plans.entries()]
|
|
533
540
|
.filter(([, plan]) => plan.billing === "api_key")
|
|
534
541
|
.map(([agent]) => agent))),
|
|
535
542
|
providerBilled: buildBilledWindows(meteredBilledRecords, asOfMs, providers)
|
|
@@ -537,6 +544,8 @@ export function buildActivitySnapshot(input) {
|
|
|
537
544
|
const unresolved = hasUnresolvedActivity ? {
|
|
538
545
|
agents: unresolvedAgents,
|
|
539
546
|
apiEquivalent: buildApiWindows(unresolvedRecords, allCalls.filter((call) => {
|
|
547
|
+
if (!isSnapshotAgent(call.agent))
|
|
548
|
+
return false;
|
|
540
549
|
const billing = plans.get(call.agent)?.billing;
|
|
541
550
|
return billing !== "subscription" && billing !== "api_key";
|
|
542
551
|
}), trustedIds, asOfMs, unresolvedCoverageForRecords(unresolvedRecords, scans, providers))
|
|
@@ -1200,7 +1209,7 @@ function inRollingWindow(timestamp, asOfMs, days) {
|
|
|
1200
1209
|
return Number.isFinite(value) && value >= asOfMs - days * DAY_MS && value <= asOfMs;
|
|
1201
1210
|
}
|
|
1202
1211
|
function isSnapshotAgent(value) {
|
|
1203
|
-
return typeof value === "string" &&
|
|
1212
|
+
return typeof value === "string" && activitySnapshotAgentValueSet.has(value);
|
|
1204
1213
|
}
|
|
1205
1214
|
function isKnownPlanId(value) {
|
|
1206
1215
|
return typeof value === "string" && activitySnapshotPlanIdValues.includes(value);
|