@aeolus-fleet/trierarch-plugin 0.33.0 → 0.34.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/dist/adapters/prisma/fleet-forgetter.d.ts +1 -1
  2. package/dist/adapters/prisma/fleet-forgetter.js +2 -2
  3. package/dist/adapters/prisma/fleet-forgetter.js.map +1 -1
  4. package/dist/adapters/prisma/generated/browser.d.ts +23 -0
  5. package/dist/adapters/prisma/generated/client.d.ts +23 -0
  6. package/dist/adapters/prisma/generated/commonInputTypes.d.ts +201 -0
  7. package/dist/adapters/prisma/generated/internal/class.d.ts +33 -0
  8. package/dist/adapters/prisma/generated/internal/class.js +4 -4
  9. package/dist/adapters/prisma/generated/internal/class.js.map +1 -1
  10. package/dist/adapters/prisma/generated/internal/prismaNamespace.d.ts +306 -1
  11. package/dist/adapters/prisma/generated/internal/prismaNamespace.js +54 -1
  12. package/dist/adapters/prisma/generated/internal/prismaNamespace.js.map +1 -1
  13. package/dist/adapters/prisma/generated/internal/prismaNamespaceBrowser.d.ts +56 -0
  14. package/dist/adapters/prisma/generated/internal/prismaNamespaceBrowser.js +54 -1
  15. package/dist/adapters/prisma/generated/internal/prismaNamespaceBrowser.js.map +1 -1
  16. package/dist/adapters/prisma/generated/models/SubscriptionReading.d.ts +1113 -0
  17. package/dist/adapters/prisma/generated/models/SubscriptionReading.js +2 -0
  18. package/dist/adapters/prisma/generated/models/SubscriptionReading.js.map +1 -0
  19. package/dist/adapters/prisma/generated/models/UsageDay.d.ts +1554 -0
  20. package/dist/adapters/prisma/generated/models/UsageDay.js +2 -0
  21. package/dist/adapters/prisma/generated/models/UsageDay.js.map +1 -0
  22. package/dist/adapters/prisma/generated/models/UsageHour.d.ts +1445 -0
  23. package/dist/adapters/prisma/generated/models/UsageHour.js +2 -0
  24. package/dist/adapters/prisma/generated/models/UsageHour.js.map +1 -0
  25. package/dist/adapters/prisma/generated/models.d.ts +3 -0
  26. package/dist/adapters/prisma/usage-history.d.ts +3 -0
  27. package/dist/adapters/prisma/usage-history.js +316 -0
  28. package/dist/adapters/prisma/usage-history.js.map +1 -0
  29. package/dist/adapters/trpc/router.d.ts +205 -1
  30. package/dist/adapters/trpc/router.js +159 -1
  31. package/dist/adapters/trpc/router.js.map +1 -1
  32. package/dist/app.js +11 -0
  33. package/dist/app.js.map +1 -1
  34. package/dist/core/shared/errors.d.ts +1 -1
  35. package/dist/core/shared/errors.js.map +1 -1
  36. package/dist/core/usage/ports.d.ts +19 -0
  37. package/dist/core/usage/ports.js +2 -0
  38. package/dist/core/usage/ports.js.map +1 -0
  39. package/dist/core/usage/read-subscription-windows.d.ts +35 -0
  40. package/dist/core/usage/read-subscription-windows.js +32 -0
  41. package/dist/core/usage/read-subscription-windows.js.map +1 -0
  42. package/dist/core/usage/read-token-usage.d.ts +61 -0
  43. package/dist/core/usage/read-token-usage.js +79 -0
  44. package/dist/core/usage/read-token-usage.js.map +1 -0
  45. package/dist/core/usage/read-usage-values.d.ts +36 -0
  46. package/dist/core/usage/read-usage-values.js +31 -0
  47. package/dist/core/usage/read-usage-values.js.map +1 -0
  48. package/dist/core/usage/ship-names.d.ts +19 -0
  49. package/dist/core/usage/ship-names.js +29 -0
  50. package/dist/core/usage/ship-names.js.map +1 -0
  51. package/dist/core/usage/subscription-windows.d.ts +28 -0
  52. package/dist/core/usage/subscription-windows.js +2 -0
  53. package/dist/core/usage/subscription-windows.js.map +1 -0
  54. package/dist/core/usage/token-usage.d.ts +61 -0
  55. package/dist/core/usage/token-usage.js +5 -0
  56. package/dist/core/usage/token-usage.js.map +1 -0
  57. package/dist/core/usage/usage-range.d.ts +12 -0
  58. package/dist/core/usage/usage-range.js +24 -0
  59. package/dist/core/usage/usage-range.js.map +1 -0
  60. package/dist/core/usage/usage-reading.d.ts +53 -0
  61. package/dist/core/usage/usage-reading.js +2 -0
  62. package/dist/core/usage/usage-reading.js.map +1 -0
  63. package/dist/core/usage/usage-values.d.ts +15 -0
  64. package/dist/core/usage/usage-values.js +2 -0
  65. package/dist/core/usage/usage-values.js.map +1 -0
  66. package/package.json +1 -1
  67. package/src/adapters/prisma/migrations/20261028120000_usage_history/migration.sql +57 -0
  68. package/src/adapters/prisma/migrations/20261028150000_usage_cost_per_kind/migration.sql +21 -0
  69. package/src/adapters/prisma/schema.prisma +79 -2
