@scp-dev/broker 0.1.3 → 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/dist/index.d.ts +28 -115
- package/dist/index.js +94 -514
- package/package.json +3 -3
- package/src/client.ts +2 -2
- package/src/index.ts +3 -2
- package/src/judge-gate.ts +14 -545
- package/src/server.ts +51 -18
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { ScopePreset, Claim, EndpointView, ScopeView, ScopeChange, Envelope, StopWaitResult, PeerView, WhyResult, SendParams, SendResult, ActivityRow, XListed, Selector } from '@scp-dev/core';
|
|
2
|
+
import { JudgeGate as JudgeGate$1, JudgeGateOptions, FederatedCore, Deliver, JudgeClientFactory } from '@scp-dev/hub';
|
|
3
|
+
export { Deliver } from '@scp-dev/hub';
|
|
4
4
|
|
|
5
5
|
interface Hello {
|
|
6
6
|
claim?: Claim;
|
|
@@ -10,9 +10,10 @@ interface Hello {
|
|
|
10
10
|
tty?: boolean;
|
|
11
11
|
/** a hook's connection: it claims like an agent but never counts as connected, and posts only event and status */
|
|
12
12
|
transient?: boolean;
|
|
13
|
-
/** with `transient`: the session joins the relay on demand, taking `handle` when given */
|
|
13
|
+
/** with `transient`: the session joins the relay on demand, taking `handle` when given, and links itself under the agent `under` */
|
|
14
14
|
join?: {
|
|
15
15
|
handle?: string;
|
|
16
|
+
under?: string;
|
|
16
17
|
};
|
|
17
18
|
/** a one-shot command: the broker announces no presence change when it connects or goes */
|
|
18
19
|
brief?: boolean;
|
|
@@ -176,6 +177,16 @@ declare class BrokerUnavailable extends Error {
|
|
|
176
177
|
*/
|
|
177
178
|
declare function connectBroker(dir: string, start?: () => void, timeoutMs?: number): Promise<RelayClient>;
|
|
178
179
|
|
|
180
|
+
/** what the broker gives the bridge: waking local waiters, telling local watchers, the local policy's state */
|
|
181
|
+
interface BridgeHooks {
|
|
182
|
+
/** a local endpoint got a message */
|
|
183
|
+
wake(endpoint: string): void;
|
|
184
|
+
/** a fleet event for local watchers only; never forwarded back */
|
|
185
|
+
fleet(event: Record<string, unknown>): void;
|
|
186
|
+
/** loads the local policy; a reason when it is unusable */
|
|
187
|
+
policyError(): string | null;
|
|
188
|
+
log?(line: string): void;
|
|
189
|
+
}
|
|
179
190
|
interface BridgeConfig {
|
|
180
191
|
/** the hub's https origin, from the caller; the socket is <origin>/v1/relay/ws */
|
|
181
192
|
url: string;
|
|
@@ -274,116 +285,9 @@ declare function privateDir(path: string): string;
|
|
|
274
285
|
*/
|
|
275
286
|
declare function socketPath(dir: string): string;
|
|
276
287
|
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
unverified?: boolean;
|
|
281
|
-
};
|
|
282
|
-
/** sends as `from` through the same path an unjudged send takes, waking recipients */
|
|
283
|
-
type Deliver = (from: string, params: SendParams, origin: Origin) => Promise<SendResult>;
|
|
284
|
-
interface JudgeGateOptions {
|
|
285
|
-
sql: Sql;
|
|
286
|
-
core: FederatedCore;
|
|
287
|
-
now: () => number;
|
|
288
|
-
/** where key_env is read */
|
|
289
|
-
env: Record<string, string | undefined>;
|
|
290
|
-
client?: JudgeClientFactory | undefined;
|
|
291
|
-
log: (line: string) => void;
|
|
292
|
-
/** an endpoint got a notice */
|
|
293
|
-
wake: (endpoint: string) => void;
|
|
294
|
-
}
|
|
295
|
-
interface HoldRow {
|
|
296
|
-
id: string;
|
|
297
|
-
from_ep: string;
|
|
298
|
-
params: string;
|
|
299
|
-
origin: string;
|
|
300
|
-
verdict: string;
|
|
301
|
-
created_at: number;
|
|
302
|
-
expires_at: number;
|
|
303
|
-
state: "held" | "releasing" | "released" | "refused" | "expired";
|
|
304
|
-
by: string | null;
|
|
305
|
-
resolved_at: number | null;
|
|
306
|
-
}
|
|
307
|
-
/** a hold as the human's review lists it: never the body */
|
|
308
|
-
interface HoldView {
|
|
309
|
-
id: string;
|
|
310
|
-
from: string;
|
|
311
|
-
to: string[];
|
|
312
|
-
state: HoldRow["state"];
|
|
313
|
-
created_at: string;
|
|
314
|
-
expires_at: string;
|
|
315
|
-
categories: string[];
|
|
316
|
-
reason: string;
|
|
317
|
-
boundary: string;
|
|
318
|
-
source: Verdict["source"];
|
|
319
|
-
bytes: number;
|
|
320
|
-
by: string | null;
|
|
321
|
-
resolved_at: string | null;
|
|
322
|
-
}
|
|
323
|
-
/**
|
|
324
|
-
* the broker's local judge (policy `judge`): shadow judges after delivery and only audits; enforce judges before delivery and passes,
|
|
325
|
-
* redacts, refuses or holds. Holds wait in `judge_holds` for the human at a terminal; their body is purged once resolved or expired
|
|
326
|
-
*/
|
|
327
|
-
declare class JudgeGate {
|
|
328
|
-
private readonly o;
|
|
329
|
-
readonly stats: _scp_dev_core.JudgeStats;
|
|
330
|
-
private policy;
|
|
331
|
-
private version;
|
|
332
|
-
private client;
|
|
333
|
-
private readonly cache;
|
|
334
|
-
private readonly shadows;
|
|
335
|
-
/** judged sends in the last hour per budget: `ep:<id>`, `tree:<root id>` and `*` for the whole broker */
|
|
336
|
-
private readonly spent;
|
|
337
|
-
constructor(o: JudgeGateOptions);
|
|
338
|
-
/** the policy's judge section; a model client only when its key is readable, else the prefilter alone */
|
|
339
|
-
configure(policy: JudgePolicy | undefined): void;
|
|
340
|
-
private keyReader;
|
|
341
|
-
/** resolves once every shadow judgement started so far finished */
|
|
342
|
-
settled(): Promise<void>;
|
|
343
|
-
/** a send or ask through the judge; an unjudged one goes straight to `deliver` */
|
|
344
|
-
send(from: string, params: SendParams, origin: Origin, deliver: Deliver): Promise<SendResult>;
|
|
345
|
-
/** an earlier judged send or waiting hold under the send's client_id: the same message is answered as before, another one refused as core refuses it */
|
|
346
|
-
private seen;
|
|
347
|
-
private remember;
|
|
348
|
-
/**
|
|
349
|
-
* a judged send counts before any model call against its sender's, its lineage tree's and the whole broker's budget, since refused and
|
|
350
|
-
* held sends never reach the send's own limits, and a new handle or a helper process must not bring a fresh budget
|
|
351
|
-
*/
|
|
352
|
-
private spend;
|
|
353
|
-
/** how many budgets are tracked (idle ones are evicted by the sweep) */
|
|
354
|
-
budgetKeys(): number;
|
|
355
|
-
/** the held messages, newest first, without bodies */
|
|
356
|
-
holds(state?: string): HoldView[];
|
|
357
|
-
/** one hold with its body and the judge's redactions while it waits */
|
|
358
|
-
show(id: string): HoldView & {
|
|
359
|
-
body?: string;
|
|
360
|
-
redactions?: {
|
|
361
|
-
quote?: string;
|
|
362
|
-
kind: string;
|
|
363
|
-
}[];
|
|
364
|
-
};
|
|
365
|
-
/** delivers a held message as its sender, as stored or redacted: scope, policy and limits are checked again by the send itself */
|
|
366
|
-
release(id: string, options: {
|
|
367
|
-
redacted?: boolean;
|
|
368
|
-
by: string;
|
|
369
|
-
}, deliver: Deliver): Promise<SendResult>;
|
|
370
|
-
/** refuses a held message: it is never delivered, and its sender hears the human's reason */
|
|
371
|
-
refuse(id: string, reason: string, by: string): HoldView;
|
|
372
|
-
/** expires holds past their message TTL (body purged, sender told) and drops resolved ones past the audit window */
|
|
373
|
-
sweep(): void;
|
|
374
|
-
private expire;
|
|
375
|
-
/** the recipients by the boundary their message crosses; throws as send does for a target the sender cannot reach */
|
|
376
|
-
private boundaries;
|
|
377
|
-
private judge;
|
|
378
|
-
private shadow;
|
|
379
|
-
private hold;
|
|
380
|
-
private detail;
|
|
381
|
-
private storedDetail;
|
|
382
|
-
/** marks a hold resolved and purges its body and the judge's quotes of it */
|
|
383
|
-
private resolve;
|
|
384
|
-
private tell;
|
|
385
|
-
private row;
|
|
386
|
-
private view;
|
|
288
|
+
/** the hub's judge gate reading `key_file` keys from disk */
|
|
289
|
+
declare class JudgeGate extends JudgeGate$1 {
|
|
290
|
+
constructor(options: JudgeGateOptions);
|
|
387
291
|
}
|
|
388
292
|
|
|
389
293
|
interface BrokerOptions {
|
|
@@ -411,6 +315,8 @@ interface BrokerOptions {
|
|
|
411
315
|
bridge?: BridgeConfig | undefined;
|
|
412
316
|
/** reads the bridge configuration again for bridge_relink; one that appeared or names another hub or machine restarts the broker */
|
|
413
317
|
bridgeConfig?: (() => Promise<BridgeConfig | undefined>) | undefined;
|
|
318
|
+
/** experimental: another link to other machines in place of the hub's, started only when `bridge` is unset */
|
|
319
|
+
link?: LinkFactory | undefined;
|
|
414
320
|
/** how often presence that decays without a request (a hook-only endpoint) is checked for changes (default 60 s) */
|
|
415
321
|
presenceEveryMs?: number | undefined;
|
|
416
322
|
/** where a judge model's key_env is read (default the broker's environment) */
|
|
@@ -418,6 +324,13 @@ interface BrokerOptions {
|
|
|
418
324
|
/** the judge model client for a policy's `judge.model` (default the provider's HTTP API) */
|
|
419
325
|
judgeClient?: JudgeClientFactory | undefined;
|
|
420
326
|
}
|
|
327
|
+
/** what a link gets from the broker: its core, the remote hooks a bridge gets, and a send as a local endpoint or a mirrored one through the judge */
|
|
328
|
+
interface LinkContext {
|
|
329
|
+
core: FederatedCore;
|
|
330
|
+
hooks: BridgeHooks;
|
|
331
|
+
send: Deliver;
|
|
332
|
+
}
|
|
333
|
+
type LinkFactory = (context: LinkContext) => Bridge;
|
|
421
334
|
interface Broker {
|
|
422
335
|
socket: string;
|
|
423
336
|
core: FederatedCore;
|
|
@@ -441,4 +354,4 @@ interface SessionMarker {
|
|
|
441
354
|
declare function readSessionMarker(dir: string, session: string): SessionMarker | undefined;
|
|
442
355
|
declare function writeSessionMarker(dir: string, session: string, marker: SessionMarker): void;
|
|
443
356
|
|
|
444
|
-
export { type Bridge, type BridgeConfig, type BridgeStatus, type Broker, type BrokerInfo, type BrokerOptions, BrokerRunning, BrokerUnavailable, type GrantParams, type GroupParams, type Hello, type HelloResult, MAX_LINE, RelayClient, type SessionMarker, accountHome, connectBroker, localHostName, policyPath, privateDir, readSessionMarker, relayDir, relaySocketUrl, shortHostname, socketPath, startBroker, systemHostname, thisHostname, writeSessionMarker };
|
|
357
|
+
export { type Bridge, type BridgeConfig, type BridgeHooks, type BridgeStatus, type Broker, type BrokerInfo, type BrokerOptions, BrokerRunning, BrokerUnavailable, type GrantParams, type GroupParams, type Hello, type HelloResult, type LinkContext, type LinkFactory, MAX_LINE, RelayClient, type SessionMarker, accountHome, connectBroker, localHostName, policyPath, privateDir, readSessionMarker, relayDir, relaySocketUrl, shortHostname, socketPath, startBroker, systemHostname, thisHostname, writeSessionMarker };
|