@sema-agent/settings-schema 32.0.0 → 33.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/fleet.d.ts CHANGED
@@ -111,8 +111,8 @@ export declare function compareGeneration(a: string, b: string): -1 | 0 | 1;
111
111
  export declare const LEASE_STATES: readonly ["none", "granted", "expired", "denied"];
112
112
  export declare const LeaseState: z.ZodEnum<{
113
113
  none: "none";
114
- granted: "granted";
115
114
  expired: "expired";
115
+ granted: "granted";
116
116
  denied: "denied";
117
117
  }>;
118
118
  export type LeaseState = z.infer<typeof LeaseState>;
@@ -283,7 +283,9 @@ export declare function readModelRefusals(body: unknown): ModelRefusalsSignal |
283
283
  /**
284
284
  * The engine's draining fact — ONE object wherever the engine says "I am draining": inside {@link EngineSignal}`.draining`
285
285
  * and as the body of a {@link DrainReceipt}.
286
- * - `actionId` — the action that put the engine into draining (idempotency key of the drain request).
286
+ * - `actionId` — the action that put the engine into draining: for a request of the identity form ({@link DrainRequest}) its `actionId`, the
287
+ * idempotency key; a request of the credential-named form ({@link CredentialDrainRequest}) carries none, and how the engine mints this one
288
+ * for it is the engine's to define (this package does not).
287
289
  * - `since` — epoch ms when draining began; it does not move when the same action repeats.
288
290
  * - `deadlineAt` — epoch ms by which the engine stops on its own.
289
291
  */
