@foldrun/core 19.0.0 → 19.2.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.
- package/dist/src/customer.d.ts +7 -0
- package/dist/src/customer.js +26 -0
- package/dist/src/data-import.d.ts +156 -0
- package/dist/src/data-import.js +670 -0
- package/dist/src/records.d.ts +4 -0
- package/package.json +1 -1
- package/src/customer.ts +25 -0
- package/src/data-import.ts +764 -0
- package/src/records.ts +4 -0
package/package.json
CHANGED
package/src/customer.ts
CHANGED
|
@@ -15,6 +15,8 @@
|
|
|
15
15
|
// never leaves foldrun.
|
|
16
16
|
|
|
17
17
|
import crypto from "node:crypto";
|
|
18
|
+
import { listRunSummaries, listWorkspaces } from "./store.ts";
|
|
19
|
+
import { records } from "./records.ts";
|
|
18
20
|
|
|
19
21
|
/** A customer id as a partner writes it: printable, no spaces, 1–128. */
|
|
20
22
|
export const CUSTOMER_ID = /^[A-Za-z0-9._:@-]{1,128}$/;
|
|
@@ -61,3 +63,26 @@ export function withProviderUser(body: Buffer, userId: string, shape: "anthropic
|
|
|
61
63
|
}
|
|
62
64
|
return Buffer.from(JSON.stringify(parsed), "utf8");
|
|
63
65
|
}
|
|
66
|
+
|
|
67
|
+
const OPEN = new Set(["queued", "running", "awaiting-approval"]);
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* How many runs of this end customer are open — queued, running or parked
|
|
71
|
+
* at a gate — across every workspace of the account. Read from the run
|
|
72
|
+
* records themselves, so a wiped cache never hands out more room than the
|
|
73
|
+
* customer has. What the platform's open-runs limit counts under its lock.
|
|
74
|
+
*/
|
|
75
|
+
export function openRunsOfCustomer(tenant: string, customer: string): number {
|
|
76
|
+
const workspaces = listWorkspaces(tenant).map((w) => w.name);
|
|
77
|
+
const port = records();
|
|
78
|
+
// The database's count covers every workspace whose records live there;
|
|
79
|
+
// a workspace still on files (its import pending — records() answers
|
|
80
|
+
// null for it) is counted from its own summaries and added (Codex review).
|
|
81
|
+
const counted = port?.openRunsOfCustomer ? port.openRunsOfCustomer(tenant, customer) : null;
|
|
82
|
+
let n = counted ?? 0;
|
|
83
|
+
for (const ws of workspaces) {
|
|
84
|
+
if (counted !== null && records(tenant, ws)) continue;
|
|
85
|
+
for (const s of listRunSummaries(tenant, ws)) if (s.customer === customer && OPEN.has(s.status)) n++;
|
|
86
|
+
}
|
|
87
|
+
return n;
|
|
88
|
+
}
|