@haywoodmarx/agent-pager 0.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/LICENSE +21 -0
- package/README.md +63 -0
- package/dist/src/broker/address.d.ts +49 -0
- package/dist/src/broker/address.js +110 -0
- package/dist/src/broker/broker.d.ts +665 -0
- package/dist/src/broker/broker.js +2270 -0
- package/dist/src/broker/database.d.ts +81 -0
- package/dist/src/broker/database.js +69 -0
- package/dist/src/broker/operator-projection.d.ts +291 -0
- package/dist/src/broker/operator-projection.js +722 -0
- package/dist/src/broker/protocol.d.ts +237 -0
- package/dist/src/broker/protocol.js +311 -0
- package/dist/src/broker/schema.d.ts +94 -0
- package/dist/src/broker/schema.js +454 -0
- package/dist/src/broker/snapshot.d.ts +171 -0
- package/dist/src/broker/snapshot.js +78 -0
- package/dist/src/configuration-defaults.d.ts +64 -0
- package/dist/src/configuration-defaults.js +48 -0
- package/dist/src/configuration.d.ts +76 -0
- package/dist/src/configuration.js +156 -0
- package/dist/src/implementations/claude/environment.d.ts +8 -0
- package/dist/src/implementations/claude/environment.js +9 -0
- package/dist/src/implementations/claude/gateway-cli.d.ts +2 -0
- package/dist/src/implementations/claude/gateway-cli.js +136 -0
- package/dist/src/implementations/claude/gateway-identity.d.ts +134 -0
- package/dist/src/implementations/claude/gateway-identity.js +103 -0
- package/dist/src/implementations/claude/gateway.d.ts +148 -0
- package/dist/src/implementations/claude/gateway.js +236 -0
- package/dist/src/implementations/claude/instructions.d.ts +33 -0
- package/dist/src/implementations/claude/instructions.js +64 -0
- package/dist/src/implementations/claude/manifest.d.ts +33 -0
- package/dist/src/implementations/claude/manifest.js +108 -0
- package/dist/src/implementations/claude/plugin-directory.d.ts +80 -0
- package/dist/src/implementations/claude/plugin-directory.js +137 -0
- package/dist/src/implementations/claude/session-continuation.d.ts +25 -0
- package/dist/src/implementations/claude/session-continuation.js +125 -0
- package/dist/src/implementations/claude/session-identity.d.ts +25 -0
- package/dist/src/implementations/claude/session-identity.js +31 -0
- package/dist/src/implementations/claude/session-start-cli.d.ts +2 -0
- package/dist/src/implementations/claude/session-start-cli.js +16 -0
- package/dist/src/implementations/claude/socket-delivery.d.ts +52 -0
- package/dist/src/implementations/claude/socket-delivery.js +159 -0
- package/dist/src/implementations/model.d.ts +162 -0
- package/dist/src/implementations/model.js +1 -0
- package/dist/src/implementations/opencode/adapter.d.ts +71 -0
- package/dist/src/implementations/opencode/adapter.js +94 -0
- package/dist/src/implementations/opencode/environment.d.ts +8 -0
- package/dist/src/implementations/opencode/environment.js +9 -0
- package/dist/src/implementations/opencode/manifest.d.ts +30 -0
- package/dist/src/implementations/opencode/manifest.js +93 -0
- package/dist/src/implementations/opencode/plugin-api.d.ts +120 -0
- package/dist/src/implementations/opencode/plugin-api.js +1 -0
- package/dist/src/implementations/opencode/plugin.d.ts +38 -0
- package/dist/src/implementations/opencode/plugin.js +303 -0
- package/dist/src/implementations/opencode/self-close-tool.d.ts +9 -0
- package/dist/src/implementations/opencode/self-close-tool.js +31 -0
- package/dist/src/implementations/orca/terminal.d.ts +48 -0
- package/dist/src/implementations/orca/terminal.js +154 -0
- package/dist/src/implementations/pi/broker-client.d.ts +56 -0
- package/dist/src/implementations/pi/broker-client.js +156 -0
- package/dist/src/implementations/pi/environment.d.ts +8 -0
- package/dist/src/implementations/pi/environment.js +9 -0
- package/dist/src/implementations/pi/extension.d.ts +57 -0
- package/dist/src/implementations/pi/extension.js +253 -0
- package/dist/src/implementations/pi/host-slots.d.ts +18 -0
- package/dist/src/implementations/pi/host-slots.js +27 -0
- package/dist/src/implementations/pi/manifest.d.ts +11 -0
- package/dist/src/implementations/pi/manifest.js +61 -0
- package/dist/src/implementations/pi/self-close-tool.d.ts +7 -0
- package/dist/src/implementations/pi/self-close-tool.js +27 -0
- package/dist/src/implementations/registry.d.ts +47 -0
- package/dist/src/implementations/registry.js +157 -0
- package/dist/src/implementations/session-key.d.ts +13 -0
- package/dist/src/implementations/session-key.js +19 -0
- package/dist/src/index.d.ts +27 -0
- package/dist/src/index.js +26 -0
- package/dist/src/launch/broker-lock.d.ts +257 -0
- package/dist/src/launch/broker-lock.js +644 -0
- package/dist/src/launch/cli.d.ts +37 -0
- package/dist/src/launch/cli.js +317 -0
- package/dist/src/launch/environment.d.ts +45 -0
- package/dist/src/launch/environment.js +48 -0
- package/dist/src/launch/launch.d.ts +235 -0
- package/dist/src/launch/launch.js +223 -0
- package/dist/src/launch/on-demand.d.ts +202 -0
- package/dist/src/launch/on-demand.js +435 -0
- package/dist/src/launch/runtime-composition.d.ts +88 -0
- package/dist/src/launch/runtime-composition.js +253 -0
- package/dist/src/launch/runtime.d.ts +79 -0
- package/dist/src/launch/runtime.js +196 -0
- package/dist/src/launch/service-system.d.ts +11 -0
- package/dist/src/launch/service-system.js +39 -0
- package/dist/src/launch/service.d.ts +173 -0
- package/dist/src/launch/service.js +492 -0
- package/dist/src/launch/skill.d.ts +57 -0
- package/dist/src/launch/skill.js +81 -0
- package/dist/src/launch/terminal.d.ts +26 -0
- package/dist/src/launch/terminal.js +43 -0
- package/dist/src/launch/workspace-branch.d.ts +10 -0
- package/dist/src/launch/workspace-branch.js +29 -0
- package/dist/src/messaging/delivery-client.d.ts +144 -0
- package/dist/src/messaging/delivery-client.js +261 -0
- package/dist/src/messaging/delivery.d.ts +75 -0
- package/dist/src/messaging/delivery.js +22 -0
- package/dist/src/messaging/inbox-socket.d.ts +98 -0
- package/dist/src/messaging/inbox-socket.js +278 -0
- package/dist/src/messaging/mcp.d.ts +53 -0
- package/dist/src/messaging/mcp.js +501 -0
- package/dist/src/messaging/notifications.d.ts +231 -0
- package/dist/src/messaging/notifications.js +489 -0
- package/dist/src/messaging/push-delivery.d.ts +77 -0
- package/dist/src/messaging/push-delivery.js +187 -0
- package/dist/src/messaging/tools.d.ts +11 -0
- package/dist/src/messaging/tools.js +102 -0
- package/dist/src/messaging/wake.d.ts +23 -0
- package/dist/src/messaging/wake.js +39 -0
- package/dist/src/operator/agent-projection.d.ts +102 -0
- package/dist/src/operator/agent-projection.js +249 -0
- package/dist/src/operator/commands.d.ts +50 -0
- package/dist/src/operator/commands.js +199 -0
- package/dist/src/operator/diagnostics.d.ts +21 -0
- package/dist/src/operator/diagnostics.js +22 -0
- package/dist/src/operator/protocol.d.ts +511 -0
- package/dist/src/operator/protocol.js +49 -0
- package/dist/src/operator/repository-system.d.ts +14 -0
- package/dist/src/operator/repository-system.js +150 -0
- package/dist/src/operator/repository.d.ts +79 -0
- package/dist/src/operator/repository.js +72 -0
- package/dist/src/operator/traffic-projection.d.ts +19 -0
- package/dist/src/operator/traffic-projection.js +229 -0
- package/dist/src/operator/transport.d.ts +87 -0
- package/dist/src/operator/transport.js +549 -0
- package/dist/src/operator/update-store.d.ts +53 -0
- package/dist/src/operator/update-store.js +162 -0
- package/dist/src/operator/updates.d.ts +94 -0
- package/dist/src/operator/updates.js +280 -0
- package/dist/src/operator/validation.d.ts +114 -0
- package/dist/src/operator/validation.js +916 -0
- package/dist/src/shared/guards.d.ts +59 -0
- package/dist/src/shared/guards.js +119 -0
- package/dist/src/shared/http.d.ts +30 -0
- package/dist/src/shared/http.js +50 -0
- package/dist/src/shared/row.d.ts +2 -0
- package/dist/src/shared/row.js +1 -0
- package/dist/src/shared/shell.d.ts +6 -0
- package/dist/src/shared/shell.js +8 -0
- package/dist/src/tui/actions.d.ts +166 -0
- package/dist/src/tui/actions.js +253 -0
- package/dist/src/tui/agent-tree.d.ts +125 -0
- package/dist/src/tui/agent-tree.js +663 -0
- package/dist/src/tui/app.d.ts +38 -0
- package/dist/src/tui/app.js +378 -0
- package/dist/src/tui/chrome.d.ts +86 -0
- package/dist/src/tui/chrome.js +85 -0
- package/dist/src/tui/client.d.ts +41 -0
- package/dist/src/tui/client.js +279 -0
- package/dist/src/tui/composition.d.ts +41 -0
- package/dist/src/tui/composition.js +146 -0
- package/dist/src/tui/message-views.d.ts +94 -0
- package/dist/src/tui/message-views.js +515 -0
- package/dist/src/tui/model.d.ts +414 -0
- package/dist/src/tui/model.js +758 -0
- package/dist/src/tui/presentation.d.ts +350 -0
- package/dist/src/tui/presentation.js +541 -0
- package/dist/src/tui/production.d.ts +79 -0
- package/dist/src/tui/production.js +253 -0
- package/dist/src/tui/run-terminal.d.ts +32 -0
- package/dist/src/tui/run-terminal.js +54 -0
- package/dist/src/tui/runtime.d.ts +113 -0
- package/dist/src/tui/runtime.js +189 -0
- package/dist/src/tui/theme.d.ts +49 -0
- package/dist/src/tui/theme.js +55 -0
- package/dist/src/tui/transport.d.ts +31 -0
- package/dist/src/tui/transport.js +255 -0
- package/dist/src/version.d.ts +11 -0
- package/dist/src/version.js +52 -0
- package/package.json +142 -0
- package/skills/pager/SKILL.md +112 -0
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Identifies the database schema this build opens; a differing marker recreates the database.
|
|
3
|
+
*
|
|
4
|
+
* Declared here rather than beside the schema it names, because the service lock compares it and is
|
|
5
|
+
* loaded by adapters running inside hosts that have no `bun:sqlite`.
|
|
6
|
+
*/
|
|
7
|
+
export declare const SCHEMA_MARKER = "agent-session-key+message-event-index+queryable-timestamps+no-body-absence-reason+message-type+session-resume-lineage+session-supersession-timestamp+message-type-required+single-delivery-state-home+checked-stored-columns+unorderable-position-index+orderable-position-predicate+no-occupancy-contract+single-session-encoding+no-reservation-bindings+reservation-id-column";
|
|
8
|
+
/**
|
|
9
|
+
* Identifies the only protocol version accepted by this process.
|
|
10
|
+
*
|
|
11
|
+
* Bump for a breaking change: one where a caller declaring this version would misinterpret data
|
|
12
|
+
* this process returns, or would need to construct a request this process now rejects.
|
|
13
|
+
*
|
|
14
|
+
* A narrowing of {@link MESSAGE_TYPE_LIMIT_CHARACTERS} is bumped under that criterion: a caller
|
|
15
|
+
* declaring the prior version that already sends a `type` between the old and new bound has a request
|
|
16
|
+
* that validated before and no longer does, for a value it is not free to shorten without changing
|
|
17
|
+
* what it means, so such a caller must see `unsupported_version` from {@link assertProtocolVersion}
|
|
18
|
+
* rather than a silent, confusing per-message rejection once it is already connected.
|
|
19
|
+
*/
|
|
20
|
+
export declare const PROTOCOL_VERSION = 4;
|
|
21
|
+
/** Names the request header a session presents its single-use attach reservation in. */
|
|
22
|
+
export declare const ATTACH_HEADER = "x-pager-attach";
|
|
23
|
+
/**
|
|
24
|
+
* Describes the build and runtime identity required for service adoption.
|
|
25
|
+
*
|
|
26
|
+
* Lives outside `launch/` because `messaging/mcp.ts` also names this type.
|
|
27
|
+
*/
|
|
28
|
+
export type BrokerServiceIdentity = {
|
|
29
|
+
/** Identifies the service ownership schema. */
|
|
30
|
+
serviceProtocolVersion: number;
|
|
31
|
+
/** Identifies the runtime kind that owns SQLite. */
|
|
32
|
+
runtime: "bun";
|
|
33
|
+
/** Identifies the runtime release that owns SQLite. */
|
|
34
|
+
runtimeVersion: string;
|
|
35
|
+
/** Identifies the package build serving requests. */
|
|
36
|
+
buildId: string;
|
|
37
|
+
/** Identifies the broker wire protocol served by the process. */
|
|
38
|
+
protocolVersion: number;
|
|
39
|
+
/**
|
|
40
|
+
* Identifies the database schema the process opens. A build whose marker differs recreates the
|
|
41
|
+
* database it adopts, so a mismatch must fail adoption rather than displace the running owner.
|
|
42
|
+
*/
|
|
43
|
+
schemaMarker: string;
|
|
44
|
+
};
|
|
45
|
+
/** Limits the serialized size of a message body accepted by the broker. */
|
|
46
|
+
export declare const MESSAGE_BODY_LIMIT_BYTES: number;
|
|
47
|
+
/** Bounds a registration session name, which is also the agent's routable alias. */
|
|
48
|
+
export declare const REGISTRATION_SESSION_NAME_MAX_LENGTH = 128;
|
|
49
|
+
/** Bounds a conversation key, which a caller supplies to rejoin an identity across restarts. */
|
|
50
|
+
export declare const SESSION_KEY_MAX_LENGTH = 256;
|
|
51
|
+
/** Matches the characters a session name or conversation key may carry. */
|
|
52
|
+
export declare const SESSION_IDENTIFIER_PATTERN: RegExp;
|
|
53
|
+
/** Bounds an implementation id. */
|
|
54
|
+
export declare const IMPLEMENTATION_ID_MAX_LENGTH = 64;
|
|
55
|
+
/** Matches a well-formed implementation id. */
|
|
56
|
+
export declare const IMPLEMENTATION_ID_PATTERN: RegExp;
|
|
57
|
+
/** Supplies the claim count a fetch takes when the caller names none. */
|
|
58
|
+
export declare const FETCH_LIMIT_DEFAULT = 50;
|
|
59
|
+
/** Bounds the claim count one fetch may take. */
|
|
60
|
+
export declare const FETCH_LIMIT_MAX = 500;
|
|
61
|
+
/** Bounds traffic and per-record lifecycle material exposed to operator projection. */
|
|
62
|
+
export declare const BROKER_OPERATOR_TRAFFIC_LIMIT = 4096;
|
|
63
|
+
/**
|
|
64
|
+
* Limits a message subject to the message log pane's default content width
|
|
65
|
+
* (`MESSAGE_LOG_COLUMNS` minus its two-column inset, `src/tui/presentation.ts`), so a subject fits
|
|
66
|
+
* in full at that width. A drag below the default, or the narrower agent-log list column, still
|
|
67
|
+
* truncates it.
|
|
68
|
+
*/
|
|
69
|
+
export declare const MESSAGE_SUBJECT_LIMIT_CHARACTERS = 40;
|
|
70
|
+
/**
|
|
71
|
+
* Bounds a message type to a short categorical tag rather than a second subject line.
|
|
72
|
+
*
|
|
73
|
+
* Sized to the collapsed team-coordination vocabulary's longest member, with no headroom to spare,
|
|
74
|
+
* keeping it visibly shorter than {@link MESSAGE_SUBJECT_LIMIT_CHARACTERS} so a type shown beside a
|
|
75
|
+
* subject never dominates it.
|
|
76
|
+
*/
|
|
77
|
+
export declare const MESSAGE_TYPE_LIMIT_CHARACTERS = 8;
|
|
78
|
+
/**
|
|
79
|
+
* Prefixes every agent identifier, and is what tells one from an alias at an addressing boundary.
|
|
80
|
+
*
|
|
81
|
+
* The type below is built from it, and the pattern below that spells the same prefix in its escaped
|
|
82
|
+
* form; those two spellings are one rule and must move together.
|
|
83
|
+
*/
|
|
84
|
+
export declare const AGENT_ID_SCHEME = "pgr://agent/";
|
|
85
|
+
/** Identifies an agent with the protocol's opaque URI scheme. */
|
|
86
|
+
export type AgentId = `${typeof AGENT_ID_SCHEME}${string}`;
|
|
87
|
+
/**
|
|
88
|
+
* Report whether an untrusted value is a well-formed agent identifier.
|
|
89
|
+
* @param value - Untrusted candidate identity.
|
|
90
|
+
* @returns - Whether the value is a well-formed agent id.
|
|
91
|
+
*/
|
|
92
|
+
export declare function isAgentId(value: unknown): value is AgentId;
|
|
93
|
+
/**
|
|
94
|
+
* Mint an agent identifier around an opaque token.
|
|
95
|
+
* @param token - Opaque high-entropy token the identity is built from.
|
|
96
|
+
* @returns - Identifier carrying the protocol's scheme.
|
|
97
|
+
*/
|
|
98
|
+
export declare function mintAgentId(token: string): AgentId;
|
|
99
|
+
/**
|
|
100
|
+
* Report whether an address names an agent identity directly rather than an alias to resolve.
|
|
101
|
+
*
|
|
102
|
+
* A shape question, not a validity one: a caller asking this is choosing between a direct lookup and
|
|
103
|
+
* alias resolution, and a malformed identity must reach the lookup so it fails as an unknown
|
|
104
|
+
* recipient rather than being resolved as an alias that happens to look like a URI.
|
|
105
|
+
* @param address - Recipient address supplied by a caller.
|
|
106
|
+
* @returns - Whether the address is in the agent-identity namespace.
|
|
107
|
+
*/
|
|
108
|
+
export declare function isDirectAgentAddress(address: string): boolean;
|
|
109
|
+
/**
|
|
110
|
+
* Assert an untrusted value is a well-formed agent identifier.
|
|
111
|
+
* @param value - Untrusted candidate identity.
|
|
112
|
+
* @param label - Names the identity's origin in the rejection message.
|
|
113
|
+
*/
|
|
114
|
+
export declare function assertAgentId(value: unknown, label: string): asserts value is AgentId;
|
|
115
|
+
/**
|
|
116
|
+
* Report whether an untrusted value is a well-formed opaque durable identifier.
|
|
117
|
+
* @param value - Untrusted candidate identifier.
|
|
118
|
+
* @returns - Whether the value is a well-formed opaque id.
|
|
119
|
+
*/
|
|
120
|
+
export declare function isOpaqueId(value: unknown): value is string;
|
|
121
|
+
/**
|
|
122
|
+
* Report whether text carries a control character.
|
|
123
|
+
* @param value - Candidate single-line text.
|
|
124
|
+
* @returns - Whether any C0 or C1 control character appears.
|
|
125
|
+
*/
|
|
126
|
+
export declare function hasControlCharacter(value: string): boolean;
|
|
127
|
+
/**
|
|
128
|
+
* Report whether an untrusted value is a well-formed conversation key.
|
|
129
|
+
* @param value - Untrusted candidate key.
|
|
130
|
+
* @returns - Whether the value is a key the broker accepts.
|
|
131
|
+
*/
|
|
132
|
+
export declare function isSessionKey(value: unknown): value is string;
|
|
133
|
+
/**
|
|
134
|
+
* Validate a caller-supplied conversation key at any boundary that accepts one.
|
|
135
|
+
* @param value - Untrusted candidate key.
|
|
136
|
+
* @returns - The validated key, unchanged.
|
|
137
|
+
*/
|
|
138
|
+
export declare function validateSessionKey(value: unknown): string;
|
|
139
|
+
/**
|
|
140
|
+
* Report whether an untrusted value is a well-formed implementation identifier.
|
|
141
|
+
* @param value - Untrusted candidate identifier.
|
|
142
|
+
* @returns - Whether the value is an identifier the broker will register.
|
|
143
|
+
*/
|
|
144
|
+
export declare function isImplementationId(value: unknown): value is string;
|
|
145
|
+
/**
|
|
146
|
+
* Validate an implementation identifier at any boundary that accepts one.
|
|
147
|
+
* @param value - Untrusted candidate identifier.
|
|
148
|
+
* @returns - The validated identifier, unchanged and unbranded.
|
|
149
|
+
*/
|
|
150
|
+
export declare function validateImplementationId(value: unknown): string;
|
|
151
|
+
/** Describes a durable message's current delivery state. */
|
|
152
|
+
export type MessageState = "queued" | "claimed" | "acknowledged" | "expired" | "dead_lettered" | "failed";
|
|
153
|
+
/**
|
|
154
|
+
* Complete vocabulary of `message_events.type` values the broker appends to a delivery lifecycle,
|
|
155
|
+
* mapped to the state each observes, or `null` when the event is informational and observes no
|
|
156
|
+
* state change. `#appendEvent` in broker.ts is typed against its keys, so an emission site naming a
|
|
157
|
+
* type absent here fails to compile.
|
|
158
|
+
*/
|
|
159
|
+
export declare const LIFECYCLE_EVENT_STATE: {
|
|
160
|
+
readonly enqueued: "queued";
|
|
161
|
+
readonly queued: "queued";
|
|
162
|
+
readonly claimed: "claimed";
|
|
163
|
+
readonly acknowledged: "acknowledged";
|
|
164
|
+
readonly expired: "expired";
|
|
165
|
+
readonly dead_lettered: "dead_lettered";
|
|
166
|
+
readonly failed: "failed";
|
|
167
|
+
readonly direct: null;
|
|
168
|
+
readonly alias_resolved: null;
|
|
169
|
+
readonly broadcast: null;
|
|
170
|
+
readonly duplicate_ignored: null;
|
|
171
|
+
readonly claim_released: null;
|
|
172
|
+
readonly claim_expired: null;
|
|
173
|
+
readonly redelivery: null;
|
|
174
|
+
readonly notify_delivered: null;
|
|
175
|
+
readonly notify_shed: null;
|
|
176
|
+
readonly notify_failed: null;
|
|
177
|
+
readonly notify_deferred: null;
|
|
178
|
+
};
|
|
179
|
+
/** Names a lifecycle event type the broker is known to append. */
|
|
180
|
+
export type LifecycleEventType = keyof typeof LIFECYCLE_EVENT_STATE;
|
|
181
|
+
/**
|
|
182
|
+
* Look up the delivery state a lifecycle event type observes.
|
|
183
|
+
* @param type - Candidate lifecycle event type name, untrusted when read back from storage.
|
|
184
|
+
* @returns - The state the type observes, `null` when it is informational, or `undefined` when the
|
|
185
|
+
* type is not part of the broker's vocabulary.
|
|
186
|
+
*/
|
|
187
|
+
export declare function lifecycleEventState(type: string): MessageState | null | undefined;
|
|
188
|
+
/** Stable structured protocol error emitted at broker trust boundaries. */
|
|
189
|
+
export declare class ProtocolError extends Error {
|
|
190
|
+
/** Identifies the machine-readable cause of the protocol failure. */
|
|
191
|
+
readonly code: "validation_failed" | "unsupported_version" | "oversized_content" | "unknown_recipient" | "recipient_alias_changed" | "alias_conflict" | "conflict" | "expired";
|
|
192
|
+
/**
|
|
193
|
+
* Constructs an error that carries a protocol failure code.
|
|
194
|
+
* @param code - Stable protocol error category exposed to callers.
|
|
195
|
+
* @param message - Safe diagnostic text exposed with the protocol error.
|
|
196
|
+
*/
|
|
197
|
+
constructor(
|
|
198
|
+
/** Identifies the machine-readable cause of the protocol failure. */
|
|
199
|
+
code: "validation_failed" | "unsupported_version" | "oversized_content" | "unknown_recipient" | "recipient_alias_changed" | "alias_conflict" | "conflict" | "expired", message: string);
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Generate a collision-resistant opaque token with a non-sensitive prefix.
|
|
203
|
+
* @param prefix - Non-secret category prefix for a newly issued opaque token.
|
|
204
|
+
* @returns - Fresh high-entropy token with the requested diagnostic prefix.
|
|
205
|
+
*/
|
|
206
|
+
export declare function issueOpaqueToken(prefix: string): string;
|
|
207
|
+
/**
|
|
208
|
+
* Assert the requested protocol version is supported at a trust boundary.
|
|
209
|
+
* @param version - Wire-protocol version whose compatibility is being asserted.
|
|
210
|
+
*/
|
|
211
|
+
export declare function assertProtocolVersion(version: unknown): asserts version is typeof PROTOCOL_VERSION;
|
|
212
|
+
/**
|
|
213
|
+
* Validate and serialize a message body, rejecting oversize input without truncation.
|
|
214
|
+
* @param body - Application payload; it must serialize to JSON.
|
|
215
|
+
* @returns - JSON text within `MESSAGE_BODY_LIMIT_BYTES`, as stored in the durable broker database.
|
|
216
|
+
*/
|
|
217
|
+
export declare function encodeMessageBody(body: unknown): string;
|
|
218
|
+
/**
|
|
219
|
+
* Validate the one-line subject every durable message carries.
|
|
220
|
+
* @param subject - Sender-supplied subject to validate.
|
|
221
|
+
* @returns The subject with surrounding whitespace removed.
|
|
222
|
+
*/
|
|
223
|
+
export declare function normalizeMessageSubject(subject: unknown): string;
|
|
224
|
+
/**
|
|
225
|
+
* Validate the sender-supplied message type, required on every send.
|
|
226
|
+
*
|
|
227
|
+
* Follows {@link normalizeMessageSubject}'s rules at its own, shorter bound.
|
|
228
|
+
* @param type - Sender-supplied type to validate.
|
|
229
|
+
* @returns The type with surrounding whitespace removed.
|
|
230
|
+
*/
|
|
231
|
+
export declare function normalizeMessageType(type: unknown): string;
|
|
232
|
+
/**
|
|
233
|
+
* Decode a stored message body.
|
|
234
|
+
* @param encoded - Stored JSON text, or null when the message has no body.
|
|
235
|
+
* @returns - The decoded body, or undefined when none was stored.
|
|
236
|
+
*/
|
|
237
|
+
export declare function decodeMessageBody(encoded: string | null): unknown;
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
import { randomBytes, randomUUID } from "node:crypto";
|
|
2
|
+
/**
|
|
3
|
+
* Identifies the database schema this build opens; a differing marker recreates the database.
|
|
4
|
+
*
|
|
5
|
+
* Declared here rather than beside the schema it names, because the service lock compares it and is
|
|
6
|
+
* loaded by adapters running inside hosts that have no `bun:sqlite`.
|
|
7
|
+
*/
|
|
8
|
+
export const SCHEMA_MARKER = "agent-session-key+message-event-index+queryable-timestamps+no-body-absence-reason+message-type+session-resume-lineage+session-supersession-timestamp+message-type-required+single-delivery-state-home+checked-stored-columns+unorderable-position-index+orderable-position-predicate+no-occupancy-contract+single-session-encoding+no-reservation-bindings+reservation-id-column";
|
|
9
|
+
/**
|
|
10
|
+
* Identifies the only protocol version accepted by this process.
|
|
11
|
+
*
|
|
12
|
+
* Bump for a breaking change: one where a caller declaring this version would misinterpret data
|
|
13
|
+
* this process returns, or would need to construct a request this process now rejects.
|
|
14
|
+
*
|
|
15
|
+
* A narrowing of {@link MESSAGE_TYPE_LIMIT_CHARACTERS} is bumped under that criterion: a caller
|
|
16
|
+
* declaring the prior version that already sends a `type` between the old and new bound has a request
|
|
17
|
+
* that validated before and no longer does, for a value it is not free to shorten without changing
|
|
18
|
+
* what it means, so such a caller must see `unsupported_version` from {@link assertProtocolVersion}
|
|
19
|
+
* rather than a silent, confusing per-message rejection once it is already connected.
|
|
20
|
+
*/
|
|
21
|
+
export const PROTOCOL_VERSION = 4;
|
|
22
|
+
/** Names the request header a session presents its single-use attach reservation in. */
|
|
23
|
+
export const ATTACH_HEADER = "x-pager-attach";
|
|
24
|
+
/** Limits the serialized size of a message body accepted by the broker. */
|
|
25
|
+
export const MESSAGE_BODY_LIMIT_BYTES = 12 * 1024;
|
|
26
|
+
/** Bounds a registration session name, which is also the agent's routable alias. */
|
|
27
|
+
export const REGISTRATION_SESSION_NAME_MAX_LENGTH = 128;
|
|
28
|
+
/** Bounds a conversation key, which a caller supplies to rejoin an identity across restarts. */
|
|
29
|
+
export const SESSION_KEY_MAX_LENGTH = 256;
|
|
30
|
+
/** Matches the characters a session name or conversation key may carry. */
|
|
31
|
+
export const SESSION_IDENTIFIER_PATTERN = /^[A-Za-z0-9._:-]+$/u;
|
|
32
|
+
/** Bounds an implementation id. */
|
|
33
|
+
export const IMPLEMENTATION_ID_MAX_LENGTH = 64;
|
|
34
|
+
/** Matches a well-formed implementation id. */
|
|
35
|
+
export const IMPLEMENTATION_ID_PATTERN = /^[a-z][a-z0-9]*(?:[.-][a-z0-9]+)*$/u;
|
|
36
|
+
/** Supplies the claim count a fetch takes when the caller names none. */
|
|
37
|
+
export const FETCH_LIMIT_DEFAULT = 50;
|
|
38
|
+
/** Bounds the claim count one fetch may take. */
|
|
39
|
+
export const FETCH_LIMIT_MAX = 500;
|
|
40
|
+
/** Bounds traffic and per-record lifecycle material exposed to operator projection. */
|
|
41
|
+
export const BROKER_OPERATOR_TRAFFIC_LIMIT = 4_096;
|
|
42
|
+
/**
|
|
43
|
+
* Limits a message subject to the message log pane's default content width
|
|
44
|
+
* (`MESSAGE_LOG_COLUMNS` minus its two-column inset, `src/tui/presentation.ts`), so a subject fits
|
|
45
|
+
* in full at that width. A drag below the default, or the narrower agent-log list column, still
|
|
46
|
+
* truncates it.
|
|
47
|
+
*/
|
|
48
|
+
export const MESSAGE_SUBJECT_LIMIT_CHARACTERS = 40;
|
|
49
|
+
/**
|
|
50
|
+
* Bounds a message type to a short categorical tag rather than a second subject line.
|
|
51
|
+
*
|
|
52
|
+
* Sized to the collapsed team-coordination vocabulary's longest member, with no headroom to spare,
|
|
53
|
+
* keeping it visibly shorter than {@link MESSAGE_SUBJECT_LIMIT_CHARACTERS} so a type shown beside a
|
|
54
|
+
* subject never dominates it.
|
|
55
|
+
*/
|
|
56
|
+
export const MESSAGE_TYPE_LIMIT_CHARACTERS = 8;
|
|
57
|
+
/**
|
|
58
|
+
* Prefixes every agent identifier, and is what tells one from an alias at an addressing boundary.
|
|
59
|
+
*
|
|
60
|
+
* The type below is built from it, and the pattern below that spells the same prefix in its escaped
|
|
61
|
+
* form; those two spellings are one rule and must move together.
|
|
62
|
+
*/
|
|
63
|
+
export const AGENT_ID_SCHEME = "pgr://agent/";
|
|
64
|
+
/**
|
|
65
|
+
* Matches a well-formed agent identifier.
|
|
66
|
+
*
|
|
67
|
+
* Bounded rather than open-ended because the operator projection and the operator wire both refuse
|
|
68
|
+
* a longer tail: an unbounded rule here mints identities the operator can never be shown.
|
|
69
|
+
*/
|
|
70
|
+
const AGENT_ID_PATTERN = /^pgr:\/\/agent\/[A-Za-z0-9._:-]{1,192}$/u;
|
|
71
|
+
/** Matches a well-formed opaque durable identifier: a command, control, audit, or traffic id. */
|
|
72
|
+
const OPAQUE_ID_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,255}$/u;
|
|
73
|
+
/** Matches the C0 and C1 control characters no single-line field may carry. */
|
|
74
|
+
// eslint-disable-next-line no-control-regex -- Matching control characters is this pattern's purpose.
|
|
75
|
+
const CONTROL_CHARACTER_PATTERN = /[\u0000-\u001f\u007f-\u009f]/u;
|
|
76
|
+
/**
|
|
77
|
+
* Report whether an untrusted value is a well-formed agent identifier.
|
|
78
|
+
* @param value - Untrusted candidate identity.
|
|
79
|
+
* @returns - Whether the value is a well-formed agent id.
|
|
80
|
+
*/
|
|
81
|
+
export function isAgentId(value) {
|
|
82
|
+
return typeof value === "string" && AGENT_ID_PATTERN.test(value);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Mint an agent identifier around an opaque token.
|
|
86
|
+
* @param token - Opaque high-entropy token the identity is built from.
|
|
87
|
+
* @returns - Identifier carrying the protocol's scheme.
|
|
88
|
+
*/
|
|
89
|
+
export function mintAgentId(token) {
|
|
90
|
+
return `${AGENT_ID_SCHEME}${token}`;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Report whether an address names an agent identity directly rather than an alias to resolve.
|
|
94
|
+
*
|
|
95
|
+
* A shape question, not a validity one: a caller asking this is choosing between a direct lookup and
|
|
96
|
+
* alias resolution, and a malformed identity must reach the lookup so it fails as an unknown
|
|
97
|
+
* recipient rather than being resolved as an alias that happens to look like a URI.
|
|
98
|
+
* @param address - Recipient address supplied by a caller.
|
|
99
|
+
* @returns - Whether the address is in the agent-identity namespace.
|
|
100
|
+
*/
|
|
101
|
+
export function isDirectAgentAddress(address) {
|
|
102
|
+
return address.startsWith(AGENT_ID_SCHEME);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Assert an untrusted value is a well-formed agent identifier.
|
|
106
|
+
* @param value - Untrusted candidate identity.
|
|
107
|
+
* @param label - Names the identity's origin in the rejection message.
|
|
108
|
+
*/
|
|
109
|
+
export function assertAgentId(value, label) {
|
|
110
|
+
if (!isAgentId(value))
|
|
111
|
+
throw new ProtocolError("validation_failed", `${label} is not a well-formed agent id`);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Report whether an untrusted value is a well-formed opaque durable identifier.
|
|
115
|
+
* @param value - Untrusted candidate identifier.
|
|
116
|
+
* @returns - Whether the value is a well-formed opaque id.
|
|
117
|
+
*/
|
|
118
|
+
export function isOpaqueId(value) {
|
|
119
|
+
return typeof value === "string" && OPAQUE_ID_PATTERN.test(value);
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Report whether text carries a control character.
|
|
123
|
+
* @param value - Candidate single-line text.
|
|
124
|
+
* @returns - Whether any C0 or C1 control character appears.
|
|
125
|
+
*/
|
|
126
|
+
export function hasControlCharacter(value) {
|
|
127
|
+
return CONTROL_CHARACTER_PATTERN.test(value);
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Report whether an untrusted value is a well-formed conversation key.
|
|
131
|
+
* @param value - Untrusted candidate key.
|
|
132
|
+
* @returns - Whether the value is a key the broker accepts.
|
|
133
|
+
*/
|
|
134
|
+
export function isSessionKey(value) {
|
|
135
|
+
return (typeof value === "string" &&
|
|
136
|
+
value.length >= 1 &&
|
|
137
|
+
value.length <= SESSION_KEY_MAX_LENGTH &&
|
|
138
|
+
SESSION_IDENTIFIER_PATTERN.test(value));
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Validate a caller-supplied conversation key at any boundary that accepts one.
|
|
142
|
+
* @param value - Untrusted candidate key.
|
|
143
|
+
* @returns - The validated key, unchanged.
|
|
144
|
+
*/
|
|
145
|
+
export function validateSessionKey(value) {
|
|
146
|
+
if (!isSessionKey(value)) {
|
|
147
|
+
throw new ProtocolError("validation_failed", `session key must be 1-${String(SESSION_KEY_MAX_LENGTH)} letters, digits, dots, colons, underscores, or hyphens`);
|
|
148
|
+
}
|
|
149
|
+
return value;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Report whether an untrusted value is a well-formed implementation identifier.
|
|
153
|
+
* @param value - Untrusted candidate identifier.
|
|
154
|
+
* @returns - Whether the value is an identifier the broker will register.
|
|
155
|
+
*/
|
|
156
|
+
export function isImplementationId(value) {
|
|
157
|
+
return (typeof value === "string" &&
|
|
158
|
+
value.length >= 1 &&
|
|
159
|
+
value.length <= IMPLEMENTATION_ID_MAX_LENGTH &&
|
|
160
|
+
IMPLEMENTATION_ID_PATTERN.test(value));
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Validate an implementation identifier at any boundary that accepts one.
|
|
164
|
+
* @param value - Untrusted candidate identifier.
|
|
165
|
+
* @returns - The validated identifier, unchanged and unbranded.
|
|
166
|
+
*/
|
|
167
|
+
export function validateImplementationId(value) {
|
|
168
|
+
if (!isImplementationId(value)) {
|
|
169
|
+
throw new ProtocolError("validation_failed", `implementation id must be 1-${String(IMPLEMENTATION_ID_MAX_LENGTH)} lowercase letters and digits, start with a letter, and carry a dot or hyphen only between two of them`);
|
|
170
|
+
}
|
|
171
|
+
return value;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Complete vocabulary of `message_events.type` values the broker appends to a delivery lifecycle,
|
|
175
|
+
* mapped to the state each observes, or `null` when the event is informational and observes no
|
|
176
|
+
* state change. `#appendEvent` in broker.ts is typed against its keys, so an emission site naming a
|
|
177
|
+
* type absent here fails to compile.
|
|
178
|
+
*/
|
|
179
|
+
export const LIFECYCLE_EVENT_STATE = {
|
|
180
|
+
enqueued: "queued",
|
|
181
|
+
queued: "queued",
|
|
182
|
+
claimed: "claimed",
|
|
183
|
+
acknowledged: "acknowledged",
|
|
184
|
+
expired: "expired",
|
|
185
|
+
dead_lettered: "dead_lettered",
|
|
186
|
+
failed: "failed",
|
|
187
|
+
direct: null,
|
|
188
|
+
alias_resolved: null,
|
|
189
|
+
broadcast: null,
|
|
190
|
+
duplicate_ignored: null,
|
|
191
|
+
claim_released: null,
|
|
192
|
+
claim_expired: null,
|
|
193
|
+
redelivery: null,
|
|
194
|
+
notify_delivered: null,
|
|
195
|
+
notify_shed: null,
|
|
196
|
+
notify_failed: null,
|
|
197
|
+
notify_deferred: null,
|
|
198
|
+
};
|
|
199
|
+
/**
|
|
200
|
+
* Look up the delivery state a lifecycle event type observes.
|
|
201
|
+
* @param type - Candidate lifecycle event type name, untrusted when read back from storage.
|
|
202
|
+
* @returns - The state the type observes, `null` when it is informational, or `undefined` when the
|
|
203
|
+
* type is not part of the broker's vocabulary.
|
|
204
|
+
*/
|
|
205
|
+
export function lifecycleEventState(type) {
|
|
206
|
+
return Object.hasOwn(LIFECYCLE_EVENT_STATE, type) ? LIFECYCLE_EVENT_STATE[type] : undefined;
|
|
207
|
+
}
|
|
208
|
+
/** Stable structured protocol error emitted at broker trust boundaries. */
|
|
209
|
+
export class ProtocolError extends Error {
|
|
210
|
+
code;
|
|
211
|
+
/**
|
|
212
|
+
* Constructs an error that carries a protocol failure code.
|
|
213
|
+
* @param code - Stable protocol error category exposed to callers.
|
|
214
|
+
* @param message - Safe diagnostic text exposed with the protocol error.
|
|
215
|
+
*/
|
|
216
|
+
constructor(
|
|
217
|
+
/** Identifies the machine-readable cause of the protocol failure. */
|
|
218
|
+
code, message) {
|
|
219
|
+
super(message);
|
|
220
|
+
this.code = code;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Generate a collision-resistant opaque token with a non-sensitive prefix.
|
|
225
|
+
* @param prefix - Non-secret category prefix for a newly issued opaque token.
|
|
226
|
+
* @returns - Fresh high-entropy token with the requested diagnostic prefix.
|
|
227
|
+
*/
|
|
228
|
+
export function issueOpaqueToken(prefix) {
|
|
229
|
+
return `${prefix}_${randomUUID()}_${randomBytes(16).toString("base64url")}`;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Assert the requested protocol version is supported at a trust boundary.
|
|
233
|
+
* @param version - Wire-protocol version whose compatibility is being asserted.
|
|
234
|
+
*/
|
|
235
|
+
export function assertProtocolVersion(version) {
|
|
236
|
+
if (version !== PROTOCOL_VERSION)
|
|
237
|
+
throw new ProtocolError("unsupported_version", "Unsupported protocol version");
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Validate and serialize a message body, rejecting oversize input without truncation.
|
|
241
|
+
* @param body - Application payload; it must serialize to JSON.
|
|
242
|
+
* @returns - JSON text within `MESSAGE_BODY_LIMIT_BYTES`, as stored in the durable broker database.
|
|
243
|
+
*/
|
|
244
|
+
export function encodeMessageBody(body) {
|
|
245
|
+
const encoded = JSON.stringify(body);
|
|
246
|
+
if (typeof encoded !== "string")
|
|
247
|
+
throw new ProtocolError("validation_failed", "Message body must be JSON serializable");
|
|
248
|
+
if (Buffer.byteLength(encoded, "utf8") > MESSAGE_BODY_LIMIT_BYTES) {
|
|
249
|
+
throw new ProtocolError("oversized_content", `Message body exceeds ${String(MESSAGE_BODY_LIMIT_BYTES)} bytes`);
|
|
250
|
+
}
|
|
251
|
+
return encoded;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Validate one bounded line of sender-supplied text, shared by every field that follows the
|
|
255
|
+
* subject's rules at its own limit.
|
|
256
|
+
*
|
|
257
|
+
* Control characters are rejected rather than stripped: the field is presented in a single character
|
|
258
|
+
* cell row, and silently altering the sender's text would make the operator view disagree with what
|
|
259
|
+
* the sender believes it sent.
|
|
260
|
+
* @param trimmed - Non-empty, already-trimmed candidate to validate.
|
|
261
|
+
* @param limit - Maximum character length this field allows.
|
|
262
|
+
* @param label - Names the field in a rejection message.
|
|
263
|
+
* @returns The input, unchanged, once it has passed the control-character and length checks.
|
|
264
|
+
*/
|
|
265
|
+
function normalizeBoundedLine(trimmed, limit, label) {
|
|
266
|
+
if (hasControlCharacter(trimmed)) {
|
|
267
|
+
throw new ProtocolError("validation_failed", `Message ${label} must be a single line without control characters`);
|
|
268
|
+
}
|
|
269
|
+
if (trimmed.length > limit) {
|
|
270
|
+
throw new ProtocolError("oversized_content", `Message ${label} exceeds ${String(limit)} characters`);
|
|
271
|
+
}
|
|
272
|
+
return trimmed;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Validate the one-line subject every durable message carries.
|
|
276
|
+
* @param subject - Sender-supplied subject to validate.
|
|
277
|
+
* @returns The subject with surrounding whitespace removed.
|
|
278
|
+
*/
|
|
279
|
+
export function normalizeMessageSubject(subject) {
|
|
280
|
+
if (typeof subject !== "string")
|
|
281
|
+
throw new ProtocolError("validation_failed", "Message subject is required");
|
|
282
|
+
const trimmed = subject.trim();
|
|
283
|
+
if (trimmed.length === 0)
|
|
284
|
+
throw new ProtocolError("validation_failed", "Message subject is required");
|
|
285
|
+
return normalizeBoundedLine(trimmed, MESSAGE_SUBJECT_LIMIT_CHARACTERS, "subject");
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Validate the sender-supplied message type, required on every send.
|
|
289
|
+
*
|
|
290
|
+
* Follows {@link normalizeMessageSubject}'s rules at its own, shorter bound.
|
|
291
|
+
* @param type - Sender-supplied type to validate.
|
|
292
|
+
* @returns The type with surrounding whitespace removed.
|
|
293
|
+
*/
|
|
294
|
+
export function normalizeMessageType(type) {
|
|
295
|
+
if (type === undefined || type === null)
|
|
296
|
+
throw new ProtocolError("validation_failed", "Message type is required");
|
|
297
|
+
if (typeof type !== "string")
|
|
298
|
+
throw new ProtocolError("validation_failed", "Message type must be text");
|
|
299
|
+
const trimmed = type.trim();
|
|
300
|
+
if (trimmed.length === 0)
|
|
301
|
+
throw new ProtocolError("validation_failed", "Message type must not be blank");
|
|
302
|
+
return normalizeBoundedLine(trimmed, MESSAGE_TYPE_LIMIT_CHARACTERS, "type");
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Decode a stored message body.
|
|
306
|
+
* @param encoded - Stored JSON text, or null when the message has no body.
|
|
307
|
+
* @returns - The decoded body, or undefined when none was stored.
|
|
308
|
+
*/
|
|
309
|
+
export function decodeMessageBody(encoded) {
|
|
310
|
+
return encoded === null ? undefined : JSON.parse(encoded);
|
|
311
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import type { BrokerDatabase } from "./database.js";
|
|
2
|
+
import { type MessageState } from "./protocol.js";
|
|
3
|
+
/** Declares one partial index over the rows of a table whose position column holds no orderable value. */
|
|
4
|
+
export type UnorderablePositionIndex = {
|
|
5
|
+
/** Index name, unique within the database. */
|
|
6
|
+
readonly name: string;
|
|
7
|
+
/** Table the index is declared on. */
|
|
8
|
+
readonly table: string;
|
|
9
|
+
/** Column the index keys on, and orders the naming read by. */
|
|
10
|
+
readonly column: string;
|
|
11
|
+
/** Column whose unorderable values the index selects for. */
|
|
12
|
+
readonly position: string;
|
|
13
|
+
};
|
|
14
|
+
/** The partial index over messages whose `sequence` holds no orderable value. */
|
|
15
|
+
export declare const MESSAGE_UNORDERABLE_POSITION: UnorderablePositionIndex;
|
|
16
|
+
/** The partial index over ping audits whose `traffic_position` holds no orderable value. */
|
|
17
|
+
export declare const PING_UNORDERABLE_POSITION: UnorderablePositionIndex;
|
|
18
|
+
/** Every index this build creates over rows whose durable position it cannot order. */
|
|
19
|
+
export declare const UNORDERABLE_POSITION_INDEXES: readonly UnorderablePositionIndex[];
|
|
20
|
+
/**
|
|
21
|
+
* Render the condition a stored traffic position meets when it can be ordered and projected.
|
|
22
|
+
* @param column - Position column the condition tests.
|
|
23
|
+
* @returns - SQL condition true for a positive safe integer.
|
|
24
|
+
*/
|
|
25
|
+
export declare function orderablePosition(column: string): string;
|
|
26
|
+
/**
|
|
27
|
+
* Render the condition a stored traffic position meets when it cannot be ordered: the complement of
|
|
28
|
+
* `orderablePosition`, spelled the way the partial index spells it so a query can use that index.
|
|
29
|
+
* @param column - Position column the condition tests.
|
|
30
|
+
* @returns - SQL condition true for anything but a positive safe integer.
|
|
31
|
+
*/
|
|
32
|
+
export declare function unorderablePosition(column: string): string;
|
|
33
|
+
/** Every delivery state `messages.state` may hold. */
|
|
34
|
+
export declare const MESSAGE_STATES: readonly MessageState[];
|
|
35
|
+
/** Names one lifecycle state of an agent; `AGENT_STATES` lists them. */
|
|
36
|
+
export type AgentLifecycleState = "active" | "terminal" | "reaped";
|
|
37
|
+
/** Every lifecycle state `agents.state` may hold. */
|
|
38
|
+
export declare const AGENT_STATES: readonly AgentLifecycleState[];
|
|
39
|
+
/** Every channel a reservation or session may occupy. */
|
|
40
|
+
export declare const ATTACHMENT_CHANNELS: readonly ("messaging" | "delivery")[];
|
|
41
|
+
/** Every author `message_events.source` may name. */
|
|
42
|
+
export declare const MESSAGE_EVENT_SOURCES: readonly ("broker" | "notify")[];
|
|
43
|
+
/** Selects the lifecycle display tone shown for a durable event or status. */
|
|
44
|
+
export type LifecycleTone = "neutral" | "danger" | "ok" | "muted" | "warn";
|
|
45
|
+
/** Every presentation tone `message_events.tone` may carry. */
|
|
46
|
+
export declare const MESSAGE_EVENT_TONES: readonly LifecycleTone[];
|
|
47
|
+
/**
|
|
48
|
+
* Render one vocabulary as a SQL `check(column in (...))` clause.
|
|
49
|
+
*
|
|
50
|
+
* Members are sorted by UTF-16 code unit rather than by locale, so reordering a union does not
|
|
51
|
+
* change the text.
|
|
52
|
+
* @param column - Column the constraint applies to.
|
|
53
|
+
* @param allowed - Values the column may hold.
|
|
54
|
+
* @returns - Constraint text for the column's declaration.
|
|
55
|
+
*/
|
|
56
|
+
export declare function vocabularyClause(column: string, allowed: readonly string[]): string;
|
|
57
|
+
/**
|
|
58
|
+
* Report whether a table's stored declaration carries the constraint this build renders for a column.
|
|
59
|
+
*
|
|
60
|
+
* Case is kept: a clause differing only in a member's case admits different values.
|
|
61
|
+
* @param tableSql - The table's `create` statement exactly as `sqlite_master` holds it.
|
|
62
|
+
* @param column - Column the constraint applies to.
|
|
63
|
+
* @param allowed - Values this build's constraint admits.
|
|
64
|
+
* @returns - True when the declaration contains the constraint.
|
|
65
|
+
*/
|
|
66
|
+
export declare function declaresVocabulary(tableSql: string, column: string, allowed: readonly string[]): boolean;
|
|
67
|
+
/**
|
|
68
|
+
* Owns broker schema creation, in-place-upgrade compatibility, and epoch assignment for one
|
|
69
|
+
* connection. Runs only from the broker's own constructor, before any other reader or writer of
|
|
70
|
+
* the connection exists.
|
|
71
|
+
*/
|
|
72
|
+
export declare class BrokerSchema {
|
|
73
|
+
#private;
|
|
74
|
+
/**
|
|
75
|
+
* Bind schema management to one connection.
|
|
76
|
+
* @param db - Connection whose schema this instance prepares.
|
|
77
|
+
* @param options - Clock, epoch-ownership policy, the unorderable-position declarations to create
|
|
78
|
+
* and require (defaulting to this build's; the create path and the check read the same list), and
|
|
79
|
+
* the operator-facing diagnostic sink for anything short of the schema-loss announcement, which is
|
|
80
|
+
* written to stderr directly because it reports data being deleted.
|
|
81
|
+
*/
|
|
82
|
+
constructor(db: BrokerDatabase, options: {
|
|
83
|
+
now: () => number;
|
|
84
|
+
epochOwner: boolean;
|
|
85
|
+
unorderablePositionIndexes?: readonly UnorderablePositionIndex[];
|
|
86
|
+
report: (message: string) => void;
|
|
87
|
+
});
|
|
88
|
+
/**
|
|
89
|
+
* Recreate an incompatible database, create the current schema if absent, reconcile the traffic
|
|
90
|
+
* position allocator against stored rows, and resolve the broker epoch — in that order.
|
|
91
|
+
* @returns - Broker epoch for this connection.
|
|
92
|
+
*/
|
|
93
|
+
prepare(): string;
|
|
94
|
+
}
|