@@ -342,8 +344,8 @@ export declare const EngineSignal: z.ZodObject<{
342
344
  generation: z.ZodOptional<z.ZodString & z.ZodType<string, string, z.core.$ZodTypeInternals<string, string>>>;
343
345
  leaseState: z.ZodOptional<z.ZodEnum<{
344
346
  none: "none";
345
- granted: "granted";
346
347
  expired: "expired";
348
+ granted: "granted";
347
349
  denied: "denied";
348
350
  }>>;
349
351
  leaseUntil: z.ZodOptional<z.ZodNumber>;
@@ -385,8 +387,8 @@ export declare const InstanceHealth: z.ZodObject<{
385
387
  generation: z.ZodOptional<z.ZodString & z.ZodType<string, string, z.core.$ZodTypeInternals<string, string>>>;
386
388
  leaseState: z.ZodOptional<z.ZodEnum<{
387
389
  none: "none";
388
- granted: "granted";
389
390
  expired: "expired";
391
+ granted: "granted";
390
392
  denied: "denied";
391
393
  }>>;
392
394
  leaseUntil: z.ZodOptional<z.ZodNumber>;
@@ -457,8 +459,8 @@ export declare const InstanceAnnouncement: z.ZodObject<{
457
459
  generation: z.ZodOptional<z.ZodString & z.ZodType<string, string, z.core.$ZodTypeInternals<string, string>>>;
458
460
  leaseState: z.ZodOptional<z.ZodEnum<{
459
461
  none: "none";
460
- granted: "granted";
461
462
  expired: "expired";
463
+ granted: "granted";
462
464
  denied: "denied";
463
465
  }>>;
464
466
  leaseUntil: z.ZodOptional<z.ZodNumber>;
@@ -506,8 +508,8 @@ export declare const InstanceRegistration: z.ZodObject<{
506
508
  generation: z.ZodOptional<z.ZodString & z.ZodType<string, string, z.core.$ZodTypeInternals<string, string>>>;
507
509
  leaseState: z.ZodOptional<z.ZodEnum<{
508
510
  none: "none";
509
- granted: "granted";
510
511
  expired: "expired";
512
+ granted: "granted";
511
513
  denied: "denied";
512
514
  }>>;
513
515
  leaseUntil: z.ZodOptional<z.ZodNumber>;
@@ -776,7 +778,8 @@ export declare const DrainRequest: z.ZodObject<{
776
778
  }, z.core.$strip>;
777
779
  export type DrainRequest = z.infer<typeof DrainRequest>;
778
780
  /** What a drain request leaves the engine in: `draining` — this call put it into draining; `already_draining` — it already was
779
- * (the same action repeated), and the receipt reports the first call's facts. */
781
+ * (for the identity form: the same action repeated), and the receipt reports the first call's facts. For the credential-named form see
782
+ * {@link CredentialDrainRequest}. */
780
783
  export declare const DRAIN_RECEIPT_STATES: readonly ["draining", "already_draining"];
781
784
  export declare const DrainReceiptState: z.ZodEnum<{
782
785
  draining: "draining";
@@ -799,6 +802,121 @@ export type DrainReceipt = z.infer<typeof DrainReceipt>;
799
802
  export declare function readDrainRequest(body: unknown): DrainRequest | undefined;
800
803
  /** Caller side: the drain endpoint's answer. Shape mismatch / non-object / throwing accessor ⇒ `undefined`, never throws. */
801
804
  export declare function readDrainReceipt(body: unknown): DrainReceipt | undefined;
805
+ /**
806
+ * The two words of {@link CredentialDrainRequest}`.turns` — a CLOSED set, owned here (a reader that switches on it exhaustively is told
807
+ * by the compiler when a word is added): how the turns that are running at the moment the engine accepts the drain give way. This package
808
+ * fixes the words; what each word does is engine-side behaviour, described here and not verified by this package.
809
+ * - `yield` — the way a drain always stops them: a running turn parks at its next clean turn boundary, and what has not finished when the
810
+ * deadline passes is cut by the hard stop. An absent `turns` means `yield`.
811
+ * - `halt` — everything `yield` does, and in the same step the engine asks every running turn that has a turn surface to stop now — the
812
+ * cut a user's Esc makes in that window. The deadline does not move; a turn that does not take the cut in time is handled as under
813
+ * `yield`. The engine honours it only for a caller that holds the operator authority to halt any run; otherwise it refuses and changes nothing.
814
+ */
815
+ export declare const DRAIN_TURNS: readonly ["yield", "halt"];
816
+ export declare const DrainTurns: z.ZodEnum<{
817
+ yield: "yield";
818
+ halt: "halt";
819
+ }>;
820
+ export type DrainTurns = z.infer<typeof DrainTurns>;
821
+ /**
822
+ * The drain endpoint's request in its CREDENTIAL-NAMED form: the sender (the side that sends the request) names the engine by the credential it
823
+ * presents (the one a launcher minted for this process), not by the identity quadruple of {@link DrainRequest} — so the body carries no action
824
+ * id, no worker, no deadline, only what is to be said about THIS call. A STRICT object: one key more, one word off, a negative / fractional /
825
+ * string / oversize count ⇒ the body is not this form (and a half-built {@link DrainRequest} is never read as a stop request). Every key is
826
+ * optional and the empty body `{}` is the whole default form. A reader never mints a key the sender did not write, and this package exports
827
+ * no default constant: the RECEIVING side applies the meaning of an absent key — an absent `turns` is `yield`, an absent `attachedAtMost`
828
+ * sets no condition.
829
+ * - `instanceId` — a non-empty string: the engine's own per-process identity ({@link InstanceHealth}`.instanceId`). When present the engine
830
+ * compares it with its own and refuses on a mismatch. The very schema of {@link DrainRequest}`.instanceId`, not a copy.
831
+ * - `turns` — how the turns running at acceptance give way ({@link DRAIN_TURNS}).
832
+ * - `attachedAtMost` — a non-negative safe integer: accept the drain only if at most this many streams are attached to the engine at the
833
+ * moment it judges the request; more ⇒ a refusal carrying {@link DrainConditionUnmet}, nothing changed. It bounds what was attached at that moment;
834
+ * it is not a promise about the streams and requests that arrive afterwards.
835
+ * The two forms of the endpoint's request share no body that is plain data (what JSON parsing yields): {@link DrainRequest} requires
836
+ * `actionId`, `worker` and `deadlineAt`, which this form refuses as unknown keys. `turns` and `attachedAtMost` belong to this form only —
837
+ * {@link DrainRequest} does not carry them; its single-form reader strips them like any unknown key, and the reader of the endpoint's body
838
+ * ({@link readDrainRequestReading}) reads an identity body that carries either of them as neither form. The answer is the same
839
+ * {@link DrainReceipt} shape for both forms. What the engine puts in it for this form — engine-side behaviour, which this package does not
840
+ * verify: `deadlineAt` is the engine's own drain window (the body names no deadline); a `halt` sent while the engine is already draining is
841
+ * answered `already_draining` with the first call's facts and cuts the turns running at that moment; while the hard stop is under way the
842
+ * receipt's `actionId` is `hard-stop` and neither `turns` nor `attachedAtMost` is read; the naming is judged before the condition (a naming
843
+ * mismatch is refused without the attached count), and the condition is judged even when the engine is already draining. How the engine
844
+ * mints the receipt's `actionId` for this form, and what it answers for other requests of this form sent while it is draining, is the
845
+ * engine's to define; this package does not.
846
+ */
847
+ export declare const CredentialDrainRequest: z.ZodObject<{
848
+ instanceId: z.ZodOptional<z.ZodString>;
849
+ turns: z.ZodOptional<z.ZodEnum<{
850
+ yield: "yield";
851
+ halt: "halt";
852
+ }>>;
853
+ attachedAtMost: z.ZodOptional<z.ZodNumber>;
854
+ }, z.core.$strict>;
855
+ export type CredentialDrainRequest = z.infer<typeof CredentialDrainRequest>;
856
+ /**
857
+ * Engine side: the request body of the drain endpoint in its credential-named form. Shape mismatch / non-object / throwing accessor ⇒
858
+ * `undefined`, never throws. A body of the identity form ({@link DrainRequest}) reads `undefined` here and a body of this form reads
859
+ * `undefined` for {@link readDrainRequest}: no plain-data body is read by both (an object that shows two different key sets to the two
860
+ * readers — a Proxy whose `ownKeys` trap lies — is outside that promise; a body parsed from JSON never is one). A request with no bytes is
861
+ * the engine's to turn into `{}` before it calls this reader (`undefined` and `null` are not objects here).
862
+ * The result is an ordinary object, like every reader's in this file: the reader looks only at the body's own keys, but an optional key it
863
+ * did not read is absent only as an own key — test for it with `Object.hasOwn`, do not read it through the prototype chain.
864
+ */
865
+ export declare function readCredentialDrainRequest(body: unknown): CredentialDrainRequest | undefined;
866
+ /**
867
+ * What {@link readDrainRequestReading} makes of a drain request body: which of the endpoint's two forms it is, and the request read in
868
+ * that form — the identity quadruple ({@link DrainRequest}) or the credential-named form ({@link CredentialDrainRequest}). Branch on
869
+ * `form`; each arm's `request` has that form's type.
870
+ */
871
+ export type DrainRequestReading = {
872
+ form: "identity";
873
+ request: DrainRequest;
874
+ } | {
875
+ form: "credential";
876
+ request: CredentialDrainRequest;
877
+ };
878
+ /** The form words of {@link DrainRequestReading}, in the order the reader tries them. `satisfies` bites a word the union does not have;
879
+ * the converse (a union arm missing from this list) is pinned by a test that compares the two. */
880
+ export declare const DRAIN_REQUEST_FORMS: readonly ["identity", "credential"];
881
+ /**
882
+ * Engine side: THE reader of the drain endpoint's request body — which form it is and the request in that form; neither ⇒ `undefined`.
883
+ * A body is one form or the other: a body that mixes the keys of the two forms is NEITHER — a body the identity reader reads that also
884
+ * carries, as its own key, a key only the credential-named form has (`turns`, `attachedAtMost`: that form's keys minus the shared
885
+ * `instanceId`) reads `undefined` here, whatever that key's value, so a condition or a turn policy sent on the identity form is refused
886
+ * instead of being stripped. It composes the two single-form readers and that one key check (no second schema): {@link readDrainRequest}
887
+ * first, then {@link readCredentialDrainRequest}; the `request` handed back is that reader's answer in this call. When this reader reads a
888
+ * body, its `request` equals the answer of that form's single-form reader; the converse does not hold: a mixed body that is plain data reads
889
+ * `undefined` here while {@link readDrainRequest} reads it (stripping the keys). For plain data the order changes nothing (no such body is
890
+ * read by both single-form readers). An object that shows the two single-form readers different key sets reads as the identity form only
891
+ * when the key check, which asks for each credential-only key's own descriptor, finds none of them; when it finds one the object is a mixed
892
+ * body and reads `undefined`. A proxy that changes itself while it is read may answer differently than when the credential reader is asked
893
+ * alone (the identity probe came first). Never throws. The single-form readers stay for a side that
894
+ * already knows which form it sent; {@link readDrainRequest} still strips the credential-named form's keys as it strips any unknown key.
895
+ */
896
+ export declare function readDrainRequestReading(body: unknown): DrainRequestReading | undefined;
897
+ /** The machine code of the drain endpoint's refusal "the condition the request set is not met": the HTTP 409 whose body carries {@link DrainConditionUnmet}.
898
+ * One spelling — the engine mints the refusal with it, a caller branches on it. */
899
+ export declare const DRAIN_CONDITION_UNMET_CODE = "conflict.drain_condition_unmet";
900
+ /**
901
+ * The facts a {@link DRAIN_CONDITION_UNMET_CODE} refusal carries at the root of its body, beside the refusal's own `error` sentence and `errorCode`:
902
+ * - `attached` — how many streams were attached when the engine judged the request;
903
+ * - `attachedAtMost` — the bound the request set, echoed.
904
+ * A refused call changed nothing, and the engine answers this only when `attached` is above `attachedAtMost` (engine-side behaviour, not
905
+ * verified by this package); the reader judges the form of the
906
+ * two numbers (non-negative safe integers), not their relation. The refusal's own keys are stripped, so the reader takes the whole body.
907
+ */
908
+ export declare const DrainConditionUnmet: z.ZodObject<{
909
+ attached: z.ZodNumber;
910
+ attachedAtMost: z.ZodNumber;
911
+ }, z.core.$strip>;
912
+ export type DrainConditionUnmet = z.infer<typeof DrainConditionUnmet>;
913
+ /**
914
+ * Caller side: the facts of a {@link DRAIN_CONDITION_UNMET_CODE} refusal. Compare the refusal's `errorCode` with {@link DRAIN_CONDITION_UNMET_CODE}
915
+ * first and read the two numbers with this only when they are equal: this reader does not judge the code, so any body that carries the two
916
+ * facts reads, whatever refusal it is. A body that does not carry both facts (another refusal of the same status, a receipt, a request) reads `undefined`.
917
+ * Shape mismatch / non-object / throwing accessor ⇒ `undefined`, never throws.
918
+ */
919
+ export declare function readDrainConditionUnmet(body: unknown): DrainConditionUnmet | undefined;
802
920
  export declare const DISPATCH_STRATEGIES: readonly ["round-robin", "least-inflight", "consistent-hash"];
803
921
  export type DispatchStrategy = (typeof DISPATCH_STRATEGIES)[number];
804
922
  /** Per-worker dispatch policy (web-admin-configured; the gateway is OPTIONAL — D3: TOC/self-maintained TOB go
package/dist/fleet.js CHANGED
@@ -26,6 +26,7 @@ import { isPlainJsonObject } from "./plain-json-object.js";
26
26
  import { buildQuotedIssue } from "./quoted-issue.js";
27
27
  import { recordOf } from "./record-seat.js";
28
28
  import { deepFreeze } from "./deep-freeze.js";
29
+ import { SafeCount } from "./api/wire-scalars.js";
29
30
  // ── Web-admin's fleet endpoints (paths, one spelling) ─────────────────────────────────────────────────────
30
31
  /**
31
32
  * Web-admin's `/api/fleet/*` endpoints that are addressed from outside web-admin, relative to its origin. ONE spelling: whoever
@@ -209,7 +210,8 @@ function judgeSignalBody(body, pick, schema) {
209
210
  * The reader behind every wire-shape read in this file that has no use for a reason: the engine-owned signals on /health
210
211
  * ({@link readEngineSignal}, {@link readModelRefusals}) and the request / reply bodies of the
211
212
  * fleet endpoints ({@link readServingLeaseRequest}, {@link readServingLeaseResponse}, {@link readDrainRequest},
212
- * {@link readDrainReceipt}). Shape mismatch, a non-object body, even a throwing accessor ⇒ `undefined` — never throws.
213
+ * {@link readCredentialDrainRequest}, {@link readDrainReceipt}, {@link readDrainConditionUnmet}; {@link readDrainRequestReading} composes
214
+ * two of them). Shape mismatch, a non-object body, even a throwing accessor ⇒ `undefined` — never throws.
213
215
  */
214
216
  function readSignalBody(body, pick, schema) {
215
217
  const judged = judgeSignalBody(body, pick, schema);
@@ -358,7 +360,9 @@ export function readModelRefusals(body) {
358
360
  /**
359
361
  * The engine's draining fact — ONE object wherever the engine says "I am draining": inside {@link EngineSignal}`.draining`
360
362
  * and as the body of a {@link DrainReceipt}.
361
- * - `actionId` — the action that put the engine into draining (idempotency key of the drain request).
363
+ * - `actionId` — the action that put the engine into draining: for a request of the identity form ({@link DrainRequest}) its `actionId`, the
364
+ * idempotency key; a request of the credential-named form ({@link CredentialDrainRequest}) carries none, and how the engine mints this one
365
+ * for it is the engine's to define (this package does not).
362
366
  * - `since` — epoch ms when draining began; it does not move when the same action repeats.
363
367
  * - `deadlineAt` — epoch ms by which the engine stops on its own.
364
368
  */
@@ -831,7 +835,8 @@ export const DrainRequest = z.object({
831
835
  term: z.string().min(1).optional(),
832
836
  });
833
837
  /** What a drain request leaves the engine in: `draining` — this call put it into draining; `already_draining` — it already was
834
- * (the same action repeated), and the receipt reports the first call's facts. */
838
+ * (for the identity form: the same action repeated), and the receipt reports the first call's facts. For the credential-named form see
839
+ * {@link CredentialDrainRequest}. */
835
840
  export const DRAIN_RECEIPT_STATES = deepFreeze(["draining", "already_draining"]);
836
841
  export const DrainReceiptState = z.enum(DRAIN_RECEIPT_STATES);
837
842
  /** The drain endpoint's answer: the engine's draining fact ({@link EngineDraining} — the same object {@link EngineSignal}
@@ -845,6 +850,136 @@ export function readDrainRequest(body) {
845
850
  export function readDrainReceipt(body) {
846
851
  return readSignalBody(body, WHOLE_BODY, DrainReceipt);
847
852
  }
853
+ /**
854
+ * The two words of {@link CredentialDrainRequest}`.turns` — a CLOSED set, owned here (a reader that switches on it exhaustively is told
855
+ * by the compiler when a word is added): how the turns that are running at the moment the engine accepts the drain give way. This package
856
+ * fixes the words; what each word does is engine-side behaviour, described here and not verified by this package.
857
+ * - `yield` — the way a drain always stops them: a running turn parks at its next clean turn boundary, and what has not finished when the
858
+ * deadline passes is cut by the hard stop. An absent `turns` means `yield`.
859
+ * - `halt` — everything `yield` does, and in the same step the engine asks every running turn that has a turn surface to stop now — the
860
+ * cut a user's Esc makes in that window. The deadline does not move; a turn that does not take the cut in time is handled as under
861
+ * `yield`. The engine honours it only for a caller that holds the operator authority to halt any run; otherwise it refuses and changes nothing.
862
+ */
863
+ export const DRAIN_TURNS = deepFreeze(["yield", "halt"]);
864
+ export const DrainTurns = z.enum(DRAIN_TURNS);
865
+ /** The member schemas of {@link CredentialDrainRequest} — the one place its keys are written: the schema is built from this very object, and the
866
+ * set of keys only that form has is read off it (a plain object, so reading its keys materializes nothing lazy inside the validator). */
867
+ const CREDENTIAL_DRAIN_SHAPE = {
868
+ instanceId: DrainRequest.shape.instanceId,
869
+ turns: DrainTurns.optional(),
870
+ attachedAtMost: SafeCount.optional(),
871
+ };
872
+ /**
873
+ * The drain endpoint's request in its CREDENTIAL-NAMED form: the sender (the side that sends the request) names the engine by the credential it
874
+ * presents (the one a launcher minted for this process), not by the identity quadruple of {@link DrainRequest} — so the body carries no action
875
+ * id, no worker, no deadline, only what is to be said about THIS call. A STRICT object: one key more, one word off, a negative / fractional /
876
+ * string / oversize count ⇒ the body is not this form (and a half-built {@link DrainRequest} is never read as a stop request). Every key is
877
+ * optional and the empty body `{}` is the whole default form. A reader never mints a key the sender did not write, and this package exports
878
+ * no default constant: the RECEIVING side applies the meaning of an absent key — an absent `turns` is `yield`, an absent `attachedAtMost`
879
+ * sets no condition.
880
+ * - `instanceId` — a non-empty string: the engine's own per-process identity ({@link InstanceHealth}`.instanceId`). When present the engine
881
+ * compares it with its own and refuses on a mismatch. The very schema of {@link DrainRequest}`.instanceId`, not a copy.
882
+ * - `turns` — how the turns running at acceptance give way ({@link DRAIN_TURNS}).
883
+ * - `attachedAtMost` — a non-negative safe integer: accept the drain only if at most this many streams are attached to the engine at the
884
+ * moment it judges the request; more ⇒ a refusal carrying {@link DrainConditionUnmet}, nothing changed. It bounds what was attached at that moment;
885
+ * it is not a promise about the streams and requests that arrive afterwards.
886
+ * The two forms of the endpoint's request share no body that is plain data (what JSON parsing yields): {@link DrainRequest} requires
887
+ * `actionId`, `worker` and `deadlineAt`, which this form refuses as unknown keys. `turns` and `attachedAtMost` belong to this form only —
888
+ * {@link DrainRequest} does not carry them; its single-form reader strips them like any unknown key, and the reader of the endpoint's body
889
+ * ({@link readDrainRequestReading}) reads an identity body that carries either of them as neither form. The answer is the same
890
+ * {@link DrainReceipt} shape for both forms. What the engine puts in it for this form — engine-side behaviour, which this package does not
891
+ * verify: `deadlineAt` is the engine's own drain window (the body names no deadline); a `halt` sent while the engine is already draining is
892
+ * answered `already_draining` with the first call's facts and cuts the turns running at that moment; while the hard stop is under way the
893
+ * receipt's `actionId` is `hard-stop` and neither `turns` nor `attachedAtMost` is read; the naming is judged before the condition (a naming
894
+ * mismatch is refused without the attached count), and the condition is judged even when the engine is already draining. How the engine
895
+ * mints the receipt's `actionId` for this form, and what it answers for other requests of this form sent while it is draining, is the
896
+ * engine's to define; this package does not.
897
+ */
898
+ export const CredentialDrainRequest = z.object(CREDENTIAL_DRAIN_SHAPE).strict();
899
+ /** The keys only the credential-named form has: its keys minus the ones {@link DrainRequest} also declares (`instanceId` is shared).
900
+ * Derived from the two shapes, never spelled again — a key added to the credential-named form joins this set by construction. */
901
+ const CREDENTIAL_ONLY_DRAIN_KEYS = deepFreeze(Object.keys(CREDENTIAL_DRAIN_SHAPE).filter((key) => !Object.hasOwn(DrainRequest.shape, key)));
902
+ /**
903
+ * Engine side: the request body of the drain endpoint in its credential-named form. Shape mismatch / non-object / throwing accessor ⇒
904
+ * `undefined`, never throws. A body of the identity form ({@link DrainRequest}) reads `undefined` here and a body of this form reads
905
+ * `undefined` for {@link readDrainRequest}: no plain-data body is read by both (an object that shows two different key sets to the two
906
+ * readers — a Proxy whose `ownKeys` trap lies — is outside that promise; a body parsed from JSON never is one). A request with no bytes is
907
+ * the engine's to turn into `{}` before it calls this reader (`undefined` and `null` are not objects here).
908
+ * The result is an ordinary object, like every reader's in this file: the reader looks only at the body's own keys, but an optional key it
909
+ * did not read is absent only as an own key — test for it with `Object.hasOwn`, do not read it through the prototype chain.
910
+ */
911
+ export function readCredentialDrainRequest(body) {
912
+ return readSignalBody(body, WHOLE_BODY, CredentialDrainRequest);
913
+ }
914
+ /** The form words of {@link DrainRequestReading}, in the order the reader tries them. `satisfies` bites a word the union does not have;
915
+ * the converse (a union arm missing from this list) is pinned by a test that compares the two. */
916
+ export const DRAIN_REQUEST_FORMS = deepFreeze(["identity", "credential"]);
917
+ /**
918
+ * Does `body` carry, as its own key, a key only the credential-named form has ({@link CREDENTIAL_ONLY_DRAIN_KEYS})? Asked by the descriptor law
919
+ * every reader in this file uses: an own key — plain data, or one that cannot be read as plain data (not enumerable, an accessor — never called)
920
+ * — or a descriptor that cannot be inspected counts as carrying it; a key the body only inherits, or does not have, does not. Never throws.
921
+ */
922
+ function carriesCredentialOnlyDrainKey(body) {
923
+ return CREDENTIAL_ONLY_DRAIN_KEYS.some((key) => {
924
+ const read = readDeclaredKey(body, key);
925
+ switch (read.presence) {
926
+ case "inherited":
927
+ case "absent":
928
+ return false;
929
+ case "own":
930
+ case "hidden":
931
+ case "unreadable":
932
+ return true;
933
+ default: {
934
+ const unhandled = read;
935
+ throw new Error(`carriesCredentialOnlyDrainKey: unhandled presence ${String(unhandled.presence)}`);
936
+ }
937
+ }
938
+ });
939
+ }
940
+ /**
941
+ * Engine side: THE reader of the drain endpoint's request body — which form it is and the request in that form; neither ⇒ `undefined`.
942
+ * A body is one form or the other: a body that mixes the keys of the two forms is NEITHER — a body the identity reader reads that also
943
+ * carries, as its own key, a key only the credential-named form has (`turns`, `attachedAtMost`: that form's keys minus the shared
944
+ * `instanceId`) reads `undefined` here, whatever that key's value, so a condition or a turn policy sent on the identity form is refused
945
+ * instead of being stripped. It composes the two single-form readers and that one key check (no second schema): {@link readDrainRequest}
946
+ * first, then {@link readCredentialDrainRequest}; the `request` handed back is that reader's answer in this call. When this reader reads a
947
+ * body, its `request` equals the answer of that form's single-form reader; the converse does not hold: a mixed body that is plain data reads
948
+ * `undefined` here while {@link readDrainRequest} reads it (stripping the keys). For plain data the order changes nothing (no such body is
949
+ * read by both single-form readers). An object that shows the two single-form readers different key sets reads as the identity form only
950
+ * when the key check, which asks for each credential-only key's own descriptor, finds none of them; when it finds one the object is a mixed
951
+ * body and reads `undefined`. A proxy that changes itself while it is read may answer differently than when the credential reader is asked
952
+ * alone (the identity probe came first). Never throws. The single-form readers stay for a side that
953
+ * already knows which form it sent; {@link readDrainRequest} still strips the credential-named form's keys as it strips any unknown key.
954
+ */
955
+ export function readDrainRequestReading(body) {
956
+ const identity = readDrainRequest(body);
957
+ if (identity !== undefined)
958
+ return carriesCredentialOnlyDrainKey(body) ? undefined : { form: "identity", request: identity };
959
+ const credential = readCredentialDrainRequest(body);
960
+ return credential === undefined ? undefined : { form: "credential", request: credential };
961
+ }
962
+ /** The machine code of the drain endpoint's refusal "the condition the request set is not met": the HTTP 409 whose body carries {@link DrainConditionUnmet}.
963
+ * One spelling — the engine mints the refusal with it, a caller branches on it. */
964
+ export const DRAIN_CONDITION_UNMET_CODE = "conflict.drain_condition_unmet";
965
+ /**
966
+ * The facts a {@link DRAIN_CONDITION_UNMET_CODE} refusal carries at the root of its body, beside the refusal's own `error` sentence and `errorCode`:
967
+ * - `attached` — how many streams were attached when the engine judged the request;
968
+ * - `attachedAtMost` — the bound the request set, echoed.
969
+ * A refused call changed nothing, and the engine answers this only when `attached` is above `attachedAtMost` (engine-side behaviour, not
970
+ * verified by this package); the reader judges the form of the
971
+ * two numbers (non-negative safe integers), not their relation. The refusal's own keys are stripped, so the reader takes the whole body.
972
+ */
973
+ export const DrainConditionUnmet = z.object({ attached: SafeCount, attachedAtMost: SafeCount });
974
+ /**
975
+ * Caller side: the facts of a {@link DRAIN_CONDITION_UNMET_CODE} refusal. Compare the refusal's `errorCode` with {@link DRAIN_CONDITION_UNMET_CODE}
976
+ * first and read the two numbers with this only when they are equal: this reader does not judge the code, so any body that carries the two
977
+ * facts reads, whatever refusal it is. A body that does not carry both facts (another refusal of the same status, a receipt, a request) reads `undefined`.
978
+ * Shape mismatch / non-object / throwing accessor ⇒ `undefined`, never throws.
979
+ */
980
+ export function readDrainConditionUnmet(body) {
981
+ return readSignalBody(body, WHOLE_BODY, DrainConditionUnmet);
982
+ }
848
983
  // ── Domain 3: dispatch policy (traffic + failover + LB — three domains, one gateway) ──────────────────────
849
984
  export const DISPATCH_STRATEGIES = deepFreeze(["round-robin", "least-inflight", "consistent-hash"]);
850
985
  /** Per-worker dispatch policy (web-admin-configured; the gateway is OPTIONAL — D3: TOC/self-maintained TOB go
@@ -0,0 +1,67 @@
1
+ /**
2
+ * 读腿读不进一份文档(或一条条目)时的**诊断句措辞** —— 包内私有(不进主桶),纯字符串函数,只 import 两只零 import 的叶(形状座位、一行回显的剥除集),所以谁都能调、不成环;句子**不含换行与双向控制符**(回显进来的键名 / 值 / 别人的句子都过 `stripControlAndBidi`)。
3
+ *
4
+ * 在这里铸的(照实):读腿两条告警的一句话({@link droppedEntrySentence} / {@link defaultedDomainSentence})、issue 的一句话({@link issueSentence})、
5
+ * 条目身份与原因的小段字,以及「读腿会怎么处置一份读不进的域文档」的后果句({@link readConsequenceSentence} —— 命令行 `migrate` 对在场文档的拒句取它)。
6
+ * 不在这里铸的:retired 域的墓碑句与它的出路(`./retired-form`,读写两面同一句)、命令行 `migrate` 拒句里 retired 域 / `remote-exec` 的后果、
7
+ * 「在 `<文件>` 里手改」那一截与整份 `why`(`./config-dir-migration`)。句子**一句一行**(不含换行):它们被日志、终端、网页端、管理台逐字渲染,
8
+ * 多行的 JSON 数组文本读起来不是一句人话。本模块剥了一行回显的剥除集之后的串不是出门形:剥掉一个隔开的字符可以拼出密钥形,铸点(`./config-fns`、
9
+ * `./config-dir-migration`)把最终的那一串再过一次本包唯一的脱敏器。
10
+ *
11
+ * 后果句读两张表的答案(`DOMAIN_READ_FALLBACK` 与 `DOMAIN_ENTRY_SALVAGE`,表在 `./config-fns`,本模块不读表、只收两张表的答案;两张表互不读,句子按两半各自穷举):
12
+ * · 整域读不进时:整域拒(`throw`,读腿抛)/ 整域退缺省(`default`);
13
+ * · 在那之前:逐条丢弃域先丢坏的那一条、其余照读(`salvage`)/ 不逐条丢(`none`);逐条丢弃域的「整域读不进」= 抢救之后剩下的仍读不进
14
+ * (不只是没有条目可丢:幸存的条目彼此相撞也是)。
15
+ */
16
+ /** 一个域在读腿上的两张表的答案(`DOMAIN_READ_FALLBACK[域]` / `DOMAIN_ENTRY_SALVAGE[域]`)。 */
17
+ export interface ReadStanceWords {
18
+ readonly fallback: "throw" | "default";
19
+ readonly salvage: "salvage" | "none";
20
+ }
21
+ /** 一条 zod issue 的形(只取本模块读的几个键;不 import zod)。 */
22
+ export interface IssueLike {
23
+ readonly message: string;
24
+ readonly code?: string;
25
+ readonly errors?: unknown;
26
+ }
27
+ /**
28
+ * 一条 zod issue 的**一句话**(不含换行):联合(`invalid_union`)自己只说 `Invalid input`,真正的拒句在各选项的 issue 里 —— 取各选项第一条的句子(去重,至多三条,用 ` / ` 连);
29
+ * 别的 issue 就是它自己的 `message`(换行折成空格)。出门前这些句子已经过本包唯一的脱敏器(`sanitizeZodError` 递归进联合的 `errors`),这里只读不改。
30
+ */
31
+ export declare function issueSentence(issue: IssueLike, depth?: number): string;
32
+ /** 一条 issue 的坐标(出门形的串,空串 = 在文档 / 条目的根上)与它的一句话。 */
33
+ export interface PathedSentence {
34
+ readonly path: string;
35
+ readonly sentence: string;
36
+ }
37
+ /** 被丢 / 触发条目的身份,一小段字:只说可披露的名与 id(扣名只说「有名但不给」);没有可说的 ⇒ `undefined`。 */
38
+ export declare function identityText(identity: {
39
+ readonly name?: string;
40
+ readonly id?: string;
41
+ readonly nameWithheld?: true;
42
+ readonly idWithheld?: true;
43
+ } | undefined): string | undefined;
44
+ /** 原因,一段字:最多三条 issue(`<坐标>: <句子>`,坐标是根时只有句子),多出来的写个数。 */
45
+ export declare function causeText(issues: readonly PathedSentence[]): string;
46
+ /**
47
+ * `entry-dropped` 的一句话:哪一条(`entry <坐标>`,有身份再接括号)· 为什么 · 后果(其余条目照常)· 出路(在这份文档里手改,改回来就读得到)。
48
+ * `entry` 是 `entry <坐标>`、`identity` 是 {@link identityText} 的答案。
49
+ */
50
+ export declare function droppedEntrySentence(a: {
51
+ readonly domain: string;
52
+ readonly entry: string;
53
+ readonly identity: string | undefined;
54
+ readonly cause: string;
55
+ }): string;
56
+ /**
57
+ * `domain-defaulted` 的一句话:后果(整域按缺省读)· 为什么(触发的坐标与原因)· 触发的条目是谁(有才写)· 出路(在这份文档里手改)。
58
+ * `culprit` = 触发的条目,一小段字(`entry <坐标>` 加身份),域级的毛病没有。
59
+ */
60
+ export declare function defaultedDomainSentence(a: {
61
+ readonly domain: string;
62
+ readonly cause: string;
63
+ readonly culprit: string | undefined;
64
+ }): string;
65
+ /** 读腿对「这个域的文档读不进」的处置,一句话(不含换行;`domain` 是闭集里的域名)。两张表各答一半、各自穷举:`fallback` 说整域读不进时怎么办,
66
+ * `salvage` 说先不先丢那一条 —— 两半拼成一句,四种组合各有自己的话(「整域拒 + 逐条丢」的域两半都说)。 */
67
+ export declare function readConsequenceSentence(domain: string, stance: ReadStanceWords): string;
@@ -0,0 +1,86 @@
1
+ import { stripControlAndBidi } from "./control-and-bidi.js"; // 一行回显的剥除集(唯一一份):句子里回显的串(zod 句子里的键名 / 值)不许带换行与双向控制符
2
+ import { isJsonArray } from "./plain-json-object.js"; // 形状只问座位:这里的「是不是数组」不裸写 `Array.isArray`(全包反向门)
3
+ /** 一行:空白(含换行、制表)的每一段折成一个空格,再剥掉一行回显的剥除集({@link stripControlAndBidi}:C0、DEL、双向控制符),两端去空白。句子里回显的任何一串(键名、值、别人的句子)都经它,一个换行伪造不出第二行。 */
4
+ const oneLine = (text) => stripControlAndBidi(text.replace(/\s+/g, " ")).trim();
5
+ /**
6
+ * 一条 zod issue 的**一句话**(不含换行):联合(`invalid_union`)自己只说 `Invalid input`,真正的拒句在各选项的 issue 里 —— 取各选项第一条的句子(去重,至多三条,用 ` / ` 连);
7
+ * 别的 issue 就是它自己的 `message`(换行折成空格)。出门前这些句子已经过本包唯一的脱敏器(`sanitizeZodError` 递归进联合的 `errors`),这里只读不改。
8
+ */
9
+ export function issueSentence(issue, depth = 0) {
10
+ if (issue.code === "invalid_union" && isJsonArray(issue.errors) && depth < 4) {
11
+ const branches = [];
12
+ for (const branch of issue.errors) {
13
+ const first = isJsonArray(branch) ? branch[0] : undefined;
14
+ if (first !== undefined && typeof first.message === "string")
15
+ branches.push(issueSentence(first, depth + 1));
16
+ }
17
+ const distinct = [...new Set(branches)].slice(0, 3);
18
+ if (distinct.length > 0)
19
+ return distinct.join(" / ");
20
+ }
21
+ return oneLine(issue.message);
22
+ }
23
+ /** 被丢 / 触发条目的身份,一小段字:只说可披露的名与 id(扣名只说「有名但不给」);没有可说的 ⇒ `undefined`。 */
24
+ export function identityText(identity) {
25
+ if (identity === undefined)
26
+ return undefined;
27
+ const parts = [];
28
+ if (identity.name !== undefined)
29
+ parts.push(`name ${JSON.stringify(identity.name)}`);
30
+ else if (identity.nameWithheld === true)
31
+ parts.push("name withheld");
32
+ if (identity.id !== undefined)
33
+ parts.push(`id ${JSON.stringify(identity.id)}`);
34
+ else if (identity.idWithheld === true)
35
+ parts.push("id withheld");
36
+ return parts.length === 0 ? undefined : parts.join(", ");
37
+ }
38
+ /** 原因,一段字:最多三条 issue(`<坐标>: <句子>`,坐标是根时只有句子),多出来的写个数。 */
39
+ export function causeText(issues) {
40
+ const shown = issues.slice(0, 3).map((i) => (i.path === "" ? i.sentence : `${i.path}: ${i.sentence}`));
41
+ const more = issues.length - shown.length;
42
+ return more > 0 ? `${shown.join("; ")} (+${more} more)` : shown.join("; ");
43
+ }
44
+ /**
45
+ * `entry-dropped` 的一句话:哪一条(`entry <坐标>`,有身份再接括号)· 为什么 · 后果(其余条目照常)· 出路(在这份文档里手改,改回来就读得到)。
46
+ * `entry` 是 `entry <坐标>`、`identity` 是 {@link identityText} 的答案。
47
+ */
48
+ export function droppedEntrySentence(a) {
49
+ const who = a.identity === undefined ? a.entry : `${a.entry} (${a.identity})`;
50
+ return oneLine(`${who} was dropped from the "${a.domain}" domain: ${a.cause === "" ? "it does not read" : a.cause}; the other entries are read as written — fix it in the "${a.domain}" document by hand to bring it back`);
51
+ }
52
+ /**
53
+ * `domain-defaulted` 的一句话:后果(整域按缺省读)· 为什么(触发的坐标与原因)· 触发的条目是谁(有才写)· 出路(在这份文档里手改)。
54
+ * `culprit` = 触发的条目,一小段字(`entry <坐标>` 加身份),域级的毛病没有。
55
+ */
56
+ export function defaultedDomainSentence(a) {
57
+ const tail = a.culprit === undefined ? "" : ` (${a.culprit})`;
58
+ return oneLine(`the whole "${a.domain}" domain is read as its default: ${a.cause === "" ? "it does not read" : a.cause}${tail}; fix it in the "${a.domain}" document by hand`);
59
+ }
60
+ /** 读腿对「这个域的文档读不进」的处置,一句话(不含换行;`domain` 是闭集里的域名)。两张表各答一半、各自穷举:`fallback` 说整域读不进时怎么办,
61
+ * `salvage` 说先不先丢那一条 —— 两半拼成一句,四种组合各有自己的话(「整域拒 + 逐条丢」的域两半都说)。 */
62
+ export function readConsequenceSentence(domain, stance) {
63
+ const whole = (() => {
64
+ switch (stance.fallback) {
65
+ case "throw":
66
+ return `refuses the whole "${domain}" domain`;
67
+ case "default":
68
+ return `reads the whole "${domain}" domain as its default`;
69
+ default: {
70
+ const unhandled = stance.fallback;
71
+ throw new Error(`readConsequenceSentence: unhandled fallback ${String(unhandled)}`);
72
+ }
73
+ }
74
+ })();
75
+ switch (stance.salvage) {
76
+ case "salvage":
77
+ // 整域那一半的条件是「抢救之后剩下的仍读不进」:没有条目可丢(域级的毛病)、一条都救不活(零幸存者),或丢掉坏的之后幸存的条目彼此相撞(重名、同一条 remote)—— 三种同一句
78
+ return `the reader drops the offending entry, or ${whole} when what is left after the drop still does not read`;
79
+ case "none":
80
+ return `the reader ${whole}`;
81
+ default: {
82
+ const unhandled = stance.salvage;
83
+ throw new Error(`readConsequenceSentence: unhandled salvage ${String(unhandled)}`);
84
+ }
85
+ }
86
+ }
@@ -32,6 +32,8 @@ export interface RetiredForm {
32
32
  /** 改写存量的一次性迁移 id(`./one-time-migrations` 的闭集;到期门核它在登记表里)。**只在那条迁移还在时写**:迁移到期删了,删码那一车删掉这一格。 */
33
33
  readonly migration?: OneTimeMigrationId;
34
34
  }
35
+ /** 一个retired 域的**出路**(拒句尾,一句一行):把还要用的值手抄到今天的位置上,再删掉旧文档(本地根上它就是 `config.d/<域>.json`)。retired 域的拒句 = 墓碑句 + 这一句,读写两面同一句。 */
36
+ export declare function retiredDomainWayOut(domain: string): string;
35
37
  export declare function retiredFormSentence(form: string, t: RetiredForm): string;
36
38
  /** 墓碑表的一行:`key` 是墓碑字段在它所在对象里的点路径(例:`runtime.sessionBackend`),`sentence` 是它的拒句整句(= 那条 zod issue 的 message)。 */
37
39
  export interface RetiredKeyRow {
@@ -27,6 +27,10 @@ export function migrateCommandFor(configDir) {
27
27
  export function migrationSignpost(migration, before) {
28
28
  return `data stored before ${before}: run the one-time migration ${migration} (@sema-agent/settings-schema/one-time-migrations, or ${MIGRATE_COMMAND_TEMPLATE})`;
29
29
  }
30
+ /** 一个retired 域的**出路**(拒句尾,一句一行):把还要用的值手抄到今天的位置上,再删掉旧文档(本地根上它就是 `config.d/<域>.json`)。retired 域的拒句 = 墓碑句 + 这一句,读写两面同一句。 */
31
+ export function retiredDomainWayOut(domain) {
32
+ return `copy the values you still need to those keys by hand, then delete the "${domain}" document (on a local root: config.d/${domain}.json)`;
33
+ }
30
34
  export function retiredFormSentence(form, t) {
31
35
  const head = `${form} was retired in ${t.retiredIn} — now ${t.now}`;
32
36
  return t.migration === undefined ? head : `${head}; ${migrationSignpost(t.migration, t.retiredIn)}`;
package/dist/types.d.ts CHANGED
@@ -616,7 +616,7 @@ export declare const RETIRED_DOMAINS: {
616
616
  export type RetiredDomainName = keyof typeof RETIRED_DOMAINS;
617
617
  /** 是不是一个retired 域名(墓碑表成员)。 */
618
618
  export declare function isRetiredDomainName(x: unknown): x is RetiredDomainName;
619
- /** 一个retired 域的拒句(读写两面同一句)。 */
619
+ /** 一个retired 域的拒句(读写两面同一句):墓碑句(哪一版 retired、事实今天住哪)加出路({@link retiredDomainWayOut}:把还要用的值手抄到今天的位置上、删掉旧文档)。整句一行。 */
620
620
  export declare function retiredDomainSentence(domain: RetiredDomainName): string;
621
621
  /** 基建计价(micro-USD/单位)。三键各自 optional:缺席 = 该项不改。**嵌套层同样 open-world**
622
622
  * (`.passthrough()`,与 {@link LimitsConfig} 顶层同判据):默认 strip 会把「消费方新增了一个计价项、
package/dist/types.js CHANGED
@@ -31,7 +31,7 @@ import { retiredEnvRefusal } from "./retired-envs.js"; // the worker env write g
31
31
  import { Sha256Digest } from "./sha256.js"; // the one `sha256:<hex>` digest form
32
32
  import { EXECUTION_LANES, EXECUTION_LANE_WORDS, LANE_SET_RULE, MEMORY_ENGINE_BACKENDS, SESSION_BACKENDS, STORE_BACKENDS, isBlankCoordinate, laneSetFlaws, retiredLaneWordRefusal } from "./execution-lanes.js"; // 7.0.0 M-R2: the lane / store vocabulary (one exported table)
33
33
  import { LANE_ENV_OWNER, LATE_LANE_ENV_KEYS, laneEnvSeat, laneRowOf } from "./execution-lane-index.js"; // package-private indexes derived from that table (none of them is in the barrel)
34
- import { migrationSignpost, retiredFormSentence, retiredKey } from "./retired-form.js"; // 11.0.0: the ONE retired-form sentence + key tombstone (package-private)
34
+ import { migrationSignpost, retiredDomainWayOut, retiredFormSentence, retiredKey } from "./retired-form.js"; // 11.0.0: the ONE retired-form sentence + key tombstone (package-private)
35
35
  import { retiredRoleWordsRefusal } from "./retired-role-words.js"; // 12.0.0: the retired role-word tombstone (package-private)
36
36
  import { buildQuotedIssue, fixed } from "./quoted-issue.js"; // THE minting point of custom issues (package-private)
37
37
  import { RECORD_MEMBER_NAME, partialRecordOf, recordOf } from "./record-seat.js"; // the one way to mint a record seat (its guard refuses a reserved own member name — the table the record reader and the center-refs resolver read) · the judge every name that keys a record seat starts from (worker name, catalog entry name, HTTP header name: a reserved name is refused where the name is minted)
@@ -959,9 +959,9 @@ export const RETIRED_DOMAINS = deepFreeze({
959
959
  export function isRetiredDomainName(x) {
960
960
  return typeof x === "string" && Object.prototype.hasOwnProperty.call(RETIRED_DOMAINS, x);
961
961
  }
962
- /** 一个retired 域的拒句(读写两面同一句)。 */
962
+ /** 一个retired 域的拒句(读写两面同一句):墓碑句(哪一版 retired、事实今天住哪)加出路({@link retiredDomainWayOut}:把还要用的值手抄到今天的位置上、删掉旧文档)。整句一行。 */
963
963
  export function retiredDomainSentence(domain) {
964
- return retiredFormSentence(`the "${domain}" config domain`, RETIRED_DOMAINS[domain]);
964
+ return [retiredFormSentence(`the "${domain}" config domain`, RETIRED_DOMAINS[domain]), retiredDomainWayOut(domain)].join("; ");
965
965
  }
966
966
  // ── Domain: limits (cost/限流族的热更新发布位 — 0.19.0, 消费方 #322 批1) ──────
967
967
  // 为什么是**新顶层域**而不是往 `runtime` 里加键(消费方亲验,不是推测):`RuntimeConfig` 是 zod 默认的