@aeolus-fleet/common 0.0.0 → 0.2.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/README.md +2 -2
- package/dist/fleet/index.d.ts +81 -0
- package/dist/fleet/index.js +48 -0
- package/dist/fleet/index.js.map +1 -0
- package/dist/ids/index.d.ts +65 -0
- package/dist/ids/index.js +151 -0
- package/dist/ids/index.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/schemas/console.d.ts +21 -0
- package/dist/schemas/console.js +21 -0
- package/dist/schemas/console.js.map +1 -0
- package/dist/schemas/delivery.d.ts +85 -0
- package/dist/schemas/delivery.js +57 -0
- package/dist/schemas/delivery.js.map +1 -0
- package/dist/schemas/fleet.d.ts +100 -0
- package/dist/schemas/fleet.js +72 -0
- package/dist/schemas/fleet.js.map +1 -0
- package/dist/schemas/index.d.ts +6 -0
- package/dist/schemas/index.js +7 -0
- package/dist/schemas/index.js.map +1 -0
- package/dist/schemas/message.d.ts +68 -0
- package/dist/schemas/message.js +72 -0
- package/dist/schemas/message.js.map +1 -0
- package/dist/schemas/ship.d.ts +63 -0
- package/dist/schemas/ship.js +51 -0
- package/dist/schemas/ship.js.map +1 -0
- package/dist/schemas/system.d.ts +7 -0
- package/dist/schemas/system.js +8 -0
- package/dist/schemas/system.js.map +1 -0
- package/package.json +19 -15
package/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# @aeolus-fleet/common
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Shared schemas, prefixed ids and types for [Aeolus](https://github.com/ThomasHendrickx/aeolus-fleet), an agent fleet manager.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Pre-v1: the API changes without notice until the v1 acceptance test passes.
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* The fleet's shared vocabulary (docs/blueprint.md, "Ubiquitous language"):
|
|
4
|
+
* scopes, ship kinds, ship statuses, lease locations, selector kinds, delivery
|
|
5
|
+
* states and event types. Server and web use the same words.
|
|
6
|
+
*/
|
|
7
|
+
/** A permission of a ship, stored on the server with the ship and checked before every call. */
|
|
8
|
+
export declare const SCOPES: readonly ["messages:send", "messages:receive", "fleet:read", "fleet:manage"];
|
|
9
|
+
export declare const scopeSchema: z.ZodEnum<{
|
|
10
|
+
"messages:send": "messages:send";
|
|
11
|
+
"messages:receive": "messages:receive";
|
|
12
|
+
"fleet:read": "fleet:read";
|
|
13
|
+
"fleet:manage": "fleet:manage";
|
|
14
|
+
}>;
|
|
15
|
+
export type Scope = z.infer<typeof scopeSchema>;
|
|
16
|
+
/** `argo` is the one ship of kind `operator` in a fleet; every other ship is an `agent`. */
|
|
17
|
+
export declare const SHIP_KINDS: readonly ["operator", "agent"];
|
|
18
|
+
export declare const shipKindSchema: z.ZodEnum<{
|
|
19
|
+
operator: "operator";
|
|
20
|
+
agent: "agent";
|
|
21
|
+
}>;
|
|
22
|
+
export type ShipKind = z.infer<typeof shipKindSchema>;
|
|
23
|
+
/** Where the session crewing a ship runs. `OTHER` carries a short description. */
|
|
24
|
+
export declare const LOCATION_KINDS: readonly ["DEVICE", "CLOUD", "SERVER", "OTHER"];
|
|
25
|
+
export declare const locationKindSchema: z.ZodEnum<{
|
|
26
|
+
DEVICE: "DEVICE";
|
|
27
|
+
CLOUD: "CLOUD";
|
|
28
|
+
SERVER: "SERVER";
|
|
29
|
+
OTHER: "OTHER";
|
|
30
|
+
}>;
|
|
31
|
+
export type LocationKind = z.infer<typeof locationKindSchema>;
|
|
32
|
+
/**
|
|
33
|
+
* Whether a ship awaits crew, is crewed or is retired. Derived from its lease
|
|
34
|
+
* and its retired date, never set by hand.
|
|
35
|
+
*/
|
|
36
|
+
export declare const SHIP_STATUSES: readonly ["awaitingCrew", "crewed", "retired"];
|
|
37
|
+
export declare const shipStatusSchema: z.ZodEnum<{
|
|
38
|
+
awaitingCrew: "awaitingCrew";
|
|
39
|
+
crewed: "crewed";
|
|
40
|
+
retired: "retired";
|
|
41
|
+
}>;
|
|
42
|
+
export type ShipStatus = z.infer<typeof shipStatusSchema>;
|
|
43
|
+
/** Who a message is for: one ship (by id or by name) or any ship of a type. Group and fleet come later. */
|
|
44
|
+
export declare const SELECTOR_KINDS: readonly ["ship", "type"];
|
|
45
|
+
export declare const selectorKindSchema: z.ZodEnum<{
|
|
46
|
+
ship: "ship";
|
|
47
|
+
type: "type";
|
|
48
|
+
}>;
|
|
49
|
+
export type SelectorKind = z.infer<typeof selectorKindSchema>;
|
|
50
|
+
/**
|
|
51
|
+
* Where one delivery stands (docs/blueprint.md, "Key flows"): pending until a
|
|
52
|
+
* ship receives it, then delivered (claimed and in flight) until it is
|
|
53
|
+
* acknowledged or returns to pending.
|
|
54
|
+
*/
|
|
55
|
+
export declare const DELIVERY_STATES: readonly ["pending", "delivered", "acknowledged", "undeliverable", "dismissed", "abandoned"];
|
|
56
|
+
export declare const deliveryStateSchema: z.ZodEnum<{
|
|
57
|
+
pending: "pending";
|
|
58
|
+
delivered: "delivered";
|
|
59
|
+
acknowledged: "acknowledged";
|
|
60
|
+
undeliverable: "undeliverable";
|
|
61
|
+
dismissed: "dismissed";
|
|
62
|
+
abandoned: "abandoned";
|
|
63
|
+
}>;
|
|
64
|
+
export type DeliveryState = z.infer<typeof deliveryStateSchema>;
|
|
65
|
+
/** The event types written so far. Each later slice adds the ones it writes. */
|
|
66
|
+
export declare const EVENT_TYPES: readonly ["FleetInitialised", "ShipCommissioned", "ShipClaimed", "LeaseRevoked", "CredentialRevoked", "StartingPromptIssued", "OperatorPasswordReset", "MessageAccepted", "DeliveryClaimed", "DeliveryAcknowledged", "DeliveryUndeliverable", "DeliveryReturned"];
|
|
67
|
+
export declare const eventTypeSchema: z.ZodEnum<{
|
|
68
|
+
FleetInitialised: "FleetInitialised";
|
|
69
|
+
ShipCommissioned: "ShipCommissioned";
|
|
70
|
+
ShipClaimed: "ShipClaimed";
|
|
71
|
+
LeaseRevoked: "LeaseRevoked";
|
|
72
|
+
CredentialRevoked: "CredentialRevoked";
|
|
73
|
+
StartingPromptIssued: "StartingPromptIssued";
|
|
74
|
+
OperatorPasswordReset: "OperatorPasswordReset";
|
|
75
|
+
MessageAccepted: "MessageAccepted";
|
|
76
|
+
DeliveryClaimed: "DeliveryClaimed";
|
|
77
|
+
DeliveryAcknowledged: "DeliveryAcknowledged";
|
|
78
|
+
DeliveryUndeliverable: "DeliveryUndeliverable";
|
|
79
|
+
DeliveryReturned: "DeliveryReturned";
|
|
80
|
+
}>;
|
|
81
|
+
export type EventType = z.infer<typeof eventTypeSchema>;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* The fleet's shared vocabulary (docs/blueprint.md, "Ubiquitous language"):
|
|
4
|
+
* scopes, ship kinds, ship statuses, lease locations, selector kinds, delivery
|
|
5
|
+
* states and event types. Server and web use the same words.
|
|
6
|
+
*/
|
|
7
|
+
/** A permission of a ship, stored on the server with the ship and checked before every call. */
|
|
8
|
+
export const SCOPES = ['messages:send', 'messages:receive', 'fleet:read', 'fleet:manage'];
|
|
9
|
+
export const scopeSchema = z.enum(SCOPES);
|
|
10
|
+
/** `argo` is the one ship of kind `operator` in a fleet; every other ship is an `agent`. */
|
|
11
|
+
export const SHIP_KINDS = ['operator', 'agent'];
|
|
12
|
+
export const shipKindSchema = z.enum(SHIP_KINDS);
|
|
13
|
+
/** Where the session crewing a ship runs. `OTHER` carries a short description. */
|
|
14
|
+
export const LOCATION_KINDS = ['DEVICE', 'CLOUD', 'SERVER', 'OTHER'];
|
|
15
|
+
export const locationKindSchema = z.enum(LOCATION_KINDS);
|
|
16
|
+
/**
|
|
17
|
+
* Whether a ship awaits crew, is crewed or is retired. Derived from its lease
|
|
18
|
+
* and its retired date, never set by hand.
|
|
19
|
+
*/
|
|
20
|
+
export const SHIP_STATUSES = ['awaitingCrew', 'crewed', 'retired'];
|
|
21
|
+
export const shipStatusSchema = z.enum(SHIP_STATUSES);
|
|
22
|
+
/** Who a message is for: one ship (by id or by name) or any ship of a type. Group and fleet come later. */
|
|
23
|
+
export const SELECTOR_KINDS = ['ship', 'type'];
|
|
24
|
+
export const selectorKindSchema = z.enum(SELECTOR_KINDS);
|
|
25
|
+
/**
|
|
26
|
+
* Where one delivery stands (docs/blueprint.md, "Key flows"): pending until a
|
|
27
|
+
* ship receives it, then delivered (claimed and in flight) until it is
|
|
28
|
+
* acknowledged or returns to pending.
|
|
29
|
+
*/
|
|
30
|
+
export const DELIVERY_STATES = ['pending', 'delivered', 'acknowledged', 'undeliverable', 'dismissed', 'abandoned'];
|
|
31
|
+
export const deliveryStateSchema = z.enum(DELIVERY_STATES);
|
|
32
|
+
/** The event types written so far. Each later slice adds the ones it writes. */
|
|
33
|
+
export const EVENT_TYPES = [
|
|
34
|
+
'FleetInitialised',
|
|
35
|
+
'ShipCommissioned',
|
|
36
|
+
'ShipClaimed',
|
|
37
|
+
'LeaseRevoked',
|
|
38
|
+
'CredentialRevoked',
|
|
39
|
+
'StartingPromptIssued',
|
|
40
|
+
'OperatorPasswordReset',
|
|
41
|
+
'MessageAccepted',
|
|
42
|
+
'DeliveryClaimed',
|
|
43
|
+
'DeliveryAcknowledged',
|
|
44
|
+
'DeliveryUndeliverable',
|
|
45
|
+
'DeliveryReturned',
|
|
46
|
+
];
|
|
47
|
+
export const eventTypeSchema = z.enum(EVENT_TYPES);
|
|
48
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/fleet/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;GAIG;AAEH,gGAAgG;AAChG,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,eAAe,EAAE,kBAAkB,EAAE,YAAY,EAAE,cAAc,CA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AAkB;CACV,CAAC;AACX,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prefixed, time-ordered ids (ADR 0005).
|
|
3
|
+
*
|
|
4
|
+
* An id is `<prefix>_<body>`. The body is a lowercase ULID: 26 Crockford base32
|
|
5
|
+
* characters holding a 48-bit Unix millisecond timestamp followed by 80 random
|
|
6
|
+
* bits. Because the alphabet is in ASCII order and the body has a fixed length,
|
|
7
|
+
* ids of one kind sort as plain text in creation order. Within one millisecond a
|
|
8
|
+
* generator increments the random part instead of drawing a new one, so the ids it
|
|
9
|
+
* hands out stay strictly ordered.
|
|
10
|
+
*/
|
|
11
|
+
import { z } from 'zod';
|
|
12
|
+
export declare const ID_PREFIXES: {
|
|
13
|
+
readonly fleet: "flt";
|
|
14
|
+
readonly ship: "shp";
|
|
15
|
+
readonly message: "msg";
|
|
16
|
+
readonly delivery: "dlv";
|
|
17
|
+
readonly event: "evt";
|
|
18
|
+
readonly lease: "lse";
|
|
19
|
+
readonly credential: "crd";
|
|
20
|
+
readonly operator: "opr";
|
|
21
|
+
readonly consoleSession: "ses";
|
|
22
|
+
};
|
|
23
|
+
export type IdKind = keyof typeof ID_PREFIXES;
|
|
24
|
+
/** Every kind of id, in the order of ID_PREFIXES. */
|
|
25
|
+
export declare const ID_KINDS: readonly IdKind[];
|
|
26
|
+
export type IdPrefix = (typeof ID_PREFIXES)[IdKind];
|
|
27
|
+
export type Id<K extends IdKind> = `${(typeof ID_PREFIXES)[K]}_${string}`;
|
|
28
|
+
export type FleetId = Id<'fleet'>;
|
|
29
|
+
export type ShipId = Id<'ship'>;
|
|
30
|
+
export type MessageId = Id<'message'>;
|
|
31
|
+
export type DeliveryId = Id<'delivery'>;
|
|
32
|
+
export type EventId = Id<'event'>;
|
|
33
|
+
export type LeaseId = Id<'lease'>;
|
|
34
|
+
export type CredentialId = Id<'credential'>;
|
|
35
|
+
export type OperatorId = Id<'operator'>;
|
|
36
|
+
export type ConsoleSessionId = Id<'consoleSession'>;
|
|
37
|
+
export interface IdGeneratorOptions {
|
|
38
|
+
/** Milliseconds since the Unix epoch. Defaults to `Date.now`. */
|
|
39
|
+
now?: () => number;
|
|
40
|
+
/** Fills the given array with random bytes. Defaults to Web Crypto. */
|
|
41
|
+
fillRandom?: (bytes: Uint8Array<ArrayBuffer>) => void;
|
|
42
|
+
}
|
|
43
|
+
export type IdGenerator = <K extends IdKind>(kind: K) => Id<K>;
|
|
44
|
+
/**
|
|
45
|
+
* Creates an id generator. Each generator keeps its own monotonic state, so ids
|
|
46
|
+
* from one generator never go backwards, even within a millisecond or when the
|
|
47
|
+
* clock steps back.
|
|
48
|
+
*/
|
|
49
|
+
export declare function createIdGenerator(options?: IdGeneratorOptions): IdGenerator;
|
|
50
|
+
export interface ParsedId {
|
|
51
|
+
kind: IdKind;
|
|
52
|
+
/** The millisecond the id was created, taken from its body. */
|
|
53
|
+
timestamp: Date;
|
|
54
|
+
}
|
|
55
|
+
/** Parses an id of any known kind. Returns undefined when the value is not a well-formed id. */
|
|
56
|
+
export declare function parseId(value: string): ParsedId | undefined;
|
|
57
|
+
/** True when the value is a well-formed id of the given kind. */
|
|
58
|
+
export declare function isId<K extends IdKind>(value: unknown, kind: K): value is Id<K>;
|
|
59
|
+
/**
|
|
60
|
+
* Parses an id of one kind arriving from outside (a request, the database) into
|
|
61
|
+
* its typed id. A template literal rather than a custom check, so the schema
|
|
62
|
+
* also describes itself in JSON Schema: a string of the prefix and a body,
|
|
63
|
+
* named by its kind, for the REST and MCP doors that explain themselves.
|
|
64
|
+
*/
|
|
65
|
+
export declare function idSchema<K extends IdKind>(kind: K): z.ZodType<Id<K>>;
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prefixed, time-ordered ids (ADR 0005).
|
|
3
|
+
*
|
|
4
|
+
* An id is `<prefix>_<body>`. The body is a lowercase ULID: 26 Crockford base32
|
|
5
|
+
* characters holding a 48-bit Unix millisecond timestamp followed by 80 random
|
|
6
|
+
* bits. Because the alphabet is in ASCII order and the body has a fixed length,
|
|
7
|
+
* ids of one kind sort as plain text in creation order. Within one millisecond a
|
|
8
|
+
* generator increments the random part instead of drawing a new one, so the ids it
|
|
9
|
+
* hands out stay strictly ordered.
|
|
10
|
+
*/
|
|
11
|
+
import { z } from 'zod';
|
|
12
|
+
export const ID_PREFIXES = {
|
|
13
|
+
fleet: 'flt',
|
|
14
|
+
ship: 'shp',
|
|
15
|
+
message: 'msg',
|
|
16
|
+
delivery: 'dlv',
|
|
17
|
+
event: 'evt',
|
|
18
|
+
lease: 'lse',
|
|
19
|
+
credential: 'crd',
|
|
20
|
+
operator: 'opr',
|
|
21
|
+
consoleSession: 'ses',
|
|
22
|
+
};
|
|
23
|
+
function isIdKind(value) {
|
|
24
|
+
return value in ID_PREFIXES;
|
|
25
|
+
}
|
|
26
|
+
/** Every kind of id, in the order of ID_PREFIXES. */
|
|
27
|
+
export const ID_KINDS = Object.keys(ID_PREFIXES).filter(isIdKind);
|
|
28
|
+
/** Crockford base32, lowercase. Leaves out i, l, o and u. */
|
|
29
|
+
const ALPHABET = '0123456789abcdefghjkmnpqrstvwxyz';
|
|
30
|
+
const TIME_LENGTH = 10;
|
|
31
|
+
const RANDOM_BYTES = 10;
|
|
32
|
+
const MAX_TIME = 2 ** 48 - 1;
|
|
33
|
+
const BODY_PATTERN = /^[0-7][0-9a-hjkmnp-tv-z]{25}$/;
|
|
34
|
+
const KIND_BY_PREFIX = new Map(ID_KINDS.map((kind) => [ID_PREFIXES[kind], kind]));
|
|
35
|
+
/**
|
|
36
|
+
* Creates an id generator. Each generator keeps its own monotonic state, so ids
|
|
37
|
+
* from one generator never go backwards, even within a millisecond or when the
|
|
38
|
+
* clock steps back.
|
|
39
|
+
*/
|
|
40
|
+
export function createIdGenerator(options = {}) {
|
|
41
|
+
const now = options.now ?? Date.now;
|
|
42
|
+
const fillRandom = options.fillRandom ??
|
|
43
|
+
((bytes) => {
|
|
44
|
+
globalThis.crypto.getRandomValues(bytes);
|
|
45
|
+
});
|
|
46
|
+
let lastTime = -1;
|
|
47
|
+
const random = new Uint8Array(RANDOM_BYTES);
|
|
48
|
+
return (kind) => {
|
|
49
|
+
const time = now();
|
|
50
|
+
if (!Number.isInteger(time) || time < 0 || time > MAX_TIME) {
|
|
51
|
+
throw new RangeError(`Id time must be an integer between 0 and ${String(MAX_TIME)}, got ${String(time)}`);
|
|
52
|
+
}
|
|
53
|
+
if (time > lastTime) {
|
|
54
|
+
lastTime = time;
|
|
55
|
+
fillRandom(random);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
increment(random);
|
|
59
|
+
}
|
|
60
|
+
const body = encodeTime(lastTime) + encodeRandom(random);
|
|
61
|
+
return `${ID_PREFIXES[kind]}_${body}`;
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/** Parses an id of any known kind. Returns undefined when the value is not a well-formed id. */
|
|
65
|
+
export function parseId(value) {
|
|
66
|
+
const separator = value.indexOf('_');
|
|
67
|
+
if (separator === -1) {
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
const kind = KIND_BY_PREFIX.get(value.slice(0, separator));
|
|
71
|
+
const body = value.slice(separator + 1);
|
|
72
|
+
if (kind === undefined || !BODY_PATTERN.test(body)) {
|
|
73
|
+
return undefined;
|
|
74
|
+
}
|
|
75
|
+
return { kind, timestamp: new Date(decodeTime(body.slice(0, TIME_LENGTH))) };
|
|
76
|
+
}
|
|
77
|
+
/** True when the value is a well-formed id of the given kind. */
|
|
78
|
+
export function isId(value, kind) {
|
|
79
|
+
return typeof value === 'string' && parseId(value)?.kind === kind;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Parses an id of one kind arriving from outside (a request, the database) into
|
|
83
|
+
* its typed id. A template literal rather than a custom check, so the schema
|
|
84
|
+
* also describes itself in JSON Schema: a string of the prefix and a body,
|
|
85
|
+
* named by its kind, for the REST and MCP doors that explain themselves.
|
|
86
|
+
*/
|
|
87
|
+
export function idSchema(kind) {
|
|
88
|
+
const named = `${kind} id (${ID_PREFIXES[kind]}_...)`;
|
|
89
|
+
return z
|
|
90
|
+
.templateLiteral([ID_PREFIXES[kind], '_', z.string().regex(BODY_PATTERN)], { error: `must be a ${named}` })
|
|
91
|
+
.meta({ description: `A ${named}` });
|
|
92
|
+
}
|
|
93
|
+
function encodeTime(time) {
|
|
94
|
+
let remaining = time;
|
|
95
|
+
let encoded = '';
|
|
96
|
+
for (let index = 0; index < TIME_LENGTH; index += 1) {
|
|
97
|
+
const digit = remaining % 32;
|
|
98
|
+
encoded = charAt(digit) + encoded;
|
|
99
|
+
remaining = (remaining - digit) / 32;
|
|
100
|
+
}
|
|
101
|
+
return encoded;
|
|
102
|
+
}
|
|
103
|
+
function decodeTime(encoded) {
|
|
104
|
+
let time = 0;
|
|
105
|
+
for (const char of encoded) {
|
|
106
|
+
time = time * 32 + ALPHABET.indexOf(char);
|
|
107
|
+
}
|
|
108
|
+
return time;
|
|
109
|
+
}
|
|
110
|
+
/** Encodes 80 bits as 16 base32 characters, most significant bits first. */
|
|
111
|
+
function encodeRandom(bytes) {
|
|
112
|
+
let encoded = '';
|
|
113
|
+
let buffer = 0;
|
|
114
|
+
let bits = 0;
|
|
115
|
+
for (const byte of bytes) {
|
|
116
|
+
buffer = (buffer << 8) | byte;
|
|
117
|
+
bits += 8;
|
|
118
|
+
while (bits >= 5) {
|
|
119
|
+
bits -= 5;
|
|
120
|
+
encoded += charAt((buffer >> bits) & 31);
|
|
121
|
+
}
|
|
122
|
+
buffer &= (1 << bits) - 1;
|
|
123
|
+
}
|
|
124
|
+
return encoded;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Adds one to the random part, big-endian. Running out of room within one
|
|
128
|
+
* millisecond is an error, and leaves the bytes as they were so a later call
|
|
129
|
+
* can never hand out a smaller id.
|
|
130
|
+
*/
|
|
131
|
+
function increment(bytes) {
|
|
132
|
+
if (bytes.every((byte) => byte === 255)) {
|
|
133
|
+
throw new RangeError('Id random part overflowed within one millisecond');
|
|
134
|
+
}
|
|
135
|
+
for (let index = bytes.length - 1; index >= 0; index -= 1) {
|
|
136
|
+
const byte = bytes[index] ?? 0;
|
|
137
|
+
if (byte < 255) {
|
|
138
|
+
bytes[index] = byte + 1;
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
bytes[index] = 0;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
function charAt(digit) {
|
|
145
|
+
const char = ALPHABET[digit];
|
|
146
|
+
if (char === undefined) {
|
|
147
|
+
throw new RangeError(`Not a base32 digit: ${String(digit)}`);
|
|
148
|
+
}
|
|
149
|
+
return char;
|
|
150
|
+
}
|
|
151
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ids/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,KAAK,EAAE,KAAK;IACZ,IAAI,EAAE,KAAK;IACX,OAAO,EAAE,KAAK;IACd,QAAQ,EAAE,KAAK;IACf,KAAK,EAAE,KAAK;IACZ,KAAK,EAAE,KAAK;IACZ,UAAU,EAAE,KAAK;IACjB,QAAQ,EAAE,KAAK;IACf,cAAc,EAAE,KAAK;CACb,CAAC;AAIX,SAAS,QAAQ,CAAC,KAAa;IAC7B,OAAO,KAAK,IAAI,WAAW,CAAC;AAC9B,CAAC;AAED,qDAAqD;AACrD,MAAM,CAAC,MAAM,QAAQ,GAAsB,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;AAcrF,6DAA6D;AAC7D,MAAM,QAAQ,GAAG,kCAAkC,CAAC;AACpD,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ACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/** The operator's email: at most 254 characters, the longest address mail carries. */
|
|
3
|
+
export declare const OPERATOR_EMAIL_MAX_LENGTH = 254;
|
|
4
|
+
/** One @ with something on each side, and no whitespace. */
|
|
5
|
+
export declare const OPERATOR_EMAIL_PATTERN: RegExp;
|
|
6
|
+
/**
|
|
7
|
+
* Any operator password up to this length: no strength rules (ADR 0016). The
|
|
8
|
+
* bound only keeps an absurd input from reaching the password hash.
|
|
9
|
+
*/
|
|
10
|
+
export declare const OPERATOR_PASSWORD_MAX_LENGTH = 1024;
|
|
11
|
+
/**
|
|
12
|
+
* Input of `console.signIn`: the operator's email and password. Whitespace
|
|
13
|
+
* around the email is dropped; the password is taken exactly as typed. The
|
|
14
|
+
* email's shape is not checked here: an email the server does not know is
|
|
15
|
+
* simply wrong, like a wrong password.
|
|
16
|
+
*/
|
|
17
|
+
export declare const signInInputSchema: z.ZodObject<{
|
|
18
|
+
email: z.ZodString;
|
|
19
|
+
password: z.ZodString;
|
|
20
|
+
}, z.core.$strip>;
|
|
21
|
+
export type SignInInput = z.infer<typeof signInInputSchema>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/** The operator's email: at most 254 characters, the longest address mail carries. */
|
|
3
|
+
export const OPERATOR_EMAIL_MAX_LENGTH = 254;
|
|
4
|
+
/** One @ with something on each side, and no whitespace. */
|
|
5
|
+
export const OPERATOR_EMAIL_PATTERN = /^[^\s@]+@[^\s@]+$/;
|
|
6
|
+
/**
|
|
7
|
+
* Any operator password up to this length: no strength rules (ADR 0016). The
|
|
8
|
+
* bound only keeps an absurd input from reaching the password hash.
|
|
9
|
+
*/
|
|
10
|
+
export const OPERATOR_PASSWORD_MAX_LENGTH = 1024;
|
|
11
|
+
/**
|
|
12
|
+
* Input of `console.signIn`: the operator's email and password. Whitespace
|
|
13
|
+
* around the email is dropped; the password is taken exactly as typed. The
|
|
14
|
+
* email's shape is not checked here: an email the server does not know is
|
|
15
|
+
* simply wrong, like a wrong password.
|
|
16
|
+
*/
|
|
17
|
+
export const signInInputSchema = z.object({
|
|
18
|
+
email: z.string().trim().min(1, 'Enter your email').max(OPERATOR_EMAIL_MAX_LENGTH),
|
|
19
|
+
password: z.string().min(1, 'Enter your password').max(OPERATOR_PASSWORD_MAX_LENGTH),
|
|
20
|
+
});
|
|
21
|
+
//# sourceMappingURL=console.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"console.js","sourceRoot":"","sources":["../../src/schemas/console.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,sFAAsF;AACtF,MAAM,CAAC,MAAM,yBAAyB,GAAG,GAAG,CAAC;AAC7C,4DAA4D;AAC5D,MAAM,CAAC,MAAM,sBAAsB,GAAG,mBAAmB,CAAC;AAC1D;;;GAGG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG,IAAI,CAAC;AAEjD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC;IACxC,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,kBAAkB,CAAC,CAAC,GAAG,CAAC,yBAAyB,CAAC;IAClF,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,qBAAqB,CAAC,CAAC,GAAG,CAAC,4BAA4B,CAAC;CACrF,CAAC,CAAC"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Inputs and outputs of receiving and acknowledging deliveries (`ship.receive`
|
|
4
|
+
* and `ship.ack`): how many deliveries a ship takes at once, what it gets for
|
|
5
|
+
* each, and which one it acknowledges.
|
|
6
|
+
*/
|
|
7
|
+
/** How many deliveries a receive returns when the ship does not say. */
|
|
8
|
+
export declare const RECEIVE_MAX_DEFAULT = 1;
|
|
9
|
+
/**
|
|
10
|
+
* The most deliveries one receive returns. The ship chooses up to this many
|
|
11
|
+
* (ADR 0016); the bound keeps one answer at ten 64 KB payloads.
|
|
12
|
+
*/
|
|
13
|
+
export declare const RECEIVE_MAX_UPPER_BOUND = 10;
|
|
14
|
+
/** Input of `ship.receive`: at most how many deliveries to return, 1 to 10. Without it, one. */
|
|
15
|
+
export declare const receiveInputSchema: z.ZodOptional<z.ZodObject<{
|
|
16
|
+
max: z.ZodOptional<z.ZodInt>;
|
|
17
|
+
}, z.core.$strip>>;
|
|
18
|
+
export type ReceiveInput = z.infer<typeof receiveInputSchema>;
|
|
19
|
+
/**
|
|
20
|
+
* Who a delivery is for, as its message's selector resolved at send time: one
|
|
21
|
+
* ship by its id, or the queue of a type.
|
|
22
|
+
*/
|
|
23
|
+
export declare const recipientSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
24
|
+
kind: z.ZodLiteral<"ship">;
|
|
25
|
+
shipId: z.ZodType<`shp_${string}`, unknown, z.core.$ZodTypeInternals<`shp_${string}`, unknown>>;
|
|
26
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
27
|
+
kind: z.ZodLiteral<"type">;
|
|
28
|
+
type: z.ZodString;
|
|
29
|
+
}, z.core.$strip>], "kind">;
|
|
30
|
+
/**
|
|
31
|
+
* One delivery a receive hands the ship, with its message. It stays in flight
|
|
32
|
+
* until the ship acknowledges it; the same crew's next receive returns it
|
|
33
|
+
* again, so the delivery id is the ship's idempotency key.
|
|
34
|
+
*/
|
|
35
|
+
export declare const receivedDeliverySchema: z.ZodObject<{
|
|
36
|
+
deliveryId: z.ZodType<`dlv_${string}`, unknown, z.core.$ZodTypeInternals<`dlv_${string}`, unknown>>;
|
|
37
|
+
messageId: z.ZodType<`msg_${string}`, unknown, z.core.$ZodTypeInternals<`msg_${string}`, unknown>>;
|
|
38
|
+
senderShipId: z.ZodType<`shp_${string}`, unknown, z.core.$ZodTypeInternals<`shp_${string}`, unknown>>;
|
|
39
|
+
senderName: z.ZodString;
|
|
40
|
+
senderType: z.ZodString;
|
|
41
|
+
recipient: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
42
|
+
kind: z.ZodLiteral<"ship">;
|
|
43
|
+
shipId: z.ZodType<`shp_${string}`, unknown, z.core.$ZodTypeInternals<`shp_${string}`, unknown>>;
|
|
44
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
45
|
+
kind: z.ZodLiteral<"type">;
|
|
46
|
+
type: z.ZodString;
|
|
47
|
+
}, z.core.$strip>], "kind">;
|
|
48
|
+
payload: z.ZodString;
|
|
49
|
+
contentType: z.ZodString;
|
|
50
|
+
inReplyTo: z.ZodNullable<z.ZodType<`msg_${string}`, unknown, z.core.$ZodTypeInternals<`msg_${string}`, unknown>>>;
|
|
51
|
+
sentAt: z.ZodISODateTime;
|
|
52
|
+
attempts: z.ZodInt;
|
|
53
|
+
}, z.core.$strip>;
|
|
54
|
+
export type ReceivedDelivery = z.infer<typeof receivedDeliverySchema>;
|
|
55
|
+
/** Output of `ship.receive`: the deliveries claimed, none when the wait ended without one. */
|
|
56
|
+
export declare const receiveOutputSchema: z.ZodObject<{
|
|
57
|
+
deliveries: z.ZodArray<z.ZodObject<{
|
|
58
|
+
deliveryId: z.ZodType<`dlv_${string}`, unknown, z.core.$ZodTypeInternals<`dlv_${string}`, unknown>>;
|
|
59
|
+
messageId: z.ZodType<`msg_${string}`, unknown, z.core.$ZodTypeInternals<`msg_${string}`, unknown>>;
|
|
60
|
+
senderShipId: z.ZodType<`shp_${string}`, unknown, z.core.$ZodTypeInternals<`shp_${string}`, unknown>>;
|
|
61
|
+
senderName: z.ZodString;
|
|
62
|
+
senderType: z.ZodString;
|
|
63
|
+
recipient: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
64
|
+
kind: z.ZodLiteral<"ship">;
|
|
65
|
+
shipId: z.ZodType<`shp_${string}`, unknown, z.core.$ZodTypeInternals<`shp_${string}`, unknown>>;
|
|
66
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
67
|
+
kind: z.ZodLiteral<"type">;
|
|
68
|
+
type: z.ZodString;
|
|
69
|
+
}, z.core.$strip>], "kind">;
|
|
70
|
+
payload: z.ZodString;
|
|
71
|
+
contentType: z.ZodString;
|
|
72
|
+
inReplyTo: z.ZodNullable<z.ZodType<`msg_${string}`, unknown, z.core.$ZodTypeInternals<`msg_${string}`, unknown>>>;
|
|
73
|
+
sentAt: z.ZodISODateTime;
|
|
74
|
+
attempts: z.ZodInt;
|
|
75
|
+
}, z.core.$strip>>;
|
|
76
|
+
}, z.core.$strip>;
|
|
77
|
+
export type ReceiveOutput = z.infer<typeof receiveOutputSchema>;
|
|
78
|
+
/** Input of `ship.ack`: the delivery the calling ship received and takes responsibility for. */
|
|
79
|
+
export declare const ackInputSchema: z.ZodObject<{
|
|
80
|
+
deliveryId: z.ZodType<`dlv_${string}`, unknown, z.core.$ZodTypeInternals<`dlv_${string}`, unknown>>;
|
|
81
|
+
}, z.core.$strip>;
|
|
82
|
+
export type AckInput = z.infer<typeof ackInputSchema>;
|
|
83
|
+
/** Output of `ship.ack`: nothing; the OK is the answer. */
|
|
84
|
+
export declare const ackOutputSchema: z.ZodObject<{}, z.core.$strict>;
|
|
85
|
+
export type AckOutput = z.infer<typeof ackOutputSchema>;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { idSchema } from '../ids/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Inputs and outputs of receiving and acknowledging deliveries (`ship.receive`
|
|
5
|
+
* and `ship.ack`): how many deliveries a ship takes at once, what it gets for
|
|
6
|
+
* each, and which one it acknowledges.
|
|
7
|
+
*/
|
|
8
|
+
/** How many deliveries a receive returns when the ship does not say. */
|
|
9
|
+
export const RECEIVE_MAX_DEFAULT = 1;
|
|
10
|
+
/**
|
|
11
|
+
* The most deliveries one receive returns. The ship chooses up to this many
|
|
12
|
+
* (ADR 0016); the bound keeps one answer at ten 64 KB payloads.
|
|
13
|
+
*/
|
|
14
|
+
export const RECEIVE_MAX_UPPER_BOUND = 10;
|
|
15
|
+
/** Input of `ship.receive`: at most how many deliveries to return, 1 to 10. Without it, one. */
|
|
16
|
+
export const receiveInputSchema = z
|
|
17
|
+
.object({ max: z.int().min(1).max(RECEIVE_MAX_UPPER_BOUND).optional() })
|
|
18
|
+
.optional();
|
|
19
|
+
/**
|
|
20
|
+
* Who a delivery is for, as its message's selector resolved at send time: one
|
|
21
|
+
* ship by its id, or the queue of a type.
|
|
22
|
+
*/
|
|
23
|
+
export const recipientSchema = z.discriminatedUnion('kind', [
|
|
24
|
+
z.object({ kind: z.literal('ship'), shipId: idSchema('ship') }),
|
|
25
|
+
z.object({ kind: z.literal('type'), type: z.string() }),
|
|
26
|
+
]);
|
|
27
|
+
/**
|
|
28
|
+
* One delivery a receive hands the ship, with its message. It stays in flight
|
|
29
|
+
* until the ship acknowledges it; the same crew's next receive returns it
|
|
30
|
+
* again, so the delivery id is the ship's idempotency key.
|
|
31
|
+
*/
|
|
32
|
+
export const receivedDeliverySchema = z.object({
|
|
33
|
+
deliveryId: idSchema('delivery'),
|
|
34
|
+
messageId: idSchema('message'),
|
|
35
|
+
senderShipId: idSchema('ship'),
|
|
36
|
+
/** The sender's name and type as they are when the delivery is received: a renamed sender goes by its new name. */
|
|
37
|
+
senderName: z.string(),
|
|
38
|
+
senderType: z.string(),
|
|
39
|
+
recipient: recipientSchema,
|
|
40
|
+
payload: z.string(),
|
|
41
|
+
contentType: z.string(),
|
|
42
|
+
/** The message this one replies to, if any. */
|
|
43
|
+
inReplyTo: idSchema('message').nullable(),
|
|
44
|
+
/** When the message was sent. ISO 8601 in UTC. */
|
|
45
|
+
sentAt: z.iso.datetime(),
|
|
46
|
+
/** How many times the delivery has been claimed, this receive included. */
|
|
47
|
+
attempts: z.int().positive(),
|
|
48
|
+
});
|
|
49
|
+
/** Output of `ship.receive`: the deliveries claimed, none when the wait ended without one. */
|
|
50
|
+
export const receiveOutputSchema = z.object({
|
|
51
|
+
deliveries: z.array(receivedDeliverySchema).max(RECEIVE_MAX_UPPER_BOUND),
|
|
52
|
+
});
|
|
53
|
+
/** Input of `ship.ack`: the delivery the calling ship received and takes responsibility for. */
|
|
54
|
+
export const ackInputSchema = z.object({ deliveryId: idSchema('delivery') });
|
|
55
|
+
/** Output of `ship.ack`: nothing; the OK is the answer. */
|
|
56
|
+
export const ackOutputSchema = z.strictObject({});
|
|
57
|
+
//# sourceMappingURL=delivery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delivery.js","sourceRoot":"","sources":["../../src/schemas/delivery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE3C;;;;GAIG;AAEH,wEAAwE;AACxE,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC;AAErC;;;GAGG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,EAAE,CAAC;AAE1C,gGAAgG;AAChG,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC;KAChC,MAAM,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC;KACvE,QAAQ,EAAE,CAAC;AAId;;;GAGG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAC,kBAAkB,CAAC,MAAM,EAAE;IAC1D,CAAC,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,EAAE,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,CAAC,CAAC"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Inputs and outputs of the fleet procedures: commission a ship, get its
|
|
4
|
+
* starting prompt, release it, list the fleet.
|
|
5
|
+
*/
|
|
6
|
+
/** A ship's name and its type are handles (docs/blueprint.md, "Ship"). */
|
|
7
|
+
export declare const SHIP_HANDLE_MAX_LENGTH = 48;
|
|
8
|
+
export declare const SHIP_HANDLE_PATTERN: RegExp;
|
|
9
|
+
export declare const shipHandleSchema: z.ZodString;
|
|
10
|
+
export declare const SHIP_NOTE_MAX_LENGTH = 500;
|
|
11
|
+
/** Input of `fleet.commission`. The note is free text for the operator; whitespace around it is dropped. */
|
|
12
|
+
export declare const commissionShipInputSchema: z.ZodObject<{
|
|
13
|
+
name: z.ZodString;
|
|
14
|
+
type: z.ZodString;
|
|
15
|
+
note: z.ZodOptional<z.ZodString>;
|
|
16
|
+
}, z.core.$strip>;
|
|
17
|
+
export type CommissionShipInput = z.infer<typeof commissionShipInputSchema>;
|
|
18
|
+
/** Input of `fleet.getStartingPrompt`. */
|
|
19
|
+
export declare const getStartingPromptInputSchema: z.ZodObject<{
|
|
20
|
+
shipId: z.ZodType<`shp_${string}`, unknown, z.core.$ZodTypeInternals<`shp_${string}`, unknown>>;
|
|
21
|
+
}, z.core.$strip>;
|
|
22
|
+
/**
|
|
23
|
+
* Output of `fleet.commission` and `fleet.getStartingPrompt`: the starting
|
|
24
|
+
* prompt, holding the ship's new secret. Shown once; the secret is never
|
|
25
|
+
* readable again.
|
|
26
|
+
*/
|
|
27
|
+
export declare const startingPromptOutputSchema: z.ZodObject<{
|
|
28
|
+
shipId: z.ZodType<`shp_${string}`, unknown, z.core.$ZodTypeInternals<`shp_${string}`, unknown>>;
|
|
29
|
+
prompt: z.ZodString;
|
|
30
|
+
}, z.core.$strip>;
|
|
31
|
+
export type StartingPromptOutput = z.infer<typeof startingPromptOutputSchema>;
|
|
32
|
+
/** Input of `fleet.release`: the crewed ship whose session loses it. */
|
|
33
|
+
export declare const releaseShipInputSchema: z.ZodObject<{
|
|
34
|
+
shipId: z.ZodType<`shp_${string}`, unknown, z.core.$ZodTypeInternals<`shp_${string}`, unknown>>;
|
|
35
|
+
}, z.core.$strip>;
|
|
36
|
+
export type ReleaseShipInput = z.infer<typeof releaseShipInputSchema>;
|
|
37
|
+
/** Output of `fleet.release`: nothing; the OK is the answer. */
|
|
38
|
+
export declare const releaseShipOutputSchema: z.ZodObject<{}, z.core.$strict>;
|
|
39
|
+
/**
|
|
40
|
+
* One ship in `fleet.list`. `startingPrompt` is the prompt holding the ship's
|
|
41
|
+
* valid secret, when there is one: when it was issued and whether a session
|
|
42
|
+
* has claimed the ship with it. `location` is where the session crewing the
|
|
43
|
+
* ship runs, as it reported on claim; null while no session crews it.
|
|
44
|
+
*/
|
|
45
|
+
export declare const listedShipSchema: z.ZodObject<{
|
|
46
|
+
id: z.ZodType<`shp_${string}`, unknown, z.core.$ZodTypeInternals<`shp_${string}`, unknown>>;
|
|
47
|
+
name: z.ZodString;
|
|
48
|
+
type: z.ZodString;
|
|
49
|
+
kind: z.ZodEnum<{
|
|
50
|
+
operator: "operator";
|
|
51
|
+
agent: "agent";
|
|
52
|
+
}>;
|
|
53
|
+
status: z.ZodEnum<{
|
|
54
|
+
awaitingCrew: "awaitingCrew";
|
|
55
|
+
crewed: "crewed";
|
|
56
|
+
retired: "retired";
|
|
57
|
+
}>;
|
|
58
|
+
startingPrompt: z.ZodNullable<z.ZodObject<{
|
|
59
|
+
issuedAt: z.ZodISODateTime;
|
|
60
|
+
isClaimed: z.ZodBoolean;
|
|
61
|
+
}, z.core.$strip>>;
|
|
62
|
+
location: z.ZodNullable<z.ZodObject<{
|
|
63
|
+
kind: z.ZodEnum<{
|
|
64
|
+
DEVICE: "DEVICE";
|
|
65
|
+
CLOUD: "CLOUD";
|
|
66
|
+
SERVER: "SERVER";
|
|
67
|
+
OTHER: "OTHER";
|
|
68
|
+
}>;
|
|
69
|
+
description: z.ZodNullable<z.ZodString>;
|
|
70
|
+
}, z.core.$strip>>;
|
|
71
|
+
}, z.core.$strip>;
|
|
72
|
+
export type ListedShip = z.infer<typeof listedShipSchema>;
|
|
73
|
+
/** Output of `fleet.list`: every ship in the caller's fleet, `argo` included. */
|
|
74
|
+
export declare const fleetListOutputSchema: z.ZodArray<z.ZodObject<{
|
|
75
|
+
id: z.ZodType<`shp_${string}`, unknown, z.core.$ZodTypeInternals<`shp_${string}`, unknown>>;
|
|
76
|
+
name: z.ZodString;
|
|
77
|
+
type: z.ZodString;
|
|
78
|
+
kind: z.ZodEnum<{
|
|
79
|
+
operator: "operator";
|
|
80
|
+
agent: "agent";
|
|
81
|
+
}>;
|
|
82
|
+
status: z.ZodEnum<{
|
|
83
|
+
awaitingCrew: "awaitingCrew";
|
|
84
|
+
crewed: "crewed";
|
|
85
|
+
retired: "retired";
|
|
86
|
+
}>;
|
|
87
|
+
startingPrompt: z.ZodNullable<z.ZodObject<{
|
|
88
|
+
issuedAt: z.ZodISODateTime;
|
|
89
|
+
isClaimed: z.ZodBoolean;
|
|
90
|
+
}, z.core.$strip>>;
|
|
91
|
+
location: z.ZodNullable<z.ZodObject<{
|
|
92
|
+
kind: z.ZodEnum<{
|
|
93
|
+
DEVICE: "DEVICE";
|
|
94
|
+
CLOUD: "CLOUD";
|
|
95
|
+
SERVER: "SERVER";
|
|
96
|
+
OTHER: "OTHER";
|
|
97
|
+
}>;
|
|
98
|
+
description: z.ZodNullable<z.ZodString>;
|
|
99
|
+
}, z.core.$strip>>;
|
|
100
|
+
}, z.core.$strip>>;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { locationKindSchema, shipKindSchema, shipStatusSchema } from '../fleet/index.js';
|
|
3
|
+
import { idSchema } from '../ids/index.js';
|
|
4
|
+
/**
|
|
5
|
+
* Inputs and outputs of the fleet procedures: commission a ship, get its
|
|
6
|
+
* starting prompt, release it, list the fleet.
|
|
7
|
+
*/
|
|
8
|
+
/** A ship's name and its type are handles (docs/blueprint.md, "Ship"). */
|
|
9
|
+
export const SHIP_HANDLE_MAX_LENGTH = 48;
|
|
10
|
+
export const SHIP_HANDLE_PATTERN = /^[a-z0-9-]+$/;
|
|
11
|
+
const HANDLE_MESSAGE = `Use 1 to ${SHIP_HANDLE_MAX_LENGTH} lowercase letters, digits or hyphens`;
|
|
12
|
+
export const shipHandleSchema = z
|
|
13
|
+
.string()
|
|
14
|
+
.max(SHIP_HANDLE_MAX_LENGTH, HANDLE_MESSAGE)
|
|
15
|
+
.regex(SHIP_HANDLE_PATTERN, HANDLE_MESSAGE);
|
|
16
|
+
export const SHIP_NOTE_MAX_LENGTH = 500;
|
|
17
|
+
/** Input of `fleet.commission`. The note is free text for the operator; whitespace around it is dropped. */
|
|
18
|
+
export const commissionShipInputSchema = z.object({
|
|
19
|
+
name: shipHandleSchema,
|
|
20
|
+
type: shipHandleSchema,
|
|
21
|
+
note: z
|
|
22
|
+
.string()
|
|
23
|
+
.trim()
|
|
24
|
+
.max(SHIP_NOTE_MAX_LENGTH, `A note is at most ${SHIP_NOTE_MAX_LENGTH} characters`)
|
|
25
|
+
.optional(),
|
|
26
|
+
});
|
|
27
|
+
/** Input of `fleet.getStartingPrompt`. */
|
|
28
|
+
export const getStartingPromptInputSchema = z.object({ shipId: idSchema('ship') });
|
|
29
|
+
/**
|
|
30
|
+
* Output of `fleet.commission` and `fleet.getStartingPrompt`: the starting
|
|
31
|
+
* prompt, holding the ship's new secret. Shown once; the secret is never
|
|
32
|
+
* readable again.
|
|
33
|
+
*/
|
|
34
|
+
export const startingPromptOutputSchema = z.object({
|
|
35
|
+
shipId: idSchema('ship'),
|
|
36
|
+
prompt: z.string(),
|
|
37
|
+
});
|
|
38
|
+
/** Input of `fleet.release`: the crewed ship whose session loses it. */
|
|
39
|
+
export const releaseShipInputSchema = z.object({ shipId: idSchema('ship') });
|
|
40
|
+
/** Output of `fleet.release`: nothing; the OK is the answer. */
|
|
41
|
+
export const releaseShipOutputSchema = z.strictObject({});
|
|
42
|
+
/**
|
|
43
|
+
* One ship in `fleet.list`. `startingPrompt` is the prompt holding the ship's
|
|
44
|
+
* valid secret, when there is one: when it was issued and whether a session
|
|
45
|
+
* has claimed the ship with it. `location` is where the session crewing the
|
|
46
|
+
* ship runs, as it reported on claim; null while no session crews it.
|
|
47
|
+
*/
|
|
48
|
+
export const listedShipSchema = z.object({
|
|
49
|
+
id: idSchema('ship'),
|
|
50
|
+
name: z.string(),
|
|
51
|
+
type: z.string(),
|
|
52
|
+
/** `operator` for `argo`, `agent` for every other ship. */
|
|
53
|
+
kind: shipKindSchema,
|
|
54
|
+
status: shipStatusSchema,
|
|
55
|
+
startingPrompt: z
|
|
56
|
+
.object({
|
|
57
|
+
/** ISO 8601 in UTC. */
|
|
58
|
+
issuedAt: z.iso.datetime(),
|
|
59
|
+
isClaimed: z.boolean(),
|
|
60
|
+
})
|
|
61
|
+
.nullable(),
|
|
62
|
+
location: z
|
|
63
|
+
.object({
|
|
64
|
+
kind: locationKindSchema,
|
|
65
|
+
/** Set for OTHER only. */
|
|
66
|
+
description: z.string().nullable(),
|
|
67
|
+
})
|
|
68
|
+
.nullable(),
|
|
69
|
+
});
|
|
70
|
+
/** Output of `fleet.list`: every ship in the caller's fleet, `argo` included. */
|
|
71
|
+
export const fleetListOutputSchema = z.array(listedShipSchema);
|
|
72
|
+
//# sourceMappingURL=fleet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fleet.js","sourceRoot":"","sources":["../../src/schemas/fleet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACzF,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE3C;;;GAGG;AAEH,0EAA0E;AAC1E,MA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C,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC;IACvC,EAAE,EAAE,QAAQ,CAAC,MAAM,CAAC;IACpB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;IAChB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;IAChB,2DAA2D;IAC3D,IAAI,EAAE,cAAc;IACpB,MAAM,EAAE,gBAAgB;IACxB,cAAc,EAAE,CAAC;SACd,MAAM,CAAC;QACN,uBAAuB;QACvB,QAAQ,EAAE,CAAC,CAAC,GAAG,CAAC,QAAQ,EAAE;QAC1B,SAAS,EAAE,CAAC,CAAC,OAAO,EAAE;KACvB,CAAC;SACD,QAAQ,EAAE;IACb,QAAQ,EAAE,CAAC;SACR,MAAM,CAAC;QACN,IAAI,EAAE,kBAAkB;QACxB,0BAA0B;QAC1B,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;KACnC,CAAC;SACD,QAAQ,EAAE;CACd,CAAC,CAAC;AAIH,iFAAiF;AACjF,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/schemas/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Inputs and outputs of sending a message (`ship.send`): who it is for, its
|
|
4
|
+
* payload and content type, the sender's idempotency key, and the message it
|
|
5
|
+
* replies to.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* A payload is at most 64 KB (ADR 0006): a message carries a reference and an
|
|
9
|
+
* instruction, not the content itself.
|
|
10
|
+
*/
|
|
11
|
+
export declare const PAYLOAD_MAX_BYTES: number;
|
|
12
|
+
/**
|
|
13
|
+
* The size of a payload serialized: the bytes of its text in UTF-8, as the
|
|
14
|
+
* database stores it and counts it.
|
|
15
|
+
*/
|
|
16
|
+
export declare function payloadBytes(payload: string): number;
|
|
17
|
+
/** The longest content type a sender may give, parameters included. */
|
|
18
|
+
export declare const CONTENT_TYPE_MAX_LENGTH = 256;
|
|
19
|
+
/** A payload's content type when its sender does not say. */
|
|
20
|
+
export declare const CONTENT_TYPE_DEFAULT = "text/plain";
|
|
21
|
+
/** Whether the value is a well-formed media type: type/subtype with optional parameters (RFC 9110). */
|
|
22
|
+
export declare function isMediaType(value: string): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* A payload's content type: any well-formed media type, taken and passed on
|
|
25
|
+
* exactly as sent, case and parameters included. The fleet never reads the
|
|
26
|
+
* payload by it (ADR 0016: no policy).
|
|
27
|
+
*/
|
|
28
|
+
export declare const contentTypeSchema: z.ZodString;
|
|
29
|
+
/** The longest idempotency key a sender may give. It is opaque: any text of 1 to this many characters. */
|
|
30
|
+
export declare const IDEMPOTENCY_KEY_MAX_LENGTH = 256;
|
|
31
|
+
/**
|
|
32
|
+
* Who a message is for (docs/blueprint.md, "Selector"): one ship, by id or by
|
|
33
|
+
* name, or any ship of a type. A name is resolved to the ship's id at send time.
|
|
34
|
+
*/
|
|
35
|
+
export declare const selectorSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
36
|
+
kind: z.ZodLiteral<"ship">;
|
|
37
|
+
shipId: z.ZodType<`shp_${string}`, unknown, z.core.$ZodTypeInternals<`shp_${string}`, unknown>>;
|
|
38
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
39
|
+
kind: z.ZodLiteral<"ship">;
|
|
40
|
+
name: z.ZodString;
|
|
41
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
42
|
+
kind: z.ZodLiteral<"type">;
|
|
43
|
+
type: z.ZodString;
|
|
44
|
+
}, z.core.$strict>]>;
|
|
45
|
+
export type SelectorInput = z.infer<typeof selectorSchema>;
|
|
46
|
+
/** Input of `ship.send`. The sender is the calling ship, never named in the input. */
|
|
47
|
+
export declare const sendInputSchema: z.ZodObject<{
|
|
48
|
+
selector: z.ZodUnion<readonly [z.ZodObject<{
|
|
49
|
+
kind: z.ZodLiteral<"ship">;
|
|
50
|
+
shipId: z.ZodType<`shp_${string}`, unknown, z.core.$ZodTypeInternals<`shp_${string}`, unknown>>;
|
|
51
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
52
|
+
kind: z.ZodLiteral<"ship">;
|
|
53
|
+
name: z.ZodString;
|
|
54
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
55
|
+
kind: z.ZodLiteral<"type">;
|
|
56
|
+
type: z.ZodString;
|
|
57
|
+
}, z.core.$strict>]>;
|
|
58
|
+
payload: z.ZodString;
|
|
59
|
+
contentType: z.ZodOptional<z.ZodString>;
|
|
60
|
+
idempotencyKey: z.ZodString;
|
|
61
|
+
inReplyTo: z.ZodOptional<z.ZodType<`msg_${string}`, unknown, z.core.$ZodTypeInternals<`msg_${string}`, unknown>>>;
|
|
62
|
+
}, z.core.$strip>;
|
|
63
|
+
export type SendInput = z.infer<typeof sendInputSchema>;
|
|
64
|
+
/** Output of `ship.send`: the message's id, the original one when the idempotency key was used before. */
|
|
65
|
+
export declare const sendOutputSchema: z.ZodObject<{
|
|
66
|
+
messageId: z.ZodType<`msg_${string}`, unknown, z.core.$ZodTypeInternals<`msg_${string}`, unknown>>;
|
|
67
|
+
}, z.core.$strip>;
|
|
68
|
+
export type SendOutput = z.infer<typeof sendOutputSchema>;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { idSchema } from '../ids/index.js';
|
|
3
|
+
import { shipHandleSchema } from './fleet.js';
|
|
4
|
+
/**
|
|
5
|
+
* Inputs and outputs of sending a message (`ship.send`): who it is for, its
|
|
6
|
+
* payload and content type, the sender's idempotency key, and the message it
|
|
7
|
+
* replies to.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* A payload is at most 64 KB (ADR 0006): a message carries a reference and an
|
|
11
|
+
* instruction, not the content itself.
|
|
12
|
+
*/
|
|
13
|
+
export const PAYLOAD_MAX_BYTES = 64 * 1024;
|
|
14
|
+
const utf8 = new TextEncoder();
|
|
15
|
+
/**
|
|
16
|
+
* The size of a payload serialized: the bytes of its text in UTF-8, as the
|
|
17
|
+
* database stores it and counts it.
|
|
18
|
+
*/
|
|
19
|
+
export function payloadBytes(payload) {
|
|
20
|
+
return utf8.encode(payload).byteLength;
|
|
21
|
+
}
|
|
22
|
+
/** The longest content type a sender may give, parameters included. */
|
|
23
|
+
export const CONTENT_TYPE_MAX_LENGTH = 256;
|
|
24
|
+
/** A payload's content type when its sender does not say. */
|
|
25
|
+
export const CONTENT_TYPE_DEFAULT = 'text/plain';
|
|
26
|
+
// A media type as RFC 9110 defines it ("Media Type"): type "/" subtype, then
|
|
27
|
+
// parameters, each `;` name `=` a token or a quoted string, with optional
|
|
28
|
+
// spaces or tabs around the `;`. Empty parameters are allowed, as there.
|
|
29
|
+
const TOKEN = "[!#$%&'*+\\-.^_`|~0-9A-Za-z]+";
|
|
30
|
+
const QUOTED_STRING = '"(?:[\\t \\x21\\x23-\\x5B\\x5D-\\x7E\\x80-\\xFF]|\\\\[\\t \\x21-\\x7E\\x80-\\xFF])*"';
|
|
31
|
+
const SPACE = '[ \\t]*';
|
|
32
|
+
const MEDIA_TYPE = new RegExp(`^${TOKEN}/${TOKEN}(?:${SPACE};${SPACE}(?:${TOKEN}=(?:${TOKEN}|${QUOTED_STRING}))?)*$`);
|
|
33
|
+
/** Whether the value is a well-formed media type: type/subtype with optional parameters (RFC 9110). */
|
|
34
|
+
export function isMediaType(value) {
|
|
35
|
+
return MEDIA_TYPE.test(value);
|
|
36
|
+
}
|
|
37
|
+
const CONTENT_TYPE_MESSAGE = `A content type is a media type such as text/plain or application/json; charset=utf-8, of at most ${CONTENT_TYPE_MAX_LENGTH} characters`;
|
|
38
|
+
/**
|
|
39
|
+
* A payload's content type: any well-formed media type, taken and passed on
|
|
40
|
+
* exactly as sent, case and parameters included. The fleet never reads the
|
|
41
|
+
* payload by it (ADR 0016: no policy).
|
|
42
|
+
*/
|
|
43
|
+
export const contentTypeSchema = z
|
|
44
|
+
.string()
|
|
45
|
+
.max(CONTENT_TYPE_MAX_LENGTH, CONTENT_TYPE_MESSAGE)
|
|
46
|
+
.refine(isMediaType, CONTENT_TYPE_MESSAGE);
|
|
47
|
+
/** The longest idempotency key a sender may give. It is opaque: any text of 1 to this many characters. */
|
|
48
|
+
export const IDEMPOTENCY_KEY_MAX_LENGTH = 256;
|
|
49
|
+
/**
|
|
50
|
+
* Who a message is for (docs/blueprint.md, "Selector"): one ship, by id or by
|
|
51
|
+
* name, or any ship of a type. A name is resolved to the ship's id at send time.
|
|
52
|
+
*/
|
|
53
|
+
export const selectorSchema = z.union([
|
|
54
|
+
z.strictObject({ kind: z.literal('ship'), shipId: idSchema('ship') }),
|
|
55
|
+
z.strictObject({ kind: z.literal('ship'), name: shipHandleSchema }),
|
|
56
|
+
z.strictObject({ kind: z.literal('type'), type: shipHandleSchema }),
|
|
57
|
+
]);
|
|
58
|
+
/** Input of `ship.send`. The sender is the calling ship, never named in the input. */
|
|
59
|
+
export const sendInputSchema = z.object({
|
|
60
|
+
selector: selectorSchema,
|
|
61
|
+
payload: z
|
|
62
|
+
.string()
|
|
63
|
+
.refine((payload) => payloadBytes(payload) <= PAYLOAD_MAX_BYTES, `A payload is at most ${PAYLOAD_MAX_BYTES} bytes (64 KB) in UTF-8`),
|
|
64
|
+
/** Without it, the payload is text/plain. */
|
|
65
|
+
contentType: contentTypeSchema.optional(),
|
|
66
|
+
idempotencyKey: z.string().min(1).max(IDEMPOTENCY_KEY_MAX_LENGTH),
|
|
67
|
+
/** The id of the message, in the same fleet, that this one replies to. */
|
|
68
|
+
inReplyTo: idSchema('message').optional(),
|
|
69
|
+
});
|
|
70
|
+
/** Output of `ship.send`: the message's id, the original one when the idempotency key was used before. */
|
|
71
|
+
export const sendOutputSchema = z.object({ messageId: idSchema('message') });
|
|
72
|
+
//# sourceMappingURL=message.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message.js","sourceRoot":"","sources":["../../src/schemas/message.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAE9C;;;;GAIG;AAEH;;;GAGG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,EAAE,GAAG,IAAI,CAAC;AAE3C,MAAM,IAAI,GAAG,IAAI,WAAW,EAAE,CAAC;AAE/B;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAC,OAAe;IAC1C,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,UAAU,CAAC;AACzC,CAAC;AAED,uEAAuE;AACvE,MAAM,CAAC,MAAM,uBAAuB,GAAG,GAAG,CAAC;AAE3C,6DAA6D;AAC7D,MAAM,CAAC,MAAM,oBAAoB,GAAG,YAAY,CAAC;AAEjD,6EAA6E;AAC7E,0EAA0E;AAC1E,yEAAyE;AACzE,MAAM,KAAK,GAAG,+BAA+B,CAAC;AAC9C,MAAM,aAAa,GAAG,sFAAsF,CAAC;AAC7G,MAAM,KAAK,GAAG,SAAS,CAAC;AACxB,MAAM,UAAU,GAAG,IAAI,MAAM,CAAC,IAAI,KAAK,IAAI,KAAK,MAAM,KAAK,IAAI,KAAK,MAAM,KAAK,OAAO,KAAK,IAAI,aAAa,QAAQ,CAAC,CAAC;AAEtH,uGAAuG;AACvG,MAAM,UAAU,WAAW,CAAC,KAAa;IACvC,OAAO,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;A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E,SAAS,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC,QAAQ,EAAE;CAC1C,CAAC,CAAC;AAIH,0GAA0G;AAC1G,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Inputs and outputs of the ship procedures: `register` claims a ship with its
|
|
4
|
+
* secret and returns a crew token; `whoami` tells the caller which ship it is;
|
|
5
|
+
* `deregister` ends the caller's own lease.
|
|
6
|
+
*/
|
|
7
|
+
/** The longest description an OTHER location carries, not counting whitespace around it. */
|
|
8
|
+
export declare const LOCATION_DESCRIPTION_MAX_LENGTH = 100;
|
|
9
|
+
/**
|
|
10
|
+
* The longest ship secret `register` takes. A real one is much shorter; the
|
|
11
|
+
* bound only keeps an absurd input from reaching the hash.
|
|
12
|
+
*/
|
|
13
|
+
export declare const SHIP_SECRET_MAX_LENGTH = 256;
|
|
14
|
+
/**
|
|
15
|
+
* Where the session claiming a ship runs (docs/blueprint.md, "Location"):
|
|
16
|
+
* DEVICE, CLOUD or SERVER, or OTHER with a short description. Stored with the
|
|
17
|
+
* lease, never interpreted.
|
|
18
|
+
*/
|
|
19
|
+
export declare const locationSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
20
|
+
kind: z.ZodEnum<{
|
|
21
|
+
DEVICE: "DEVICE";
|
|
22
|
+
CLOUD: "CLOUD";
|
|
23
|
+
SERVER: "SERVER";
|
|
24
|
+
}>;
|
|
25
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
26
|
+
kind: z.ZodLiteral<"OTHER">;
|
|
27
|
+
description: z.ZodString;
|
|
28
|
+
}, z.core.$strict>], "kind">;
|
|
29
|
+
export type LocationInput = z.infer<typeof locationSchema>;
|
|
30
|
+
/** Input of `ship.register`: the ship id and secret from the starting prompt, and where the session runs. */
|
|
31
|
+
export declare const registerInputSchema: z.ZodObject<{
|
|
32
|
+
shipId: z.ZodType<`shp_${string}`, unknown, z.core.$ZodTypeInternals<`shp_${string}`, unknown>>;
|
|
33
|
+
secret: z.ZodString;
|
|
34
|
+
location: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
35
|
+
kind: z.ZodEnum<{
|
|
36
|
+
DEVICE: "DEVICE";
|
|
37
|
+
CLOUD: "CLOUD";
|
|
38
|
+
SERVER: "SERVER";
|
|
39
|
+
}>;
|
|
40
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
41
|
+
kind: z.ZodLiteral<"OTHER">;
|
|
42
|
+
description: z.ZodString;
|
|
43
|
+
}, z.core.$strict>], "kind">;
|
|
44
|
+
}, z.core.$strip>;
|
|
45
|
+
export type RegisterInput = z.infer<typeof registerInputSchema>;
|
|
46
|
+
/**
|
|
47
|
+
* Output of `ship.register`: the crew token every later ship call carries
|
|
48
|
+
* (ADR 0015). Returned once; only its hash is stored.
|
|
49
|
+
*/
|
|
50
|
+
export declare const registerOutputSchema: z.ZodObject<{
|
|
51
|
+
crewToken: z.ZodString;
|
|
52
|
+
}, z.core.$strip>;
|
|
53
|
+
export type RegisterOutput = z.infer<typeof registerOutputSchema>;
|
|
54
|
+
/** Output of `ship.whoami`: the caller's ship. */
|
|
55
|
+
export declare const whoamiOutputSchema: z.ZodObject<{
|
|
56
|
+
shipId: z.ZodType<`shp_${string}`, unknown, z.core.$ZodTypeInternals<`shp_${string}`, unknown>>;
|
|
57
|
+
fleetId: z.ZodType<`flt_${string}`, unknown, z.core.$ZodTypeInternals<`flt_${string}`, unknown>>;
|
|
58
|
+
name: z.ZodString;
|
|
59
|
+
type: z.ZodString;
|
|
60
|
+
}, z.core.$strip>;
|
|
61
|
+
export type WhoamiOutput = z.infer<typeof whoamiOutputSchema>;
|
|
62
|
+
/** Output of `ship.deregister`: nothing; the OK is the answer. */
|
|
63
|
+
export declare const deregisterOutputSchema: z.ZodObject<{}, z.core.$strict>;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { idSchema } from '../ids/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Inputs and outputs of the ship procedures: `register` claims a ship with its
|
|
5
|
+
* secret and returns a crew token; `whoami` tells the caller which ship it is;
|
|
6
|
+
* `deregister` ends the caller's own lease.
|
|
7
|
+
*/
|
|
8
|
+
/** The longest description an OTHER location carries, not counting whitespace around it. */
|
|
9
|
+
export const LOCATION_DESCRIPTION_MAX_LENGTH = 100;
|
|
10
|
+
/**
|
|
11
|
+
* The longest ship secret `register` takes. A real one is much shorter; the
|
|
12
|
+
* bound only keeps an absurd input from reaching the hash.
|
|
13
|
+
*/
|
|
14
|
+
export const SHIP_SECRET_MAX_LENGTH = 256;
|
|
15
|
+
/**
|
|
16
|
+
* Where the session claiming a ship runs (docs/blueprint.md, "Location"):
|
|
17
|
+
* DEVICE, CLOUD or SERVER, or OTHER with a short description. Stored with the
|
|
18
|
+
* lease, never interpreted.
|
|
19
|
+
*/
|
|
20
|
+
export const locationSchema = z.discriminatedUnion('kind', [
|
|
21
|
+
z.strictObject({ kind: z.enum(['DEVICE', 'CLOUD', 'SERVER']) }),
|
|
22
|
+
z.strictObject({
|
|
23
|
+
kind: z.literal('OTHER'),
|
|
24
|
+
description: z
|
|
25
|
+
.string()
|
|
26
|
+
.trim()
|
|
27
|
+
.min(1, 'An OTHER location needs a description')
|
|
28
|
+
.max(LOCATION_DESCRIPTION_MAX_LENGTH, `A description is at most ${LOCATION_DESCRIPTION_MAX_LENGTH} characters`),
|
|
29
|
+
}),
|
|
30
|
+
]);
|
|
31
|
+
/** Input of `ship.register`: the ship id and secret from the starting prompt, and where the session runs. */
|
|
32
|
+
export const registerInputSchema = z.object({
|
|
33
|
+
shipId: idSchema('ship'),
|
|
34
|
+
secret: z.string().min(1).max(SHIP_SECRET_MAX_LENGTH),
|
|
35
|
+
location: locationSchema,
|
|
36
|
+
});
|
|
37
|
+
/**
|
|
38
|
+
* Output of `ship.register`: the crew token every later ship call carries
|
|
39
|
+
* (ADR 0015). Returned once; only its hash is stored.
|
|
40
|
+
*/
|
|
41
|
+
export const registerOutputSchema = z.object({ crewToken: z.string() });
|
|
42
|
+
/** Output of `ship.whoami`: the caller's ship. */
|
|
43
|
+
export const whoamiOutputSchema = z.object({
|
|
44
|
+
shipId: idSchema('ship'),
|
|
45
|
+
fleetId: idSchema('fleet'),
|
|
46
|
+
name: z.string(),
|
|
47
|
+
type: z.string(),
|
|
48
|
+
});
|
|
49
|
+
/** Output of `ship.deregister`: nothing; the OK is the answer. */
|
|
50
|
+
export const deregisterOutputSchema = z.strictObject({});
|
|
51
|
+
//# sourceMappingURL=ship.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ship.js","sourceRoot":"","sources":["../../src/schemas/ship.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE3C;;;;GAIG;AAEH,4FAA4F;AAC5F,MAAM,CAAC,MAAM,+BAA+B,GAAG,GAAG,CAAC;AAEnD;;;GAGG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,GAAG,CAAC;AAE1C;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC,kBAAkB,CAAC,MAAM,EAAE;IACzD,CAAC,CAAC,YAAY,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC,EAAE,CAAC;IAC/D,CAAC,CAAC,YAAY,CAAC;QACb,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC;QACxB,WAAW,EAAE,CAAC;aACX,MAAM,EAAE;aACR,IAAI,EAAE;aACN,GAAG,CAAC,CAAC,EAAE,uCAAuC,CAAC;aAC/C,GAAG,CAAC,+BAA+B,EAAE,4BAA4B,+BAA+B,aAAa,CAAC;KAClH,CAAC;CACH,CAAC,CAAC;AAIH,6GAA6G;AAC7G,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC1C,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC;IACxB,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,sBAAsB,CAAC;IACrD,QAAQ,EAAE,cAAc;CACzB,CAAC,CAAC;AAIH;;;GAGG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;AAIxE,kDAAkD;AAClD,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,CAAC,MAAM,CAAC;IACzC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC;IACxB,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC;IAC1B,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;IAChB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;CACjB,CAAC,CAAC;AAIH,kEAAkE;AAClE,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/** Output of `system.ping`: the server's clock and how many fleets its database holds. */
|
|
3
|
+
export declare const pingOutputSchema: z.ZodObject<{
|
|
4
|
+
serverTime: z.ZodISODateTime;
|
|
5
|
+
fleetCount: z.ZodInt;
|
|
6
|
+
}, z.core.$strip>;
|
|
7
|
+
export type PingOutput = z.infer<typeof pingOutputSchema>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/** Output of `system.ping`: the server's clock and how many fleets its database holds. */
|
|
3
|
+
export const pingOutputSchema = z.object({
|
|
4
|
+
/** ISO 8601 in UTC. */
|
|
5
|
+
serverTime: z.iso.datetime(),
|
|
6
|
+
fleetCount: z.int().nonnegative(),
|
|
7
|
+
});
|
|
8
|
+
//# sourceMappingURL=system.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"system.js","sourceRoot":"","sources":["../../src/schemas/system.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,0FAA0F;AAC1F,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC;IACvC,uBAAuB;IACvB,UAAU,EAAE,CAAC,CAAC,GAAG,CAAC,QAAQ,EAAE;IAC5B,UAAU,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,WAAW,EAAE;CAClC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,28 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aeolus-fleet/common",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Aeolus
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Aeolus shared schemas, prefixed ids and types.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
|
-
"
|
|
7
|
-
"homepage": "https://github.com/ThomasHendrickx/aeolus-fleet#readme",
|
|
6
|
+
"type": "module",
|
|
8
7
|
"repository": {
|
|
9
8
|
"type": "git",
|
|
10
9
|
"url": "git+https://github.com/ThomasHendrickx/aeolus-fleet.git",
|
|
11
10
|
"directory": "packages/common"
|
|
12
11
|
},
|
|
13
|
-
"
|
|
14
|
-
"
|
|
12
|
+
"engines": {
|
|
13
|
+
"node": ">=26"
|
|
14
|
+
},
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"@aeolus-fleet/source": "./src/index.ts",
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"default": "./dist/index.js"
|
|
20
|
+
}
|
|
15
21
|
},
|
|
16
|
-
"keywords": [
|
|
17
|
-
"aeolus",
|
|
18
|
-
"agents",
|
|
19
|
-
"fleet",
|
|
20
|
-
"message-broker"
|
|
21
|
-
],
|
|
22
22
|
"files": [
|
|
23
|
-
"
|
|
23
|
+
"dist"
|
|
24
24
|
],
|
|
25
|
-
"
|
|
26
|
-
"
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "tsc --project tsconfig.build.json",
|
|
27
|
+
"typecheck": "tsc --project tsconfig.json"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"zod": "^4.6.5"
|
|
27
31
|
}
|
|
28
32
|
}
|