byollm 0.1.2 → 0.1.4
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/README.md +1 -1
- package/dist/bin.js +1 -1
- package/dist/{chunk-K7QYAF7V.js → chunk-LGN2DHFP.js} +316 -48
- package/dist/chunk-LGN2DHFP.js.map +1 -0
- package/dist/index.d.ts +59 -6
- package/dist/index.js +1 -1
- package/package.json +2 -2
- package/dist/chunk-K7QYAF7V.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<!-- release-note 0.1.1 -->
|
|
2
|
-
> **`0.1.
|
|
2
|
+
> **`0.1.4` is documentation only — nothing to upgrade.** `PROTOCOL_VERSION`
|
|
3
3
|
> is still `2`, so a 0.1.0 party and a 0.1.1 party talk to each other in both
|
|
4
4
|
> directions. No dependency, schema, wire field or on-disk shape moved.
|
|
5
5
|
>
|
package/dist/bin.js
CHANGED
|
@@ -194,6 +194,10 @@ function asHttpOrigin(candidate) {
|
|
|
194
194
|
|
|
195
195
|
// src/local-server.ts
|
|
196
196
|
import { spawn } from "child_process";
|
|
197
|
+
import {
|
|
198
|
+
BACKEND_IDS,
|
|
199
|
+
backendDescriptor
|
|
200
|
+
} from "@byollm/protocol";
|
|
197
201
|
function startCommandFor(id) {
|
|
198
202
|
switch (id) {
|
|
199
203
|
case "ollama":
|
|
@@ -202,6 +206,18 @@ function startCommandFor(id) {
|
|
|
202
206
|
return void 0;
|
|
203
207
|
}
|
|
204
208
|
}
|
|
209
|
+
function startableAt(origin) {
|
|
210
|
+
for (const id of BACKEND_IDS) {
|
|
211
|
+
if (startCommandFor(id) === void 0) continue;
|
|
212
|
+
const address = backendDescriptor(id).defaultBaseUrl;
|
|
213
|
+
if (address === void 0) continue;
|
|
214
|
+
try {
|
|
215
|
+
if (new URL(address).origin === origin) return id;
|
|
216
|
+
} catch {
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
return void 0;
|
|
220
|
+
}
|
|
205
221
|
function isLoopback(baseUrl) {
|
|
206
222
|
let host;
|
|
207
223
|
try {
|
|
@@ -360,7 +376,7 @@ import {
|
|
|
360
376
|
BackendIdSchema,
|
|
361
377
|
JobKind,
|
|
362
378
|
OfferScope,
|
|
363
|
-
backendDescriptor,
|
|
379
|
+
backendDescriptor as backendDescriptor2,
|
|
364
380
|
effectiveOfferScope,
|
|
365
381
|
classifyCost
|
|
366
382
|
} from "@byollm/protocol";
|
|
@@ -520,7 +536,19 @@ var CommunityBudget = z.object({
|
|
|
520
536
|
/** Output-size ceiling for one community job. */
|
|
521
537
|
maxOutputBytes: z.number().int().positive().default(256 * 1024),
|
|
522
538
|
/** Payload-size ceiling — stricter than the protocol's absolute limit. */
|
|
523
|
-
maxPayloadChars: z.number().int().positive().default(1e5)
|
|
539
|
+
maxPayloadChars: z.number().int().positive().default(1e5),
|
|
540
|
+
/**
|
|
541
|
+
* Whether a teammate's job on a METERED service you shared counts toward
|
|
542
|
+
* the two job caps above.
|
|
543
|
+
*
|
|
544
|
+
* Off by default, because that work is already bounded by the service's
|
|
545
|
+
* daily spend ceiling, in your own dollars — and counting it twice is how
|
|
546
|
+
* a teammate's writing assistant stopped at twenty jobs an hour on a
|
|
547
|
+
* service that had spent $0.80 of $25.00 (10-22). The payload, wall-clock
|
|
548
|
+
* and output ceilings apply either way, and work on a free service — your
|
|
549
|
+
* GPU, which no dollar ceiling bounds — is always counted.
|
|
550
|
+
*/
|
|
551
|
+
countTeamJobs: z.boolean().default(false)
|
|
524
552
|
}).strict();
|
|
525
553
|
var IngressRetention = z.object({
|
|
526
554
|
/**
|
|
@@ -776,7 +804,7 @@ function resolveConfig(config) {
|
|
|
776
804
|
}
|
|
777
805
|
for (const [name, service] of Object.entries(config.services)) {
|
|
778
806
|
const where = `services.${name}`;
|
|
779
|
-
const descriptor =
|
|
807
|
+
const descriptor = backendDescriptor2(service.type);
|
|
780
808
|
const baseUrl = service.baseUrl ?? descriptor.defaultBaseUrl;
|
|
781
809
|
if (descriptor.class === "http") {
|
|
782
810
|
if (baseUrl === void 0) {
|
|
@@ -1088,7 +1116,7 @@ function serviceLine(input) {
|
|
|
1088
1116
|
}
|
|
1089
1117
|
case "unstartable":
|
|
1090
1118
|
return {
|
|
1091
|
-
line: `${service} \u2014 ${state.model}, not running, and ${device} cannot start it for you: start it yourself, then it will be offered`
|
|
1119
|
+
line: `${service} \u2014 ${state.model}, not running, and ${device} cannot start it for you: start it yourself, then it will be offered` + (state.startableAs === void 0 ? "" : ` \u2014 or set "type": "${state.startableAs}" on it in ~/.byollm/config.json and byollm will start it for you`)
|
|
1092
1120
|
};
|
|
1093
1121
|
case "blocked": {
|
|
1094
1122
|
const when = state.until === void 0 ? "it needs time, not a fix" : `back around ${clockTime(state.until)}`;
|
|
@@ -1395,7 +1423,7 @@ function realUpdateDeps(input) {
|
|
|
1395
1423
|
}
|
|
1396
1424
|
|
|
1397
1425
|
// src/backends/index.ts
|
|
1398
|
-
import { backendDescriptor as
|
|
1426
|
+
import { backendDescriptor as backendDescriptor3 } from "@byollm/protocol";
|
|
1399
1427
|
|
|
1400
1428
|
// src/backends/claude-cli.ts
|
|
1401
1429
|
import { execFile as execFile2 } from "child_process";
|
|
@@ -2392,7 +2420,7 @@ function stopReasonOf(result) {
|
|
|
2392
2420
|
|
|
2393
2421
|
// src/backends/index.ts
|
|
2394
2422
|
function createBackend(id, init) {
|
|
2395
|
-
const kind =
|
|
2423
|
+
const kind = backendDescriptor3(id).class;
|
|
2396
2424
|
switch (kind) {
|
|
2397
2425
|
// Process class dispatches by **id**, not by class, and the difference is
|
|
2398
2426
|
// not stylistic. `case "process": return new ClaudeCliBackend()` was
|
|
@@ -3439,6 +3467,13 @@ Someone else's terms are not yours to lend.
|
|
|
3439
3467
|
continue;
|
|
3440
3468
|
}
|
|
3441
3469
|
row.capCents = cents;
|
|
3470
|
+
io.out(
|
|
3471
|
+
` Your team's jobs on ${row.name} stop at that amount. They are not
|
|
3472
|
+
also counted against the hourly and daily job caps for other
|
|
3473
|
+
people's work \u2014 to count them too:
|
|
3474
|
+
byollm budget community --count-team-jobs yes
|
|
3475
|
+
`
|
|
3476
|
+
);
|
|
3442
3477
|
}
|
|
3443
3478
|
anyShared = shareable.some((row) => row.shared);
|
|
3444
3479
|
}
|
|
@@ -3856,6 +3891,12 @@ var BudgetFile = z3.object({
|
|
|
3856
3891
|
/** Epoch-ms timestamps of community jobs accepted, newest last. */
|
|
3857
3892
|
accepted: z3.array(z3.number().int().positive())
|
|
3858
3893
|
}).strict();
|
|
3894
|
+
var BudgetRefusal = z3.enum([
|
|
3895
|
+
"hourly-cap",
|
|
3896
|
+
"daily-cap",
|
|
3897
|
+
"payload-too-large",
|
|
3898
|
+
"ledger-untrusted"
|
|
3899
|
+
]);
|
|
3859
3900
|
var Budgets = class {
|
|
3860
3901
|
#path;
|
|
3861
3902
|
#limits;
|
|
@@ -3892,8 +3933,13 @@ var Budgets = class {
|
|
|
3892
3933
|
*
|
|
3893
3934
|
* @param payloadChars - total payload text length, checked against the
|
|
3894
3935
|
* stricter community limit rather than the protocol's absolute ceiling.
|
|
3936
|
+
* @param counted - whether this job counts toward the hourly and daily
|
|
3937
|
+
* caps. `false` only for a teammate's job on a metered service the owner
|
|
3938
|
+
* shared, which the spend ceiling already bounds — see
|
|
3939
|
+
* {@link CommunityBudget}'s `countTeamJobs`. The payload limit applies
|
|
3940
|
+
* either way.
|
|
3895
3941
|
*/
|
|
3896
|
-
check(now, payloadChars) {
|
|
3942
|
+
check(now, payloadChars, counted = true) {
|
|
3897
3943
|
if (!this.#loaded) throw new Error("budgets used before load()");
|
|
3898
3944
|
if (this.#untrusted !== void 0) {
|
|
3899
3945
|
return {
|
|
@@ -3910,6 +3956,7 @@ var Budgets = class {
|
|
|
3910
3956
|
detail: `community jobs are limited to ${String(this.#limits.maxPayloadChars)} characters; this one is ${String(payloadChars)}`
|
|
3911
3957
|
};
|
|
3912
3958
|
}
|
|
3959
|
+
if (!counted) return { ok: true };
|
|
3913
3960
|
const hour = this.#countSince(now - 36e5);
|
|
3914
3961
|
if (hour >= this.#limits.maxJobsPerHour) {
|
|
3915
3962
|
return {
|
|
@@ -4223,11 +4270,7 @@ var TEST_YOUR_DEVICE = "TEST YOUR DEVICE: Visit https://test.byollm.cloud and pr
|
|
|
4223
4270
|
// src/diagnose.ts
|
|
4224
4271
|
import { execFile as execFile4 } from "child_process";
|
|
4225
4272
|
import { promisify as promisify2 } from "util";
|
|
4226
|
-
import {
|
|
4227
|
-
BACKEND_IDS,
|
|
4228
|
-
backendDescriptor as backendDescriptor3,
|
|
4229
|
-
backendName as backendName2
|
|
4230
|
-
} from "@byollm/protocol";
|
|
4273
|
+
import { backendName as backendName2 } from "@byollm/protocol";
|
|
4231
4274
|
var run = promisify2(execFile4);
|
|
4232
4275
|
var BY_PORT = {
|
|
4233
4276
|
"11434": {
|
|
@@ -4282,18 +4325,6 @@ var whichProbe = async (binary) => {
|
|
|
4282
4325
|
return code === 1 || code === "ENOENT" ? false : void 0;
|
|
4283
4326
|
}
|
|
4284
4327
|
};
|
|
4285
|
-
function startableAt(origin) {
|
|
4286
|
-
for (const id of BACKEND_IDS) {
|
|
4287
|
-
if (startCommandFor(id) === void 0) continue;
|
|
4288
|
-
const address = backendDescriptor3(id).defaultBaseUrl;
|
|
4289
|
-
if (address === void 0) continue;
|
|
4290
|
-
try {
|
|
4291
|
-
if (new URL(address).origin === origin) return id;
|
|
4292
|
-
} catch {
|
|
4293
|
-
}
|
|
4294
|
-
}
|
|
4295
|
-
return void 0;
|
|
4296
|
-
}
|
|
4297
4328
|
async function diagnoseRoute(input) {
|
|
4298
4329
|
const onPath = input.onPath ?? whichProbe;
|
|
4299
4330
|
const reach = input.reach ?? fetchProbe;
|
|
@@ -4537,7 +4568,20 @@ var OutcomeEntry = z4.object({
|
|
|
4537
4568
|
* reason a log is a log: if an adapter gains a signal in a later release,
|
|
4538
4569
|
* entries written before that should still read as they were true.
|
|
4539
4570
|
*/
|
|
4540
|
-
stopKind: z4.enum(["declared", "unavailable", "unverified"]).optional()
|
|
4571
|
+
stopKind: z4.enum(["declared", "unavailable", "unverified"]).optional(),
|
|
4572
|
+
/**
|
|
4573
|
+
* Which community brake refused this job, when one did — 10-22.
|
|
4574
|
+
*
|
|
4575
|
+
* `detail` already said it in words, and `byollm status` could not tell
|
|
4576
|
+
* the hourly cap from the payload limit without parsing a sentence: Lis
|
|
4577
|
+
* was refused 21 times and the screen said which cap was full only by
|
|
4578
|
+
* arithmetic. The code is what status groups by and names the fix for.
|
|
4579
|
+
*
|
|
4580
|
+
* Optional, like everything added here. A build older than this one reads
|
|
4581
|
+
* a line carrying it as malformed and skips it — one refusal missing from
|
|
4582
|
+
* an older binary's count, which is the cost of a strict reader.
|
|
4583
|
+
*/
|
|
4584
|
+
brake: BudgetRefusal.optional()
|
|
4541
4585
|
}).strict();
|
|
4542
4586
|
var MemoryEntry = z4.object({
|
|
4543
4587
|
type: z4.literal("memory"),
|
|
@@ -4597,7 +4641,8 @@ var IngressLog = class {
|
|
|
4597
4641
|
...input.outputChars === void 0 ? {} : { outputChars: input.outputChars },
|
|
4598
4642
|
...input.detail === void 0 ? {} : { detail: input.detail },
|
|
4599
4643
|
...input.stop === void 0 ? {} : { stop: input.stop },
|
|
4600
|
-
...input.stopKind === void 0 ? {} : { stopKind: input.stopKind }
|
|
4644
|
+
...input.stopKind === void 0 ? {} : { stopKind: input.stopKind },
|
|
4645
|
+
...input.brake === void 0 ? {} : { brake: input.brake }
|
|
4601
4646
|
});
|
|
4602
4647
|
}
|
|
4603
4648
|
/** Record what the memory guard decided — B080. */
|
|
@@ -6446,10 +6491,12 @@ var Runner = class {
|
|
|
6446
6491
|
usable = health.healthy && (health.models.length === 0 || modelPresent(health.models, route.model));
|
|
6447
6492
|
const remedy = backend.signIn === void 0 ? {} : { signIn: backend.signIn };
|
|
6448
6493
|
if (!health.healthy) {
|
|
6494
|
+
const baseUrl = this.#options.loaded.config.services[route.service]?.baseUrl;
|
|
6495
|
+
const onPath = this.#options.onPath === void 0 ? {} : { onPath: this.#options.onPath };
|
|
6449
6496
|
const startable = await startability({
|
|
6450
6497
|
id: route.backendId,
|
|
6451
|
-
baseUrl
|
|
6452
|
-
...
|
|
6498
|
+
baseUrl,
|
|
6499
|
+
...onPath
|
|
6453
6500
|
});
|
|
6454
6501
|
const starts = this.#options.spawnServer !== void 0;
|
|
6455
6502
|
usable = startable.startable && starts;
|
|
@@ -6466,7 +6513,11 @@ var Runner = class {
|
|
|
6466
6513
|
* Only `not-installed` is `missing`. The advertising decision is
|
|
6467
6514
|
* unchanged: nothing here is offered either way.
|
|
6468
6515
|
*/
|
|
6469
|
-
state: startable.startable ? { kind: "stopped", model: route.model, starts } : startable.why === "not-installed" ? { kind: "missing" } : {
|
|
6516
|
+
state: startable.startable ? { kind: "stopped", model: route.model, starts } : startable.why === "not-installed" ? { kind: "missing" } : {
|
|
6517
|
+
kind: "unstartable",
|
|
6518
|
+
model: route.model,
|
|
6519
|
+
...await this.#startableAs(route.backendId, baseUrl)
|
|
6520
|
+
},
|
|
6470
6521
|
...remedy
|
|
6471
6522
|
});
|
|
6472
6523
|
} else if (options.canary !== true || backend.canary === void 0) {
|
|
@@ -6549,6 +6600,35 @@ var Runner = class {
|
|
|
6549
6600
|
this.#now()
|
|
6550
6601
|
);
|
|
6551
6602
|
}
|
|
6603
|
+
/**
|
|
6604
|
+
* Does this other person's job count toward the community job caps?
|
|
6605
|
+
*
|
|
6606
|
+
* Not when it is a teammate's job on a metered service the owner shared
|
|
6607
|
+
* with a ceiling, unless the owner set `community.countTeamJobs`: that work
|
|
6608
|
+
* is already counted, in dollars, against a limit the owner chose, and
|
|
6609
|
+
* counting it a second time as a stranger's job is what stopped Lis at
|
|
6610
|
+
* twenty an hour on a service that had spent $0.80 of $25.00 (10-22).
|
|
6611
|
+
*
|
|
6612
|
+
* Everything else is counted, and that is the bound byollm_016 §5 and
|
|
6613
|
+
* byollm_001 lean on: a free service is the owner's GPU, which no dollar
|
|
6614
|
+
* ceiling bounds, so a teammate's runaway loop there still stops at the
|
|
6615
|
+
* hourly cap. An unresolved route counts — the safe direction for a
|
|
6616
|
+
* question asked about somebody else's work.
|
|
6617
|
+
*
|
|
6618
|
+
* "Metered" is the cost class this daemon resolved for the service, and
|
|
6619
|
+
* "team" is a team-scoped service reached under a signed grant — never
|
|
6620
|
+
* anything the job says about itself (owl, #15096). The grant has already
|
|
6621
|
+
* been verified by `#grantAdmits` on every path that reaches here; asking
|
|
6622
|
+
* for it again is what keeps a future caller that skips admission from
|
|
6623
|
+
* inheriting the exemption.
|
|
6624
|
+
*/
|
|
6625
|
+
#countsTowardJobCaps(job, route) {
|
|
6626
|
+
const granted = "grant" in job && job.grant !== void 0;
|
|
6627
|
+
if (route === void 0 || !granted) return true;
|
|
6628
|
+
if (this.#options.loaded.config.community.countTeamJobs) return true;
|
|
6629
|
+
const boundedBySpend = route.cost === "metered" && route.offerScope === "team" && route.spendAcknowledged && route.spendDailyCapCents !== void 0;
|
|
6630
|
+
return !boundedBySpend;
|
|
6631
|
+
}
|
|
6552
6632
|
/**
|
|
6553
6633
|
* The route a job takes — byollm_016 Phase B, both sides of it.
|
|
6554
6634
|
*
|
|
@@ -6812,9 +6892,16 @@ var Runner = class {
|
|
|
6812
6892
|
if (job.owner !== this.#options.owner) {
|
|
6813
6893
|
const decision = this.#options.budgets.check(
|
|
6814
6894
|
this.#now(),
|
|
6815
|
-
sizeClassCeiling(job.sizeClass)
|
|
6895
|
+
sizeClassCeiling(job.sizeClass),
|
|
6896
|
+
this.#countsTowardJobCaps(job, route)
|
|
6816
6897
|
);
|
|
6817
|
-
if (!decision.ok)
|
|
6898
|
+
if (!decision.ok) {
|
|
6899
|
+
return {
|
|
6900
|
+
ok: false,
|
|
6901
|
+
reason: decision.detail,
|
|
6902
|
+
brake: decision.refusal
|
|
6903
|
+
};
|
|
6904
|
+
}
|
|
6818
6905
|
}
|
|
6819
6906
|
if (!this.#served.has(job.site)) {
|
|
6820
6907
|
this.#served.add(job.site);
|
|
@@ -6861,6 +6948,33 @@ var Runner = class {
|
|
|
6861
6948
|
* too, and none of them should be able to start a model server as a side
|
|
6862
6949
|
* effect of asking a question.
|
|
6863
6950
|
*/
|
|
6951
|
+
/**
|
|
6952
|
+
* The type that WOULD be started at this address, for the owner's line —
|
|
6953
|
+
* B098's offer, reaching `byollm status`.
|
|
6954
|
+
*
|
|
6955
|
+
* Asks `startableAt`, the one function `byollm diagnose` asks, and then
|
|
6956
|
+
* asks `startability` of THAT type at this address — so the offer is made
|
|
6957
|
+
* only where taking it would actually work: loopback, a start command, and
|
|
6958
|
+
* the binary on PATH. Retyping a service into one that then reads "not
|
|
6959
|
+
* found" is a remedy that moves the problem rather than fixing it.
|
|
6960
|
+
*/
|
|
6961
|
+
async #startableAs(configured, baseUrl) {
|
|
6962
|
+
if (baseUrl === void 0 || !isLoopback(baseUrl)) return {};
|
|
6963
|
+
let origin;
|
|
6964
|
+
try {
|
|
6965
|
+
origin = new URL(baseUrl).origin;
|
|
6966
|
+
} catch {
|
|
6967
|
+
return {};
|
|
6968
|
+
}
|
|
6969
|
+
const id = startableAt(origin);
|
|
6970
|
+
if (id === void 0 || id === configured) return {};
|
|
6971
|
+
const would = await startability({
|
|
6972
|
+
id,
|
|
6973
|
+
baseUrl,
|
|
6974
|
+
...this.#options.onPath === void 0 ? {} : { onPath: this.#options.onPath }
|
|
6975
|
+
});
|
|
6976
|
+
return would.startable ? { startableAs: id } : {};
|
|
6977
|
+
}
|
|
6864
6978
|
/**
|
|
6865
6979
|
* Should this machine take a job that loads a model right now — B080.
|
|
6866
6980
|
*
|
|
@@ -7023,7 +7137,9 @@ var Runner = class {
|
|
|
7023
7137
|
model: route.model,
|
|
7024
7138
|
prompt
|
|
7025
7139
|
});
|
|
7026
|
-
if (community
|
|
7140
|
+
if (community && this.#countsTowardJobCaps(job, route)) {
|
|
7141
|
+
await this.#options.budgets.record(this.#now());
|
|
7142
|
+
}
|
|
7027
7143
|
const backend = this.#backendFor(route);
|
|
7028
7144
|
const gate = await this.#memoryDecision(route, job.id);
|
|
7029
7145
|
const result = gate !== void 0 && !gate.admit ? {
|
|
@@ -7571,7 +7687,7 @@ var Runner = class {
|
|
|
7571
7687
|
}
|
|
7572
7688
|
const admission = this.admit(job);
|
|
7573
7689
|
if (!admission.ok) {
|
|
7574
|
-
await this.#refuseOnOurOwnRules(job, admission.reason);
|
|
7690
|
+
await this.#refuseOnOurOwnRules(job, admission.reason, admission.brake);
|
|
7575
7691
|
return;
|
|
7576
7692
|
}
|
|
7577
7693
|
const fetched = await this.#fetchWhenSealed(job);
|
|
@@ -7620,15 +7736,15 @@ var Runner = class {
|
|
|
7620
7736
|
}
|
|
7621
7737
|
this.#gaveUpFetching.delete(jobKey(job));
|
|
7622
7738
|
const payload = await this.#openPayload(job, fetched.envelope);
|
|
7739
|
+
const resolved = job.grant?.service;
|
|
7740
|
+
const route = this.#routeFor(job.kind, resolved);
|
|
7623
7741
|
if (job.owner !== this.#options.owner) {
|
|
7624
|
-
const refusal = this.#withinCommunityBudget(job, payload);
|
|
7742
|
+
const refusal = this.#withinCommunityBudget(job, payload, route);
|
|
7625
7743
|
if (refusal !== void 0) {
|
|
7626
|
-
await this.#refuseOnOurOwnRules(job, refusal);
|
|
7744
|
+
await this.#refuseOnOurOwnRules(job, refusal.detail, refusal.refusal);
|
|
7627
7745
|
return;
|
|
7628
7746
|
}
|
|
7629
7747
|
}
|
|
7630
|
-
const resolved = job.grant?.service;
|
|
7631
|
-
const route = this.#routeFor(job.kind, resolved);
|
|
7632
7748
|
const { outcome, ran } = await this.runJob({
|
|
7633
7749
|
...job,
|
|
7634
7750
|
payload,
|
|
@@ -7821,7 +7937,7 @@ var Runner = class {
|
|
|
7821
7937
|
* `refused` rather than a lapse, because a lapse means "ask me later" and
|
|
7822
7938
|
* this device's answer will not change.
|
|
7823
7939
|
*/
|
|
7824
|
-
async #refuseOnOurOwnRules(job, reason) {
|
|
7940
|
+
async #refuseOnOurOwnRules(job, reason, brake) {
|
|
7825
7941
|
this.#jobSettled(job);
|
|
7826
7942
|
this.#refused += 1;
|
|
7827
7943
|
await this.#options.ingress.recordOutcome({
|
|
@@ -7829,7 +7945,8 @@ var Runner = class {
|
|
|
7829
7945
|
jobId: job.id,
|
|
7830
7946
|
site: job.site,
|
|
7831
7947
|
outcome: "refused",
|
|
7832
|
-
detail: reason
|
|
7948
|
+
detail: reason,
|
|
7949
|
+
...brake === void 0 ? {} : { brake }
|
|
7833
7950
|
});
|
|
7834
7951
|
this.#options.onEvent?.({ type: "refused", jobId: job.id, reason });
|
|
7835
7952
|
await this.#safely(
|
|
@@ -7845,6 +7962,10 @@ var Runner = class {
|
|
|
7845
7962
|
*
|
|
7846
7963
|
* Returns the refusal to give, or `undefined` to proceed.
|
|
7847
7964
|
*
|
|
7965
|
+
* `route` decides only whether the job caps apply
|
|
7966
|
+
* ({@link ByollmRunner.#countsTowardJobCaps}); the payload is measured
|
|
7967
|
+
* whatever it says.
|
|
7968
|
+
*
|
|
7848
7969
|
* The admission-time call passes `sizeClassCeiling(job.sizeClass)`, a number
|
|
7849
7970
|
* the sender chose. This passes `payloadTextLength` of the opened payload,
|
|
7850
7971
|
* which is the same function the site used to derive that class — so a job
|
|
@@ -7856,15 +7977,16 @@ var Runner = class {
|
|
|
7856
7977
|
* hourly cap has the same answer for this job, and splitting the predicate
|
|
7857
7978
|
* would be a second copy of the rule for the sake of a narrower question.
|
|
7858
7979
|
*/
|
|
7859
|
-
#withinCommunityBudget(job, payload) {
|
|
7980
|
+
#withinCommunityBudget(job, payload, route) {
|
|
7860
7981
|
const decision = this.#options.budgets.check(
|
|
7861
7982
|
this.#now(),
|
|
7862
7983
|
payloadTextLength({
|
|
7863
7984
|
kind: job.kind,
|
|
7864
7985
|
payload
|
|
7865
|
-
})
|
|
7986
|
+
}),
|
|
7987
|
+
this.#countsTowardJobCaps(job, route)
|
|
7866
7988
|
);
|
|
7867
|
-
return decision.ok ? void 0 : decision
|
|
7989
|
+
return decision.ok ? void 0 : decision;
|
|
7868
7990
|
}
|
|
7869
7991
|
async #openPayload(job, envelope) {
|
|
7870
7992
|
const identity = this.#options.identity;
|
|
@@ -8782,6 +8904,7 @@ async function writeUnit(path, contents, encoding) {
|
|
|
8782
8904
|
|
|
8783
8905
|
// src/service-states.ts
|
|
8784
8906
|
import { readFile as readFile13, writeFile as writeFile8 } from "fs/promises";
|
|
8907
|
+
import { BackendIdSchema as BackendIdSchema2 } from "@byollm/protocol";
|
|
8785
8908
|
import { z as z8 } from "zod";
|
|
8786
8909
|
var Stored = z8.record(
|
|
8787
8910
|
z8.string(),
|
|
@@ -8795,7 +8918,13 @@ var Stored = z8.record(
|
|
|
8795
8918
|
z8.object({ kind: z8.literal("missing") }),
|
|
8796
8919
|
/* B098. Stopped and unstartable is not the same as absent, and the
|
|
8797
8920
|
file `byollm status` reads has to be able to tell them apart. */
|
|
8798
|
-
z8.object({
|
|
8921
|
+
z8.object({
|
|
8922
|
+
kind: z8.literal("unstartable"),
|
|
8923
|
+
model: z8.string(),
|
|
8924
|
+
/* An id this build does not know degrades to no offer, rather than
|
|
8925
|
+
failing the whole file and blanking every service's line. */
|
|
8926
|
+
startableAs: BackendIdSchema2.optional().catch(void 0)
|
|
8927
|
+
}),
|
|
8799
8928
|
/**
|
|
8800
8929
|
* Installed here, not running, and startable — B056.
|
|
8801
8930
|
*
|
|
@@ -8858,6 +8987,7 @@ var USAGE = `byollm \u2014 run an app's LLM jobs on your own models.
|
|
|
8858
8987
|
byollm services manage turn services on and off, and share them
|
|
8859
8988
|
byollm model <svc> <name> check a model answers, then use it
|
|
8860
8989
|
byollm offer <service> <scope> who a service is offered to (private|team)
|
|
8990
|
+
byollm budget community how many jobs other people may run here
|
|
8861
8991
|
byollm sites which sites this device serves
|
|
8862
8992
|
|
|
8863
8993
|
Config lives in ~/.byollm/config.json. Everything this daemon has ever run is
|
|
@@ -8982,7 +9112,9 @@ async function runCli(argv, options = {}) {
|
|
|
8982
9112
|
case "disallow":
|
|
8983
9113
|
return commandRetiredAdmission("disallow", io);
|
|
8984
9114
|
case "offer":
|
|
8985
|
-
return commandOffer(paths, rest, io);
|
|
9115
|
+
return commandOffer(paths, rest, io, service, options.env);
|
|
9116
|
+
case "budget":
|
|
9117
|
+
return commandBudget(paths, rest, io, service, options.env);
|
|
8986
9118
|
case "sites":
|
|
8987
9119
|
return commandSites(paths, io);
|
|
8988
9120
|
case "approve":
|
|
@@ -10310,12 +10442,27 @@ async function commandStatus(paths, io, service) {
|
|
|
10310
10442
|
io.out(" your own jobs on these are not counted here and have no cap.\n");
|
|
10311
10443
|
}
|
|
10312
10444
|
const usage = budgets.usage(now);
|
|
10445
|
+
const entries = await ingress.read();
|
|
10313
10446
|
io.out("\ncommunity work done for others\n");
|
|
10314
10447
|
io.out(
|
|
10315
10448
|
` ${String(usage.hour)} in the last hour (cap ${String(usage.limits.maxJobsPerHour)}), ${String(usage.day)} today (cap ${String(usage.limits.maxJobsPerDay)})
|
|
10316
10449
|
`
|
|
10317
10450
|
);
|
|
10318
|
-
const entries
|
|
10451
|
+
for (const line of brakeLines(entries, now, usage.limits, paths.config)) {
|
|
10452
|
+
io.out(` ${line}
|
|
10453
|
+
`);
|
|
10454
|
+
}
|
|
10455
|
+
if (!loaded.config.community.countTeamJobs) {
|
|
10456
|
+
for (const route of metered) {
|
|
10457
|
+
if (route.offerScope !== "team" || !route.spendAcknowledged || route.spendDailyCapCents === void 0) {
|
|
10458
|
+
continue;
|
|
10459
|
+
}
|
|
10460
|
+
io.out(
|
|
10461
|
+
` your team's jobs on ${route.service} are not counted here \u2014 its daily spend ceiling bounds them
|
|
10462
|
+
`
|
|
10463
|
+
);
|
|
10464
|
+
}
|
|
10465
|
+
}
|
|
10319
10466
|
const prompts = entries.filter((entry) => entry.type === "prompt");
|
|
10320
10467
|
const outcomes = entries.filter((entry) => entry.type === "outcome");
|
|
10321
10468
|
io.out("\nthis device has run\n");
|
|
@@ -10330,6 +10477,23 @@ async function commandStatus(paths, io, service) {
|
|
|
10330
10477
|
);
|
|
10331
10478
|
return 0;
|
|
10332
10479
|
}
|
|
10480
|
+
function brakeLines(entries, now, limits, configPath) {
|
|
10481
|
+
const counts = /* @__PURE__ */ new Map();
|
|
10482
|
+
for (const entry of entries) {
|
|
10483
|
+
if (entry.type !== "outcome" || entry.brake === void 0) continue;
|
|
10484
|
+
if (entry.at < now - 36e5) continue;
|
|
10485
|
+
counts.set(entry.brake, (counts.get(entry.brake) ?? 0) + 1);
|
|
10486
|
+
}
|
|
10487
|
+
const why = {
|
|
10488
|
+
"hourly-cap": `hourly cap (${String(limits.maxJobsPerHour)}) \u2014 raise it: byollm budget community --per-hour N`,
|
|
10489
|
+
"daily-cap": `daily cap (${String(limits.maxJobsPerDay)}) \u2014 raise it: byollm budget community --per-day N`,
|
|
10490
|
+
"payload-too-large": `payload limit (${String(limits.maxPayloadChars)} characters) \u2014 community.maxPayloadChars in ${configPath}`,
|
|
10491
|
+
"ledger-untrusted": 'its record of community work cannot be read \u2014 see "bookkeeping this device cannot read" above'
|
|
10492
|
+
};
|
|
10493
|
+
return [...counts].map(
|
|
10494
|
+
([brake, count]) => `refused ${String(count)} in the last hour: ${why[brake]}`
|
|
10495
|
+
);
|
|
10496
|
+
}
|
|
10333
10497
|
function split(entry) {
|
|
10334
10498
|
const parts = [];
|
|
10335
10499
|
if (entry.spawnMs !== void 0) parts.push(`spawn ${String(entry.spawnMs)}`);
|
|
@@ -10444,7 +10608,7 @@ function offerSummary(input) {
|
|
|
10444
10608
|
narrowedBy: void 0
|
|
10445
10609
|
};
|
|
10446
10610
|
}
|
|
10447
|
-
async function commandOffer(paths, args, io) {
|
|
10611
|
+
async function commandOffer(paths, args, io, serviceIo, env = process.env) {
|
|
10448
10612
|
const [serviceKey, scope, ...rest] = args;
|
|
10449
10613
|
if (serviceKey === void 0 || scope === void 0) {
|
|
10450
10614
|
io.err("usage: byollm offer <service> <private|team> [--cap <cents>]\n");
|
|
@@ -10586,6 +10750,110 @@ Offer ${serviceKey} to your team?`
|
|
|
10586
10750
|
io.out(
|
|
10587
10751
|
`${serviceKey} is now offered to ${scope}` + (written === void 0 || !widening ? "" : `, capped at ${dollars(written)} a day`) + "\n"
|
|
10588
10752
|
);
|
|
10753
|
+
await pickUpTheChange(paths, io, serviceIo, env);
|
|
10754
|
+
return 0;
|
|
10755
|
+
}
|
|
10756
|
+
async function pickUpTheChange(paths, io, serviceIo, env) {
|
|
10757
|
+
const told = tellSupervisor(void 0, env);
|
|
10758
|
+
if (told === "told") {
|
|
10759
|
+
io.out(
|
|
10760
|
+
"\nTold the supervisor \u2014 this device is picking the change up now.\n"
|
|
10761
|
+
);
|
|
10762
|
+
return;
|
|
10763
|
+
}
|
|
10764
|
+
if (told === "gone") {
|
|
10765
|
+
io.out(
|
|
10766
|
+
"\nThis device's supervisor is not answering, so nothing is serving the\nnew configuration yet. Restarting the device picks it up.\n"
|
|
10767
|
+
);
|
|
10768
|
+
return;
|
|
10769
|
+
}
|
|
10770
|
+
if (await serviceIsInstalled(serviceTarget(paths, serviceIo))) {
|
|
10771
|
+
io.out(
|
|
10772
|
+
"\nThe background service is running with the config it started on.\n byollm stop && byollm start pick this up\n"
|
|
10773
|
+
);
|
|
10774
|
+
}
|
|
10775
|
+
}
|
|
10776
|
+
var BUDGET_USAGE = "usage: byollm budget community [--per-hour N] [--per-day N] [--count-team-jobs yes|no]\n";
|
|
10777
|
+
async function commandBudget(paths, args, io, serviceIo, env = process.env) {
|
|
10778
|
+
const [scope, ...flags] = args;
|
|
10779
|
+
if (scope !== "community") {
|
|
10780
|
+
io.err(BUDGET_USAGE);
|
|
10781
|
+
return 2;
|
|
10782
|
+
}
|
|
10783
|
+
const changes = {};
|
|
10784
|
+
for (let i = 0; i < flags.length; i += 2) {
|
|
10785
|
+
const flag = flags[i];
|
|
10786
|
+
const value = flags[i + 1];
|
|
10787
|
+
if (flag === "--per-hour" || flag === "--per-day") {
|
|
10788
|
+
if (value === void 0 || !/^[0-9]+$/.test(value) || Number(value) <= 0) {
|
|
10789
|
+
io.err(
|
|
10790
|
+
`${flag} takes a whole number of jobs, greater than zero` + (value === void 0 ? "" : ` \u2014 not "${value}"`) + "\n"
|
|
10791
|
+
);
|
|
10792
|
+
return 2;
|
|
10793
|
+
}
|
|
10794
|
+
if (flag === "--per-hour") changes.perHour = Number(value);
|
|
10795
|
+
else changes.perDay = Number(value);
|
|
10796
|
+
continue;
|
|
10797
|
+
}
|
|
10798
|
+
if (flag === "--count-team-jobs") {
|
|
10799
|
+
if (value !== "yes" && value !== "no") {
|
|
10800
|
+
io.err("--count-team-jobs takes yes or no\n");
|
|
10801
|
+
return 2;
|
|
10802
|
+
}
|
|
10803
|
+
changes.countTeam = value === "yes";
|
|
10804
|
+
continue;
|
|
10805
|
+
}
|
|
10806
|
+
io.err(`unknown option "${flag ?? ""}"
|
|
10807
|
+
${BUDGET_USAGE}`);
|
|
10808
|
+
return 2;
|
|
10809
|
+
}
|
|
10810
|
+
let raw;
|
|
10811
|
+
try {
|
|
10812
|
+
raw = await readFile14(paths.config, "utf8");
|
|
10813
|
+
} catch {
|
|
10814
|
+
io.err(
|
|
10815
|
+
`no config at ${paths.config} \u2014 nothing to set a budget on yet.
|
|
10816
|
+
Run \`byollm setup\` first.
|
|
10817
|
+
`
|
|
10818
|
+
);
|
|
10819
|
+
return 1;
|
|
10820
|
+
}
|
|
10821
|
+
let parsed;
|
|
10822
|
+
try {
|
|
10823
|
+
parsed = JSON.parse(raw);
|
|
10824
|
+
} catch {
|
|
10825
|
+
io.err(`${paths.config} is not valid JSON \u2014 fix it by hand first
|
|
10826
|
+
`);
|
|
10827
|
+
return 1;
|
|
10828
|
+
}
|
|
10829
|
+
const result = DaemonConfig.safeParse(parsed);
|
|
10830
|
+
if (!result.success) {
|
|
10831
|
+
io.err(`${paths.config} is not a valid byollm config \u2014 fix it first
|
|
10832
|
+
`);
|
|
10833
|
+
return 1;
|
|
10834
|
+
}
|
|
10835
|
+
const community = result.data.community;
|
|
10836
|
+
const changed = Object.keys(changes).length > 0;
|
|
10837
|
+
if (changed) {
|
|
10838
|
+
result.data.community = {
|
|
10839
|
+
...community,
|
|
10840
|
+
...changes.perHour === void 0 ? {} : { maxJobsPerHour: changes.perHour },
|
|
10841
|
+
...changes.perDay === void 0 ? {} : { maxJobsPerDay: changes.perDay },
|
|
10842
|
+
...changes.countTeam === void 0 ? {} : { countTeamJobs: changes.countTeam }
|
|
10843
|
+
};
|
|
10844
|
+
await writeConfig(paths.config, result.data);
|
|
10845
|
+
}
|
|
10846
|
+
const now = result.data.community;
|
|
10847
|
+
io.out(
|
|
10848
|
+
`other people's jobs on this device: up to ${String(now.maxJobsPerHour)} an hour, ${String(now.maxJobsPerDay)} a day
|
|
10849
|
+
` + (now.countTeamJobs ? " your team's jobs on metered services you shared count toward these\n" : " your team's jobs on metered services you shared do not count toward\n these \u2014 the service's daily spend ceiling bounds them\n")
|
|
10850
|
+
);
|
|
10851
|
+
if (!changed) {
|
|
10852
|
+
io.out(`
|
|
10853
|
+
${BUDGET_USAGE.replace("usage: ", "change it: ")}`);
|
|
10854
|
+
return 0;
|
|
10855
|
+
}
|
|
10856
|
+
await pickUpTheChange(paths, io, serviceIo, env);
|
|
10589
10857
|
return 0;
|
|
10590
10858
|
}
|
|
10591
10859
|
async function commandForget(paths, args, io) {
|
|
@@ -10884,7 +11152,7 @@ async function exists(path) {
|
|
|
10884
11152
|
}
|
|
10885
11153
|
|
|
10886
11154
|
// src/index.ts
|
|
10887
|
-
var DAEMON_VERSION = "0.1.
|
|
11155
|
+
var DAEMON_VERSION = "0.1.4";
|
|
10888
11156
|
function daemonVersion() {
|
|
10889
11157
|
return {
|
|
10890
11158
|
daemon: DAEMON_VERSION,
|
|
@@ -10943,4 +11211,4 @@ export {
|
|
|
10943
11211
|
runCli,
|
|
10944
11212
|
main
|
|
10945
11213
|
};
|
|
10946
|
-
//# sourceMappingURL=chunk-
|
|
11214
|
+
//# sourceMappingURL=chunk-LGN2DHFP.js.map
|