@aeolus-fleet/trierarch-plugin 0.32.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 (84) hide show
  1. package/dist/adapters/fleet/operator-fleet.d.ts +2 -0
  2. package/dist/adapters/fleet/operator-fleet.js +50 -0
  3. package/dist/adapters/fleet/operator-fleet.js.map +1 -0
  4. package/dist/adapters/fleet/rest-fleet-door.js +2 -1
  5. package/dist/adapters/fleet/rest-fleet-door.js.map +1 -1
  6. package/dist/adapters/prisma/fleet-forgetter.d.ts +1 -1
  7. package/dist/adapters/prisma/fleet-forgetter.js +2 -2
  8. package/dist/adapters/prisma/fleet-forgetter.js.map +1 -1
  9. package/dist/adapters/prisma/generated/browser.d.ts +23 -0
  10. package/dist/adapters/prisma/generated/client.d.ts +23 -0
  11. package/dist/adapters/prisma/generated/commonInputTypes.d.ts +201 -0
  12. package/dist/adapters/prisma/generated/internal/class.d.ts +33 -0
  13. package/dist/adapters/prisma/generated/internal/class.js +4 -4
  14. package/dist/adapters/prisma/generated/internal/class.js.map +1 -1
  15. package/dist/adapters/prisma/generated/internal/prismaNamespace.d.ts +306 -1
  16. package/dist/adapters/prisma/generated/internal/prismaNamespace.js +54 -1
  17. package/dist/adapters/prisma/generated/internal/prismaNamespace.js.map +1 -1
  18. package/dist/adapters/prisma/generated/internal/prismaNamespaceBrowser.d.ts +56 -0
  19. package/dist/adapters/prisma/generated/internal/prismaNamespaceBrowser.js +54 -1
  20. package/dist/adapters/prisma/generated/internal/prismaNamespaceBrowser.js.map +1 -1
  21. package/dist/adapters/prisma/generated/models/SubscriptionReading.d.ts +1113 -0
  22. package/dist/adapters/prisma/generated/models/SubscriptionReading.js +2 -0
  23. package/dist/adapters/prisma/generated/models/SubscriptionReading.js.map +1 -0
  24. package/dist/adapters/prisma/generated/models/UsageDay.d.ts +1554 -0
  25. package/dist/adapters/prisma/generated/models/UsageDay.js +2 -0
  26. package/dist/adapters/prisma/generated/models/UsageDay.js.map +1 -0
  27. package/dist/adapters/prisma/generated/models/UsageHour.d.ts +1445 -0
  28. package/dist/adapters/prisma/generated/models/UsageHour.js +2 -0
  29. package/dist/adapters/prisma/generated/models/UsageHour.js.map +1 -0
  30. package/dist/adapters/prisma/generated/models.d.ts +3 -0
  31. package/dist/adapters/prisma/usage-history.d.ts +3 -0
  32. package/dist/adapters/prisma/usage-history.js +316 -0
  33. package/dist/adapters/prisma/usage-history.js.map +1 -0
  34. package/dist/adapters/trpc/router.d.ts +225 -1
  35. package/dist/adapters/trpc/router.js +185 -1
  36. package/dist/adapters/trpc/router.js.map +1 -1
  37. package/dist/app.js +16 -0
  38. package/dist/app.js.map +1 -1
  39. package/dist/core/connection/ports.d.ts +1 -0
  40. package/dist/core/machines/join-machine.js +2 -4
  41. package/dist/core/machines/join-machine.js.map +1 -1
  42. package/dist/core/machines/new-setup-line.d.ts +32 -0
  43. package/dist/core/machines/new-setup-line.js +45 -0
  44. package/dist/core/machines/new-setup-line.js.map +1 -0
  45. package/dist/core/machines/setup-line.d.ts +14 -0
  46. package/dist/core/machines/setup-line.js +13 -0
  47. package/dist/core/machines/setup-line.js.map +1 -0
  48. package/dist/core/operator/ports.d.ts +27 -2
  49. package/dist/core/shared/errors.d.ts +1 -1
  50. package/dist/core/shared/errors.js.map +1 -1
  51. package/dist/core/usage/ports.d.ts +19 -0
  52. package/dist/core/usage/ports.js +2 -0
  53. package/dist/core/usage/ports.js.map +1 -0
  54. package/dist/core/usage/read-subscription-windows.d.ts +35 -0
  55. package/dist/core/usage/read-subscription-windows.js +32 -0
  56. package/dist/core/usage/read-subscription-windows.js.map +1 -0
  57. package/dist/core/usage/read-token-usage.d.ts +61 -0
  58. package/dist/core/usage/read-token-usage.js +79 -0
  59. package/dist/core/usage/read-token-usage.js.map +1 -0
  60. package/dist/core/usage/read-usage-values.d.ts +36 -0
  61. package/dist/core/usage/read-usage-values.js +31 -0
  62. package/dist/core/usage/read-usage-values.js.map +1 -0
  63. package/dist/core/usage/ship-names.d.ts +19 -0
  64. package/dist/core/usage/ship-names.js +29 -0
  65. package/dist/core/usage/ship-names.js.map +1 -0
  66. package/dist/core/usage/subscription-windows.d.ts +28 -0
  67. package/dist/core/usage/subscription-windows.js +2 -0
  68. package/dist/core/usage/subscription-windows.js.map +1 -0
  69. package/dist/core/usage/token-usage.d.ts +61 -0
  70. package/dist/core/usage/token-usage.js +5 -0
  71. package/dist/core/usage/token-usage.js.map +1 -0
  72. package/dist/core/usage/usage-range.d.ts +12 -0
  73. package/dist/core/usage/usage-range.js +24 -0
  74. package/dist/core/usage/usage-range.js.map +1 -0
  75. package/dist/core/usage/usage-reading.d.ts +53 -0
  76. package/dist/core/usage/usage-reading.js +2 -0
  77. package/dist/core/usage/usage-reading.js.map +1 -0
  78. package/dist/core/usage/usage-values.d.ts +15 -0
  79. package/dist/core/usage/usage-values.js +2 -0
  80. package/dist/core/usage/usage-values.js.map +1 -0
  81. package/package.json +1 -1
  82. package/src/adapters/prisma/migrations/20261028120000_usage_history/migration.sql +57 -0
  83. package/src/adapters/prisma/migrations/20261028150000_usage_cost_per_kind/migration.sql +21 -0
  84. package/src/adapters/prisma/schema.prisma +79 -2
@@ -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.32.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
+ }