@looply/core 0.5.8 → 0.5.10
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/delivery-settings.d.ts +122 -0
- package/dist/delivery-settings.d.ts.map +1 -0
- package/dist/delivery-settings.js +184 -0
- package/dist/delivery-settings.js.map +1 -0
- package/dist/goal.d.ts +25 -0
- package/dist/goal.d.ts.map +1 -1
- package/dist/goal.js +13 -0
- package/dist/goal.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/machine-settings.d.ts +91 -0
- package/dist/machine-settings.d.ts.map +1 -0
- package/dist/machine-settings.js +134 -0
- package/dist/machine-settings.js.map +1 -0
- package/dist/provider-accounts.d.ts +228 -0
- package/dist/provider-accounts.d.ts.map +1 -0
- package/dist/provider-accounts.js +453 -0
- package/dist/provider-accounts.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* WHERE A MACHINE'S CHECKOUTS GO, AND HOW MUCH DISK THEY MAY TAKE — the shape
|
|
4
|
+
* the server stores and the machine obeys.
|
|
5
|
+
*
|
|
6
|
+
* 🔴 ON 2026-10-16 CHECKOUTS FILLED THE OWNER'S C: (about 100 GB). These are
|
|
7
|
+
* the three knobs a person gets for that, per machine, from the console or
|
|
8
|
+
* AutoRyn:
|
|
9
|
+
*
|
|
10
|
+
* workspacesRoot the folder new checkouts go in. Null: `~/.looply/workspaces`.
|
|
11
|
+
* checkoutsCapGb GB all checkouts together may use. Null: no cap.
|
|
12
|
+
* minFreeGb GB that must stay free on the checkout drive. Null: 20.
|
|
13
|
+
*
|
|
14
|
+
* One declaration, shared, so a value the server accepts is a value the machine
|
|
15
|
+
* can at least read. The server can only check a folder's SHAPE; whether it is
|
|
16
|
+
* on a local fixed drive, writable, outside every served repository and outside
|
|
17
|
+
* `~/.looply` is a fact about the machine, so the machine checks that itself
|
|
18
|
+
* before using it (`packages/cli/src/machine-settings.ts`) and refuses in words.
|
|
19
|
+
*
|
|
20
|
+
* ⚠️ THE MACHINE'S OWN SAY STILL WINS: `LOOPLY_WORKSPACES_ROOT` and
|
|
21
|
+
* `~/.looply/machine-settings.json` override whatever is set here.
|
|
22
|
+
*/
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.WORKSPACES_SOURCES = exports.WORKSPACES_ROOT_MAX = exports.DEFAULT_MACHINE_SETTINGS = exports.DEFAULT_MIN_FREE_GB = exports.MACHINE_SETTING_KEYS = void 0;
|
|
25
|
+
exports.folderShapeProblem = folderShapeProblem;
|
|
26
|
+
exports.validateMachineSettingsPatch = validateMachineSettingsPatch;
|
|
27
|
+
exports.validateMachineSettings = validateMachineSettings;
|
|
28
|
+
exports.MACHINE_SETTING_KEYS = ['workspacesRoot', 'checkoutsCapGb', 'minFreeGb'];
|
|
29
|
+
/** No new checkout is made when its drive has less free space than this (GB). */
|
|
30
|
+
exports.DEFAULT_MIN_FREE_GB = 20;
|
|
31
|
+
/** What null means for each field, for a client to render "default" honestly. */
|
|
32
|
+
exports.DEFAULT_MACHINE_SETTINGS = {
|
|
33
|
+
workspacesRoot: null,
|
|
34
|
+
checkoutsCapGb: null,
|
|
35
|
+
minFreeGb: exports.DEFAULT_MIN_FREE_GB,
|
|
36
|
+
};
|
|
37
|
+
/** Longest folder accepted: leaves room under Windows' 260 for a checkout's own paths. */
|
|
38
|
+
exports.WORKSPACES_ROOT_MAX = 240;
|
|
39
|
+
const CAP_MAX_GB = 100_000;
|
|
40
|
+
const MIN_FREE_MAX_GB = 10_000;
|
|
41
|
+
/**
|
|
42
|
+
* Why `path` cannot be a checkout folder on ANY machine, or null when its shape
|
|
43
|
+
* is fine. Absolute (`X:\…` or `/…`), not a network path, no `..` segment, no
|
|
44
|
+
* control characters, not too long. Platform-free on purpose: the server runs
|
|
45
|
+
* on Linux and judges a Windows path, so `path.isAbsolute` would answer wrong.
|
|
46
|
+
*/
|
|
47
|
+
function folderShapeProblem(path) {
|
|
48
|
+
if (path.trim() !== path || path === '')
|
|
49
|
+
return 'must be a folder path with no leading or trailing spaces';
|
|
50
|
+
if (path.length > exports.WORKSPACES_ROOT_MAX)
|
|
51
|
+
return `must be at most ${exports.WORKSPACES_ROOT_MAX} characters`;
|
|
52
|
+
// eslint-disable-next-line no-control-regex
|
|
53
|
+
if (/[\u0000-\u001f\u007f]/.test(path))
|
|
54
|
+
return 'must not contain control characters';
|
|
55
|
+
if (/^[\\/]{2}/.test(path))
|
|
56
|
+
return 'must be on a local drive, not a network path';
|
|
57
|
+
const windows = /^[A-Za-z]:[\\/]/.test(path);
|
|
58
|
+
if (!windows && !path.startsWith('/'))
|
|
59
|
+
return 'must be an absolute path, like D:\\looply\\workspaces or /data/looply';
|
|
60
|
+
if (windows && /[<>"|?*]/.test(path.slice(2)))
|
|
61
|
+
return 'must not contain < > " | ? *';
|
|
62
|
+
if (path.split(/[\\/]/).some((s) => s === '..' || s === '.'))
|
|
63
|
+
return 'must not contain . or .. segments';
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
function gbProblem(value, min, max) {
|
|
67
|
+
if (typeof value !== 'number' || !Number.isFinite(value))
|
|
68
|
+
return 'must be a number of GB';
|
|
69
|
+
if (value < min || value > max)
|
|
70
|
+
return `must be between ${min} and ${max} GB`;
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* A partial update: a key left out is unchanged, `null` puts it back to the
|
|
75
|
+
* machine default. Unknown keys are refused rather than dropped, so a typo is
|
|
76
|
+
* a 400 and not a setting that silently never applies.
|
|
77
|
+
*/
|
|
78
|
+
function validateMachineSettingsPatch(raw) {
|
|
79
|
+
if (typeof raw !== 'object' || raw === null || Array.isArray(raw)) {
|
|
80
|
+
return { ok: false, key: 'settings', because: 'must be an object of workspacesRoot, checkoutsCapGb, minFreeGb' };
|
|
81
|
+
}
|
|
82
|
+
const patch = {};
|
|
83
|
+
for (const [key, value] of Object.entries(raw)) {
|
|
84
|
+
if (!exports.MACHINE_SETTING_KEYS.includes(key)) {
|
|
85
|
+
return { ok: false, key, because: `is not a machine setting (expected ${exports.MACHINE_SETTING_KEYS.join(', ')})` };
|
|
86
|
+
}
|
|
87
|
+
if (value === null) {
|
|
88
|
+
patch[key] = null;
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
if (key === 'workspacesRoot') {
|
|
92
|
+
if (typeof value !== 'string')
|
|
93
|
+
return { ok: false, key, because: 'must be a folder path or null' };
|
|
94
|
+
const why = folderShapeProblem(value);
|
|
95
|
+
if (why !== null)
|
|
96
|
+
return { ok: false, key, because: why };
|
|
97
|
+
patch.workspacesRoot = value;
|
|
98
|
+
}
|
|
99
|
+
else if (key === 'checkoutsCapGb') {
|
|
100
|
+
const why = gbProblem(value, 1, CAP_MAX_GB);
|
|
101
|
+
if (why !== null)
|
|
102
|
+
return { ok: false, key, because: why };
|
|
103
|
+
patch.checkoutsCapGb = value;
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
const why = gbProblem(value, 0, MIN_FREE_MAX_GB);
|
|
107
|
+
if (why !== null)
|
|
108
|
+
return { ok: false, key, because: why };
|
|
109
|
+
patch.minFreeGb = value;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return { ok: true, patch };
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* A whole stored or fetched value: every key, missing ones read as null. A
|
|
116
|
+
* value that does not validate is refused whole — a machine must not act on
|
|
117
|
+
* half of a setting it could not read.
|
|
118
|
+
*/
|
|
119
|
+
function validateMachineSettings(raw) {
|
|
120
|
+
const v = validateMachineSettingsPatch(raw);
|
|
121
|
+
if (!v.ok)
|
|
122
|
+
return v;
|
|
123
|
+
return {
|
|
124
|
+
ok: true,
|
|
125
|
+
settings: {
|
|
126
|
+
workspacesRoot: v.patch.workspacesRoot ?? null,
|
|
127
|
+
checkoutsCapGb: v.patch.checkoutsCapGb ?? null,
|
|
128
|
+
minFreeGb: v.patch.minFreeGb ?? null,
|
|
129
|
+
},
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
/** Where the folder a machine is using came from. */
|
|
133
|
+
exports.WORKSPACES_SOURCES = ['local', 'remote', 'default'];
|
|
134
|
+
//# sourceMappingURL=machine-settings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"machine-settings.js","sourceRoot":"","sources":["../src/machine-settings.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAgCH,gDAWC;AAmBD,oEA6BC;AAOD,0DAaC;AA7GY,QAAA,oBAAoB,GAAG,CAAC,gBAAgB,EAAE,gBAAgB,EAAE,WAAW,CAAU,CAAC;AAS/F,iFAAiF;AACpE,QAAA,mBAAmB,GAAG,EAAE,CAAC;AAEtC,iFAAiF;AACpE,QAAA,wBAAwB,GAAoB;IACvD,cAAc,EAAE,IAAI;IACpB,cAAc,EAAE,IAAI;IACpB,SAAS,EAAE,2BAAmB;CAC/B,CAAC;AAEF,0FAA0F;AAC7E,QAAA,mBAAmB,GAAG,GAAG,CAAC;AACvC,MAAM,UAAU,GAAG,OAAO,CAAC;AAC3B,MAAM,eAAe,GAAG,MAAM,CAAC;AAE/B;;;;;GAKG;AACH,SAAgB,kBAAkB,CAAC,IAAY;IAC7C,IAAI,IAAI,CAAC,IAAI,EAAE,KAAK,IAAI,IAAI,IAAI,KAAK,EAAE;QAAE,OAAO,0DAA0D,CAAC;IAC3G,IAAI,IAAI,CAAC,MAAM,GAAG,2BAAmB;QAAE,OAAO,mBAAmB,2BAAmB,aAAa,CAAC;IAClG,4CAA4C;IAC5C,IAAI,uBAAuB,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO,qCAAqC,CAAC;IACrF,IAAI,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO,8CAA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CAAC,SAAS,GAAG,KAAe,CAAC;QACpC,CAAC;IACH,CAAC;IACD,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;AAC7B,CAAC;AAED;;;;GAIG;AACH,SAAgB,uBAAuB,CACrC,GAAY;IAEZ,MAAM,CAAC,GAAG,4BAA4B,CAAC,GAAG,CAAC,CAAC;IAC5C,IAAI,CAAC,CAAC,CAAC,EAAE;QAAE,OAAO,CAAC,CAAC;IACpB,OAAO;QACL,EAAE,EAAE,IAAI;QACR,QAAQ,EAAE;YACR,cAAc,EAAE,CAAC,CAAC,KAAK,CAAC,cAAc,IAAI,IAAI;YAC9C,cAAc,EAAE,CAAC,CAAC,KAAK,CAAC,cAAc,IAAI,IAAI;YAC9C,SAAS,EAAE,CAAC,CAAC,KAAK,CAAC,SAAS,IAAI,IAAI;SACrC;KACF,CAAC;AACJ,CAAC;AAED,qDAAqD;AACxC,QAAA,kBAAkB,GAAG,CAAC,OAAO,EAAE,QAAQ,EAAE,SAAS,CAAU,CAAC"}
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SEVERAL AI ACCOUNTS PER MACHINE, AND WHICH ONE A MODEL CALL USES.
|
|
3
|
+
*
|
|
4
|
+
* A machine can hold several named provider logins, each in its own profile
|
|
5
|
+
* directory (`looply provider login --name <n>`). The credentials never leave
|
|
6
|
+
* the machine; what crosses to the server is a REPORT (label, kind, plan,
|
|
7
|
+
* readiness, resting until, usage) and what comes back is a POLICY set by the
|
|
8
|
+
* account's owner (who may use it, for which projects and roles, in what order,
|
|
9
|
+
* under what token caps).
|
|
10
|
+
*
|
|
11
|
+
* One declaration, shared: the server validates a policy with the same function
|
|
12
|
+
* the machine applies, and the machine then checks what only it can know (that
|
|
13
|
+
* the account exists, and whether it is a personal subscription).
|
|
14
|
+
*
|
|
15
|
+
* 🔴 A PERSONAL SUBSCRIPTION IS FOR ONE PERSON. An individual Pro or Max login
|
|
16
|
+
* is never offered to the whole workspace: `policyProblemFor` refuses
|
|
17
|
+
* `sharing: 'workspace'` on one, on the machine, whatever the server said.
|
|
18
|
+
* Workspace-shared use is an API-key or a Team/Enterprise account.
|
|
19
|
+
*
|
|
20
|
+
* ⚠️ RESTING IS NOT A WAY ROUND A LIMIT. When an account reports a usage limit it
|
|
21
|
+
* rests until its reset, and work continues only on accounts their owners
|
|
22
|
+
* allowed for that work. With one account, a limit still means waiting.
|
|
23
|
+
*/
|
|
24
|
+
export declare const ACCOUNT_PROVIDERS: readonly ["claude", "codex"];
|
|
25
|
+
export type AccountProvider = (typeof ACCOUNT_PROVIDERS)[number];
|
|
26
|
+
export declare const ACCOUNT_ROLES: readonly ["brain", "implementer", "verifier", "prover", "scanner"];
|
|
27
|
+
export type AccountRole = (typeof ACCOUNT_ROLES)[number];
|
|
28
|
+
export declare const ACCOUNT_SHARINGS: readonly ["owner", "workspace"];
|
|
29
|
+
export type AccountSharing = (typeof ACCOUNT_SHARINGS)[number];
|
|
30
|
+
export declare const ACCOUNT_PLANS: readonly ["pro", "max", "team", "enterprise"];
|
|
31
|
+
export type AccountPlan = (typeof ACCOUNT_PLANS)[number];
|
|
32
|
+
/** Why a machine says an account cannot run: the same words the heartbeat's `provider.reason` uses. */
|
|
33
|
+
export declare const ACCOUNT_NOT_READY_REASONS: readonly ["not_logged_in", "not_installed", "outdated", "unknown"];
|
|
34
|
+
export type AccountNotReadyReason = (typeof ACCOUNT_NOT_READY_REASONS)[number];
|
|
35
|
+
/** The legacy single profile (`~/.looply/provider-profile`) is the account with this name. */
|
|
36
|
+
export declare const DEFAULT_ACCOUNT_NAME = "default";
|
|
37
|
+
export declare const ACCOUNT_NAME_PATTERN: RegExp;
|
|
38
|
+
/** Priority of an account with no policy: `default` goes first, every other after it, by name. */
|
|
39
|
+
export declare const DEFAULT_ACCOUNT_PRIORITY = 100;
|
|
40
|
+
export declare const ACCOUNT_PRIORITY_MAX = 1000;
|
|
41
|
+
export declare const ACCOUNT_PROJECTS_MAX = 50;
|
|
42
|
+
export declare const ACCOUNT_LABEL_MAX = 60;
|
|
43
|
+
/** The compliance sentence, word for word, wherever the refusal is shown. */
|
|
44
|
+
export declare const PERSONAL_NOT_SHAREABLE: string;
|
|
45
|
+
export declare function isAccountName(x: unknown): x is string;
|
|
46
|
+
/** What the account's owner decided. Stored by the server, obeyed by the machine. */
|
|
47
|
+
export interface AccountPolicy {
|
|
48
|
+
name: string;
|
|
49
|
+
/** Opaque id of the person who owns the account (for AutoRyn, its user id). */
|
|
50
|
+
ownerRef: string | null;
|
|
51
|
+
ownerLabel: string | null;
|
|
52
|
+
sharing: AccountSharing;
|
|
53
|
+
/** Looply project ids it may work for; empty = every project on its machine. */
|
|
54
|
+
projects: string[];
|
|
55
|
+
/** Roles it may serve; empty = every role. */
|
|
56
|
+
roles: AccountRole[];
|
|
57
|
+
/** Lower is tried first. */
|
|
58
|
+
priority: number;
|
|
59
|
+
dailyTokenCap: number | null;
|
|
60
|
+
weeklyTokenCap: number | null;
|
|
61
|
+
enabled: boolean;
|
|
62
|
+
}
|
|
63
|
+
export type AccountPolicyPatch = Partial<Omit<AccountPolicy, 'name'>>;
|
|
64
|
+
export declare const ACCOUNT_POLICY_KEYS: readonly ["ownerRef", "ownerLabel", "sharing", "projects", "roles", "priority", "dailyTokenCap", "weeklyTokenCap", "enabled"];
|
|
65
|
+
/** A policy for `name` that changes nothing: what an account with no policy behaves like. */
|
|
66
|
+
export declare function defaultAccountPolicy(name: string): AccountPolicy;
|
|
67
|
+
export type AccountPolicyPatchCheck = {
|
|
68
|
+
ok: true;
|
|
69
|
+
patch: AccountPolicyPatch;
|
|
70
|
+
} | {
|
|
71
|
+
ok: false;
|
|
72
|
+
key: string;
|
|
73
|
+
because: string;
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* A partial change: a key left out is unchanged. Unknown keys are refused
|
|
77
|
+
* rather than dropped, so a typo is an error the person sees, not a setting
|
|
78
|
+
* that silently did nothing.
|
|
79
|
+
*/
|
|
80
|
+
export declare function validateAccountPolicyPatch(raw: unknown): AccountPolicyPatchCheck;
|
|
81
|
+
/** A whole stored policy, checked. Anything not usable reads as null, never as a guess. */
|
|
82
|
+
export declare function accountPolicyOf(raw: unknown): AccountPolicy | null;
|
|
83
|
+
/** A personal subscription: never workspace-shareable. An API key or a Team/Enterprise plan is not personal. */
|
|
84
|
+
export declare function isPersonalAccount(authMethod: string | null, plan: AccountPlan | null): boolean;
|
|
85
|
+
/**
|
|
86
|
+
* Why the MACHINE will not apply this policy to this account, or null. The
|
|
87
|
+
* server cannot know whether an account is a personal subscription; the
|
|
88
|
+
* machine can, and it has the last word.
|
|
89
|
+
*/
|
|
90
|
+
export declare function policyProblemFor(policy: AccountPolicy, account: {
|
|
91
|
+
personal: boolean;
|
|
92
|
+
}): string | null;
|
|
93
|
+
/** What a machine reports about one account. No email, no credential, no organisation id. */
|
|
94
|
+
export interface AccountReport {
|
|
95
|
+
name: string;
|
|
96
|
+
provider: AccountProvider;
|
|
97
|
+
label: string;
|
|
98
|
+
authMethod: string | null;
|
|
99
|
+
plan: AccountPlan | null;
|
|
100
|
+
personal: boolean;
|
|
101
|
+
ready: boolean;
|
|
102
|
+
reason: AccountNotReadyReason | null;
|
|
103
|
+
restingUntil: string | null;
|
|
104
|
+
restingBecause: string | null;
|
|
105
|
+
usage: {
|
|
106
|
+
dayTokens: number;
|
|
107
|
+
weekTokens: number;
|
|
108
|
+
};
|
|
109
|
+
policyRefused: string | null;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* One reported account, checked; null when it is not one. Lenient on the
|
|
113
|
+
* optional parts (a missing usage is zero, an unreadable time is null), strict
|
|
114
|
+
* on what identifies it.
|
|
115
|
+
*/
|
|
116
|
+
export declare function accountReportOf(raw: unknown): AccountReport | null;
|
|
117
|
+
/** The heartbeat's `accounts` list, checked: at most 20, unknown entries dropped, names unique. */
|
|
118
|
+
export declare function accountReportsOf(raw: unknown): AccountReport[] | undefined;
|
|
119
|
+
/** A machine's run slots as its heartbeat reports them. */
|
|
120
|
+
export interface MachineSlots {
|
|
121
|
+
running: number;
|
|
122
|
+
max: number;
|
|
123
|
+
}
|
|
124
|
+
export declare function machineSlotsOf(raw: unknown): MachineSlots | undefined;
|
|
125
|
+
/** One account as the chooser sees it: what the machine knows, plus what the owner set (null = no policy). */
|
|
126
|
+
export interface AccountCandidate {
|
|
127
|
+
name: string;
|
|
128
|
+
provider: AccountProvider;
|
|
129
|
+
ready: boolean;
|
|
130
|
+
personal: boolean;
|
|
131
|
+
/** Epoch ms; null when not resting. */
|
|
132
|
+
restingUntil: number | null;
|
|
133
|
+
usage: {
|
|
134
|
+
dayTokens: number;
|
|
135
|
+
weekTokens: number;
|
|
136
|
+
};
|
|
137
|
+
policy: AccountPolicy | null;
|
|
138
|
+
}
|
|
139
|
+
export interface AccountCallContext {
|
|
140
|
+
provider: AccountProvider;
|
|
141
|
+
role: AccountRole;
|
|
142
|
+
/** The Looply project the call works for; null when unknown (then a project-limited account is not used). */
|
|
143
|
+
projectId: string | null;
|
|
144
|
+
/** Who asked for this work (`requestedBy.ref` on the goal); null when nobody named one. */
|
|
145
|
+
requesterRef: string | null;
|
|
146
|
+
now: number;
|
|
147
|
+
}
|
|
148
|
+
export type AccountVerdict = {
|
|
149
|
+
name: string;
|
|
150
|
+
usable: true;
|
|
151
|
+
} | {
|
|
152
|
+
name: string;
|
|
153
|
+
usable: false;
|
|
154
|
+
why: string;
|
|
155
|
+
};
|
|
156
|
+
/** Whether one account may take this call, and why not in plain words. */
|
|
157
|
+
export declare function accountVerdict(c: AccountCandidate, ctx: AccountCallContext): AccountVerdict;
|
|
158
|
+
/**
|
|
159
|
+
* The accounts this call may use, best first (priority, then name), and why
|
|
160
|
+
* each of the others may not.
|
|
161
|
+
*/
|
|
162
|
+
export declare function chooseAccounts(candidates: readonly AccountCandidate[], ctx: AccountCallContext): {
|
|
163
|
+
usable: string[];
|
|
164
|
+
refused: {
|
|
165
|
+
name: string;
|
|
166
|
+
why: string;
|
|
167
|
+
}[];
|
|
168
|
+
};
|
|
169
|
+
/** A machine's account standing, as the server summarises a heartbeat. */
|
|
170
|
+
export interface AccountSummary {
|
|
171
|
+
total: number;
|
|
172
|
+
usable: number;
|
|
173
|
+
resting: number;
|
|
174
|
+
nextResetAt: string | null;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Summarise a machine's reported accounts for a requester: how many it could
|
|
178
|
+
* use right now. Policies are applied when known; caps and project limits are
|
|
179
|
+
* the machine's business at call time, so this is the server's best view, not
|
|
180
|
+
* a promise.
|
|
181
|
+
*/
|
|
182
|
+
export declare function summariseAccounts(reports: readonly AccountReport[], policies: readonly AccountPolicy[], opts: {
|
|
183
|
+
provider?: AccountProvider;
|
|
184
|
+
requesterRef?: string | null;
|
|
185
|
+
projectId?: string | null;
|
|
186
|
+
now: number;
|
|
187
|
+
}): AccountSummary;
|
|
188
|
+
export interface RepoGroupMember {
|
|
189
|
+
projectId: string;
|
|
190
|
+
projectName: string;
|
|
191
|
+
machineId: string;
|
|
192
|
+
machineName: string;
|
|
193
|
+
online: boolean;
|
|
194
|
+
providerReady: boolean | null;
|
|
195
|
+
slots: MachineSlots | null;
|
|
196
|
+
accounts: AccountSummary | null;
|
|
197
|
+
}
|
|
198
|
+
export interface RepoGroupPickRequest {
|
|
199
|
+
runOn?: string | null;
|
|
200
|
+
preferMachines?: readonly string[];
|
|
201
|
+
order?: readonly string[];
|
|
202
|
+
}
|
|
203
|
+
export interface RepoGroupCandidate {
|
|
204
|
+
machineId: string;
|
|
205
|
+
projectId: string;
|
|
206
|
+
eligible: boolean;
|
|
207
|
+
why: string;
|
|
208
|
+
}
|
|
209
|
+
export interface RepoGroupPick {
|
|
210
|
+
pick: {
|
|
211
|
+
projectId: string;
|
|
212
|
+
machineId: string;
|
|
213
|
+
} | null;
|
|
214
|
+
because: string;
|
|
215
|
+
candidates: RepoGroupCandidate[];
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Which machine of a repository group takes the next piece of work.
|
|
219
|
+
*
|
|
220
|
+
* 1. A person's "Run on" wins, and is not silently overridden: when that
|
|
221
|
+
* machine cannot take it, there is no pick and the reason says so.
|
|
222
|
+
* 2. Otherwise only eligible machines: online, provider not known-broken, a
|
|
223
|
+
* free slot (when reported), a usable account (when reported).
|
|
224
|
+
* 3. Then preferred machines (the requester's own, in the order given), then
|
|
225
|
+
* the configured order, then the most free slots, then the id.
|
|
226
|
+
*/
|
|
227
|
+
export declare function pickRepoGroupMember(members: readonly RepoGroupMember[], req: RepoGroupPickRequest): RepoGroupPick;
|
|
228
|
+
//# sourceMappingURL=provider-accounts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider-accounts.d.ts","sourceRoot":"","sources":["../src/provider-accounts.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,eAAO,MAAM,iBAAiB,8BAA+B,CAAC;AAC9D,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEjE,eAAO,MAAM,aAAa,oEAAqE,CAAC;AAChG,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,CAAC,CAAC;AAEzD,eAAO,MAAM,gBAAgB,iCAAkC,CAAC;AAChE,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAC;AAE/D,eAAO,MAAM,aAAa,+CAAgD,CAAC;AAC3E,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,CAAC,CAAC;AAEzD,uGAAuG;AACvG,eAAO,MAAM,yBAAyB,oEAAqE,CAAC;AAC5G,MAAM,MAAM,qBAAqB,GAAG,CAAC,OAAO,yBAAyB,CAAC,CAAC,MAAM,CAAC,CAAC;AAE/E,8FAA8F;AAC9F,eAAO,MAAM,oBAAoB,YAAY,CAAC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