@byollm/protocol 0.1.0-alpha.2 → 0.1.0-alpha.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 +5 -1
- package/dist/index.d.ts +763 -66
- package/dist/index.js +849 -88
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
package/dist/index.d.ts
CHANGED
|
@@ -5,9 +5,10 @@ import { z } from 'zod';
|
|
|
5
5
|
* Rev 1 §A, because the two classes have different threat surfaces.
|
|
6
6
|
*
|
|
7
7
|
* - `http`: an OpenAI-compatible HTTP server (Ollama, `mlx_lm.server`,
|
|
8
|
-
* llama.cpp server, vLLM
|
|
9
|
-
*
|
|
10
|
-
*
|
|
8
|
+
* llama.cpp server, vLLM, and every hosted provider that speaks the same
|
|
9
|
+
* wire format). Spawns nothing, so byollm_004 §2's argv, stdin, env and
|
|
10
|
+
* sandbox requirements are not applicable by construction. Its threat
|
|
11
|
+
* surface is SSRF-shaped and bounded by {@link MUSTS.HTTP_BASE_URL_SAFE}.
|
|
11
12
|
* - `process`: spawns a binary (`claude` CLI today, `mlx_lm.lora` for a
|
|
12
13
|
* future `train.*` kind). All of byollm_004 §2 is mandatory here.
|
|
13
14
|
*/
|
|
@@ -17,20 +18,26 @@ declare const BackendClass: z.ZodEnum<{
|
|
|
17
18
|
}>;
|
|
18
19
|
type BackendClass = z.infer<typeof BackendClass>;
|
|
19
20
|
/**
|
|
20
|
-
*
|
|
21
|
+
* Who pays, and how — byollm_007.
|
|
21
22
|
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
23
|
+
* This replaced a two-valued `account` field that conflated two unrelated
|
|
24
|
+
* constraints and, in doing so, left a hole: `openai-http` was "open", but it
|
|
25
|
+
* accepts an API key, so an owner could point it at a paid endpoint, offer it
|
|
26
|
+
* `public`, and donate their credit balance to strangers. The community
|
|
27
|
+
* budgets cap job *count*, not spend.
|
|
28
|
+
*
|
|
29
|
+
* - `free` — local compute. Costs electricity, not money. Shareable.
|
|
30
|
+
* - `metered` — per-token billing against the owner's account. Legal to
|
|
31
|
+
* share and ruinous to share by accident.
|
|
32
|
+
* - `subscription` — a vendor account whose terms forbid third-party work.
|
|
33
|
+
* Sharing is a terms violation, not merely expensive.
|
|
28
34
|
*/
|
|
29
|
-
declare const
|
|
30
|
-
|
|
35
|
+
declare const BackendCost: z.ZodEnum<{
|
|
36
|
+
free: "free";
|
|
37
|
+
metered: "metered";
|
|
31
38
|
subscription: "subscription";
|
|
32
39
|
}>;
|
|
33
|
-
type
|
|
40
|
+
type BackendCost = z.infer<typeof BackendCost>;
|
|
34
41
|
/** The immutable facts about a backend that the protocol reasons over. */
|
|
35
42
|
interface BackendDescriptor {
|
|
36
43
|
/** Stable backend id, as written in `byollm.config.json`. */
|
|
@@ -39,33 +46,86 @@ interface BackendDescriptor {
|
|
|
39
46
|
readonly label: string;
|
|
40
47
|
/** Determines which isolation requirements apply. */
|
|
41
48
|
readonly class: BackendClass;
|
|
42
|
-
/**
|
|
43
|
-
|
|
49
|
+
/**
|
|
50
|
+
* Who pays. Fixed here for every named provider and **not overridable by
|
|
51
|
+
* configuration** ({@link MUSTS.COST_NOT_CONFIGURABLE}) — `openai` is
|
|
52
|
+
* metered because it is, and no setting changes that.
|
|
53
|
+
*
|
|
54
|
+
* `null` only for the generic {@link BACKENDS."openai-http"} entry, whose
|
|
55
|
+
* cost is inferred from its base URL instead
|
|
56
|
+
* ({@link MUSTS.REMOTE_IS_NEVER_FREE}).
|
|
57
|
+
*/
|
|
58
|
+
readonly cost: BackendCost | null;
|
|
44
59
|
/**
|
|
45
60
|
* Which adversarial corpus byollm_004 §5 runs against this backend. A
|
|
46
61
|
* backend cannot be registered without one — the coverage check in the
|
|
47
62
|
* adversarial suite enforces it.
|
|
48
63
|
*/
|
|
49
64
|
readonly adversarialCorpus: "process" | "http";
|
|
65
|
+
/**
|
|
66
|
+
* Where this provider lives, when that is knowable. Owner config may
|
|
67
|
+
* override it; a provider with no default requires one to be given.
|
|
68
|
+
*/
|
|
69
|
+
readonly defaultBaseUrl?: string;
|
|
50
70
|
}
|
|
51
71
|
/**
|
|
52
|
-
* The
|
|
72
|
+
* The backend registry.
|
|
53
73
|
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
* OpenAI-compatible `/v1/chat/completions
|
|
57
|
-
* owner
|
|
58
|
-
*
|
|
74
|
+
* **Providers are entries, not implementations.** Every HTTP-class provider
|
|
75
|
+
* below shares the single `openai-http` transport, because they all speak
|
|
76
|
+
* OpenAI-compatible `/v1/chat/completions`. An entry adds a stable id, a cost
|
|
77
|
+
* class the owner cannot override, and a default base URL. Adding a provider
|
|
78
|
+
* is therefore one line and no new code — which is why the adversarial corpus
|
|
79
|
+
* still covers all of them, and why a PR adding one is reviewable at a glance.
|
|
59
80
|
*/
|
|
60
81
|
declare const BACKENDS: Readonly<{
|
|
82
|
+
readonly ollama: BackendDescriptor;
|
|
83
|
+
readonly mlx: BackendDescriptor;
|
|
84
|
+
readonly llamacpp: BackendDescriptor;
|
|
85
|
+
readonly vllm: BackendDescriptor;
|
|
86
|
+
readonly lmstudio: BackendDescriptor;
|
|
87
|
+
readonly jan: BackendDescriptor;
|
|
88
|
+
readonly localai: BackendDescriptor;
|
|
89
|
+
/**
|
|
90
|
+
* Note the pair: `anthropic` and {@link BACKENDS."claude-cli"} reach the
|
|
91
|
+
* same vendor and land in different cost classes. That is not an
|
|
92
|
+
* inconsistency — it is the axis working. One bills a key per token, the
|
|
93
|
+
* other runs under a personal plan whose terms cover one person's work. Who
|
|
94
|
+
* pays and under what terms is the question; which company is not.
|
|
95
|
+
*/
|
|
96
|
+
readonly anthropic: BackendDescriptor;
|
|
97
|
+
readonly openai: BackendDescriptor;
|
|
98
|
+
readonly gemini: BackendDescriptor;
|
|
99
|
+
readonly grok: BackendDescriptor;
|
|
100
|
+
readonly groq: BackendDescriptor;
|
|
101
|
+
readonly openrouter: BackendDescriptor;
|
|
102
|
+
readonly together: BackendDescriptor;
|
|
103
|
+
readonly deepseek: BackendDescriptor;
|
|
104
|
+
readonly mistral: BackendDescriptor;
|
|
61
105
|
readonly "openai-http": BackendDescriptor;
|
|
62
106
|
readonly "claude-cli": BackendDescriptor;
|
|
63
107
|
}>;
|
|
64
108
|
/** The id of a registered backend. */
|
|
65
109
|
type BackendId = keyof typeof BACKENDS;
|
|
66
110
|
/** All registered backend ids — the adversarial coverage check iterates this. */
|
|
67
|
-
declare const BACKEND_IDS: readonly ("openai-http" | "claude-cli")[];
|
|
111
|
+
declare const BACKEND_IDS: readonly ("ollama" | "mlx" | "llamacpp" | "vllm" | "lmstudio" | "jan" | "localai" | "anthropic" | "openai" | "gemini" | "grok" | "groq" | "openrouter" | "together" | "deepseek" | "mistral" | "openai-http" | "claude-cli")[];
|
|
68
112
|
declare const BackendIdSchema: z.ZodEnum<{
|
|
113
|
+
ollama: "ollama";
|
|
114
|
+
mlx: "mlx";
|
|
115
|
+
llamacpp: "llamacpp";
|
|
116
|
+
vllm: "vllm";
|
|
117
|
+
lmstudio: "lmstudio";
|
|
118
|
+
jan: "jan";
|
|
119
|
+
localai: "localai";
|
|
120
|
+
anthropic: "anthropic";
|
|
121
|
+
openai: "openai";
|
|
122
|
+
gemini: "gemini";
|
|
123
|
+
grok: "grok";
|
|
124
|
+
groq: "groq";
|
|
125
|
+
openrouter: "openrouter";
|
|
126
|
+
together: "together";
|
|
127
|
+
deepseek: "deepseek";
|
|
128
|
+
mistral: "mistral";
|
|
69
129
|
"openai-http": "openai-http";
|
|
70
130
|
"claude-cli": "claude-cli";
|
|
71
131
|
}>;
|
|
@@ -78,6 +138,34 @@ declare function isBackendId(value: string): value is BackendId;
|
|
|
78
138
|
* adversarial corpus, so refusing is the safe direction.
|
|
79
139
|
*/
|
|
80
140
|
declare function backendDescriptor(id: BackendId): BackendDescriptor;
|
|
141
|
+
/**
|
|
142
|
+
* Is this host local enough that compute there is free?
|
|
143
|
+
*
|
|
144
|
+
* Loopback and the private ranges only. This is the rule that makes
|
|
145
|
+
* {@link MUSTS.REMOTE_IS_NEVER_FREE} enforceable rather than a promise: an
|
|
146
|
+
* owner cannot reach a paid API through the generic backend and call it free,
|
|
147
|
+
* because "free" is derived from the address, not from what the config claims.
|
|
148
|
+
*
|
|
149
|
+
* **What this cannot see.** The address is all it reads. A proxy on
|
|
150
|
+
* `127.0.0.1` forwarding to a paid API classes as `free` and nothing
|
|
151
|
+
* downstream will contradict it. That is deliberate: standing up a relay is
|
|
152
|
+
* an act by the machine's owner against their own account, and the threat
|
|
153
|
+
* model here is a hostile *job*, not an owner routing around a rule that
|
|
154
|
+
* exists to protect them. What this catches is the accident — a remote paid
|
|
155
|
+
* endpoint offered `public` because nobody thought about the bill. See
|
|
156
|
+
* `docs/security.md` §4a.
|
|
157
|
+
*/
|
|
158
|
+
declare function isLocalHost(hostname: string): boolean;
|
|
159
|
+
/**
|
|
160
|
+
* The cost class of a configured backend instance.
|
|
161
|
+
*
|
|
162
|
+
* For every named provider this is whatever the registry says, full stop
|
|
163
|
+
* ({@link MUSTS.COST_NOT_CONFIGURABLE}). For the generic `openai-http` entry
|
|
164
|
+
* it is inferred from the base URL, and a base URL that cannot be parsed is
|
|
165
|
+
* treated as `metered` — the expensive side, because guessing "free" wrong
|
|
166
|
+
* costs the owner money.
|
|
167
|
+
*/
|
|
168
|
+
declare function resolveCost(id: BackendId, baseUrl: string | undefined): BackendCost;
|
|
81
169
|
|
|
82
170
|
/**
|
|
83
171
|
* Who may run a job, declared by the app that enqueued it.
|
|
@@ -121,6 +209,8 @@ declare const MatchRefusal: z.ZodEnum<{
|
|
|
121
209
|
"not-in-server-allowlist": "not-in-server-allowlist";
|
|
122
210
|
"offer-scope-too-narrow": "offer-scope-too-narrow";
|
|
123
211
|
"subscription-self-lock": "subscription-self-lock";
|
|
212
|
+
"metered-no-spend-consent": "metered-no-spend-consent";
|
|
213
|
+
"metered-ceiling-reached": "metered-ceiling-reached";
|
|
124
214
|
}>;
|
|
125
215
|
type MatchRefusal = z.infer<typeof MatchRefusal>;
|
|
126
216
|
/** The outcome of an audience match. */
|
|
@@ -130,16 +220,30 @@ type MatchResult = {
|
|
|
130
220
|
readonly ok: false;
|
|
131
221
|
readonly refusal: MatchRefusal;
|
|
132
222
|
};
|
|
223
|
+
/** What the owner has agreed to spend on other people's work, if anything. */
|
|
224
|
+
interface SpendConsent {
|
|
225
|
+
/** The owner explicitly acknowledged that sharing this backend costs money. */
|
|
226
|
+
readonly acknowledged: boolean;
|
|
227
|
+
/** Their ceiling. Absent means no ceiling was set, which is not consent. */
|
|
228
|
+
readonly ceilingReached?: boolean;
|
|
229
|
+
}
|
|
133
230
|
/**
|
|
134
231
|
* The effective offer scope of a backend.
|
|
135
232
|
*
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
*
|
|
233
|
+
* Three rules, applied at the one place both the daemon's config loader and
|
|
234
|
+
* its matcher call, so no code path can observe a scope wider than the cost
|
|
235
|
+
* class allows:
|
|
236
|
+
*
|
|
237
|
+
* - `subscription` is locked to `self` regardless of config
|
|
238
|
+
* ({@link MUSTS.SUBSCRIPTION_SELF_LOCK}) — someone else's terms.
|
|
239
|
+
* - `metered` narrows to `self` unless the owner has explicitly acknowledged
|
|
240
|
+
* the spend ({@link MUSTS.METERED_DEFAULTS_SELF}) — their money.
|
|
241
|
+
* - `free` passes through — their electricity.
|
|
242
|
+
*
|
|
243
|
+
* Note the asymmetry: subscription can never be widened, metered can be
|
|
244
|
+
* widened deliberately. Conflating those was byollm_007's bug.
|
|
141
245
|
*/
|
|
142
|
-
declare function effectiveOfferScope(configured: OfferScope,
|
|
246
|
+
declare function effectiveOfferScope(configured: OfferScope, cost: BackendCost, spend?: SpendConsent): OfferScope;
|
|
143
247
|
/** The job-side facts a match needs. */
|
|
144
248
|
interface MatchJob {
|
|
145
249
|
/** The app's id for the user who enqueued the job. */
|
|
@@ -159,8 +263,10 @@ interface MatchDaemon {
|
|
|
159
263
|
readonly owner: string;
|
|
160
264
|
/** Effective scope of the backend that would run the job. */
|
|
161
265
|
readonly offerScope: OfferScope;
|
|
162
|
-
/**
|
|
163
|
-
readonly
|
|
266
|
+
/** Who pays for that backend's tokens. */
|
|
267
|
+
readonly cost: BackendCost;
|
|
268
|
+
/** What the owner agreed to spend on others, for a `metered` backend. */
|
|
269
|
+
readonly spend?: SpendConsent | undefined;
|
|
164
270
|
/**
|
|
165
271
|
* Does this daemon's *local* allowlist admit the given owner for the server
|
|
166
272
|
* origin the job came from? Supplied as a predicate so the protocol package
|
|
@@ -189,7 +295,7 @@ interface MatchDaemon {
|
|
|
189
295
|
* {
|
|
190
296
|
* owner: "bob",
|
|
191
297
|
* offerScope: "named",
|
|
192
|
-
*
|
|
298
|
+
* cost: "free",
|
|
193
299
|
* locallyAllows: (o) => o === "alice",
|
|
194
300
|
* },
|
|
195
301
|
* );
|
|
@@ -342,6 +448,7 @@ declare function isTerminal(state: JobState): boolean;
|
|
|
342
448
|
declare function canTransition(from: JobState, to: JobState): boolean;
|
|
343
449
|
/** A lease: the right to work on a job until `expiresAt`. */
|
|
344
450
|
declare const Lease: z.ZodObject<{
|
|
451
|
+
id: z.ZodString;
|
|
345
452
|
runnerId: z.ZodString;
|
|
346
453
|
expiresAt: z.ZodNumber;
|
|
347
454
|
}, z.core.$strip>;
|
|
@@ -398,6 +505,7 @@ declare const ClaimedJob: z.ZodObject<{
|
|
|
398
505
|
owner: z.ZodString;
|
|
399
506
|
audienceAllow: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
400
507
|
lease: z.ZodObject<{
|
|
508
|
+
id: z.ZodString;
|
|
401
509
|
runnerId: z.ZodString;
|
|
402
510
|
expiresAt: z.ZodNumber;
|
|
403
511
|
}, z.core.$strip>;
|
|
@@ -508,6 +616,353 @@ declare const DeliveredResult: z.ZodObject<{
|
|
|
508
616
|
}, z.core.$strict>>;
|
|
509
617
|
}, z.core.$strict>;
|
|
510
618
|
type DeliveredResult = z.infer<typeof DeliveredResult>;
|
|
619
|
+
/**
|
|
620
|
+
* How big a payload is, in buckets — byollm_009 §6.
|
|
621
|
+
*
|
|
622
|
+
* A relay routes without reading, and matching a job to a machine needs some
|
|
623
|
+
* notion of size. Buckets rather than byte counts because the exact figure is
|
|
624
|
+
* a stronger fingerprint than the routing decision requires, and because a
|
|
625
|
+
* bucket survives compression and encoding changes that an exact count does
|
|
626
|
+
* not.
|
|
627
|
+
*
|
|
628
|
+
* `unbounded` exists for streamed jobs, which have no size when they start.
|
|
629
|
+
* It is reserved now rather than added later: byollm_009 §8.1 — adding a
|
|
630
|
+
* field to a published envelope is the v2 break all over again.
|
|
631
|
+
*/
|
|
632
|
+
declare const SizeClass: z.ZodEnum<{
|
|
633
|
+
small: "small";
|
|
634
|
+
medium: "medium";
|
|
635
|
+
large: "large";
|
|
636
|
+
unbounded: "unbounded";
|
|
637
|
+
}>;
|
|
638
|
+
type SizeClass = z.infer<typeof SizeClass>;
|
|
639
|
+
/** Where the bucket boundaries sit, in characters of payload text. */
|
|
640
|
+
declare const SIZE_CLASS_LIMITS: Readonly<{
|
|
641
|
+
small: 4000;
|
|
642
|
+
medium: 64000;
|
|
643
|
+
large: number;
|
|
644
|
+
}>;
|
|
645
|
+
/**
|
|
646
|
+
* The most a payload in this bucket can be.
|
|
647
|
+
*
|
|
648
|
+
* Used where a decision must be made from a stub, before the payload has been
|
|
649
|
+
* fetched — a budget check, for instance. Charging the bucket's ceiling is the
|
|
650
|
+
* conservative direction: it refuses slightly too eagerly rather than
|
|
651
|
+
* admitting work that turns out larger than the budget allowed.
|
|
652
|
+
*
|
|
653
|
+
* `unbounded` returns `Infinity`, which fails every ceiling. That is correct
|
|
654
|
+
* until byollm_006 defines how a streamed job is budgeted — failing closed on
|
|
655
|
+
* a case nobody has designed beats inventing an allowance for it.
|
|
656
|
+
*/
|
|
657
|
+
declare function sizeClassCeiling(sizeClass: SizeClass): number;
|
|
658
|
+
/** Bucket a payload by its text length. */
|
|
659
|
+
declare function sizeClassOf(textChars: number): SizeClass;
|
|
660
|
+
/**
|
|
661
|
+
* Everything an upstream may see about a job — byollm_009 §6.
|
|
662
|
+
*
|
|
663
|
+
* **This list is exhaustive and normative.** It is a commitment about the
|
|
664
|
+
* metadata surface, not an accident of what the implementation happens to
|
|
665
|
+
* send: an upstream that requires more has exceeded the protocol, and an
|
|
666
|
+
* endpoint that emits more has leaked past it
|
|
667
|
+
* ({@link MUSTS.STUB_METADATA_EXHAUSTIVE}).
|
|
668
|
+
*
|
|
669
|
+
* What is absent is the point. No payload, no model, no prompt, no result.
|
|
670
|
+
* `kind` is here because capability matching happens upstream; if a later
|
|
671
|
+
* revision moves matching to the daemon, `kind` moves into the ciphertext.
|
|
672
|
+
*/
|
|
673
|
+
declare const JobStub: z.ZodObject<{
|
|
674
|
+
id: z.ZodString;
|
|
675
|
+
kind: z.ZodEnum<{
|
|
676
|
+
"llm.generate": "llm.generate";
|
|
677
|
+
"llm.chat": "llm.chat";
|
|
678
|
+
}>;
|
|
679
|
+
owner: z.ZodString;
|
|
680
|
+
audience: z.ZodEnum<{
|
|
681
|
+
self: "self";
|
|
682
|
+
named: "named";
|
|
683
|
+
public: "public";
|
|
684
|
+
}>;
|
|
685
|
+
audienceAllow: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
686
|
+
sizeClass: z.ZodEnum<{
|
|
687
|
+
small: "small";
|
|
688
|
+
medium: "medium";
|
|
689
|
+
large: "large";
|
|
690
|
+
unbounded: "unbounded";
|
|
691
|
+
}>;
|
|
692
|
+
streaming: z.ZodBoolean;
|
|
693
|
+
deadlineAt: z.ZodNumber;
|
|
694
|
+
}, z.core.$strict>;
|
|
695
|
+
type JobStub = z.infer<typeof JobStub>;
|
|
696
|
+
/** A stub, plus the lease the claiming runner now holds for it. */
|
|
697
|
+
declare const ClaimedStub: z.ZodObject<{
|
|
698
|
+
id: z.ZodString;
|
|
699
|
+
kind: z.ZodEnum<{
|
|
700
|
+
"llm.generate": "llm.generate";
|
|
701
|
+
"llm.chat": "llm.chat";
|
|
702
|
+
}>;
|
|
703
|
+
owner: z.ZodString;
|
|
704
|
+
audience: z.ZodEnum<{
|
|
705
|
+
self: "self";
|
|
706
|
+
named: "named";
|
|
707
|
+
public: "public";
|
|
708
|
+
}>;
|
|
709
|
+
audienceAllow: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
710
|
+
sizeClass: z.ZodEnum<{
|
|
711
|
+
small: "small";
|
|
712
|
+
medium: "medium";
|
|
713
|
+
large: "large";
|
|
714
|
+
unbounded: "unbounded";
|
|
715
|
+
}>;
|
|
716
|
+
streaming: z.ZodBoolean;
|
|
717
|
+
deadlineAt: z.ZodNumber;
|
|
718
|
+
lease: z.ZodObject<{
|
|
719
|
+
id: z.ZodString;
|
|
720
|
+
runnerId: z.ZodString;
|
|
721
|
+
expiresAt: z.ZodNumber;
|
|
722
|
+
}, z.core.$strip>;
|
|
723
|
+
}, z.core.$strict>;
|
|
724
|
+
type ClaimedStub = z.infer<typeof ClaimedStub>;
|
|
725
|
+
|
|
726
|
+
/**
|
|
727
|
+
* Device and site keys — byollm_009 §3.
|
|
728
|
+
*
|
|
729
|
+
* **Two keypairs per party, and the split is load-bearing.** An Ed25519
|
|
730
|
+
* *identity* key signs; an X25519 *encryption* key receives sealed envelopes.
|
|
731
|
+
* The encryption key is signed by the identity key, and **the identity key is
|
|
732
|
+
* what gets pinned**. So "who sent this" and "who can read this" are answered
|
|
733
|
+
* by different keys — which is what lets an encryption key rotate without
|
|
734
|
+
* re-establishing trust, and what byollm_009 §6's signed-then-sealed envelope
|
|
735
|
+
* depends on.
|
|
736
|
+
*
|
|
737
|
+
* **No new dependency.** byollm_009 §2 says established primitives only, via
|
|
738
|
+
* libsodium. Everything *this* module needs — Ed25519 signing, X25519 key
|
|
739
|
+
* generation — Node provides natively, and using it costs nothing and adds no
|
|
740
|
+
* install weight to a daemon that must land fast on a stranger's laptop.
|
|
741
|
+
*
|
|
742
|
+
* libsodium becomes necessary at envelope v2, where sealing does. That is a
|
|
743
|
+
* real dependency decision and it belongs in the change that needs it: a
|
|
744
|
+
* sealed box is a specific reviewed construction, and rebuilding it out of
|
|
745
|
+
* Node primitives is exactly the "novel construction" §2 rules out. Deferring
|
|
746
|
+
* the dependency is not the same as deferring the rule.
|
|
747
|
+
*/
|
|
748
|
+
/** A public identity, as it travels on the wire. All values base64url. */
|
|
749
|
+
declare const PublicIdentity: z.ZodObject<{
|
|
750
|
+
identity: z.ZodString;
|
|
751
|
+
encryption: z.ZodString;
|
|
752
|
+
encryptionSig: z.ZodString;
|
|
753
|
+
}, z.core.$strict>;
|
|
754
|
+
type PublicIdentity = z.infer<typeof PublicIdentity>;
|
|
755
|
+
/** Private key material, as stored on disk. Never leaves the machine. */
|
|
756
|
+
declare const StoredKeys: z.ZodObject<{
|
|
757
|
+
version: z.ZodLiteral<1>;
|
|
758
|
+
identityPublic: z.ZodString;
|
|
759
|
+
identityPrivate: z.ZodString;
|
|
760
|
+
encryptionPublic: z.ZodString;
|
|
761
|
+
encryptionPrivate: z.ZodString;
|
|
762
|
+
encryptionSig: z.ZodString;
|
|
763
|
+
createdAt: z.ZodNumber;
|
|
764
|
+
}, z.core.$strict>;
|
|
765
|
+
type StoredKeys = z.infer<typeof StoredKeys>;
|
|
766
|
+
/** Generate a fresh pair of keypairs and bind them together. */
|
|
767
|
+
declare function generateKeys(now: number): StoredKeys;
|
|
768
|
+
/** The public half, for the wire. */
|
|
769
|
+
declare function publicIdentityOf(keys: StoredKeys): PublicIdentity;
|
|
770
|
+
/**
|
|
771
|
+
* Check that an encryption key really belongs to the identity presenting it.
|
|
772
|
+
*
|
|
773
|
+
* Called on everything received, including from an upstream we otherwise
|
|
774
|
+
* trust — the point of pinning the identity is that nothing else needs to be
|
|
775
|
+
* trusted, and that only holds if this is checked every time rather than at
|
|
776
|
+
* first sight.
|
|
777
|
+
*/
|
|
778
|
+
declare function verifyPublicIdentity(identity: PublicIdentity): boolean;
|
|
779
|
+
/** Sign arbitrary bytes with an identity key. */
|
|
780
|
+
declare function signWith(keys: StoredKeys, data: Uint8Array): string;
|
|
781
|
+
/** Verify bytes against a raw Ed25519 public key. */
|
|
782
|
+
declare function verifyWith(identityPublic: string, data: Uint8Array, signature: string): boolean;
|
|
783
|
+
/**
|
|
784
|
+
* A fingerprint a human can compare out loud.
|
|
785
|
+
*
|
|
786
|
+
* 120 bits of SHA-256 over the raw identity key, as six groups of four. Long
|
|
787
|
+
* enough that grinding a colliding key is not worth anyone's afternoon, short
|
|
788
|
+
* enough to read down a phone line — which is the whole point. A fingerprint
|
|
789
|
+
* nobody can be bothered to compare provides no security at all, so
|
|
790
|
+
* legibility is a security property here, not a nicety.
|
|
791
|
+
*
|
|
792
|
+
* Formatted with a `BYOLLM-` prefix so a pasted fingerprint is recognisable
|
|
793
|
+
* out of context, in a support thread or a screenshot.
|
|
794
|
+
*/
|
|
795
|
+
declare function fingerprint(identityPublic: string): string;
|
|
796
|
+
/** The short id used in envelopes and provenance. Stable, and comparable. */
|
|
797
|
+
declare const keyId: (identityPublic: string) => string;
|
|
798
|
+
|
|
799
|
+
declare function cryptoReady(): Promise<void>;
|
|
800
|
+
/**
|
|
801
|
+
* How long a sealed payload is worth keeping, from creation.
|
|
802
|
+
*
|
|
803
|
+
* Bound into every envelope and recomputed when one is opened, so it lives
|
|
804
|
+
* here rather than in the two places that need it. Two copies of a value the
|
|
805
|
+
* signature depends on is the same bug as two clock readings: it works until
|
|
806
|
+
* they disagree, and then nothing can be opened.
|
|
807
|
+
*
|
|
808
|
+
* Not a job's TTL. That answers how long the *work* is worth doing, belongs
|
|
809
|
+
* to the app and the store, and may legitimately differ per deployment.
|
|
810
|
+
*/
|
|
811
|
+
declare const ENVELOPE_MAX_AGE_MS: number;
|
|
812
|
+
/** Which leg an envelope belongs to. Bound into the signature. */
|
|
813
|
+
declare const EnvelopeDirection: z.ZodEnum<{
|
|
814
|
+
payload: "payload";
|
|
815
|
+
result: "result";
|
|
816
|
+
}>;
|
|
817
|
+
type EnvelopeDirection = z.infer<typeof EnvelopeDirection>;
|
|
818
|
+
declare const SealedEnvelope: z.ZodObject<{
|
|
819
|
+
ciphertext: z.ZodString;
|
|
820
|
+
recipientKeyId: z.ZodString;
|
|
821
|
+
senderKeyId: z.ZodString;
|
|
822
|
+
direction: z.ZodEnum<{
|
|
823
|
+
payload: "payload";
|
|
824
|
+
result: "result";
|
|
825
|
+
}>;
|
|
826
|
+
deadlineAt: z.ZodNumber;
|
|
827
|
+
}, z.core.$strict>;
|
|
828
|
+
type SealedEnvelope = z.infer<typeof SealedEnvelope>;
|
|
829
|
+
/** Everything the signature covers besides the plaintext itself. */
|
|
830
|
+
interface EnvelopeContext {
|
|
831
|
+
readonly jobId: string;
|
|
832
|
+
readonly senderKeyId: string;
|
|
833
|
+
readonly recipientKeyId: string;
|
|
834
|
+
readonly deadlineAt: number;
|
|
835
|
+
readonly direction: EnvelopeDirection;
|
|
836
|
+
}
|
|
837
|
+
/** Seal a plaintext to a recipient, signed by the sender's identity. */
|
|
838
|
+
declare function seal(input: {
|
|
839
|
+
plaintext: string;
|
|
840
|
+
senderKeys: StoredKeys;
|
|
841
|
+
recipientEncryptionPublic: string;
|
|
842
|
+
context: EnvelopeContext;
|
|
843
|
+
}): Promise<SealedEnvelope>;
|
|
844
|
+
/** Why an envelope was refused. Never distinguished to a remote caller. */
|
|
845
|
+
type EnvelopeFailure = "not-for-us" | "unopenable" | "malformed" | "bad-signature" | "context-mismatch";
|
|
846
|
+
type OpenResult = {
|
|
847
|
+
readonly ok: true;
|
|
848
|
+
readonly plaintext: string;
|
|
849
|
+
} | {
|
|
850
|
+
readonly ok: false;
|
|
851
|
+
readonly reason: EnvelopeFailure;
|
|
852
|
+
};
|
|
853
|
+
/**
|
|
854
|
+
* Open an envelope and verify it came from the pinned sender.
|
|
855
|
+
*
|
|
856
|
+
* Every failure returns rather than throws: this runs on input from the
|
|
857
|
+
* network, and a crash here is a denial of service on the delivery path.
|
|
858
|
+
*
|
|
859
|
+
* The context is checked against the signature, not merely read from the
|
|
860
|
+
* envelope. An envelope carries its own claims about who sent it and to
|
|
861
|
+
* whom — believing those would authenticate the attacker's assertion rather
|
|
862
|
+
* than the sender's key.
|
|
863
|
+
*/
|
|
864
|
+
declare function open(input: {
|
|
865
|
+
envelope: SealedEnvelope;
|
|
866
|
+
recipientKeys: StoredKeys;
|
|
867
|
+
senderIdentityPublic: string;
|
|
868
|
+
/** The deadline is taken from the envelope and checked against its signature. */
|
|
869
|
+
expected: Omit<EnvelopeContext, "deadlineAt">;
|
|
870
|
+
}): Promise<OpenResult>;
|
|
871
|
+
|
|
872
|
+
/**
|
|
873
|
+
* Request signing — byollm_009 §4.2.
|
|
874
|
+
*
|
|
875
|
+
* Every authenticated call is signed by the calling device's identity key.
|
|
876
|
+
* There is no bearer token on the daemon plane: possession of a file no
|
|
877
|
+
* longer grants access, possession of a *key* does, and the key never leaves
|
|
878
|
+
* the machine.
|
|
879
|
+
*
|
|
880
|
+
* ## Why this is not the server-issued nonce the spec first described
|
|
881
|
+
*
|
|
882
|
+
* byollm_009 §4.2 says "the upstream issues a nonce; the daemon signs it".
|
|
883
|
+
* Implementing that costs one of two things: a round trip before every
|
|
884
|
+
* request, or server-side session state — and sessions reintroduce a bearer
|
|
885
|
+
* credential, which is the thing being removed.
|
|
886
|
+
*
|
|
887
|
+
* Signing *the request itself* gets the same property without either, because
|
|
888
|
+
* of something the protocol already guarantees. A captured signature is valid
|
|
889
|
+
* only for the exact request it covers — same endpoint, same runner, same
|
|
890
|
+
* body — and every authenticated endpoint here is idempotent by design:
|
|
891
|
+
* `RESULT_IDEMPOTENT` makes a replayed result a no-op, a replayed claim from
|
|
892
|
+
* the same runner returns what that runner already holds, and heartbeat and
|
|
893
|
+
* release are idempotent in effect. So a replay inside the freshness window
|
|
894
|
+
* gains an attacker nothing they could not obtain by forwarding the original,
|
|
895
|
+
* which a relay can do anyway.
|
|
896
|
+
*
|
|
897
|
+
* That is the whole argument, and it is worth stating because it rests
|
|
898
|
+
* entirely on the endpoints being idempotent. Two ways that can fail, and the
|
|
899
|
+
* second is the one that actually bit:
|
|
900
|
+
*
|
|
901
|
+
* 1. **A future endpoint that is not idempotent cannot use this scheme
|
|
902
|
+
* unchanged** — it would need a server-issued nonce.
|
|
903
|
+
* 2. **Idempotence must hold per *addressed instance*, not per endpoint.** A
|
|
904
|
+
* request that names a mutable target — a lease, a session, a
|
|
905
|
+
* subscription — must name the *instance*, or a replay lands on a
|
|
906
|
+
* different one than the sender meant and the endpoint's idempotence buys
|
|
907
|
+
* nothing. `release` was idempotent per lease and ambiguous across them:
|
|
908
|
+
* it named a job and a runner, both of which survive a
|
|
909
|
+
* claim-release-reclaim cycle, so a replayed release yanked a later grant.
|
|
910
|
+
* Fixed by giving a lease its own id and requiring it.
|
|
911
|
+
*
|
|
912
|
+
* The rule for anything added later: if a signed request can be replayed onto
|
|
913
|
+
* a target that has changed underneath it, the request has to say which
|
|
914
|
+
* target it meant.
|
|
915
|
+
*/
|
|
916
|
+
/** How far a request's timestamp may be from the server's clock. */
|
|
917
|
+
declare const MAX_CLOCK_SKEW_MS = 120000;
|
|
918
|
+
/** The signed material a request carries. */
|
|
919
|
+
declare const RequestSignature: z.ZodObject<{
|
|
920
|
+
runnerId: z.ZodString;
|
|
921
|
+
issuedAt: z.ZodNumber;
|
|
922
|
+
signature: z.ZodString;
|
|
923
|
+
}, z.core.$strict>;
|
|
924
|
+
type RequestSignature = z.infer<typeof RequestSignature>;
|
|
925
|
+
/**
|
|
926
|
+
* The exact bytes both sides sign and verify.
|
|
927
|
+
*
|
|
928
|
+
* Newline-separated with a version prefix and a domain separator. Every field
|
|
929
|
+
* that decides what the request *does* is in here: leave one out and it
|
|
930
|
+
* becomes something an intermediary can change without breaking the
|
|
931
|
+
* signature.
|
|
932
|
+
*
|
|
933
|
+
* The body is included by hash rather than by value, so signing does not
|
|
934
|
+
* depend on both sides serialising JSON identically — which they would not.
|
|
935
|
+
*/
|
|
936
|
+
declare function canonicalRequest(input: {
|
|
937
|
+
endpoint: string;
|
|
938
|
+
runnerId: string;
|
|
939
|
+
issuedAt: number;
|
|
940
|
+
body: string;
|
|
941
|
+
}): Buffer;
|
|
942
|
+
/** Sign an outgoing request with this machine's identity key. */
|
|
943
|
+
declare function signRequest(keys: StoredKeys, input: {
|
|
944
|
+
endpoint: string;
|
|
945
|
+
runnerId: string;
|
|
946
|
+
issuedAt: number;
|
|
947
|
+
body: string;
|
|
948
|
+
}): RequestSignature;
|
|
949
|
+
/** Why a signed request was refused. Never returned to the caller verbatim. */
|
|
950
|
+
type SignatureFailure = "stale" | "bad-signature";
|
|
951
|
+
/**
|
|
952
|
+
* Verify a signed request against a runner's pinned identity key.
|
|
953
|
+
*
|
|
954
|
+
* Freshness is checked in **both** directions. A clock far ahead is as much a
|
|
955
|
+
* problem as one behind: it would let a captured request stay replayable long
|
|
956
|
+
* after it was made, which is the one thing the window exists to bound.
|
|
957
|
+
*/
|
|
958
|
+
declare function verifyRequest(input: {
|
|
959
|
+
identityPublic: string;
|
|
960
|
+
endpoint: string;
|
|
961
|
+
body: string;
|
|
962
|
+
signature: RequestSignature;
|
|
963
|
+
now: number;
|
|
964
|
+
maxSkewMs?: number;
|
|
965
|
+
}): SignatureFailure | null;
|
|
511
966
|
|
|
512
967
|
/**
|
|
513
968
|
* The normative MUSTs of protocol v0, as data.
|
|
@@ -524,6 +979,30 @@ type DeliveredResult = z.infer<typeof DeliveredResult>;
|
|
|
524
979
|
*/
|
|
525
980
|
/** Which side of the wire is obliged to enforce a given MUST. */
|
|
526
981
|
type MustEnforcer = "daemon" | "server" | "both";
|
|
982
|
+
/**
|
|
983
|
+
* How a MUST is actually verified — which is not the same question as who
|
|
984
|
+
* enforces it, and is the one that decides what "byollm-compatible" means.
|
|
985
|
+
*
|
|
986
|
+
* The conformance kit's credibility rests on an implicit claim that every
|
|
987
|
+
* MUST is checkable. Ten of them were not, and the kit reported that honestly
|
|
988
|
+
* while nothing acted on it. Making the kind explicit turns "uncovered" from
|
|
989
|
+
* a number needing a paragraph of explanation into a number that should be
|
|
990
|
+
* zero.
|
|
991
|
+
*
|
|
992
|
+
* - `conformance` — the kit asserts it against *any* implementation. This is
|
|
993
|
+
* the strong kind: a third party runs the suite and learns something.
|
|
994
|
+
* - `adversarial` — proved by the reference daemon's own suites in this repo
|
|
995
|
+
* (the hostile-payload corpus, or its unit tests). Real verification, and
|
|
996
|
+
* it runs in CI — but it proves things about *our* daemon, not about
|
|
997
|
+
* someone else's, so the kit cannot carry it.
|
|
998
|
+
* - `construction` — true by the shape of the code, where a test could only
|
|
999
|
+
* sample. A reviewer verifies it; a suite cannot.
|
|
1000
|
+
* - `operator` — a claim about how someone runs a deployment, verifiable only
|
|
1001
|
+
* by audit or by reading source. The honest category, and the one that
|
|
1002
|
+
* exists so a property nobody can check from outside is *labelled* as such
|
|
1003
|
+
* rather than laundered by association with the checkable ones.
|
|
1004
|
+
*/
|
|
1005
|
+
type MustVerification = "conformance" | "adversarial" | "construction" | "operator";
|
|
527
1006
|
/** A single normative requirement of the protocol. */
|
|
528
1007
|
interface Must {
|
|
529
1008
|
/** Stable public id, cited by conformance output. */
|
|
@@ -532,6 +1011,11 @@ interface Must {
|
|
|
532
1011
|
readonly statement: string;
|
|
533
1012
|
/** Which implementation is obliged to enforce it. */
|
|
534
1013
|
readonly enforcedBy: MustEnforcer;
|
|
1014
|
+
/**
|
|
1015
|
+
* How this is verified. `conformance` is the only kind the kit can assert;
|
|
1016
|
+
* see {@link MustVerification} for why the others exist.
|
|
1017
|
+
*/
|
|
1018
|
+
readonly verifiedBy: MustVerification;
|
|
535
1019
|
/** Spec section this was adjudicated in. */
|
|
536
1020
|
readonly source: string;
|
|
537
1021
|
}
|
|
@@ -547,6 +1031,12 @@ declare const MUSTS: Readonly<{
|
|
|
547
1031
|
readonly PAIR_ONE_USER: Must;
|
|
548
1032
|
readonly PAIR_INTERACTIVE: Must;
|
|
549
1033
|
readonly PAIR_CODE_EXPIRES: Must;
|
|
1034
|
+
readonly VERSION_HANDSHAKE_REQUIRED: Must;
|
|
1035
|
+
readonly KEYS_EXCHANGED_AT_CONSENT: Must;
|
|
1036
|
+
readonly REQUESTS_SIGNED_NOT_BEARER: Must;
|
|
1037
|
+
readonly LEASE_SCOPED_BY_GRANT: Must;
|
|
1038
|
+
readonly STUB_METADATA_EXHAUSTIVE: Must;
|
|
1039
|
+
readonly ENVELOPE_SEALED_AND_SIGNED: Must;
|
|
550
1040
|
readonly KIND_TYPED_ONLY: Must;
|
|
551
1041
|
readonly KIND_NO_CODE: Must;
|
|
552
1042
|
readonly CLAIM_REQUIRES_CAPABILITY: Must;
|
|
@@ -556,6 +1046,10 @@ declare const MUSTS: Readonly<{
|
|
|
556
1046
|
readonly LEASE_RECLAIMABLE: Must;
|
|
557
1047
|
readonly AUDIENCE_BOTH_SIDES: Must;
|
|
558
1048
|
readonly SUBSCRIPTION_SELF_LOCK: Must;
|
|
1049
|
+
readonly METERED_DEFAULTS_SELF: Must;
|
|
1050
|
+
readonly METERED_REQUIRES_CEILING: Must;
|
|
1051
|
+
readonly COST_NOT_CONFIGURABLE: Must;
|
|
1052
|
+
readonly REMOTE_IS_NEVER_FREE: Must;
|
|
559
1053
|
readonly NAMED_LOCAL_ALLOWLIST: Must;
|
|
560
1054
|
readonly REFUSAL_NOT_REOFFERED: Must;
|
|
561
1055
|
readonly REVOCATION_HONORED: Must;
|
|
@@ -576,14 +1070,64 @@ declare const MUSTS: Readonly<{
|
|
|
576
1070
|
/** The id of any normative MUST. */
|
|
577
1071
|
type MustId = keyof typeof MUSTS;
|
|
578
1072
|
/** All MUST ids, for coverage checks. */
|
|
579
|
-
declare const MUST_IDS: readonly ("PAIR_ONE_USER" | "PAIR_INTERACTIVE" | "PAIR_CODE_EXPIRES" | "KIND_TYPED_ONLY" | "KIND_NO_CODE" | "CLAIM_REQUIRES_CAPABILITY" | "CAPABILITY_IS_DETECTED" | "CLAIM_ATOMIC" | "LEASE_HONORED" | "LEASE_RECLAIMABLE" | "AUDIENCE_BOTH_SIDES" | "SUBSCRIPTION_SELF_LOCK" | "NAMED_LOCAL_ALLOWLIST" | "REFUSAL_NOT_REOFFERED" | "REVOCATION_HONORED" | "CANCEL_HONORED" | "DEPENDS_ON_GATING" | "TTL_EXPIRY" | "NO_RUNNER_SIGNAL" | "RESULT_IDEMPOTENT" | "RESULT_PROVENANCE" | "INGRESS_LOGGED_BEFORE_EXECUTION" | "NO_SHELL_INTERPOLATION" | "NO_PAYLOAD_ROUTING" | "STRIPPED_CHILD_ENV" | "HTTP_BASE_URL_SAFE" | "OUTPUT_INERT" | "COMMUNITY_BUDGETS")[];
|
|
1073
|
+
declare const MUST_IDS: readonly ("PAIR_ONE_USER" | "PAIR_INTERACTIVE" | "PAIR_CODE_EXPIRES" | "VERSION_HANDSHAKE_REQUIRED" | "KEYS_EXCHANGED_AT_CONSENT" | "REQUESTS_SIGNED_NOT_BEARER" | "LEASE_SCOPED_BY_GRANT" | "STUB_METADATA_EXHAUSTIVE" | "ENVELOPE_SEALED_AND_SIGNED" | "KIND_TYPED_ONLY" | "KIND_NO_CODE" | "CLAIM_REQUIRES_CAPABILITY" | "CAPABILITY_IS_DETECTED" | "CLAIM_ATOMIC" | "LEASE_HONORED" | "LEASE_RECLAIMABLE" | "AUDIENCE_BOTH_SIDES" | "SUBSCRIPTION_SELF_LOCK" | "METERED_DEFAULTS_SELF" | "METERED_REQUIRES_CEILING" | "COST_NOT_CONFIGURABLE" | "REMOTE_IS_NEVER_FREE" | "NAMED_LOCAL_ALLOWLIST" | "REFUSAL_NOT_REOFFERED" | "REVOCATION_HONORED" | "CANCEL_HONORED" | "DEPENDS_ON_GATING" | "TTL_EXPIRY" | "NO_RUNNER_SIGNAL" | "RESULT_IDEMPOTENT" | "RESULT_PROVENANCE" | "INGRESS_LOGGED_BEFORE_EXECUTION" | "NO_SHELL_INTERPOLATION" | "NO_PAYLOAD_ROUTING" | "STRIPPED_CHILD_ENV" | "HTTP_BASE_URL_SAFE" | "OUTPUT_INERT" | "COMMUNITY_BUDGETS")[];
|
|
1074
|
+
/** Every MUST verified a particular way. */
|
|
1075
|
+
declare function mustsVerifiedBy(kind: MustVerification): MustId[];
|
|
580
1076
|
|
|
581
1077
|
/** Protocol version carried on every request; servers refuse what they can't speak. */
|
|
582
1078
|
declare const PROTOCOL_VERSION: "0";
|
|
1079
|
+
/**
|
|
1080
|
+
* Every protocol version this build can serve, **oldest first**.
|
|
1081
|
+
*
|
|
1082
|
+
* One entry today. It is a list rather than a constant because the shape of
|
|
1083
|
+
* the check is the point: a server supporting two versions through a
|
|
1084
|
+
* migration should not need a different code path from one supporting one.
|
|
1085
|
+
*/
|
|
1086
|
+
declare const SUPPORTED_PROTOCOL_VERSIONS: readonly string[];
|
|
1087
|
+
/**
|
|
1088
|
+
* The oldest version this build will talk to — derived, not declared.
|
|
1089
|
+
*
|
|
1090
|
+
* Stating it separately would be a second thing to keep in step with the list
|
|
1091
|
+
* above, and the failure would be silent: a minimum that no longer matches
|
|
1092
|
+
* what is supported produces a refusal naming a version the server would in
|
|
1093
|
+
* fact have accepted.
|
|
1094
|
+
*/
|
|
1095
|
+
declare const MIN_PROTOCOL_VERSION: string;
|
|
1096
|
+
/** A structured refusal, so a daemon can say something useful to its owner. */
|
|
1097
|
+
interface VersionRefusal {
|
|
1098
|
+
readonly error: "unsupported-protocol-version";
|
|
1099
|
+
readonly message: string;
|
|
1100
|
+
readonly supported: readonly string[];
|
|
1101
|
+
readonly minimum: string;
|
|
1102
|
+
}
|
|
1103
|
+
/**
|
|
1104
|
+
* Check the protocol version on an incoming request
|
|
1105
|
+
* ({@link MUSTS.VERSION_HANDSHAKE_REQUIRED}).
|
|
1106
|
+
*
|
|
1107
|
+
* Returns a refusal, or `null` to proceed.
|
|
1108
|
+
*
|
|
1109
|
+
* **A missing version is refused the same way a wrong one is.** That is the
|
|
1110
|
+
* half worth stating: before this existed, the version travelled as a
|
|
1111
|
+
* `z.literal` inside each endpoint's schema, so a mismatch surfaced as a
|
|
1112
|
+
* generic `bad-request` — a daemon and a server discovered they disagreed by
|
|
1113
|
+
* failing, with nothing in the response naming the disagreement. An error a
|
|
1114
|
+
* user cannot act on is barely better than a hang.
|
|
1115
|
+
*
|
|
1116
|
+
* The message names the fix, because the person reading it is usually the one
|
|
1117
|
+
* who has to apply it.
|
|
1118
|
+
*/
|
|
1119
|
+
declare function checkProtocolVersion(body: unknown): VersionRefusal | null;
|
|
583
1120
|
/** The path prefix all endpoints mount under. */
|
|
584
1121
|
declare const PROTOCOL_PREFIX: "/byollm";
|
|
585
|
-
/**
|
|
586
|
-
|
|
1122
|
+
/**
|
|
1123
|
+
* The endpoint names, in the order byollm_001 lists them, plus `fetch`.
|
|
1124
|
+
*
|
|
1125
|
+
* `fetch` is byollm_009 §6's second phase: a claim returns a stub, and the
|
|
1126
|
+
* payload is collected separately by the device that took it. Two steps
|
|
1127
|
+
* rather than one because a payload can only be sealed once its recipient is
|
|
1128
|
+
* known — which is also what makes multi-device free.
|
|
1129
|
+
*/
|
|
1130
|
+
declare const ENDPOINTS: readonly ["pair", "claim", "fetch", "heartbeat", "result", "release"];
|
|
587
1131
|
type Endpoint = (typeof ENDPOINTS)[number];
|
|
588
1132
|
/**
|
|
589
1133
|
* One entry of the capability matrix: a kind this daemon can actually serve,
|
|
@@ -601,6 +1145,22 @@ declare const Capability: z.ZodObject<{
|
|
|
601
1145
|
"llm.chat": "llm.chat";
|
|
602
1146
|
}>;
|
|
603
1147
|
backendId: z.ZodEnum<{
|
|
1148
|
+
ollama: "ollama";
|
|
1149
|
+
mlx: "mlx";
|
|
1150
|
+
llamacpp: "llamacpp";
|
|
1151
|
+
vllm: "vllm";
|
|
1152
|
+
lmstudio: "lmstudio";
|
|
1153
|
+
jan: "jan";
|
|
1154
|
+
localai: "localai";
|
|
1155
|
+
anthropic: "anthropic";
|
|
1156
|
+
openai: "openai";
|
|
1157
|
+
gemini: "gemini";
|
|
1158
|
+
grok: "grok";
|
|
1159
|
+
groq: "groq";
|
|
1160
|
+
openrouter: "openrouter";
|
|
1161
|
+
together: "together";
|
|
1162
|
+
deepseek: "deepseek";
|
|
1163
|
+
mistral: "mistral";
|
|
604
1164
|
"openai-http": "openai-http";
|
|
605
1165
|
"claude-cli": "claude-cli";
|
|
606
1166
|
}>;
|
|
@@ -623,6 +1183,22 @@ declare const CapabilityMatrix: z.ZodArray<z.ZodObject<{
|
|
|
623
1183
|
"llm.chat": "llm.chat";
|
|
624
1184
|
}>;
|
|
625
1185
|
backendId: z.ZodEnum<{
|
|
1186
|
+
ollama: "ollama";
|
|
1187
|
+
mlx: "mlx";
|
|
1188
|
+
llamacpp: "llamacpp";
|
|
1189
|
+
vllm: "vllm";
|
|
1190
|
+
lmstudio: "lmstudio";
|
|
1191
|
+
jan: "jan";
|
|
1192
|
+
localai: "localai";
|
|
1193
|
+
anthropic: "anthropic";
|
|
1194
|
+
openai: "openai";
|
|
1195
|
+
gemini: "gemini";
|
|
1196
|
+
grok: "grok";
|
|
1197
|
+
groq: "groq";
|
|
1198
|
+
openrouter: "openrouter";
|
|
1199
|
+
together: "together";
|
|
1200
|
+
deepseek: "deepseek";
|
|
1201
|
+
mistral: "mistral";
|
|
626
1202
|
"openai-http": "openai-http";
|
|
627
1203
|
"claude-cli": "claude-cli";
|
|
628
1204
|
}>;
|
|
@@ -657,12 +1233,33 @@ declare const PairStartRequest: z.ZodObject<{
|
|
|
657
1233
|
win32: "win32";
|
|
658
1234
|
}>;
|
|
659
1235
|
}, z.core.$strip>;
|
|
1236
|
+
device: z.ZodObject<{
|
|
1237
|
+
identity: z.ZodString;
|
|
1238
|
+
encryption: z.ZodString;
|
|
1239
|
+
encryptionSig: z.ZodString;
|
|
1240
|
+
}, z.core.$strict>;
|
|
660
1241
|
capabilities: z.ZodArray<z.ZodObject<{
|
|
661
1242
|
kind: z.ZodEnum<{
|
|
662
1243
|
"llm.generate": "llm.generate";
|
|
663
1244
|
"llm.chat": "llm.chat";
|
|
664
1245
|
}>;
|
|
665
1246
|
backendId: z.ZodEnum<{
|
|
1247
|
+
ollama: "ollama";
|
|
1248
|
+
mlx: "mlx";
|
|
1249
|
+
llamacpp: "llamacpp";
|
|
1250
|
+
vllm: "vllm";
|
|
1251
|
+
lmstudio: "lmstudio";
|
|
1252
|
+
jan: "jan";
|
|
1253
|
+
localai: "localai";
|
|
1254
|
+
anthropic: "anthropic";
|
|
1255
|
+
openai: "openai";
|
|
1256
|
+
gemini: "gemini";
|
|
1257
|
+
grok: "grok";
|
|
1258
|
+
groq: "groq";
|
|
1259
|
+
openrouter: "openrouter";
|
|
1260
|
+
together: "together";
|
|
1261
|
+
deepseek: "deepseek";
|
|
1262
|
+
mistral: "mistral";
|
|
666
1263
|
"openai-http": "openai-http";
|
|
667
1264
|
"claude-cli": "claude-cli";
|
|
668
1265
|
}>;
|
|
@@ -705,6 +1302,11 @@ declare const PairPollResponse: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
705
1302
|
runnerId: z.ZodString;
|
|
706
1303
|
owner: z.ZodString;
|
|
707
1304
|
ownerLabel: z.ZodOptional<z.ZodString>;
|
|
1305
|
+
site: z.ZodObject<{
|
|
1306
|
+
identity: z.ZodString;
|
|
1307
|
+
encryption: z.ZodString;
|
|
1308
|
+
encryptionSig: z.ZodString;
|
|
1309
|
+
}, z.core.$strict>;
|
|
708
1310
|
}, z.core.$strict>], "status">;
|
|
709
1311
|
type PairPollResponse = z.infer<typeof PairPollResponse>;
|
|
710
1312
|
declare const PairRequest: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
@@ -719,12 +1321,33 @@ declare const PairRequest: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
719
1321
|
win32: "win32";
|
|
720
1322
|
}>;
|
|
721
1323
|
}, z.core.$strip>;
|
|
1324
|
+
device: z.ZodObject<{
|
|
1325
|
+
identity: z.ZodString;
|
|
1326
|
+
encryption: z.ZodString;
|
|
1327
|
+
encryptionSig: z.ZodString;
|
|
1328
|
+
}, z.core.$strict>;
|
|
722
1329
|
capabilities: z.ZodArray<z.ZodObject<{
|
|
723
1330
|
kind: z.ZodEnum<{
|
|
724
1331
|
"llm.generate": "llm.generate";
|
|
725
1332
|
"llm.chat": "llm.chat";
|
|
726
1333
|
}>;
|
|
727
1334
|
backendId: z.ZodEnum<{
|
|
1335
|
+
ollama: "ollama";
|
|
1336
|
+
mlx: "mlx";
|
|
1337
|
+
llamacpp: "llamacpp";
|
|
1338
|
+
vllm: "vllm";
|
|
1339
|
+
lmstudio: "lmstudio";
|
|
1340
|
+
jan: "jan";
|
|
1341
|
+
localai: "localai";
|
|
1342
|
+
anthropic: "anthropic";
|
|
1343
|
+
openai: "openai";
|
|
1344
|
+
gemini: "gemini";
|
|
1345
|
+
grok: "grok";
|
|
1346
|
+
groq: "groq";
|
|
1347
|
+
openrouter: "openrouter";
|
|
1348
|
+
together: "together";
|
|
1349
|
+
deepseek: "deepseek";
|
|
1350
|
+
mistral: "mistral";
|
|
728
1351
|
"openai-http": "openai-http";
|
|
729
1352
|
"claude-cli": "claude-cli";
|
|
730
1353
|
}>;
|
|
@@ -754,6 +1377,22 @@ declare const ClaimRequest: z.ZodObject<{
|
|
|
754
1377
|
"llm.chat": "llm.chat";
|
|
755
1378
|
}>;
|
|
756
1379
|
backendId: z.ZodEnum<{
|
|
1380
|
+
ollama: "ollama";
|
|
1381
|
+
mlx: "mlx";
|
|
1382
|
+
llamacpp: "llamacpp";
|
|
1383
|
+
vllm: "vllm";
|
|
1384
|
+
lmstudio: "lmstudio";
|
|
1385
|
+
jan: "jan";
|
|
1386
|
+
localai: "localai";
|
|
1387
|
+
anthropic: "anthropic";
|
|
1388
|
+
openai: "openai";
|
|
1389
|
+
gemini: "gemini";
|
|
1390
|
+
grok: "grok";
|
|
1391
|
+
groq: "groq";
|
|
1392
|
+
openrouter: "openrouter";
|
|
1393
|
+
together: "together";
|
|
1394
|
+
deepseek: "deepseek";
|
|
1395
|
+
mistral: "mistral";
|
|
757
1396
|
"openai-http": "openai-http";
|
|
758
1397
|
"claude-cli": "claude-cli";
|
|
759
1398
|
}>;
|
|
@@ -778,28 +1417,23 @@ declare const ClaimResponse: z.ZodObject<{
|
|
|
778
1417
|
"llm.generate": "llm.generate";
|
|
779
1418
|
"llm.chat": "llm.chat";
|
|
780
1419
|
}>;
|
|
781
|
-
|
|
782
|
-
prompt: z.ZodString;
|
|
783
|
-
system: z.ZodOptional<z.ZodString>;
|
|
784
|
-
}, z.core.$strict>, z.ZodObject<{
|
|
785
|
-
messages: z.ZodArray<z.ZodObject<{
|
|
786
|
-
role: z.ZodEnum<{
|
|
787
|
-
system: "system";
|
|
788
|
-
user: "user";
|
|
789
|
-
assistant: "assistant";
|
|
790
|
-
}>;
|
|
791
|
-
content: z.ZodString;
|
|
792
|
-
}, z.core.$strip>>;
|
|
793
|
-
system: z.ZodOptional<z.ZodString>;
|
|
794
|
-
}, z.core.$strict>]>;
|
|
1420
|
+
owner: z.ZodString;
|
|
795
1421
|
audience: z.ZodEnum<{
|
|
796
1422
|
self: "self";
|
|
797
1423
|
named: "named";
|
|
798
1424
|
public: "public";
|
|
799
1425
|
}>;
|
|
800
|
-
owner: z.ZodString;
|
|
801
1426
|
audienceAllow: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
1427
|
+
sizeClass: z.ZodEnum<{
|
|
1428
|
+
small: "small";
|
|
1429
|
+
medium: "medium";
|
|
1430
|
+
large: "large";
|
|
1431
|
+
unbounded: "unbounded";
|
|
1432
|
+
}>;
|
|
1433
|
+
streaming: z.ZodBoolean;
|
|
1434
|
+
deadlineAt: z.ZodNumber;
|
|
802
1435
|
lease: z.ZodObject<{
|
|
1436
|
+
id: z.ZodString;
|
|
803
1437
|
runnerId: z.ZodString;
|
|
804
1438
|
expiresAt: z.ZodNumber;
|
|
805
1439
|
}, z.core.$strip>;
|
|
@@ -817,6 +1451,22 @@ declare const HeartbeatRequest: z.ZodObject<{
|
|
|
817
1451
|
"llm.chat": "llm.chat";
|
|
818
1452
|
}>;
|
|
819
1453
|
backendId: z.ZodEnum<{
|
|
1454
|
+
ollama: "ollama";
|
|
1455
|
+
mlx: "mlx";
|
|
1456
|
+
llamacpp: "llamacpp";
|
|
1457
|
+
vllm: "vllm";
|
|
1458
|
+
lmstudio: "lmstudio";
|
|
1459
|
+
jan: "jan";
|
|
1460
|
+
localai: "localai";
|
|
1461
|
+
anthropic: "anthropic";
|
|
1462
|
+
openai: "openai";
|
|
1463
|
+
gemini: "gemini";
|
|
1464
|
+
grok: "grok";
|
|
1465
|
+
groq: "groq";
|
|
1466
|
+
openrouter: "openrouter";
|
|
1467
|
+
together: "together";
|
|
1468
|
+
deepseek: "deepseek";
|
|
1469
|
+
mistral: "mistral";
|
|
820
1470
|
"openai-http": "openai-http";
|
|
821
1471
|
"claude-cli": "claude-cli";
|
|
822
1472
|
}>;
|
|
@@ -831,7 +1481,10 @@ declare const HeartbeatRequest: z.ZodObject<{
|
|
|
831
1481
|
public: "public";
|
|
832
1482
|
}>;
|
|
833
1483
|
}, z.core.$strict>>;
|
|
834
|
-
|
|
1484
|
+
activeLeases: z.ZodArray<z.ZodObject<{
|
|
1485
|
+
jobId: z.ZodString;
|
|
1486
|
+
leaseId: z.ZodString;
|
|
1487
|
+
}, z.core.$strip>>;
|
|
835
1488
|
paused: z.ZodBoolean;
|
|
836
1489
|
}, z.core.$strict>;
|
|
837
1490
|
type HeartbeatRequest = z.infer<typeof HeartbeatRequest>;
|
|
@@ -846,22 +1499,43 @@ declare const HeartbeatResponse: z.ZodObject<{
|
|
|
846
1499
|
serverTime: z.ZodNumber;
|
|
847
1500
|
}, z.core.$strict>;
|
|
848
1501
|
type HeartbeatResponse = z.infer<typeof HeartbeatResponse>;
|
|
1502
|
+
/**
|
|
1503
|
+
* What an intermediary learns about how a job ended — byollm_009 §6.
|
|
1504
|
+
*
|
|
1505
|
+
* The discriminator and nothing else. A relay has to know a job reached a
|
|
1506
|
+
* terminal state, and whether it failed, because that decides whether the job
|
|
1507
|
+
* leaves the queue or the app may re-enqueue. It does not have to know what
|
|
1508
|
+
* the model said, or what an error said, and this is where that line is drawn.
|
|
1509
|
+
*
|
|
1510
|
+
* Kept identical to `JobOutcome`'s discriminator rather than coarsened to
|
|
1511
|
+
* ok/not-ok: a cancelled job and a failed one are different routing outcomes,
|
|
1512
|
+
* and collapsing them would make the relay guess.
|
|
1513
|
+
*/
|
|
1514
|
+
declare const ResultDisposition: z.ZodEnum<{
|
|
1515
|
+
ok: "ok";
|
|
1516
|
+
error: "error";
|
|
1517
|
+
canceled: "canceled";
|
|
1518
|
+
}>;
|
|
1519
|
+
type ResultDisposition = z.infer<typeof ResultDisposition>;
|
|
849
1520
|
declare const ResultRequest: z.ZodObject<{
|
|
850
1521
|
protocolVersion: z.ZodLiteral<"0">;
|
|
851
1522
|
runnerId: z.ZodString;
|
|
852
1523
|
jobId: z.ZodString;
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
}, z.core.$strict
|
|
863
|
-
|
|
864
|
-
|
|
1524
|
+
envelope: z.ZodObject<{
|
|
1525
|
+
ciphertext: z.ZodString;
|
|
1526
|
+
recipientKeyId: z.ZodString;
|
|
1527
|
+
senderKeyId: z.ZodString;
|
|
1528
|
+
direction: z.ZodEnum<{
|
|
1529
|
+
payload: "payload";
|
|
1530
|
+
result: "result";
|
|
1531
|
+
}>;
|
|
1532
|
+
deadlineAt: z.ZodNumber;
|
|
1533
|
+
}, z.core.$strict>;
|
|
1534
|
+
disposition: z.ZodEnum<{
|
|
1535
|
+
ok: "ok";
|
|
1536
|
+
error: "error";
|
|
1537
|
+
canceled: "canceled";
|
|
1538
|
+
}>;
|
|
865
1539
|
model: z.ZodString;
|
|
866
1540
|
backendClass: z.ZodEnum<{
|
|
867
1541
|
http: "http";
|
|
@@ -878,7 +1552,10 @@ type ResultResponse = z.infer<typeof ResultResponse>;
|
|
|
878
1552
|
declare const ReleaseRequest: z.ZodObject<{
|
|
879
1553
|
protocolVersion: z.ZodLiteral<"0">;
|
|
880
1554
|
runnerId: z.ZodString;
|
|
881
|
-
|
|
1555
|
+
leases: z.ZodArray<z.ZodObject<{
|
|
1556
|
+
jobId: z.ZodString;
|
|
1557
|
+
leaseId: z.ZodString;
|
|
1558
|
+
}, z.core.$strip>>;
|
|
882
1559
|
reason: z.ZodEnum<{
|
|
883
1560
|
revoked: "revoked";
|
|
884
1561
|
shutdown: "shutdown";
|
|
@@ -901,9 +1578,9 @@ type ReleaseResponse = z.infer<typeof ReleaseResponse>;
|
|
|
901
1578
|
* with no response at all.
|
|
902
1579
|
*/
|
|
903
1580
|
declare const WireErrorCode: z.ZodEnum<{
|
|
1581
|
+
"unsupported-protocol-version": "unsupported-protocol-version";
|
|
904
1582
|
revoked: "revoked";
|
|
905
1583
|
"bad-request": "bad-request";
|
|
906
|
-
"unsupported-protocol-version": "unsupported-protocol-version";
|
|
907
1584
|
unauthorized: "unauthorized";
|
|
908
1585
|
"not-found": "not-found";
|
|
909
1586
|
"rate-limited": "rate-limited";
|
|
@@ -912,9 +1589,9 @@ declare const WireErrorCode: z.ZodEnum<{
|
|
|
912
1589
|
type WireErrorCode = z.infer<typeof WireErrorCode>;
|
|
913
1590
|
declare const WireError: z.ZodObject<{
|
|
914
1591
|
error: z.ZodEnum<{
|
|
1592
|
+
"unsupported-protocol-version": "unsupported-protocol-version";
|
|
915
1593
|
revoked: "revoked";
|
|
916
1594
|
"bad-request": "bad-request";
|
|
917
|
-
"unsupported-protocol-version": "unsupported-protocol-version";
|
|
918
1595
|
unauthorized: "unauthorized";
|
|
919
1596
|
"not-found": "not-found";
|
|
920
1597
|
"rate-limited": "rate-limited";
|
|
@@ -926,5 +1603,25 @@ declare const WireError: z.ZodObject<{
|
|
|
926
1603
|
type WireError = z.infer<typeof WireError>;
|
|
927
1604
|
/** HTTP status each error code is served with. */
|
|
928
1605
|
declare const ERROR_STATUS: Readonly<Record<WireErrorCode, number>>;
|
|
1606
|
+
declare const FetchRequest: z.ZodObject<{
|
|
1607
|
+
protocolVersion: z.ZodString;
|
|
1608
|
+
runnerId: z.ZodString;
|
|
1609
|
+
jobId: z.ZodString;
|
|
1610
|
+
leaseId: z.ZodString;
|
|
1611
|
+
}, z.core.$strict>;
|
|
1612
|
+
type FetchRequest = z.infer<typeof FetchRequest>;
|
|
1613
|
+
declare const FetchResponse: z.ZodObject<{
|
|
1614
|
+
envelope: z.ZodObject<{
|
|
1615
|
+
ciphertext: z.ZodString;
|
|
1616
|
+
recipientKeyId: z.ZodString;
|
|
1617
|
+
senderKeyId: z.ZodString;
|
|
1618
|
+
direction: z.ZodEnum<{
|
|
1619
|
+
payload: "payload";
|
|
1620
|
+
result: "result";
|
|
1621
|
+
}>;
|
|
1622
|
+
deadlineAt: z.ZodNumber;
|
|
1623
|
+
}, z.core.$strict>;
|
|
1624
|
+
}, z.core.$strict>;
|
|
1625
|
+
type FetchResponse = z.infer<typeof FetchResponse>;
|
|
929
1626
|
|
|
930
|
-
export { AUDIENCES, Audience, BACKENDS, BACKEND_IDS,
|
|
1627
|
+
export { AUDIENCES, Audience, BACKENDS, BACKEND_IDS, BackendClass, BackendCost, type BackendDescriptor, type BackendId, BackendIdSchema, Capability, CapabilityMatrix, ChatMessage, ChatPayload, ClaimRequest, ClaimResponse, ClaimedJob, ClaimedStub, DeliveredResult, ENDPOINTS, ENVELOPE_MAX_AGE_MS, ERROR_STATUS, type Endpoint, type EnvelopeContext, EnvelopeDirection, type EnvelopeFailure, FetchRequest, FetchResponse, GeneratePayload, HeartbeatRequest, HeartbeatResponse, JOB_KINDS, JobKind, JobOutcome, JobPayload, JobResultCanceled, JobResultError, JobResultOk, JobState, JobStub, KindedPayload, Lease, MAX_CLOCK_SKEW_MS, MIN_PROTOCOL_VERSION, MUSTS, MUST_IDS, type MatchDaemon, type MatchJob, MatchRefusal, type MatchResult, type Must, type MustEnforcer, type MustId, type MustVerification, OFFER_SCOPES, OfferScope, type OpenResult, PAYLOAD_LIMITS, PROTOCOL_PREFIX, PROTOCOL_VERSION, PairPollRequest, PairPollResponse, PairRequest, PairStartRequest, PairStartResponse, type PayloadFor, PublicIdentity, REFUSAL_MESSAGES, ReleaseRequest, ReleaseResponse, RequestSignature, ResultDisposition, ResultProvenance, ResultRequest, ResultResponse, SIZE_CLASS_LIMITS, SUPPORTED_PROTOCOL_VERSIONS, SealedEnvelope, type SignatureFailure, SizeClass, type SpendConsent, StoredKeys, TERMINAL_STATES, type VersionRefusal, WireError, WireErrorCode, backendDescriptor, canTransition, canonicalRequest, checkProtocolVersion, cryptoReady, effectiveOfferScope, fingerprint, generateKeys, isBackendId, isJobKind, isLocalHost, isTerminal, keyId, matchAudience, mustsVerifiedBy, open, payloadTextLength, provenanceFor, publicIdentityOf, resolveCost, seal, signRequest, signWith, sizeClassCeiling, sizeClassOf, verifyPublicIdentity, verifyRequest, verifyWith };
|