@@ -0,0 +1 @@
1
+ {"version":3,"file":"read-token-usage.js","sourceRoot":"","sources":["../../../src/core/usage/read-token-usage.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,EAAE,EAAe,MAAM,qBAAqB,CAAC;AAItD,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,kEAAkE;AAClE,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,YAAY,CAAmD,CAAC;AAkC5H,MAAM,SAAS,GAAgB,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,CAAC;AAEpF,MAAM,UAAU,oBAAoB,CAAC,IAA4E;IAC/G,OAAO,KAAK,EAAE,OAAO,EAAE,EAAE;QACvB,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;QACpC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;YAClB,OAAO,OAAO,CAAC;QACjB,CAAC;QACD,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAE5B,MAAM,QAAQ,GAAG,OAAO,CAAC,OAAO,KAAK,MAAM,CAAC;QAC5C,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC,OAAO,EAAE;YACzD,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,EAAE,EAAE,OAAO,CAAC,EAA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AAc,EAAE,KAAK,CAAC,cAAc,GAAG,MAAM,CAAC,cAAc;KAC7D,CAAC,EACF,EAAE,MAAM,EAAE,SAAS,EAAE,gBAAgB,EAAE,CAAC,EAAE,cAAc,EAAE,CAAC,EAAE,CAC9D,CAAC;AACJ,CAAC"}
@@ -0,0 +1,36 @@
1
+ import type { FleetId } from '@aeolus-fleet/common';
2
+ import type { ConnectionStore, FleetDoor } from '../connection/ports.js';
3
+ import type { DomainError } from '../shared/errors.js';
4
+ import { type Result } from '../shared/result.js';
5
+ import type { UsageHistory } from './ports.js';
6
+ import type { UsageBreakdown } from './token-usage.js';
7
+ import type { UsageValue } from './usage-values.js';
8
+ /** The values a filter menu shows at a time. */
9
+ export declare const USAGE_VALUES_PAGE = 20;
10
+ export interface UsageValuesRequest {
11
+ readonly fleetId: FleetId;
12
+ readonly from: Date;
13
+ readonly to: Date;
14
+ readonly breakdown: UsageBreakdown;
15
+ /** The last value of the page before; null for the first page. */
16
+ readonly after: UsageValue | null;
17
+ }
18
+ /** A page of values, each named as the token usage read names it, and where the next page starts; null when none is left. */
19
+ export interface UsageValuesPage {
20
+ readonly values: readonly (UsageValue & {
21
+ readonly name: string | null;
22
+ })[];
23
+ readonly next: UsageValue | null;
24
+ }
25
+ export type ReadUsageValues = (request: UsageValuesRequest) => Promise<Result<UsageValuesPage, DomainError<'INVALID_RANGE' | 'NOT_CONNECTED' | 'FLEET_UNAVAILABLE'>>>;
26
+ /**
27
+ * Use case: the values of one breakdown in a range, for the Usage page's
28
+ * filter menus (the usage design, usage.values): 20 a page, largest by tokens
29
+ * first, in the grain token usage is read in. Machines and ships are named
30
+ * from one read of the fleet's ships, retired ones included.
31
+ */
32
+ export declare function createReadUsageValues(deps: {
33
+ usage: UsageHistory;
34
+ door: FleetDoor;
35
+ connections: ConnectionStore;
36
+ }): ReadUsageValues;
@@ -0,0 +1,31 @@
1
+ import { ok } from '../shared/result.js';
2
+ import { nameOfValue, readShipNames } from './ship-names.js';
3
+ import { usageGrain } from './usage-range.js';
4
+ /** The values a filter menu shows at a time. */
5
+ export const USAGE_VALUES_PAGE = 20;
6
+ /**
7
+ * Use case: the values of one breakdown in a range, for the Usage page's
8
+ * filter menus (the usage design, usage.values): 20 a page, largest by tokens
9
+ * first, in the grain token usage is read in. Machines and ships are named
10
+ * from one read of the fleet's ships, retired ones included.
11
+ */
12
+ export function createReadUsageValues(deps) {
13
+ return async (request) => {
14
+ const grain = usageGrain(request);
15
+ if (!grain.isOk) {
16
+ return grain;
17
+ }
18
+ // One more than a page tells whether another follows.
19
+ const values = await deps.usage.readValues(request.fleetId, { from: request.from, to: request.to, grain: grain.value, breakdown: request.breakdown, after: request.after, limit: USAGE_VALUES_PAGE + 1 });
20
+ const page = values.slice(0, USAGE_VALUES_PAGE);
21
+ const names = await readShipNames(deps, { fleetId: request.fleetId, breakdown: request.breakdown });
22
+ if (!names.isOk) {
23
+ return names;
24
+ }
25
+ return ok({
26
+ values: page.map((value) => ({ ...value, name: nameOfValue(value.value, names.value) })),
27
+ next: values.length > USAGE_VALUES_PAGE ? (page.at(-1) ?? null) : null,
28
+ });
29
+ };
30
+ }
31
+ //# sourceMappingURL=read-usage-values.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"read-usage-values.js","sourceRoot":"","sources":["../../../src/core/usage/read-usage-values.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,EAAE,EAAe,MAAM,qBAAqB,CAAC;AAGtD,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAG9C,gDAAgD;AAChD,MAAM,CAAC,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAmBpC;;;;;GAKG;AACH,MAAM,UAAU,qBAAqB,CAAC,IAA4E;IAChH,OAAO,KAAK,EAAE,OAAO,EAAE,EAAE;QACvB,MAAM,KAAK,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;QAClC,IAAI,CAA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3
+ import { type DomainError } from '../shared/errors.js';
4
+ import { type Result } from '../shared/result.js';
5
+ import type { UsageBreakdown } from './token-usage.js';
6
+ /**
7
+ * The names of the fleet's ships by id, from one read of them, retired ones
8
+ * included, so usage of a ship released long ago keeps its name. Read only for
9
+ * a breakdown of machines or ships: other values are their own names.
10
+ */
11
+ export declare function readShipNames(deps: {
12
+ door: FleetDoor;
13
+ connections: ConnectionStore;
14
+ }, read: {
15
+ fleetId: FleetId;
16
+ breakdown: UsageBreakdown | 'kind' | null;
17
+ }): Promise<Result<ReadonlyMap<string, string> | undefined, DomainError<'NOT_CONNECTED' | 'FLEET_UNAVAILABLE'>>>;
18
+ /** A value's name: a machine or ship by its name in the fleet, any other value itself; a login not reported has none. */
19
+ export declare function nameOfValue(value: string | null, shipNames: ReadonlyMap<string, string> | undefined): string | null;
@@ -0,0 +1,29 @@
1
+ import { refuse } from '../shared/errors.js';
2
+ import { ok } from '../shared/result.js';
3
+ /**
4
+ * The names of the fleet's ships by id, from one read of them, retired ones
5
+ * included, so usage of a ship released long ago keeps its name. Read only for
6
+ * a breakdown of machines or ships: other values are their own names.
7
+ */
8
+ export async function readShipNames(deps, read) {
9
+ if (read.breakdown !== 'machine' && read.breakdown !== 'ship') {
10
+ return ok(undefined);
11
+ }
12
+ const crew = await deps.connections.find(read.fleetId);
13
+ if (!crew) {
14
+ return refuse('NOT_CONNECTED', 'The trierarch plugin is not connected to this fleet: connect it in the console');
15
+ }
16
+ const listed = await deps.door.listShips(crew.crewToken);
17
+ if (!listed.isOk) {
18
+ return refuse('FLEET_UNAVAILABLE', `The fleet did not answer its ships: ${listed.error.message}`);
19
+ }
20
+ return ok(new Map(listed.value.map((ship) => [ship.shipId, ship.name])));
21
+ }
22
+ /** A value's name: a machine or ship by its name in the fleet, any other value itself; a login not reported has none. */
23
+ export function nameOfValue(value, shipNames) {
24
+ if (value === null) {
25
+ return null;
26
+ }
27
+ return shipNames ? (shipNames.get(value) ?? null) : value;
28
+ }
29
+ //# sourceMappingURL=ship-names.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ship-names.js","sourceRoot":"","sources":["../../../src/core/usage/ship-names.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAoB,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EAAE,EAAE,EAAe,MAAM,qBAAqB,CAAC;AAGtD;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,IAAuD,EACvD,IAAqE;IAErE,IAAI,IAAI,CAAC,SAAS,KAAK,SAAS,IAAI,IAAI,CAAC,SAAS,KAAK,MAAM,EAAE,CAAC;QAC9D,OAAO,EAAE,CAAC,SAAS,CAAC,CAAC;IACvB,CAAC;IACD,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACvD,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,OAAO,MAAM,CAAC,eAAe,EAAE,gFAAgF,CAAC,CAAC;IACnH,CAAC;IACD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACzD,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;QACjB,OAAO,MAAM,CAAC,mBAAmB,EAAE,uCAAuC,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;IACpG,CAAC;IACD,OAAO,EAAE,CAAC,IAAI,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAoB,EAAE,CAAC,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AAC7F,CAAC;AAED,yHAAyH;AACzH,MAAM,UAAU,WAAW,CAAC,KAAoB,EAAE,SAAkD;IAClG,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QACnB,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;AAC5D,CAAC"}
@@ -0,0 +1,28 @@
1
+ import type { ShipId } from '@aeolus-fleet/common';
2
+ /** One machine and harness: where a page of subscription windows left off. */
3
+ export interface WindowsChartKey {
4
+ readonly machineShipId: ShipId;
5
+ readonly harness: string;
6
+ }
7
+ /** The subscription windows of one harness on one machine in a range: each window's readings, oldest first. */
8
+ export interface SubscriptionWindows extends WindowsChartKey {
9
+ readonly windows: readonly {
10
+ readonly windowMinutes: number;
11
+ readonly readings: readonly {
12
+ readonly readAt: Date;
13
+ readonly usedPercent: number;
14
+ readonly resetsAt: Date;
15
+ }[];
16
+ }[];
17
+ }
18
+ /** One page of machine and harness charts in a range, from inclusive, to exclusive, ordered by machine then harness. */
19
+ export interface WindowsQuery {
20
+ readonly from: Date;
21
+ readonly to: Date;
22
+ readonly filters: {
23
+ readonly machineShipIds?: readonly ShipId[];
24
+ readonly harnesses?: readonly string[];
25
+ };
26
+ readonly after: WindowsChartKey | null;
27
+ readonly limit: number;
28
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=subscription-windows.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subscription-windows.js","sourceRoot":"","sources":["../../../src/core/usage/subscription-windows.ts"],"names":[],"mappings":""}
@@ -0,0 +1,61 @@
1
+ import type { ShipId } from '@aeolus-fleet/common';
2
+ import type { TokenCosts, TokenCounts } from './usage-reading.js';
3
+ /** What usage splits by, besides token kind: one of the setup that used the tokens. */
4
+ export declare const USAGE_BREAKDOWNS: readonly ["machine", "harness", "model", "ship", "login"];
5
+ export type UsageBreakdown = (typeof USAGE_BREAKDOWNS)[number];
6
+ /** What the series are ranked and shown by: tokens (all four kinds) or the estimated cost. */
7
+ export declare const USAGE_MEASURES: readonly ["tokens", "cost"];
8
+ export type UsageMeasure = (typeof USAGE_MEASURES)[number];
9
+ /** Hours (from usage_hours) or UTC days (from their rollup). */
10
+ export type UsageGrain = 'hour' | 'day';
11
+ /** The values usage is narrowed to, per breakdown; a breakdown left out is not narrowed. A null login is "not reported". */
12
+ export interface UsageFilters {
13
+ readonly machineShipIds?: readonly ShipId[];
14
+ readonly harnesses?: readonly string[];
15
+ readonly models?: readonly string[];
16
+ readonly shipIds?: readonly ShipId[];
17
+ readonly logins?: readonly (string | null)[];
18
+ }
19
+ /** One read of token usage: a range of whole hours or whole UTC days, from inclusive, to exclusive. */
20
+ export interface TokenUsageQuery {
21
+ readonly from: Date;
22
+ readonly to: Date;
23
+ readonly grain: UsageGrain;
24
+ /** None: one series for all of it. */
25
+ readonly splitBy: UsageBreakdown | null;
26
+ readonly measure: UsageMeasure;
27
+ readonly filters: UsageFilters;
28
+ }
29
+ /** The tokens and estimated cost of one series in one bucket, each kind apart. */
30
+ export interface UsageAmounts {
31
+ readonly tokens: TokenCounts;
32
+ /** Of the priced tokens only. */
33
+ readonly estimatedCostUsd: TokenCosts;
34
+ /** The tokens of models the trierarch does not price. */
35
+ readonly unpricedTokens: TokenCounts;
36
+ }
37
+ /** A series of the read: one value of the breakdown (a null login is "not reported"), the rest as other, or all of it unsplit. */
38
+ export type UsageSeriesKey = {
39
+ readonly kind: 'value';
40
+ readonly value: string | null;
41
+ } | {
42
+ readonly kind: 'other';
43
+ } | {
44
+ readonly kind: 'all';
45
+ };
46
+ /**
47
+ * Token usage as the history answers it: the series by their total in the
48
+ * range, largest first, at most 7 and other for the rest; each bucket that
49
+ * holds usage, oldest first, with the amounts of each series in it by index;
50
+ * and the models in the range the trierarch does not price.
51
+ */
52
+ export interface TokenUsage {
53
+ readonly series: readonly UsageSeriesKey[];
54
+ readonly buckets: readonly {
55
+ readonly at: Date;
56
+ readonly amounts: readonly (UsageAmounts & {
57
+ readonly series: number;
58
+ })[];
59
+ }[];
60
+ readonly unpricedModels: readonly string[];
61
+ }
@@ -0,0 +1,5 @@
1
+ /** What usage splits by, besides token kind: one of the setup that used the tokens. */
2
+ export const USAGE_BREAKDOWNS = ['machine', 'harness', 'model', 'ship', 'login'];
3
+ /** What the series are ranked and shown by: tokens (all four kinds) or the estimated cost. */
4
+ export const USAGE_MEASURES = ['tokens', 'cost'];
5
+ //# sourceMappingURL=token-usage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"token-usage.js","sourceRoot":"","sources":["../../../src/core/usage/token-usage.ts"],"names":[],"mappings":"AAIA,uFAAuF;AACvF,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAU,CAAC;AAG1F,8FAA8F;AAC9F,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAU,CAAC"}
@@ -0,0 +1,12 @@
1
+ import { type DomainError } from '../shared/errors.js';
2
+ import { type Result } from '../shared/result.js';
3
+ import type { UsageGrain } from './token-usage.js';
4
+ /**
5
+ * The grain a range of usage is read in (the usage design, U15): hours up to 7
6
+ * days, UTC days past that. A range starts before it ends, and starts and ends
7
+ * on its grain: a whole hour, or a UTC midnight.
8
+ */
9
+ export declare function usageGrain(range: {
10
+ readonly from: Date;
11
+ readonly to: Date;
12
+ }): Result<UsageGrain, DomainError<'INVALID_RANGE'>>;
@@ -0,0 +1,24 @@
1
+ import { refuse } from '../shared/errors.js';
2
+ import { ok } from '../shared/result.js';
3
+ /** The longest range read in hours; anything longer is read in UTC days. */
4
+ const HOURS_UP_TO_MS = 7 * 24 * 60 * 60 * 1000;
5
+ const HOUR_MS = 60 * 60 * 1000;
6
+ const DAY_MS = 24 * HOUR_MS;
7
+ /**
8
+ * The grain a range of usage is read in (the usage design, U15): hours up to 7
9
+ * days, UTC days past that. A range starts before it ends, and starts and ends
10
+ * on its grain: a whole hour, or a UTC midnight.
11
+ */
12
+ export function usageGrain(range) {
13
+ const length = range.to.getTime() - range.from.getTime();
14
+ if (length <= 0) {
15
+ return refuse('INVALID_RANGE', 'A range ends after it starts');
16
+ }
17
+ const grain = length <= HOURS_UP_TO_MS ? 'hour' : 'day';
18
+ const unit = grain === 'hour' ? HOUR_MS : DAY_MS;
19
+ if (range.from.getTime() % unit !== 0 || range.to.getTime() % unit !== 0) {
20
+ return refuse('INVALID_RANGE', grain === 'hour' ? 'A range of hours starts and ends on a whole hour' : 'A range of days starts and ends at a UTC midnight');
21
+ }
22
+ return ok(grain);
23
+ }
24
+ //# sourceMappingURL=usage-range.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usage-range.js","sourceRoot":"","sources":["../../../src/core/usage/usage-range.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAoB,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EAAE,EAAE,EAAe,MAAM,qBAAqB,CAAC;AAGtD,4EAA4E;AAC5E,MAAM,cAAc,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAC/C,MAAM,OAAO,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAC/B,MAAM,MAAM,GAAG,EAAE,GAAG,OAAO,CAAC;AAE5B;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAC,KAAiD;IAC1E,MAAM,MAAM,GAAG,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;IACzD,IAAI,MAAM,IAAI,CAAC,EAAE,CAAC;QAChB,OAAO,MAAM,CAAC,eAAe,EAAE,8BAA8B,CAAC,CAAC;IACjE,CAAC;IACD,MAAM,KAAK,GAAe,MAAM,IAAI,cAAc,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC;IACpE,MAAM,IAAI,GAAG,KAAK,KAAK,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC;IACjD,IAAI,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,IAAI,KAAK,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,IAAI,KAAK,CAAC,EAAE,CAAC;QACzE,OAAO,MAAM,CAAC,eAAe,EAAE,KAAK,KAAK,MAAM,CAAC,CAAC,CAAC,kDAAkD,CAAC,CAAC,CAAC,mDAAmD,CAAC,CAAC;IAC9J,CAAC;IACD,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC;AACnB,CAAC"}
@@ -0,0 +1,53 @@
1
+ import type { ShipId } from '@aeolus-fleet/common';
2
+ /** The four kinds of tokens a trierarch reads from a harness's transcripts, each a count. */
3
+ export interface TokenCounts {
4
+ readonly input: number;
5
+ readonly output: number;
6
+ readonly cacheRead: number;
7
+ readonly cacheWrite: number;
8
+ }
9
+ /** The estimated cost in USD of each kind of tokens, at the trierarch's price table. */
10
+ export interface TokenCosts {
11
+ readonly input: number;
12
+ readonly output: number;
13
+ readonly cacheRead: number;
14
+ readonly cacheWrite: number;
15
+ }
16
+ /**
17
+ * One ship's tokens of one model in one UTC hour, in one folder of the ship on
18
+ * the machine (the usage design): the hour's total so far, set, never added.
19
+ */
20
+ export interface UsageHour {
21
+ /** The start of the UTC hour the tokens were used in, by the transcript's own time. */
22
+ readonly hour: Date;
23
+ readonly shipId: ShipId;
24
+ /** Tells two folders of one ship on one machine apart. */
25
+ readonly folderMadeAt: Date;
26
+ readonly model: string;
27
+ readonly harness: string;
28
+ /** The subscription or API key the ship ran on; null while the trierarch reports none. */
29
+ readonly login: string | null;
30
+ readonly tokens: TokenCounts;
31
+ /** Per kind, at the trierarch's price table when it was read; null for a model it does not price. */
32
+ readonly estimatedCostUsd: TokenCosts | null;
33
+ }
34
+ /** How full one subscription window of a harness was when the trierarch read it. */
35
+ export interface SubscriptionWindow {
36
+ readonly windowMinutes: number;
37
+ readonly usedPercent: number;
38
+ readonly resetsAt: Date;
39
+ }
40
+ /** One reading of a harness's subscription windows on the machine. */
41
+ export interface SubscriptionReading {
42
+ readonly harness: string;
43
+ readonly readAt: Date;
44
+ readonly windows: readonly SubscriptionWindow[];
45
+ }
46
+ /** What one trierarch sends of its machine's usage: the hours changed since its last send, and its subscription readings since. */
47
+ export interface UsageReading {
48
+ /** The trierarch ship of the machine that read it. */
49
+ readonly machineShipId: ShipId;
50
+ readonly readAt: Date;
51
+ readonly hours: readonly UsageHour[];
52
+ readonly subscriptions: readonly SubscriptionReading[];
53
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=usage-reading.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usage-reading.js","sourceRoot":"","sources":["../../../src/core/usage/usage-reading.ts"],"names":[],"mappings":""}
@@ -0,0 +1,15 @@
1
+ import type { UsageBreakdown, UsageGrain } from './token-usage.js';
2
+ /** One value of a breakdown with its tokens (all four kinds) in the range; a null login is "not reported". */
3
+ export interface UsageValue {
4
+ readonly value: string | null;
5
+ readonly tokens: number;
6
+ }
7
+ /** One page of a breakdown's values in a range, largest first, then by value; after the last value of the page before. */
8
+ export interface UsageValuesQuery {
9
+ readonly from: Date;
10
+ readonly to: Date;
11
+ readonly grain: UsageGrain;
12
+ readonly breakdown: UsageBreakdown;
13
+ readonly after: UsageValue | null;
14
+ readonly limit: number;
15
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=usage-values.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usage-values.js","sourceRoot":"","sources":["../../../src/core/usage/usage-values.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aeolus-fleet/trierarch-plugin",
3
- "version": "0.33.0",
3
+ "version": "0.34.0",
4
4
  "description": "Brings your machines into an Aeolus fleet and places crew requests on them.",
5
5
  "keywords": [
6
6
  "aeolus",
@@ -0,0 +1,57 @@
1
+ -- CreateTable
2
+ CREATE TABLE "usage_hours" (
3
+ "fleet_id" TEXT NOT NULL,
4
+ "hour" TIMESTAMPTZ(3) NOT NULL,
5
+ "machine_ship_id" TEXT NOT NULL,
6
+ "ship_id" TEXT NOT NULL,
7
+ "folder_made_at" TIMESTAMPTZ(3) NOT NULL,
8
+ "model" TEXT NOT NULL,
9
+ "harness" TEXT NOT NULL,
10
+ "login" TEXT,
11
+ "input" BIGINT NOT NULL,
12
+ "output" BIGINT NOT NULL,
13
+ "cache_read" BIGINT NOT NULL,
14
+ "cache_write" BIGINT NOT NULL,
15
+ "estimated_cost_usd" DECIMAL(18,6),
16
+ "read_at" TIMESTAMPTZ(3) NOT NULL,
17
+
18
+ CONSTRAINT "usage_hours_pkey" PRIMARY KEY ("fleet_id","hour","machine_ship_id","ship_id","folder_made_at","model")
19
+ );
20
+
21
+ -- CreateTable
22
+ CREATE TABLE "usage_days" (
23
+ "id" BIGSERIAL NOT NULL,
24
+ "fleet_id" TEXT NOT NULL,
25
+ "day" DATE NOT NULL,
26
+ "machine_ship_id" TEXT NOT NULL,
27
+ "ship_id" TEXT NOT NULL,
28
+ "model" TEXT NOT NULL,
29
+ "harness" TEXT NOT NULL,
30
+ "login" TEXT,
31
+ "input" BIGINT NOT NULL,
32
+ "output" BIGINT NOT NULL,
33
+ "cache_read" BIGINT NOT NULL,
34
+ "cache_write" BIGINT NOT NULL,
35
+ "estimated_cost_usd" DECIMAL(18,6) NOT NULL,
36
+ "unpriced_tokens" BIGINT NOT NULL,
37
+
38
+ CONSTRAINT "usage_days_pkey" PRIMARY KEY ("id")
39
+ );
40
+
41
+ -- CreateTable
42
+ CREATE TABLE "subscription_readings" (
43
+ "fleet_id" TEXT NOT NULL,
44
+ "machine_ship_id" TEXT NOT NULL,
45
+ "harness" TEXT NOT NULL,
46
+ "window_minutes" INTEGER NOT NULL,
47
+ "read_at" TIMESTAMPTZ(3) NOT NULL,
48
+ "used_percent" DECIMAL(5,2) NOT NULL,
49
+ "resets_at" TIMESTAMPTZ(3) NOT NULL,
50
+
51
+ CONSTRAINT "subscription_readings_pkey" PRIMARY KEY ("fleet_id","machine_ship_id","harness","window_minutes","read_at")
52
+ );
53
+
54
+ -- CreateIndex
55
+ -- NULLS NOT DISTINCT, written by hand: a login not reported is one key, not a new row each time.
56
+ CREATE UNIQUE INDEX "usage_days_fleet_id_day_machine_ship_id_ship_id_model_harne_key" ON "usage_days"("fleet_id", "day", "machine_ship_id", "ship_id", "model", "harness", "login") NULLS NOT DISTINCT;
57
+
@@ -0,0 +1,21 @@
1
+ -- The estimated cost per token kind (the usage design, U14). Nothing writes these tables yet,
2
+ -- so the columns are replaced rather than filled from the old ones.
3
+ -- AlterTable
4
+ ALTER TABLE "usage_hours" DROP COLUMN "estimated_cost_usd",
5
+ ADD COLUMN "estimated_cost_cache_read_usd" DECIMAL(18,6),
6
+ ADD COLUMN "estimated_cost_cache_write_usd" DECIMAL(18,6),
7
+ ADD COLUMN "estimated_cost_input_usd" DECIMAL(18,6),
8
+ ADD COLUMN "estimated_cost_output_usd" DECIMAL(18,6);
9
+
10
+ -- AlterTable
11
+ ALTER TABLE "usage_days" DROP COLUMN "estimated_cost_usd",
12
+ DROP COLUMN "unpriced_tokens",
13
+ ADD COLUMN "estimated_cost_cache_read_usd" DECIMAL(18,6) NOT NULL,
14
+ ADD COLUMN "estimated_cost_cache_write_usd" DECIMAL(18,6) NOT NULL,
15
+ ADD COLUMN "estimated_cost_input_usd" DECIMAL(18,6) NOT NULL,
16
+ ADD COLUMN "estimated_cost_output_usd" DECIMAL(18,6) NOT NULL,
17
+ ADD COLUMN "unpriced_cache_read" BIGINT NOT NULL,
18
+ ADD COLUMN "unpriced_cache_write" BIGINT NOT NULL,
19
+ ADD COLUMN "unpriced_input" BIGINT NOT NULL,
20
+ ADD COLUMN "unpriced_output" BIGINT NOT NULL;
21
+
@@ -1,6 +1,6 @@
1
1
  // The trierarch plugin's tables, in its own small database (decision 0030): per
2
- // fleet only its connection, its switch and its enabled models (decision 0063),
3
- // and the installation's requests.
2
+ // fleet only its connection, its switch, its enabled models (decision 0063) and
3
+ // its usage history, and the installation's requests.
4
4
  // Everything else (crew requests, statuses, machines) lives in the fleet, which
5
5
  // it reaches only through its public API, as the ship it crews.
6
6
  //
@@ -68,3 +68,80 @@ model EnabledModel {
68
68
  @@id([fleetId, model])
69
69
  @@map("enabled_models")
70
70
  }
71
+
72
+ /// One ship's tokens of one model in one UTC hour, in one folder of the ship on
73
+ /// one machine, as its trierarch read them (decision 0030, the usage design). The
74
+ /// hour's total so far: a row is kept only when its read_at is newer than the
75
+ /// stored one. Its primary key, fleet and hour first, serves a range of hours.
76
+ model UsageHour {
77
+ fleetId String @map("fleet_id")
78
+ hour DateTime @db.Timestamptz(3)
79
+ machineShipId String @map("machine_ship_id")
80
+ shipId String @map("ship_id")
81
+ folderMadeAt DateTime @map("folder_made_at") @db.Timestamptz(3)
82
+ model String
83
+ harness String
84
+ /// Null: the trierarch reported no login.
85
+ login String?
86
+ input BigInt
87
+ output BigInt
88
+ cacheRead BigInt @map("cache_read")
89
+ cacheWrite BigInt @map("cache_write")
90
+ /// The estimated cost of each kind of tokens; all four null: the trierarch does not price the model.
91
+ estimatedCostInputUsd Decimal? @map("estimated_cost_input_usd") @db.Decimal(18, 6)
92
+ estimatedCostOutputUsd Decimal? @map("estimated_cost_output_usd") @db.Decimal(18, 6)
93
+ estimatedCostCacheReadUsd Decimal? @map("estimated_cost_cache_read_usd") @db.Decimal(18, 6)
94
+ estimatedCostCacheWriteUsd Decimal? @map("estimated_cost_cache_write_usd") @db.Decimal(18, 6)
95
+ readAt DateTime @map("read_at") @db.Timestamptz(3)
96
+
97
+ @@id([fleetId, hour, machineShipId, shipId, folderMadeAt, model])
98
+ @@map("usage_hours")
99
+ }
100
+
101
+ /// The hours of one UTC day added up, per machine, ship, model, harness and
102
+ /// login: the rollup ranges over 7 days read. Written in the same transaction as
103
+ /// each usage_hours row, by the difference between the new and the stored row.
104
+ /// Its key holds the login, which may be null, so the migration makes that
105
+ /// unique index NULLS NOT DISTINCT, which this schema cannot say.
106
+ model UsageDay {
107
+ id BigInt @id @default(autoincrement())
108
+ fleetId String @map("fleet_id")
109
+ day DateTime @db.Date
110
+ machineShipId String @map("machine_ship_id")
111
+ shipId String @map("ship_id")
112
+ model String
113
+ harness String
114
+ login String?
115
+ input BigInt
116
+ output BigInt
117
+ cacheRead BigInt @map("cache_read")
118
+ cacheWrite BigInt @map("cache_write")
119
+ /// The estimated cost of each kind of tokens, of the priced hours only.
120
+ estimatedCostInputUsd Decimal @map("estimated_cost_input_usd") @db.Decimal(18, 6)
121
+ estimatedCostOutputUsd Decimal @map("estimated_cost_output_usd") @db.Decimal(18, 6)
122
+ estimatedCostCacheReadUsd Decimal @map("estimated_cost_cache_read_usd") @db.Decimal(18, 6)
123
+ estimatedCostCacheWriteUsd Decimal @map("estimated_cost_cache_write_usd") @db.Decimal(18, 6)
124
+ /// The tokens of each kind of the hours whose model the trierarch does not price.
125
+ unpricedInput BigInt @map("unpriced_input")
126
+ unpricedOutput BigInt @map("unpriced_output")
127
+ unpricedCacheRead BigInt @map("unpriced_cache_read")
128
+ unpricedCacheWrite BigInt @map("unpriced_cache_write")
129
+
130
+ @@unique([fleetId, day, machineShipId, shipId, model, harness, login])
131
+ @@map("usage_days")
132
+ }
133
+
134
+ /// How full one subscription window of a harness on one machine was when its
135
+ /// trierarch read it. Kept once: a repeat changes nothing.
136
+ model SubscriptionReading {
137
+ fleetId String @map("fleet_id")
138
+ machineShipId String @map("machine_ship_id")
139
+ harness String
140
+ windowMinutes Int @map("window_minutes")
141
+ readAt DateTime @map("read_at") @db.Timestamptz(3)
142
+ usedPercent Decimal @map("used_percent") @db.Decimal(5, 2)
143
+ resetsAt DateTime @map("resets_at") @db.Timestamptz(3)
144
+
145
+ @@id([fleetId, machineShipId, harness, windowMinutes, readAt])
146
+ @@map("subscription_readings")
147
+ }