@aeolus-fleet/trierarch-plugin 0.39.0 → 0.39.2
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 +16 -8
- package/dist/adapters/crypto/sealed-box-sealer.d.ts +1 -1
- package/dist/adapters/fleet/console-sessions.js +3 -3
- package/dist/adapters/fleet/console-sessions.js.map +1 -1
- package/dist/adapters/fleet/rest-fleet-door.js +1 -1
- package/dist/adapters/fleet/rest-fleet-door.js.map +1 -1
- package/dist/adapters/prisma/fleet-forgetter.d.ts +1 -1
- package/dist/adapters/prisma/fleet-forgetter.js +2 -2
- package/dist/adapters/prisma/fleet-forgetter.js.map +1 -1
- package/dist/adapters/prisma/generated/browser.d.ts +32 -0
- package/dist/adapters/prisma/generated/client.d.ts +32 -0
- package/dist/adapters/prisma/generated/commonInputTypes.d.ts +150 -0
- package/dist/adapters/prisma/generated/internal/class.d.ts +44 -0
- package/dist/adapters/prisma/generated/internal/class.js +4 -4
- package/dist/adapters/prisma/generated/internal/class.js.map +1 -1
- package/dist/adapters/prisma/generated/internal/prismaNamespace.d.ts +360 -1
- package/dist/adapters/prisma/generated/internal/prismaNamespace.js +46 -1
- package/dist/adapters/prisma/generated/internal/prismaNamespace.js.map +1 -1
- package/dist/adapters/prisma/generated/internal/prismaNamespaceBrowser.d.ts +51 -0
- package/dist/adapters/prisma/generated/internal/prismaNamespaceBrowser.js +46 -1
- package/dist/adapters/prisma/generated/internal/prismaNamespaceBrowser.js.map +1 -1
- package/dist/adapters/prisma/generated/models/McpConfiguration.d.ts +1004 -0
- package/dist/adapters/prisma/generated/models/McpConfiguration.js +2 -0
- package/dist/adapters/prisma/generated/models/McpConfiguration.js.map +1 -0
- package/dist/adapters/prisma/generated/models/McpConfigurationEvent.d.ts +1141 -0
- package/dist/adapters/prisma/generated/models/McpConfigurationEvent.js +2 -0
- package/dist/adapters/prisma/generated/models/McpConfigurationEvent.js.map +1 -0
- package/dist/adapters/prisma/generated/models/McpDelivery.d.ts +1204 -0
- package/dist/adapters/prisma/generated/models/McpDelivery.js +2 -0
- package/dist/adapters/prisma/generated/models/McpDelivery.js.map +1 -0
- package/dist/adapters/prisma/generated/models/McpSecret.d.ts +948 -0
- package/dist/adapters/prisma/generated/models/McpSecret.js +2 -0
- package/dist/adapters/prisma/generated/models/McpSecret.js.map +1 -0
- package/dist/adapters/prisma/generated/models.d.ts +4 -0
- package/dist/adapters/prisma/mcp-configurations.d.ts +11 -0
- package/dist/adapters/prisma/mcp-configurations.js +44 -0
- package/dist/adapters/prisma/mcp-configurations.js.map +1 -0
- package/dist/adapters/prisma/mcp-deliveries.d.ts +9 -0
- package/dist/adapters/prisma/mcp-deliveries.js +47 -0
- package/dist/adapters/prisma/mcp-deliveries.js.map +1 -0
- package/dist/adapters/trpc/router.d.ts +63 -5
- package/dist/adapters/trpc/router.js +60 -2
- package/dist/adapters/trpc/router.js.map +1 -1
- package/dist/app.d.ts +2 -6
- package/dist/app.js +56 -59
- package/dist/app.js.map +1 -1
- package/dist/bin/aeolus-trierarch-plugin.js +1 -2
- package/dist/bin/aeolus-trierarch-plugin.js.map +1 -1
- package/dist/config.d.ts +6 -10
- package/dist/config.js +5 -54
- package/dist/config.js.map +1 -1
- package/dist/core/assignment/assign-crews.d.ts +5 -1
- package/dist/core/assignment/assign-crews.js +4 -2
- package/dist/core/assignment/assign-crews.js.map +1 -1
- package/dist/core/assignment/check-crew-settings.d.ts +3 -0
- package/dist/core/assignment/check-crew-settings.js +2 -1
- package/dist/core/assignment/check-crew-settings.js.map +1 -1
- package/dist/core/assignment/placement.d.ts +2 -0
- package/dist/core/assignment/placement.js +6 -2
- package/dist/core/assignment/placement.js.map +1 -1
- package/dist/core/assignment/read-placement.d.ts +7 -1
- package/dist/core/assignment/read-placement.js +14 -2
- package/dist/core/assignment/read-placement.js.map +1 -1
- package/dist/core/connection/ports.d.ts +2 -0
- package/dist/core/mcp-configuration/distribute-mcp-configuration.d.ts +38 -0
- package/dist/core/mcp-configuration/distribute-mcp-configuration.js +97 -0
- package/dist/core/mcp-configuration/distribute-mcp-configuration.js.map +1 -0
- package/dist/core/mcp-configuration/mcp-configuration.d.ts +107 -0
- package/dist/core/mcp-configuration/mcp-configuration.js +205 -0
- package/dist/core/mcp-configuration/mcp-configuration.js.map +1 -0
- package/dist/core/mcp-configuration/mcp-delivery.d.ts +59 -0
- package/dist/core/mcp-configuration/mcp-delivery.js +32 -0
- package/dist/core/mcp-configuration/mcp-delivery.js.map +1 -0
- package/dist/core/mcp-configuration/ports.d.ts +79 -0
- package/dist/core/mcp-configuration/ports.js.map +1 -0
- package/dist/core/mcp-configuration/read-mcp-configuration.d.ts +8 -0
- package/dist/core/mcp-configuration/read-mcp-configuration.js +6 -0
- package/dist/core/mcp-configuration/read-mcp-configuration.js.map +1 -0
- package/dist/core/mcp-configuration/replace-mcp-configuration.d.ts +24 -0
- package/dist/core/mcp-configuration/replace-mcp-configuration.js +30 -0
- package/dist/core/mcp-configuration/replace-mcp-configuration.js.map +1 -0
- package/dist/core/mcp-configuration/sealing-key.js.map +1 -0
- package/dist/core/mcp-configuration/take-mcp-configuration-message.d.ts +30 -0
- package/dist/core/mcp-configuration/take-mcp-configuration-message.js +74 -0
- package/dist/core/mcp-configuration/take-mcp-configuration-message.js.map +1 -0
- package/dist/core/operator/authenticate-operator.d.ts +3 -1
- package/dist/core/operator/authenticate-operator.js +7 -4
- package/dist/core/operator/authenticate-operator.js.map +1 -1
- package/dist/core/operator/ports.d.ts +2 -1
- package/dist/core/shared/errors.d.ts +1 -1
- package/dist/core/shared/errors.js.map +1 -1
- package/package.json +1 -1
- package/src/adapters/prisma/migrations/20261109120000_mcp_configurations/migration.sql +35 -0
- package/src/adapters/prisma/migrations/20261109130000_mcp_deliveries/migration.sql +15 -0
- package/src/adapters/prisma/schema.prisma +65 -0
- package/dist/core/mcp-servers/mcp-servers.d.ts +0 -46
- package/dist/core/mcp-servers/mcp-servers.js +0 -112
- package/dist/core/mcp-servers/mcp-servers.js.map +0 -1
- package/dist/core/mcp-servers/ports.d.ts +0 -13
- package/dist/core/mcp-servers/ports.js.map +0 -1
- package/dist/core/mcp-servers/resend-mcp-servers.d.ts +0 -15
- package/dist/core/mcp-servers/resend-mcp-servers.js +0 -19
- package/dist/core/mcp-servers/resend-mcp-servers.js.map +0 -1
- package/dist/core/mcp-servers/resend-secrets.d.ts +0 -15
- package/dist/core/mcp-servers/resend-secrets.js +0 -19
- package/dist/core/mcp-servers/resend-secrets.js.map +0 -1
- package/dist/core/mcp-servers/sealing-key.js.map +0 -1
- package/dist/core/mcp-servers/secrets.d.ts +0 -31
- package/dist/core/mcp-servers/secrets.js +0 -90
- package/dist/core/mcp-servers/secrets.js.map +0 -1
- package/dist/core/mcp-servers/share-mcp-servers.d.ts +0 -25
- package/dist/core/mcp-servers/share-mcp-servers.js +0 -45
- package/dist/core/mcp-servers/share-mcp-servers.js.map +0 -1
- package/dist/core/mcp-servers/share-secrets.d.ts +0 -36
- package/dist/core/mcp-servers/share-secrets.js +0 -71
- package/dist/core/mcp-servers/share-secrets.js.map +0 -1
- /package/dist/core/{mcp-servers → mcp-configuration}/ports.js +0 -0
- /package/dist/core/{mcp-servers → mcp-configuration}/sealing-key.d.ts +0 -0
- /package/dist/core/{mcp-servers → mcp-configuration}/sealing-key.js +0 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The delivery of a fleet's MCP configuration to one of its trierarchs (the
|
|
3
|
+
* fleet crew MCP design, section 5): the attempt last made, under the
|
|
4
|
+
* idempotency key it keeps until the fleet took it, and the version and key
|
|
5
|
+
* the trierarch confirmed it applied. Reconciliation converges on the latest
|
|
6
|
+
* set: confirmed application, never a send or its acknowledgement, ends it.
|
|
7
|
+
*/
|
|
8
|
+
import type { ShipId } from '@aeolus-fleet/common';
|
|
9
|
+
/** A sealed copy of one version for one key: what it carried, under which key, and when the fleet took it; null while that is not known. */
|
|
10
|
+
export interface McpAttempt {
|
|
11
|
+
readonly version: number;
|
|
12
|
+
readonly publicKey: string;
|
|
13
|
+
readonly idempotencyKey: string;
|
|
14
|
+
/** The message as sent: a retry under its key sends the very same, as the fleet takes a key only for one message. */
|
|
15
|
+
readonly payload: string;
|
|
16
|
+
readonly sentAt: Date | null;
|
|
17
|
+
}
|
|
18
|
+
/** A version and key a trierarch confirmed it applied. */
|
|
19
|
+
export interface McpApplied {
|
|
20
|
+
readonly version: number;
|
|
21
|
+
readonly publicKey: string;
|
|
22
|
+
}
|
|
23
|
+
/** One trierarch's delivery: its last attempt, its confirmation, and whether it asked for the set since. */
|
|
24
|
+
export interface McpDelivery {
|
|
25
|
+
readonly trierarchShipId: ShipId;
|
|
26
|
+
readonly attempt: McpAttempt | null;
|
|
27
|
+
readonly applied: McpApplied | null;
|
|
28
|
+
readonly isRequested: boolean;
|
|
29
|
+
}
|
|
30
|
+
/** What a trierarch needs: the fleet's current version, sealed to the key its report states. */
|
|
31
|
+
export interface McpTarget {
|
|
32
|
+
readonly version: number;
|
|
33
|
+
readonly publicKey: string;
|
|
34
|
+
}
|
|
35
|
+
/** What a pass does for a trierarch: nothing; the attempt it made again, under its key; or a new attempt under a new key. */
|
|
36
|
+
export type McpSend = {
|
|
37
|
+
readonly kind: 'none';
|
|
38
|
+
} | {
|
|
39
|
+
readonly kind: 'retry';
|
|
40
|
+
readonly attempt: McpAttempt;
|
|
41
|
+
} | {
|
|
42
|
+
readonly kind: 'new';
|
|
43
|
+
};
|
|
44
|
+
/** How long after a copy the fleet took, with no confirmation since, a pass sends another: a lost delivery or confirmation is made up for, without a copy every pass. */
|
|
45
|
+
export declare const RESEND_UNCONFIRMED_AFTER_MS: number;
|
|
46
|
+
/** Whether the trierarch confirmed the version for the key: what placement and the next send rely on. */
|
|
47
|
+
export declare function isMcpConfigurationCurrent(delivery: McpDelivery | undefined, target: McpTarget): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Policy: what a pass sends a trierarch. Confirmed for the version and its
|
|
50
|
+
* key, and not asked since: nothing. Asked: a new attempt, even if one was
|
|
51
|
+
* sent. An attempt of the version and key the fleet has not taken yet: the
|
|
52
|
+
* same again, under its key. One the fleet took: nothing until
|
|
53
|
+
* RESEND_UNCONFIRMED_AFTER_MS passed without a confirmation, then a new
|
|
54
|
+
* attempt. Any other version or key: a new attempt.
|
|
55
|
+
*/
|
|
56
|
+
export declare function nextMcpSend(delivery: McpDelivery | undefined, at: {
|
|
57
|
+
target: McpTarget;
|
|
58
|
+
now: Date;
|
|
59
|
+
}): McpSend;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/** How long after a copy the fleet took, with no confirmation since, a pass sends another: a lost delivery or confirmation is made up for, without a copy every pass. */
|
|
2
|
+
export const RESEND_UNCONFIRMED_AFTER_MS = 5 * 60_000;
|
|
3
|
+
/** Whether the trierarch confirmed the version for the key: what placement and the next send rely on. */
|
|
4
|
+
export function isMcpConfigurationCurrent(delivery, target) {
|
|
5
|
+
return delivery?.applied?.version === target.version && delivery.applied.publicKey === target.publicKey;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Policy: what a pass sends a trierarch. Confirmed for the version and its
|
|
9
|
+
* key, and not asked since: nothing. Asked: a new attempt, even if one was
|
|
10
|
+
* sent. An attempt of the version and key the fleet has not taken yet: the
|
|
11
|
+
* same again, under its key. One the fleet took: nothing until
|
|
12
|
+
* RESEND_UNCONFIRMED_AFTER_MS passed without a confirmation, then a new
|
|
13
|
+
* attempt. Any other version or key: a new attempt.
|
|
14
|
+
*/
|
|
15
|
+
export function nextMcpSend(delivery, at) {
|
|
16
|
+
const { target, now } = at;
|
|
17
|
+
if (delivery?.isRequested === true) {
|
|
18
|
+
return { kind: 'new' };
|
|
19
|
+
}
|
|
20
|
+
if (isMcpConfigurationCurrent(delivery, target)) {
|
|
21
|
+
return { kind: 'none' };
|
|
22
|
+
}
|
|
23
|
+
const attempt = delivery?.attempt;
|
|
24
|
+
if (attempt?.version !== target.version || attempt.publicKey !== target.publicKey) {
|
|
25
|
+
return { kind: 'new' };
|
|
26
|
+
}
|
|
27
|
+
if (attempt.sentAt === null) {
|
|
28
|
+
return { kind: 'retry', attempt };
|
|
29
|
+
}
|
|
30
|
+
return now.getTime() - attempt.sentAt.getTime() >= RESEND_UNCONFIRMED_AFTER_MS ? { kind: 'new' } : { kind: 'none' };
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=mcp-delivery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-delivery.js","sourceRoot":"","sources":["../../../src/core/mcp-configuration/mcp-delivery.ts"],"names":[],"mappings":"AA0CA,yKAAyK;AACzK,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,GAAG,MAAM,CAAC;AAEtD,yGAAyG;AACzG,MAAM,UAAU,yBAAyB,CAAC,QAAiC,EAAE,MAAiB;IAC5F,OAAO,QAAQ,EAAE,OAAO,EAAE,OAAO,KAAK,MAAM,CAAC,OAAO,IAAI,QAAQ,CAAC,OAAO,CAAC,SAAS,KAAK,MAAM,CAAC,SAAS,CAAC;AAC1G,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,WAAW,CAAC,QAAiC,EAAE,EAAoC;IACjG,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;IAC3B,IAAI,QAAQ,EAAE,WAAW,KAAK,IAAI,EAAE,CAAC;QACnC,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;IACzB,CAAC;IACD,IAAI,yBAAyB,CAAC,QAAQ,EAAE,MAAM,CAAC,EAAE,CAAC;QAChD,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;IAC1B,CAAC;IACD,MAAM,OAAO,GAAG,QAAQ,EAAE,OAAO,CAAC;IAClC,IAAI,OAAO,EAAE,OAAO,KAAK,MAAM,CAAC,OAAO,IAAI,OAAO,CAAC,SAAS,KAAK,MAAM,CAAC,SAAS,EAAE,CAAC;QAClF,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;IACzB,CAAC;IACD,IAAI,OAAO,CAAC,MAAM,KAAK,IAAI,EAAE,CAAC;QAC5B,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;IACpC,CAAC;IACD,OAAO,GAAG,CAAC,OAAO,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,IAAI,2BAA2B,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;AACtH,CAAC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { FleetId, ShipId } from '@aeolus-fleet/common';
|
|
2
|
+
import type { Result } from '../shared/result.js';
|
|
3
|
+
import type { McpChange, McpConfiguration } from './mcp-configuration.js';
|
|
4
|
+
import type { McpApplied, McpAttempt, McpDelivery } from './mcp-delivery.js';
|
|
5
|
+
/** Who replaced a set: the console session's kind and account, as `console.session` answers them; never a credential. */
|
|
6
|
+
export interface McpActor {
|
|
7
|
+
readonly kind: string;
|
|
8
|
+
readonly accountId: string | null;
|
|
9
|
+
}
|
|
10
|
+
/** The event of a replacement: its fleet, the version it saved, its actor and the names it changed, never a value. */
|
|
11
|
+
export interface McpConfigurationReplaced {
|
|
12
|
+
readonly type: 'McpConfigurationReplaced';
|
|
13
|
+
readonly fleetId: FleetId;
|
|
14
|
+
readonly version: number;
|
|
15
|
+
readonly actor: McpActor;
|
|
16
|
+
readonly changed: McpChange;
|
|
17
|
+
readonly at: Date;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Outbound port: each fleet's one current MCP configuration (design section
|
|
21
|
+
* 4), the plugin's credential store: readable to the service, never shown.
|
|
22
|
+
*/
|
|
23
|
+
export interface McpConfigurations {
|
|
24
|
+
/** The fleet's current set; the empty one at version 0 before its first replacement. */
|
|
25
|
+
read(fleetId: FleetId): Promise<McpConfiguration>;
|
|
26
|
+
/**
|
|
27
|
+
* Saves the set and its event in one unit of work, only while the fleet's
|
|
28
|
+
* stored version is still `expectedVersion`: one of two writers of the same
|
|
29
|
+
* version saves, the other is answered `conflict` with nothing written. A
|
|
30
|
+
* failure saves neither and throws.
|
|
31
|
+
*/
|
|
32
|
+
replace(fleetId: FleetId, replacement: {
|
|
33
|
+
expectedVersion: number;
|
|
34
|
+
configuration: McpConfiguration;
|
|
35
|
+
event: McpConfigurationReplaced;
|
|
36
|
+
}): Promise<'replaced' | 'conflict'>;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Outbound port: each fleet's deliveries of its MCP configuration, one per
|
|
40
|
+
* trierarch ship, kept across restarts. Each change touches only its own
|
|
41
|
+
* part, so a pass and the inbox round may change one delivery at once.
|
|
42
|
+
*/
|
|
43
|
+
export interface McpDeliveries {
|
|
44
|
+
list(fleetId: FleetId): Promise<McpDelivery[]>;
|
|
45
|
+
/** Keeps a new attempt, before it is sent: the trierarch's request, if any, is answered by it. */
|
|
46
|
+
recordAttempt(fleetId: FleetId, recorded: {
|
|
47
|
+
trierarchShipId: ShipId;
|
|
48
|
+
attempt: McpAttempt;
|
|
49
|
+
}): Promise<void>;
|
|
50
|
+
/** The fleet took the attempt under this key; a later attempt is left as it is. */
|
|
51
|
+
markSent(fleetId: FleetId, sent: {
|
|
52
|
+
trierarchShipId: ShipId;
|
|
53
|
+
idempotencyKey: string;
|
|
54
|
+
at: Date;
|
|
55
|
+
}): Promise<void>;
|
|
56
|
+
recordApplied(fleetId: FleetId, recorded: {
|
|
57
|
+
trierarchShipId: ShipId;
|
|
58
|
+
applied: McpApplied;
|
|
59
|
+
}): Promise<void>;
|
|
60
|
+
/**
|
|
61
|
+
* The trierarch asked for the set, as it does when its lease starts: its
|
|
62
|
+
* confirmation is forgotten at once, so placement waits for the new lease's,
|
|
63
|
+
* and the next pass sends it a new attempt.
|
|
64
|
+
*/
|
|
65
|
+
markRequested(fleetId: FleetId, trierarchShipId: ShipId): Promise<void>;
|
|
66
|
+
forget(fleetId: FleetId, trierarchShipIds: readonly ShipId[]): Promise<void>;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Outbound port: seals a value to a trierarch's public key so that only the
|
|
70
|
+
* holder of its private key opens it (decision M5): the NaCl anonymous sealed
|
|
71
|
+
* box, the value as UTF-8, the public key (as `readSealingKey` read it) and
|
|
72
|
+
* the sealed box as standard base64. A key no box can be sealed to, such as a
|
|
73
|
+
* low-order point, is KEY_REFUSED.
|
|
74
|
+
*/
|
|
75
|
+
export interface Sealer {
|
|
76
|
+
seal(value: string, publicKey: string): Promise<Result<string, {
|
|
77
|
+
kind: 'KEY_REFUSED';
|
|
78
|
+
}>>;
|
|
79
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ports.js","sourceRoot":"","sources":["../../../src/core/mcp-configuration/ports.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { FleetId } from '@aeolus-fleet/common';
|
|
2
|
+
import { type McpConfigurationMetadata } from './mcp-configuration.js';
|
|
3
|
+
import type { McpConfigurations } from './ports.js';
|
|
4
|
+
export type ReadMcpConfiguration = (fleetId: FleetId) => Promise<McpConfigurationMetadata>;
|
|
5
|
+
/** Use case: a fleet's MCP configuration as `mcp.get` answers it (design section 4): its version, servers and secret names, never a value. */
|
|
6
|
+
export declare function createReadMcpConfiguration(deps: {
|
|
7
|
+
configurations: McpConfigurations;
|
|
8
|
+
}): ReadMcpConfiguration;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { mcpConfigurationMetadata } from './mcp-configuration.js';
|
|
2
|
+
/** Use case: a fleet's MCP configuration as `mcp.get` answers it (design section 4): its version, servers and secret names, never a value. */
|
|
3
|
+
export function createReadMcpConfiguration(deps) {
|
|
4
|
+
return async (fleetId) => mcpConfigurationMetadata(await deps.configurations.read(fleetId));
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=read-mcp-configuration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-mcp-configuration.js","sourceRoot":"","sources":["../../../src/core/mcp-configuration/read-mcp-configuration.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,wBAAwB,EAAiC,MAAM,wBAAwB,CAAC;AAKjG,8IAA8I;AAC9I,MAAM,UAAU,0BAA0B,CAAC,IAA2C;IACpF,OAAO,KAAK,EAAE,OAAO,EAAE,EAAE,CAAC,wBAAwB,CAAC,MAAM,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;AAC9F,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { FleetId } from '@aeolus-fleet/common';
|
|
2
|
+
import type { Clock } from '../shared/clock.js';
|
|
3
|
+
import { type DomainError } from '../shared/errors.js';
|
|
4
|
+
import { type Result } from '../shared/result.js';
|
|
5
|
+
import { type McpReplacement } from './mcp-configuration.js';
|
|
6
|
+
import type { McpActor, McpConfigurations } from './ports.js';
|
|
7
|
+
export type ReplaceMcpConfiguration = (request: {
|
|
8
|
+
fleetId: FleetId;
|
|
9
|
+
actor: McpActor;
|
|
10
|
+
replacement: McpReplacement;
|
|
11
|
+
}) => Promise<Result<{
|
|
12
|
+
version: number;
|
|
13
|
+
}, DomainError<'VERSION_CONFLICT' | 'INVALID_CONFIGURATION'>>>;
|
|
14
|
+
/**
|
|
15
|
+
* Use case: a manager replaces their fleet's MCP configuration whole (design
|
|
16
|
+
* section 4): read the current set, replace it by the model's rules, then save
|
|
17
|
+
* it with its value-free event, only while the version is still the one
|
|
18
|
+
* read. A writer that lost to another of the same version is answered the
|
|
19
|
+
* conflict, nothing written. Success means saved, not yet applied anywhere.
|
|
20
|
+
*/
|
|
21
|
+
export declare function createReplaceMcpConfiguration(deps: {
|
|
22
|
+
configurations: McpConfigurations;
|
|
23
|
+
clock: Clock;
|
|
24
|
+
}): ReplaceMcpConfiguration;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { refuse } from '../shared/errors.js';
|
|
2
|
+
import { ok } from '../shared/result.js';
|
|
3
|
+
import { replaceMcpConfiguration } from './mcp-configuration.js';
|
|
4
|
+
/**
|
|
5
|
+
* Use case: a manager replaces their fleet's MCP configuration whole (design
|
|
6
|
+
* section 4): read the current set, replace it by the model's rules, then save
|
|
7
|
+
* it with its value-free event, only while the version is still the one
|
|
8
|
+
* read. A writer that lost to another of the same version is answered the
|
|
9
|
+
* conflict, nothing written. Success means saved, not yet applied anywhere.
|
|
10
|
+
*/
|
|
11
|
+
export function createReplaceMcpConfiguration(deps) {
|
|
12
|
+
return async ({ fleetId, actor, replacement }) => {
|
|
13
|
+
const current = await deps.configurations.read(fleetId);
|
|
14
|
+
const replaced = replaceMcpConfiguration({ fleetId, current }, replacement);
|
|
15
|
+
if (!replaced.isOk) {
|
|
16
|
+
return replaced;
|
|
17
|
+
}
|
|
18
|
+
const { configuration, changed } = replaced.value;
|
|
19
|
+
const saved = await deps.configurations.replace(fleetId, {
|
|
20
|
+
expectedVersion: current.version,
|
|
21
|
+
configuration,
|
|
22
|
+
event: { type: 'McpConfigurationReplaced', fleetId, version: configuration.version, actor, changed, at: deps.clock.now() },
|
|
23
|
+
});
|
|
24
|
+
if (saved === 'conflict') {
|
|
25
|
+
return refuse('VERSION_CONFLICT', `The MCP configuration changed from version ${String(current.version)} meanwhile: read it again before replacing it`);
|
|
26
|
+
}
|
|
27
|
+
return ok({ version: configuration.version });
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=replace-mcp-configuration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"replace-mcp-configuration.js","sourceRoot":"","sources":["../../../src/core/mcp-configuration/replace-mcp-configuration.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAoB,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EAAE,EAAE,EAAe,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,uBAAuB,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EAAE,MAAM,KAAK,CAAC;AAExB,gFAAgF;AAChF,MAAM,MAAM,GAAG,iBAAiB,CAAC;AAEjC,+GAA+G;AAC/G,MAAM,iBAAiB,GAAG,wCAAwC,CAAC;AAEnE,2EAA2E;AAC3E,MAAM,QAAQ,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,GAAG,CAAC;AAEtC,MAAM,aAAa,GAAG,CAAC,CAAC,MAAM,CAAC;IAC7B,UAAU,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,KAAK,QAAQ,CAAC,EAAE,CAAC;CAClJ,CAAC,CAAC;AAEH;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,OAAgB;IAC7C,MAAM,IAAI,GAAG,aAAa,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;IAC9C,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC;AACnE,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { PluginCrew, PluginDelivery } from '../connection/ports.js';
|
|
2
|
+
import type { McpConfigurations, McpDeliveries } from './ports.js';
|
|
3
|
+
/** What became of a delivery to the plugin's ship: not of the MCP configuration; a confirmation recorded; a request marked; or ignored, and why. */
|
|
4
|
+
export type TakenMcpMessage = {
|
|
5
|
+
readonly kind: 'notMcpConfiguration';
|
|
6
|
+
} | {
|
|
7
|
+
readonly kind: 'applied';
|
|
8
|
+
} | {
|
|
9
|
+
readonly kind: 'requested';
|
|
10
|
+
} | {
|
|
11
|
+
readonly kind: 'ignored';
|
|
12
|
+
readonly reason: string;
|
|
13
|
+
};
|
|
14
|
+
export type TakeMcpConfigurationMessage = (crew: PluginCrew, delivery: PluginDelivery) => Promise<TakenMcpMessage>;
|
|
15
|
+
/**
|
|
16
|
+
* Use case: a trierarch's message about its fleet's MCP configuration to the
|
|
17
|
+
* plugin's ship (the fleet crew MCP design, section 5). The fleet names the
|
|
18
|
+
* sender and its status; the payload's identity must agree with this fleet
|
|
19
|
+
* and this plugin ship, and never authorises itself. A confirmation counts
|
|
20
|
+
* only from a crewed trierarch, for the fleet's current version and the key
|
|
21
|
+
* its last attempt was sealed to: it is recorded against that trierarch. A
|
|
22
|
+
* request, which a trierarch sends when its lease starts, forgets its
|
|
23
|
+
* confirmation and marks it so the next pass sends it a new copy. Anything
|
|
24
|
+
* else of the contract is ignored, recording nothing, with a reason that
|
|
25
|
+
* holds no payload.
|
|
26
|
+
*/
|
|
27
|
+
export declare function createTakeMcpConfigurationMessage(deps: {
|
|
28
|
+
configurations: McpConfigurations;
|
|
29
|
+
deliveries: McpDeliveries;
|
|
30
|
+
}): TakeMcpConfigurationMessage;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { idSchema } from '@aeolus-fleet/common';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { TRIERARCH_TYPE } from '../machines/join-machine.js';
|
|
4
|
+
import { MCP_CONFIGURATION_APPLIED_CONTENT_TYPE, MCP_CONFIGURATION_REQUEST_CONTENT_TYPE } from './mcp-configuration.js';
|
|
5
|
+
const appliedSchema = z.strictObject({ fleetId: idSchema('fleet'), pluginShipId: idSchema('ship'), version: z.int().nonnegative(), publicKey: z.string() });
|
|
6
|
+
const requestSchema = z.strictObject({ fleetId: idSchema('fleet'), pluginShipId: idSchema('ship') });
|
|
7
|
+
const OTHER_IDENTITY = 'it names another fleet or plugin ship';
|
|
8
|
+
/** Whether the payload names this fleet and this plugin ship, as the configured identity is. */
|
|
9
|
+
function isOwn(crew, named) {
|
|
10
|
+
return named.fleetId === crew.fleetId && named.pluginShipId === crew.shipId;
|
|
11
|
+
}
|
|
12
|
+
/** The payload read by the schema, or undefined for text that is not JSON or does not fit it. */
|
|
13
|
+
function readPayload(payload, schema) {
|
|
14
|
+
try {
|
|
15
|
+
const read = schema.safeParse(JSON.parse(payload));
|
|
16
|
+
return read.success ? read.data : undefined;
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
// Not JSON: not a message of this contract.
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Use case: a trierarch's message about its fleet's MCP configuration to the
|
|
25
|
+
* plugin's ship (the fleet crew MCP design, section 5). The fleet names the
|
|
26
|
+
* sender and its status; the payload's identity must agree with this fleet
|
|
27
|
+
* and this plugin ship, and never authorises itself. A confirmation counts
|
|
28
|
+
* only from a crewed trierarch, for the fleet's current version and the key
|
|
29
|
+
* its last attempt was sealed to: it is recorded against that trierarch. A
|
|
30
|
+
* request, which a trierarch sends when its lease starts, forgets its
|
|
31
|
+
* confirmation and marks it so the next pass sends it a new copy. Anything
|
|
32
|
+
* else of the contract is ignored, recording nothing, with a reason that
|
|
33
|
+
* holds no payload.
|
|
34
|
+
*/
|
|
35
|
+
export function createTakeMcpConfigurationMessage(deps) {
|
|
36
|
+
return async (crew, delivery) => {
|
|
37
|
+
const isApplied = delivery.contentType === MCP_CONFIGURATION_APPLIED_CONTENT_TYPE;
|
|
38
|
+
if (!isApplied && delivery.contentType !== MCP_CONFIGURATION_REQUEST_CONTENT_TYPE) {
|
|
39
|
+
return { kind: 'notMcpConfiguration' };
|
|
40
|
+
}
|
|
41
|
+
if (delivery.senderType !== TRIERARCH_TYPE || delivery.senderStatus !== 'crewed') {
|
|
42
|
+
return { kind: 'ignored', reason: 'its sender is not a crewed trierarch' };
|
|
43
|
+
}
|
|
44
|
+
if (!isApplied) {
|
|
45
|
+
const request = readPayload(delivery.payload, requestSchema);
|
|
46
|
+
if (request === undefined) {
|
|
47
|
+
return { kind: 'ignored', reason: 'its payload is not { fleetId, pluginShipId }' };
|
|
48
|
+
}
|
|
49
|
+
if (!isOwn(crew, request)) {
|
|
50
|
+
return { kind: 'ignored', reason: OTHER_IDENTITY };
|
|
51
|
+
}
|
|
52
|
+
await deps.deliveries.markRequested(crew.fleetId, delivery.senderShipId);
|
|
53
|
+
return { kind: 'requested' };
|
|
54
|
+
}
|
|
55
|
+
const read = readPayload(delivery.payload, appliedSchema);
|
|
56
|
+
if (read === undefined) {
|
|
57
|
+
return { kind: 'ignored', reason: 'its payload is not { fleetId, pluginShipId, version, publicKey }' };
|
|
58
|
+
}
|
|
59
|
+
if (!isOwn(crew, read)) {
|
|
60
|
+
return { kind: 'ignored', reason: OTHER_IDENTITY };
|
|
61
|
+
}
|
|
62
|
+
const { version } = await deps.configurations.read(crew.fleetId);
|
|
63
|
+
if (read.version !== version) {
|
|
64
|
+
return { kind: 'ignored', reason: `it confirms version ${String(read.version)}, not the current version ${String(version)}` };
|
|
65
|
+
}
|
|
66
|
+
const attempt = (await deps.deliveries.list(crew.fleetId)).find((each) => each.trierarchShipId === delivery.senderShipId)?.attempt;
|
|
67
|
+
if (attempt?.version !== read.version || attempt.publicKey !== read.publicKey) {
|
|
68
|
+
return { kind: 'ignored', reason: 'it confirms a version and key it was not sent' };
|
|
69
|
+
}
|
|
70
|
+
await deps.deliveries.recordApplied(crew.fleetId, { trierarchShipId: delivery.senderShipId, applied: { version: read.version, publicKey: read.publicKey } });
|
|
71
|
+
return { kind: 'applied' };
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=take-mcp-configuration-message.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"take-mcp-configuration-message.js","sourceRoot":"","sources":["../../../src/core/mcp-configuration/take-mcp-configuration-message.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,EAAE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7
|
kind: ConsoleSessionOutput["kind"];
|
|
8
|
+
accountId?: string;
|
|
8
9
|
scopes: readonly ScopeName[];
|
|
9
10
|
}, DomainError<"NOT_THE_OPERATOR">>>;
|
|
10
11
|
/**
|
|
@@ -15,7 +16,8 @@ export type AuthenticateOperator = (cookie: string | undefined) => Promise<Resul
|
|
|
15
16
|
* operator there is let through as the operator of their own fleet. A
|
|
16
17
|
* viewer session is let through too, with the viewer ship's scopes, which
|
|
17
18
|
* the fleet answers; what each scope may call is the API's to check
|
|
18
|
-
* (decision 0022).
|
|
19
|
+
* (decision 0022). An account's session carries its account, which a
|
|
20
|
+
* change records as its actor.
|
|
19
21
|
*/
|
|
20
22
|
export declare function createAuthenticateOperator(deps: {
|
|
21
23
|
sessions: ConsoleSessions;
|
|
@@ -8,7 +8,8 @@ import { ok } from "../shared/result.js";
|
|
|
8
8
|
* operator there is let through as the operator of their own fleet. A
|
|
9
9
|
* viewer session is let through too, with the viewer ship's scopes, which
|
|
10
10
|
* the fleet answers; what each scope may call is the API's to check
|
|
11
|
-
* (decision 0022).
|
|
11
|
+
* (decision 0022). An account's session carries its account, which a
|
|
12
|
+
* change records as its actor.
|
|
12
13
|
*/
|
|
13
14
|
export function createAuthenticateOperator(deps) {
|
|
14
15
|
const refusal = refuse("NOT_THE_OPERATOR", "Sign in to the console of your fleet");
|
|
@@ -20,10 +21,12 @@ export function createAuthenticateOperator(deps) {
|
|
|
20
21
|
if (!session.isOk) {
|
|
21
22
|
return refusal;
|
|
22
23
|
}
|
|
24
|
+
const { fleetId, kind, accountId, scopes } = session.value;
|
|
23
25
|
return ok({
|
|
24
|
-
fleetId
|
|
25
|
-
kind
|
|
26
|
-
|
|
26
|
+
fleetId,
|
|
27
|
+
kind,
|
|
28
|
+
...(accountId !== undefined && { accountId }),
|
|
29
|
+
scopes,
|
|
27
30
|
});
|
|
28
31
|
};
|
|
29
32
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authenticate-operator.js","sourceRoot":"","sources":["../../../src/core/operator/authenticate-operator.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,MAAM,EAAoB,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EAAE,EAAE,EAAe,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"authenticate-operator.js","sourceRoot":"","sources":["../../../src/core/operator/authenticate-operator.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,MAAM,EAAoB,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EAAE,EAAE,EAAe,MAAM,qBAAqB,CAAC;AAiBtD;;;;;;;;;;GAUG;AACH,MAAM,UAAU,0BAA0B,CAAC,IAE1C;IACC,MAAM,OAAO,GAAG,MAAM,CACpB,kBAAkB,EAClB,sCAAsC,CACvC,CAAC;IACF,OAAO,KAAK,EAAE,MAAM,EAAE,EAAE;QACtB,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YACzB,OAAO,OAAO,CAAC;QACjB,CAAC;QACD,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QAClD,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;YAClB,OAAO,OAAO,CAAC;QACjB,CAAC;QACD,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,KAAK,CAAC;QAC3D,OAAO,EAAE,CAAC;YACR,OAAO;YACP,IAAI;YACJ,GAAG,CAAC,SAAS,KAAK,SAAS,IAAI,EAAE,SAAS,EAAE,CAAC;YAC7C,MAAM;SACP,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -4,12 +4,13 @@ import type { Result } from '../shared/result.js';
|
|
|
4
4
|
/**
|
|
5
5
|
* Outbound port: asks the fleet whether a forwarded console session cookie is
|
|
6
6
|
* a signed-in operator's or a viewer's (`console.session`, decisions 0012 and
|
|
7
|
-
* 0022), with its ship's scopes.
|
|
7
|
+
* 0022), with its ship's scopes and, for an account's session, its account.
|
|
8
8
|
*/
|
|
9
9
|
export interface ConsoleSessions {
|
|
10
10
|
check(cookie: string): Promise<Result<{
|
|
11
11
|
fleetId: FleetId;
|
|
12
12
|
kind: ConsoleSessionOutput['kind'];
|
|
13
|
+
accountId?: string;
|
|
13
14
|
scopes: readonly ScopeName[];
|
|
14
15
|
}, FleetRefusal>>;
|
|
15
16
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type Err } from './result.js';
|
|
2
2
|
/** Every reason the trierarch plugin's core refuses a request. */
|
|
3
|
-
export type DomainErrorKind = 'ALREADY_CONNECTED' | 'SECRET_REFUSED' | 'OTHER_FLEET' | 'MISSING_SCOPES' | 'NOT_THE_OPERATOR' | 'REQUEST_ID_USED' | 'NOT_CONNECTED' | 'NAME_TAKEN' | 'NEEDS_SCOPE' | 'FLEET_UNAVAILABLE' | 'NOT_A_MACHINE' | 'FLEET_REFUSED' | 'INVALID_RANGE';
|
|
3
|
+
export type DomainErrorKind = 'ALREADY_CONNECTED' | 'SECRET_REFUSED' | 'OTHER_FLEET' | 'MISSING_SCOPES' | 'NOT_THE_OPERATOR' | 'REQUEST_ID_USED' | 'NOT_CONNECTED' | 'NAME_TAKEN' | 'NEEDS_SCOPE' | 'FLEET_UNAVAILABLE' | 'NOT_A_MACHINE' | 'FLEET_REFUSED' | 'INVALID_RANGE' | 'VERSION_CONFLICT' | 'INVALID_CONFIGURATION';
|
|
4
4
|
/** Why the core refused a request. Adapters map the kind to their own error shape; the message is safe to show. */
|
|
5
5
|
export interface DomainError<K extends DomainErrorKind = DomainErrorKind> {
|
|
6
6
|
readonly kind: K;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/core/shared/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAY,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/core/shared/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAY,MAAM,aAAa,CAAC;AA0B5C,qDAAqD;AACrD,MAAM,UAAU,MAAM,CAA4B,IAAO,EAAE,OAAe;IACxE,OAAO,GAAG,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;AAChC,CAAC"}
|
package/package.json
CHANGED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
-- CreateTable
|
|
2
|
+
CREATE TABLE "mcp_configurations" (
|
|
3
|
+
"fleet_id" TEXT NOT NULL,
|
|
4
|
+
"version" INTEGER NOT NULL,
|
|
5
|
+
"servers" JSONB NOT NULL,
|
|
6
|
+
"replaced_at" TIMESTAMPTZ(3) NOT NULL,
|
|
7
|
+
|
|
8
|
+
CONSTRAINT "mcp_configurations_pkey" PRIMARY KEY ("fleet_id")
|
|
9
|
+
);
|
|
10
|
+
|
|
11
|
+
-- CreateTable
|
|
12
|
+
CREATE TABLE "mcp_secrets" (
|
|
13
|
+
"fleet_id" TEXT NOT NULL,
|
|
14
|
+
"name" TEXT NOT NULL,
|
|
15
|
+
"value" TEXT NOT NULL,
|
|
16
|
+
|
|
17
|
+
CONSTRAINT "mcp_secrets_pkey" PRIMARY KEY ("fleet_id","name")
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
-- CreateTable
|
|
21
|
+
CREATE TABLE "mcp_configuration_events" (
|
|
22
|
+
"id" BIGSERIAL NOT NULL,
|
|
23
|
+
"fleet_id" TEXT NOT NULL,
|
|
24
|
+
"version" INTEGER NOT NULL,
|
|
25
|
+
"actor_kind" TEXT NOT NULL,
|
|
26
|
+
"actor_account_id" TEXT,
|
|
27
|
+
"changed_servers" TEXT[],
|
|
28
|
+
"changed_secrets" TEXT[],
|
|
29
|
+
"at" TIMESTAMPTZ(3) NOT NULL,
|
|
30
|
+
|
|
31
|
+
CONSTRAINT "mcp_configuration_events_pkey" PRIMARY KEY ("id")
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
-- CreateIndex
|
|
35
|
+
CREATE UNIQUE INDEX "mcp_configuration_events_fleet_id_version_key" ON "mcp_configuration_events"("fleet_id", "version");
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
-- CreateTable
|
|
2
|
+
CREATE TABLE "mcp_deliveries" (
|
|
3
|
+
"fleet_id" TEXT NOT NULL,
|
|
4
|
+
"trierarch_ship_id" TEXT NOT NULL,
|
|
5
|
+
"attempt_version" INTEGER,
|
|
6
|
+
"attempt_public_key" TEXT,
|
|
7
|
+
"attempt_idempotency_key" TEXT,
|
|
8
|
+
"attempt_payload" TEXT,
|
|
9
|
+
"attempt_sent_at" TIMESTAMPTZ(3),
|
|
10
|
+
"applied_version" INTEGER,
|
|
11
|
+
"applied_public_key" TEXT,
|
|
12
|
+
"is_requested" BOOLEAN NOT NULL DEFAULT false,
|
|
13
|
+
|
|
14
|
+
CONSTRAINT "mcp_deliveries_pkey" PRIMARY KEY ("fleet_id","trierarch_ship_id")
|
|
15
|
+
);
|
|
@@ -145,3 +145,68 @@ model SubscriptionReading {
|
|
|
145
145
|
@@id([fleetId, machineShipId, harness, windowMinutes, readAt])
|
|
146
146
|
@@map("subscription_readings")
|
|
147
147
|
}
|
|
148
|
+
|
|
149
|
+
/// Each fleet's one current MCP configuration (the fleet crew MCP design,
|
|
150
|
+
/// section 4): its version, which guards every replacement, and its servers as
|
|
151
|
+
/// the model saved them. No row before the fleet's first replacement: version 0
|
|
152
|
+
/// with nothing. Its secrets are in mcp_secrets, so this row holds no value.
|
|
153
|
+
model McpConfiguration {
|
|
154
|
+
fleetId String @id @map("fleet_id")
|
|
155
|
+
version Int
|
|
156
|
+
servers Json
|
|
157
|
+
replacedAt DateTime @map("replaced_at") @db.Timestamptz(3)
|
|
158
|
+
|
|
159
|
+
@@map("mcp_configurations")
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/// The secrets of each fleet's MCP configuration, with their values: the
|
|
163
|
+
/// plugin's credential store, readable to the service and its database
|
|
164
|
+
/// administrators. Replaced with the set, in the same transaction.
|
|
165
|
+
model McpSecret {
|
|
166
|
+
fleetId String @map("fleet_id")
|
|
167
|
+
name String
|
|
168
|
+
value String
|
|
169
|
+
|
|
170
|
+
@@id([fleetId, name])
|
|
171
|
+
@@map("mcp_secrets")
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/// One row per replacement of a fleet's MCP configuration, written in the same
|
|
175
|
+
/// transaction: the version it saved, the console session's kind and account,
|
|
176
|
+
/// and the server and secret names it changed. Never a value.
|
|
177
|
+
model McpConfigurationEvent {
|
|
178
|
+
id BigInt @id @default(autoincrement())
|
|
179
|
+
fleetId String @map("fleet_id")
|
|
180
|
+
version Int
|
|
181
|
+
actorKind String @map("actor_kind")
|
|
182
|
+
actorAccountId String? @map("actor_account_id")
|
|
183
|
+
changedServers String[] @map("changed_servers")
|
|
184
|
+
changedSecrets String[] @map("changed_secrets")
|
|
185
|
+
at DateTime @db.Timestamptz(3)
|
|
186
|
+
|
|
187
|
+
@@unique([fleetId, version])
|
|
188
|
+
@@map("mcp_configuration_events")
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/// The delivery of a fleet's MCP configuration to one of its trierarch ships
|
|
192
|
+
/// (the fleet crew MCP design, section 5): the attempt last made, kept under its
|
|
193
|
+
/// idempotency key before it is sent, with the very message, as the fleet takes
|
|
194
|
+
/// a key only for one message; the version and key the trierarch confirmed it
|
|
195
|
+
/// applied; and whether it asked for the set since. Its secrets are only sealed
|
|
196
|
+
/// to the trierarch's key. Forgotten when the trierarch is seen not crewed.
|
|
197
|
+
model McpDelivery {
|
|
198
|
+
fleetId String @map("fleet_id")
|
|
199
|
+
trierarchShipId String @map("trierarch_ship_id")
|
|
200
|
+
attemptVersion Int? @map("attempt_version")
|
|
201
|
+
attemptPublicKey String? @map("attempt_public_key")
|
|
202
|
+
attemptIdempotencyKey String? @map("attempt_idempotency_key")
|
|
203
|
+
attemptPayload String? @map("attempt_payload")
|
|
204
|
+
/// Null while the fleet is not known to have taken the attempt.
|
|
205
|
+
attemptSentAt DateTime? @map("attempt_sent_at") @db.Timestamptz(3)
|
|
206
|
+
appliedVersion Int? @map("applied_version")
|
|
207
|
+
appliedPublicKey String? @map("applied_public_key")
|
|
208
|
+
isRequested Boolean @default(false) @map("is_requested")
|
|
209
|
+
|
|
210
|
+
@@id([fleetId, trierarchShipId])
|
|
211
|
+
@@map("mcp_deliveries")
|
|
212
|
+
}
|