@aeolus-fleet/trierarch-plugin 0.38.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.
Files changed (135) hide show
  1. package/README.md +16 -8
  2. package/dist/adapters/crypto/sealed-box-sealer.d.ts +1 -1
  3. package/dist/adapters/fleet/console-sessions.js +3 -3
  4. package/dist/adapters/fleet/console-sessions.js.map +1 -1
  5. package/dist/adapters/fleet/core-version.d.ts +1 -1
  6. package/dist/adapters/fleet/core-version.js +1 -1
  7. package/dist/adapters/fleet/rest-fleet-door.js +6 -5
  8. package/dist/adapters/fleet/rest-fleet-door.js.map +1 -1
  9. package/dist/adapters/prisma/fleet-forgetter.d.ts +1 -1
  10. package/dist/adapters/prisma/fleet-forgetter.js +2 -2
  11. package/dist/adapters/prisma/fleet-forgetter.js.map +1 -1
  12. package/dist/adapters/prisma/generated/browser.d.ts +32 -0
  13. package/dist/adapters/prisma/generated/client.d.ts +32 -0
  14. package/dist/adapters/prisma/generated/commonInputTypes.d.ts +150 -0
  15. package/dist/adapters/prisma/generated/internal/class.d.ts +44 -0
  16. package/dist/adapters/prisma/generated/internal/class.js +4 -4
  17. package/dist/adapters/prisma/generated/internal/class.js.map +1 -1
  18. package/dist/adapters/prisma/generated/internal/prismaNamespace.d.ts +360 -1
  19. package/dist/adapters/prisma/generated/internal/prismaNamespace.js +46 -1
  20. package/dist/adapters/prisma/generated/internal/prismaNamespace.js.map +1 -1
  21. package/dist/adapters/prisma/generated/internal/prismaNamespaceBrowser.d.ts +51 -0
  22. package/dist/adapters/prisma/generated/internal/prismaNamespaceBrowser.js +46 -1
  23. package/dist/adapters/prisma/generated/internal/prismaNamespaceBrowser.js.map +1 -1
  24. package/dist/adapters/prisma/generated/models/McpConfiguration.d.ts +1004 -0
  25. package/dist/adapters/prisma/generated/models/McpConfiguration.js +2 -0
  26. package/dist/adapters/prisma/generated/models/McpConfiguration.js.map +1 -0
  27. package/dist/adapters/prisma/generated/models/McpConfigurationEvent.d.ts +1141 -0
  28. package/dist/adapters/prisma/generated/models/McpConfigurationEvent.js +2 -0
  29. package/dist/adapters/prisma/generated/models/McpConfigurationEvent.js.map +1 -0
  30. package/dist/adapters/prisma/generated/models/McpDelivery.d.ts +1204 -0
  31. package/dist/adapters/prisma/generated/models/McpDelivery.js +2 -0
  32. package/dist/adapters/prisma/generated/models/McpDelivery.js.map +1 -0
  33. package/dist/adapters/prisma/generated/models/McpSecret.d.ts +948 -0
  34. package/dist/adapters/prisma/generated/models/McpSecret.js +2 -0
  35. package/dist/adapters/prisma/generated/models/McpSecret.js.map +1 -0
  36. package/dist/adapters/prisma/generated/models.d.ts +4 -0
  37. package/dist/adapters/prisma/mcp-configurations.d.ts +11 -0
  38. package/dist/adapters/prisma/mcp-configurations.js +44 -0
  39. package/dist/adapters/prisma/mcp-configurations.js.map +1 -0
  40. package/dist/adapters/prisma/mcp-deliveries.d.ts +9 -0
  41. package/dist/adapters/prisma/mcp-deliveries.js +47 -0
  42. package/dist/adapters/prisma/mcp-deliveries.js.map +1 -0
  43. package/dist/adapters/trpc/router.d.ts +63 -5
  44. package/dist/adapters/trpc/router.js +60 -2
  45. package/dist/adapters/trpc/router.js.map +1 -1
  46. package/dist/app.d.ts +2 -6
  47. package/dist/app.js +78 -54
  48. package/dist/app.js.map +1 -1
  49. package/dist/bin/aeolus-trierarch-plugin.js +1 -2
  50. package/dist/bin/aeolus-trierarch-plugin.js.map +1 -1
  51. package/dist/config.d.ts +6 -10
  52. package/dist/config.js +5 -54
  53. package/dist/config.js.map +1 -1
  54. package/dist/core/assignment/assign-crews.d.ts +5 -1
  55. package/dist/core/assignment/assign-crews.js +4 -2
  56. package/dist/core/assignment/assign-crews.js.map +1 -1
  57. package/dist/core/assignment/check-crew-settings.d.ts +3 -0
  58. package/dist/core/assignment/check-crew-settings.js +2 -1
  59. package/dist/core/assignment/check-crew-settings.js.map +1 -1
  60. package/dist/core/assignment/placement.d.ts +6 -0
  61. package/dist/core/assignment/placement.js +12 -4
  62. package/dist/core/assignment/placement.js.map +1 -1
  63. package/dist/core/assignment/read-placement.d.ts +7 -1
  64. package/dist/core/assignment/read-placement.js +14 -2
  65. package/dist/core/assignment/read-placement.js.map +1 -1
  66. package/dist/core/assignment/tell-crew-request-reasons.d.ts +35 -0
  67. package/dist/core/assignment/tell-crew-request-reasons.js +110 -0
  68. package/dist/core/assignment/tell-crew-request-reasons.js.map +1 -0
  69. package/dist/core/connection/answer-pings.d.ts +13 -1
  70. package/dist/core/connection/answer-pings.js +11 -2
  71. package/dist/core/connection/answer-pings.js.map +1 -1
  72. package/dist/core/connection/ports.d.ts +23 -6
  73. package/dist/core/connection/ports.js +2 -1
  74. package/dist/core/connection/ports.js.map +1 -1
  75. package/dist/core/mcp-configuration/distribute-mcp-configuration.d.ts +38 -0
  76. package/dist/core/mcp-configuration/distribute-mcp-configuration.js +97 -0
  77. package/dist/core/mcp-configuration/distribute-mcp-configuration.js.map +1 -0
  78. package/dist/core/mcp-configuration/mcp-configuration.d.ts +107 -0
  79. package/dist/core/mcp-configuration/mcp-configuration.js +205 -0
  80. package/dist/core/mcp-configuration/mcp-configuration.js.map +1 -0
  81. package/dist/core/mcp-configuration/mcp-delivery.d.ts +59 -0
  82. package/dist/core/mcp-configuration/mcp-delivery.js +32 -0
  83. package/dist/core/mcp-configuration/mcp-delivery.js.map +1 -0
  84. package/dist/core/mcp-configuration/ports.d.ts +79 -0
  85. package/dist/core/mcp-configuration/ports.js.map +1 -0
  86. package/dist/core/mcp-configuration/read-mcp-configuration.d.ts +8 -0
  87. package/dist/core/mcp-configuration/read-mcp-configuration.js +6 -0
  88. package/dist/core/mcp-configuration/read-mcp-configuration.js.map +1 -0
  89. package/dist/core/mcp-configuration/replace-mcp-configuration.d.ts +24 -0
  90. package/dist/core/mcp-configuration/replace-mcp-configuration.js +30 -0
  91. package/dist/core/mcp-configuration/replace-mcp-configuration.js.map +1 -0
  92. package/dist/core/mcp-configuration/sealing-key.js.map +1 -0
  93. package/dist/core/mcp-configuration/take-mcp-configuration-message.d.ts +30 -0
  94. package/dist/core/mcp-configuration/take-mcp-configuration-message.js +74 -0
  95. package/dist/core/mcp-configuration/take-mcp-configuration-message.js.map +1 -0
  96. package/dist/core/models/answer-enabled-models-asks.d.ts +18 -0
  97. package/dist/core/models/answer-enabled-models-asks.js +32 -0
  98. package/dist/core/models/answer-enabled-models-asks.js.map +1 -0
  99. package/dist/core/operator/authenticate-operator.d.ts +3 -1
  100. package/dist/core/operator/authenticate-operator.js +7 -4
  101. package/dist/core/operator/authenticate-operator.js.map +1 -1
  102. package/dist/core/operator/ports.d.ts +2 -1
  103. package/dist/core/shared/errors.d.ts +1 -1
  104. package/dist/core/shared/errors.js.map +1 -1
  105. package/dist/core/usage/ship-names.d.ts +1 -1
  106. package/dist/core/usage/ship-names.js +2 -1
  107. package/dist/core/usage/ship-names.js.map +1 -1
  108. package/package.json +3 -3
  109. package/src/adapters/prisma/migrations/20261109120000_mcp_configurations/migration.sql +35 -0
  110. package/src/adapters/prisma/migrations/20261109130000_mcp_deliveries/migration.sql +15 -0
  111. package/src/adapters/prisma/schema.prisma +65 -0
  112. package/dist/core/mcp-servers/mcp-servers.d.ts +0 -46
  113. package/dist/core/mcp-servers/mcp-servers.js +0 -112
  114. package/dist/core/mcp-servers/mcp-servers.js.map +0 -1
  115. package/dist/core/mcp-servers/ports.d.ts +0 -13
  116. package/dist/core/mcp-servers/ports.js.map +0 -1
  117. package/dist/core/mcp-servers/resend-mcp-servers.d.ts +0 -15
  118. package/dist/core/mcp-servers/resend-mcp-servers.js +0 -19
  119. package/dist/core/mcp-servers/resend-mcp-servers.js.map +0 -1
  120. package/dist/core/mcp-servers/resend-secrets.d.ts +0 -15
  121. package/dist/core/mcp-servers/resend-secrets.js +0 -19
  122. package/dist/core/mcp-servers/resend-secrets.js.map +0 -1
  123. package/dist/core/mcp-servers/sealing-key.js.map +0 -1
  124. package/dist/core/mcp-servers/secrets.d.ts +0 -31
  125. package/dist/core/mcp-servers/secrets.js +0 -90
  126. package/dist/core/mcp-servers/secrets.js.map +0 -1
  127. package/dist/core/mcp-servers/share-mcp-servers.d.ts +0 -25
  128. package/dist/core/mcp-servers/share-mcp-servers.js +0 -45
  129. package/dist/core/mcp-servers/share-mcp-servers.js.map +0 -1
  130. package/dist/core/mcp-servers/share-secrets.d.ts +0 -36
  131. package/dist/core/mcp-servers/share-secrets.js +0 -71
  132. package/dist/core/mcp-servers/share-secrets.js.map +0 -1
  133. /package/dist/core/{mcp-servers → mcp-configuration}/ports.js +0 -0
  134. /package/dist/core/{mcp-servers → mcp-configuration}/sealing-key.d.ts +0 -0
  135. /package/dist/core/{mcp-servers → mcp-configuration}/sealing-key.js +0 -0
@@ -0,0 +1,97 @@
1
+ import { TRIERARCH_TYPE } from '../machines/join-machine.js';
2
+ import { isSilent } from '../machines/silent.js';
3
+ import { readSealingKey } from './sealing-key.js';
4
+ import { refuse } from '../shared/errors.js';
5
+ import { ok } from '../shared/result.js';
6
+ import { MCP_CONFIGURATION_CONTENT_TYPE, mcpConfigurationPayload } from './mcp-configuration.js';
7
+ import { nextMcpSend } from './mcp-delivery.js';
8
+ /** The refusal that means no answer came: the pass stops, and the next one tries again. */
9
+ const UNAVAILABLE = 'UNAVAILABLE';
10
+ /**
11
+ * Use case: one pass of reconciling a fleet's MCP configuration with its
12
+ * trierarchs (the fleet crew MCP design, section 5). It reads the set once,
13
+ * then every trierarch ship that is crewed and not silent and states a
14
+ * sealing key: what `nextMcpSend` says it needs is sent as the plugin's ship,
15
+ * the complete set at its version with every secret sealed to that key, an
16
+ * empty set too. A new attempt is kept, under its new idempotency key, before
17
+ * it is sent; one the fleet did not take is sent again, the same message
18
+ * under the same key. A trierarch seen not crewed is forgotten, so its next
19
+ * lease is sent the set again and confirms again. A trierarch without a key
20
+ * is sent nothing, and so is one whose key the sealer refuses: it is named in
21
+ * `unsealable`. A fleet that does not answer stops the pass; one that refuses
22
+ * a send leaves that trierarch for the next pass.
23
+ */
24
+ export function createDistributeMcpConfiguration(deps) {
25
+ const unavailable = (refusal) => refuse('FLEET_UNAVAILABLE', `The fleet did not answer distributing the MCP configuration: ${refusal.message}`);
26
+ /** The set's secrets each sealed to the key, or undefined when the sealer refuses the key. */
27
+ const sealedTo = async (configuration, publicKey) => {
28
+ const secrets = [];
29
+ for (const { name, value } of configuration.secrets) {
30
+ const sealed = await deps.sealer.seal(value, publicKey);
31
+ if (!sealed.isOk) {
32
+ return undefined;
33
+ }
34
+ secrets.push({ name, sealed: sealed.value });
35
+ }
36
+ return secrets;
37
+ };
38
+ return async (fleetId) => {
39
+ const crew = await deps.connections.find(fleetId);
40
+ if (!crew) {
41
+ return refuse('NOT_CONNECTED', 'The trierarch plugin is not connected to this fleet: connect it in the console');
42
+ }
43
+ const listed = await deps.door.listShips(crew.crewToken);
44
+ if (!listed.isOk) {
45
+ return unavailable(listed.error);
46
+ }
47
+ const now = deps.clock.now();
48
+ const configuration = await deps.configurations.read(fleetId);
49
+ const deliveries = new Map((await deps.deliveries.list(fleetId)).map((delivery) => [delivery.trierarchShipId, delivery]));
50
+ const crewed = listed.value.filter((ship) => ship.type === TRIERARCH_TYPE && ship.status === 'crewed');
51
+ const ended = [...deliveries.keys()].filter((shipId) => !crewed.some((ship) => ship.shipId === shipId));
52
+ if (ended.length > 0) {
53
+ await deps.deliveries.forget(fleetId, ended);
54
+ }
55
+ let sent = 0;
56
+ const unsealable = [];
57
+ for (const ship of crewed.filter((each) => !isSilent(each.lastSeenAt, { now, silentAfterMs: deps.silentAfterMs }))) {
58
+ const read = await deps.door.getShip(crew.crewToken, { shipId: ship.shipId });
59
+ if (!read.isOk && read.error.code === UNAVAILABLE) {
60
+ return unavailable(read.error);
61
+ }
62
+ const publicKey = read.isOk ? readSealingKey(read.value.report?.details) : undefined;
63
+ if (publicKey === undefined) {
64
+ continue;
65
+ }
66
+ const next = nextMcpSend(deliveries.get(ship.shipId), { target: { version: configuration.version, publicKey }, now });
67
+ if (next.kind === 'none') {
68
+ continue;
69
+ }
70
+ let attempt;
71
+ if (next.kind === 'retry') {
72
+ ({ attempt } = next);
73
+ }
74
+ else {
75
+ const secrets = await sealedTo(configuration, publicKey);
76
+ if (secrets === undefined) {
77
+ unsealable.push({ shipId: ship.shipId, publicKey });
78
+ continue;
79
+ }
80
+ const payload = mcpConfigurationPayload({ fleetId, pluginShipId: crew.shipId, version: configuration.version, publicKey, servers: configuration.servers, secrets });
81
+ attempt = { version: configuration.version, publicKey, idempotencyKey: deps.keys.next(), payload, sentAt: null };
82
+ // Kept before it is sent: a send the fleet may have taken is made again under this key, never under a new one.
83
+ await deps.deliveries.recordAttempt(fleetId, { trierarchShipId: ship.shipId, attempt });
84
+ }
85
+ const done = await deps.door.send(crew.crewToken, { shipId: ship.shipId, contentType: MCP_CONFIGURATION_CONTENT_TYPE, payload: attempt.payload, idempotencyKey: attempt.idempotencyKey });
86
+ if (!done.isOk && done.error.code === UNAVAILABLE) {
87
+ return unavailable(done.error);
88
+ }
89
+ if (done.isOk) {
90
+ await deps.deliveries.markSent(fleetId, { trierarchShipId: ship.shipId, idempotencyKey: attempt.idempotencyKey, at: now });
91
+ sent += 1;
92
+ }
93
+ }
94
+ return ok({ sent, unsealable });
95
+ };
96
+ }
97
+ //# sourceMappingURL=distribute-mcp-configuration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"distribute-mcp-configuration.js","sourceRoot":"","sources":["../../../src/core/mcp-configuration/distribute-mcp-configuration.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAE7D,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,OAAO,EAAE,MAAM,EAAoB,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EAAE,EAAE,EAAe,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,8BAA8B,EAAE,uBAAuB,EAAyB,MAA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EAAE,CAAC,CAAC;IAClC,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,107 @@
1
+ /**
2
+ * A fleet's MCP configuration (the fleet crew MCP design, section 4): the
3
+ * remote servers (Streamable HTTP) a session of that fleet may be crewed
4
+ * with, each by name with its URL, the tools a session may call and the
5
+ * credential its proxy adds, and the secrets those credentials name, with
6
+ * their values. One current set per fleet, in the trierarch plugin's own
7
+ * database, at a version that moves on by one with every replacement. A
8
+ * replacement is whole: the complete server list, the complete list of the
9
+ * secrets it retains and the values it sets. A value is never shown, logged
10
+ * or told in a reason; it leaves the trierarch plugin only sealed to a
11
+ * trierarch's key, so the set, once sealed, fits one message.
12
+ */
13
+ import { type FleetId } from '@aeolus-fleet/common';
14
+ import { type DomainError } from '../shared/errors.js';
15
+ import { type Result } from '../shared/result.js';
16
+ /** What the trierarch's proxy adds to what it forwards to a server: the header, set to the named secret's value verbatim (decision M6). */
17
+ export interface McpCredential {
18
+ readonly secret: string;
19
+ readonly header: string;
20
+ }
21
+ /** A server of the set, with its credential when it needs one. */
22
+ export interface McpServer {
23
+ readonly name: string;
24
+ readonly url: string;
25
+ readonly tools: readonly string[];
26
+ readonly credential?: McpCredential;
27
+ }
28
+ /** A secret of the set, by name, with its value: fit for an HTTP header verbatim. */
29
+ export interface McpSecret {
30
+ readonly name: string;
31
+ readonly value: string;
32
+ }
33
+ /** A fleet's set as saved: its version, its servers and its secrets, each in name order. Built only by `replaceMcpConfiguration`. */
34
+ export interface McpConfiguration {
35
+ readonly version: number;
36
+ readonly servers: readonly McpServer[];
37
+ readonly secrets: readonly McpSecret[];
38
+ }
39
+ /** What `mcp.get` answers: the version, the servers and the secrets by name, never a value. */
40
+ export interface McpConfigurationMetadata {
41
+ readonly version: number;
42
+ readonly servers: readonly McpServer[];
43
+ readonly secrets: readonly string[];
44
+ }
45
+ /** A fleet's set before its first replacement. */
46
+ export declare const EMPTY_MCP_CONFIGURATION: McpConfiguration;
47
+ /**
48
+ * A whole replacement as a manager asks it: the version it read, every
49
+ * server, every secret it retains by name, and the new or replacement
50
+ * values, by name, of secrets it retains.
51
+ */
52
+ export interface McpReplacement {
53
+ readonly expectedVersion: number;
54
+ readonly servers: readonly {
55
+ readonly name: string;
56
+ readonly url: string;
57
+ readonly tools: readonly string[];
58
+ readonly credential?: McpCredential;
59
+ }[];
60
+ readonly secrets: readonly string[];
61
+ readonly secretValues: Readonly<Record<string, string>>;
62
+ }
63
+ /** What a replacement changed, by name: never a value. */
64
+ export interface McpChange {
65
+ readonly servers: readonly string[];
66
+ readonly secrets: readonly string[];
67
+ }
68
+ /** The content type of the message that carries a fleet's set, whole and sealed, to a trierarch. */
69
+ export declare const MCP_CONFIGURATION_CONTENT_TYPE = "application/vnd.aeolus.trierarch.mcp-configuration+json";
70
+ /** The content type of the message a trierarch asks for its fleet's set with. */
71
+ export declare const MCP_CONFIGURATION_REQUEST_CONTENT_TYPE = "application/vnd.aeolus.trierarch.mcp-configuration-request+json";
72
+ /** The content type of the message a trierarch confirms with that it applied a version, sealed to a key. */
73
+ export declare const MCP_CONFIGURATION_APPLIED_CONTENT_TYPE = "application/vnd.aeolus.trierarch.mcp-configuration-applied+json";
74
+ /**
75
+ * Policy: the fleet's set after a whole replacement, one version on, and what
76
+ * it changed by name; or why not, the whole replacement refused: a version
77
+ * other than the current one, a server or secret that fails the rules, a
78
+ * credential naming a secret it does not retain, a retained secret with
79
+ * neither a value nor one held, a value for a secret it does not retain, or
80
+ * a set too large for one message once sealed. No reason holds a value.
81
+ */
82
+ export declare function replaceMcpConfiguration({ fleetId, current }: {
83
+ fleetId: FleetId;
84
+ current: McpConfiguration;
85
+ }, replacement: McpReplacement): Result<{
86
+ configuration: McpConfiguration;
87
+ changed: McpChange;
88
+ }, DomainError<'VERSION_CONFLICT' | 'INVALID_CONFIGURATION'>>;
89
+ /** The set as `mcp.get` shows it: the secrets by name only. */
90
+ export declare function mcpConfigurationMetadata(configuration: McpConfiguration): McpConfigurationMetadata;
91
+ /**
92
+ * The set as a trierarch receives it (design section 5): `{ fleetId,
93
+ * pluginShipId, version, publicKey, servers: [{ name, url, transport, tools,
94
+ * credential? }], secrets: [{ name, sealed }] }`, each value sealed to the
95
+ * public key named.
96
+ */
97
+ export declare function mcpConfigurationPayload(message: {
98
+ fleetId: FleetId;
99
+ pluginShipId: string;
100
+ version: number;
101
+ publicKey: string;
102
+ servers: readonly McpServer[];
103
+ secrets: readonly {
104
+ name: string;
105
+ sealed: string;
106
+ }[];
107
+ }): string;
@@ -0,0 +1,205 @@
1
+ /**
2
+ * A fleet's MCP configuration (the fleet crew MCP design, section 4): the
3
+ * remote servers (Streamable HTTP) a session of that fleet may be crewed
4
+ * with, each by name with its URL, the tools a session may call and the
5
+ * credential its proxy adds, and the secrets those credentials name, with
6
+ * their values. One current set per fleet, in the trierarch plugin's own
7
+ * database, at a version that moves on by one with every replacement. A
8
+ * replacement is whole: the complete server list, the complete list of the
9
+ * secrets it retains and the values it sets. A value is never shown, logged
10
+ * or told in a reason; it leaves the trierarch plugin only sealed to a
11
+ * trierarch's key, so the set, once sealed, fits one message.
12
+ */
13
+ import { PAYLOAD_MAX_BYTES, payloadBytes, trierarchNameSchema } from '@aeolus-fleet/common';
14
+ import { z } from 'zod';
15
+ import { refuse } from '../shared/errors.js';
16
+ import { ok } from '../shared/result.js';
17
+ /** A fleet's set before its first replacement. */
18
+ export const EMPTY_MCP_CONFIGURATION = { version: 0, servers: [], secrets: [] };
19
+ /** The content type of the message that carries a fleet's set, whole and sealed, to a trierarch. */
20
+ export const MCP_CONFIGURATION_CONTENT_TYPE = 'application/vnd.aeolus.trierarch.mcp-configuration+json';
21
+ /** The content type of the message a trierarch asks for its fleet's set with. */
22
+ export const MCP_CONFIGURATION_REQUEST_CONTENT_TYPE = 'application/vnd.aeolus.trierarch.mcp-configuration-request+json';
23
+ /** The content type of the message a trierarch confirms with that it applied a version, sealed to a key. */
24
+ export const MCP_CONFIGURATION_APPLIED_CONTENT_TYPE = 'application/vnd.aeolus.trierarch.mcp-configuration-applied+json';
25
+ /** The one transport a server speaks (decision M8), named in each server of the message. */
26
+ const TRANSPORT = 'streamable-http';
27
+ const BYTES_PER_KB = 1024;
28
+ /** The most a value may hold, in bytes of UTF-8, as the trierarch takes it. */
29
+ const VALUE_MAX_BYTES = 8192;
30
+ /** What a sealed box adds to the value: the ephemeral public key and the tag. */
31
+ const SEALED_BOX_OVERHEAD_BYTES = 48;
32
+ /** A public key of the sealing scheme, in bytes. */
33
+ const PUBLIC_KEY_BYTES = 32;
34
+ /** A ship id as the fleet makes one, every id the same length: what the size check counts for the plugin's ship. */
35
+ const SHIP_ID_SHAPE = `shp_${'0'.repeat(26)}`;
36
+ const URL_REFUSED = 'an MCP server is an http:// or https:// URL with no user, query or fragment, never a credential';
37
+ const VALUE_REFUSED = `a value is 1 to ${String(VALUE_MAX_BYTES)} bytes of UTF-8 with no CR, LF or NUL`;
38
+ /** Whether the URL is a remote server's, which carries no credential in itself. */
39
+ function isCredentialFree(url) {
40
+ if (!URL.canParse(url)) {
41
+ return false;
42
+ }
43
+ const parsed = new URL(url);
44
+ return (parsed.protocol === 'https:' || parsed.protocol === 'http:') && parsed.hostname !== '' && parsed.username === '' && parsed.password === '' && parsed.search === '' && parsed.hash === '';
45
+ }
46
+ /** An HTTP field name: an RFC 9110 token. */
47
+ const HEADER_TOKEN = /^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/;
48
+ /** The headers the proxy itself owns, or that frame the request or its session: never a credential's. */
49
+ const HEADERS_REFUSED = new Set(['host', 'content-length', 'transfer-encoding', 'connection', 'upgrade', 'te', 'trailer', 'keep-alive', 'cookie', 'content-type', 'accept', 'accept-encoding', 'last-event-id', 'mcp-session-id', 'mcp-protocol-version']);
50
+ /** Whether a credential may go in the header: a token the proxy does not own. */
51
+ function isCredentialHeader(header) {
52
+ const lower = header.toLowerCase();
53
+ return HEADER_TOKEN.test(header) && !HEADERS_REFUSED.has(lower) && !lower.startsWith('proxy-');
54
+ }
55
+ const serverSchema = z.object({
56
+ url: z.string().refine(isCredentialFree, { error: URL_REFUSED }),
57
+ credential: z.object({ secret: trierarchNameSchema, header: z.string().refine(isCredentialHeader, { error: 'a credential header is an HTTP field name the proxy does not set itself' }) }).optional(),
58
+ tools: z
59
+ .array(z.string().min(1, { error: 'a tool has a name' }))
60
+ .min(1, { error: 'a server lists the tools a session may call' })
61
+ .refine((tools) => new Set(tools).size === tools.length, { error: 'a tool is listed once' }),
62
+ });
63
+ /** Whether the value can go in an HTTP header verbatim and the trierarch takes it. */
64
+ function isValue(value) {
65
+ const bytes = Buffer.byteLength(value, 'utf8');
66
+ return bytes >= 1 && bytes <= VALUE_MAX_BYTES && !['\r', '\n', '\u0000'].some((refused) => value.includes(refused));
67
+ }
68
+ /** The length of standard base64 with padding of so many bytes. */
69
+ function base64Length(bytes) {
70
+ const BASE64_GROUP_BYTES = 3;
71
+ const BASE64_GROUP_CHARACTERS = 4;
72
+ return Math.ceil(bytes / BASE64_GROUP_BYTES) * BASE64_GROUP_CHARACTERS;
73
+ }
74
+ const byName = (first, second) => first.name.localeCompare(second.name);
75
+ const invalid = (message) => refuse('INVALID_CONFIGURATION', message);
76
+ /** The servers, read and in name order, or why not: each told by its name, or by its position when its name is not one. */
77
+ function readServers(listed) {
78
+ const servers = [];
79
+ for (const [index, server] of listed.entries()) {
80
+ const named = trierarchNameSchema.safeParse(server.name);
81
+ if (!named.success) {
82
+ return invalid(`server ${String(index + 1)}: ${named.error.issues[0]?.message ?? 'not a name'}`);
83
+ }
84
+ if (servers.some((each) => each.name === server.name)) {
85
+ return invalid(`${server.name}: a server is named once`);
86
+ }
87
+ const read = serverSchema.safeParse(server);
88
+ if (!read.success) {
89
+ return invalid(`${server.name}: ${read.error.issues[0]?.message ?? 'not a server'}`);
90
+ }
91
+ const { url, tools, credential } = read.data;
92
+ servers.push(credential === undefined ? { name: server.name, url, tools } : { name: server.name, url, tools, credential: { secret: credential.secret, header: credential.header } });
93
+ }
94
+ return ok(servers.sort(byName));
95
+ }
96
+ /**
97
+ * The secrets the replacement retains, each with its new value or the one it
98
+ * holds, in name order, or why not. A name that fails the rules may be a
99
+ * value put in its place, so it is told by position; so is a value's name
100
+ * the retained list does not hold.
101
+ */
102
+ function readSecrets(current, replacement) {
103
+ const secrets = [];
104
+ for (const [index, name] of replacement.secrets.entries()) {
105
+ if (!trierarchNameSchema.safeParse(name).success) {
106
+ return invalid(`secret ${String(index + 1)}: not a name: a secret is named as a server is`);
107
+ }
108
+ if (secrets.some((each) => each.name === name)) {
109
+ return invalid(`${name}: a secret is retained once`);
110
+ }
111
+ const value = Object.hasOwn(replacement.secretValues, name) ? replacement.secretValues[name] : current.secrets.find((each) => each.name === name)?.value;
112
+ if (value === undefined) {
113
+ return invalid(`${name}: a retained secret needs a value until it holds one`);
114
+ }
115
+ if (!isValue(value)) {
116
+ return invalid(`${name}: ${VALUE_REFUSED}`);
117
+ }
118
+ secrets.push({ name, value });
119
+ }
120
+ const unretained = Object.keys(replacement.secretValues).findIndex((name) => !replacement.secrets.includes(name));
121
+ if (unretained !== -1) {
122
+ return invalid(`secret value ${String(unretained + 1)}: names no secret the replacement retains`);
123
+ }
124
+ return ok(secrets.sort(byName));
125
+ }
126
+ /** The names whose entry the replacement added, removed or changed, in name order. */
127
+ function changedNames({ before, after }, isSame) {
128
+ const names = new Set([...before, ...after].map((each) => each.name));
129
+ return [...names]
130
+ .filter((name) => {
131
+ const old = before.find((each) => each.name === name);
132
+ const updated = after.find((each) => each.name === name);
133
+ return old === undefined || updated === undefined || !isSame(old, updated);
134
+ })
135
+ .sort((first, second) => first.localeCompare(second));
136
+ }
137
+ /** The size of the message that carries the set to a trierarch of the fleet once sealed, which a sealed box makes exact. */
138
+ function sealedPayloadBytes(fleetId, configuration) {
139
+ return payloadBytes(mcpConfigurationPayload({
140
+ fleetId,
141
+ pluginShipId: SHIP_ID_SHAPE,
142
+ version: configuration.version,
143
+ publicKey: 'A'.repeat(base64Length(PUBLIC_KEY_BYTES)),
144
+ servers: configuration.servers,
145
+ secrets: configuration.secrets.map(({ name, value }) => ({ name, sealed: 'A'.repeat(base64Length(Buffer.byteLength(value, 'utf8') + SEALED_BOX_OVERHEAD_BYTES)) })),
146
+ }));
147
+ }
148
+ /**
149
+ * Policy: the fleet's set after a whole replacement, one version on, and what
150
+ * it changed by name; or why not, the whole replacement refused: a version
151
+ * other than the current one, a server or secret that fails the rules, a
152
+ * credential naming a secret it does not retain, a retained secret with
153
+ * neither a value nor one held, a value for a secret it does not retain, or
154
+ * a set too large for one message once sealed. No reason holds a value.
155
+ */
156
+ export function replaceMcpConfiguration({ fleetId, current }, replacement) {
157
+ if (replacement.expectedVersion !== current.version) {
158
+ return refuse('VERSION_CONFLICT', `The MCP configuration is at version ${String(current.version)}, not ${String(replacement.expectedVersion)}: read it again before replacing it`);
159
+ }
160
+ const servers = readServers(replacement.servers);
161
+ if (!servers.isOk) {
162
+ return servers;
163
+ }
164
+ const secrets = readSecrets(current, replacement);
165
+ if (!secrets.isOk) {
166
+ return secrets;
167
+ }
168
+ for (const server of servers.value) {
169
+ if (server.credential !== undefined && !replacement.secrets.includes(server.credential.secret)) {
170
+ return invalid(`${server.name}: its credential names the secret ${server.credential.secret}, which the replacement does not retain`);
171
+ }
172
+ }
173
+ const configuration = { version: current.version + 1, servers: servers.value, secrets: secrets.value };
174
+ if (sealedPayloadBytes(fleetId, configuration) > PAYLOAD_MAX_BYTES) {
175
+ return invalid(`the MCP configuration does not fit one message of ${String(PAYLOAD_MAX_BYTES / BYTES_PER_KB)} KB once sealed`);
176
+ }
177
+ return ok({
178
+ configuration,
179
+ changed: {
180
+ servers: changedNames({ before: current.servers, after: configuration.servers }, (first, second) => JSON.stringify(first) === JSON.stringify(second)),
181
+ secrets: changedNames({ before: current.secrets, after: configuration.secrets }, (first, second) => first.value === second.value && !Object.hasOwn(replacement.secretValues, second.name)),
182
+ },
183
+ });
184
+ }
185
+ /** The set as `mcp.get` shows it: the secrets by name only. */
186
+ export function mcpConfigurationMetadata(configuration) {
187
+ return { version: configuration.version, servers: configuration.servers, secrets: configuration.secrets.map((secret) => secret.name) };
188
+ }
189
+ /**
190
+ * The set as a trierarch receives it (design section 5): `{ fleetId,
191
+ * pluginShipId, version, publicKey, servers: [{ name, url, transport, tools,
192
+ * credential? }], secrets: [{ name, sealed }] }`, each value sealed to the
193
+ * public key named.
194
+ */
195
+ export function mcpConfigurationPayload(message) {
196
+ return JSON.stringify({
197
+ fleetId: message.fleetId,
198
+ pluginShipId: message.pluginShipId,
199
+ version: message.version,
200
+ publicKey: message.publicKey,
201
+ servers: message.servers.map(({ name, url, tools, credential }) => ({ name, url, transport: TRANSPORT, tools, ...(credential && { credential: { secret: credential.secret, header: credential.header } }) })),
202
+ secrets: message.secrets.map(({ name, sealed }) => ({ name, sealed })),
203
+ });
204
+ }
205
+ //# sourceMappingURL=mcp-configuration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-configuration.js","sourceRoot":"","sources":["../../../src/core/mcp-configuration/mcp-configuration.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,mBAAmB,EAAgB,MAAM,sBAAsB,CAAC;AAC1G,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,MAAM,EAAoB,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EAAE,EAAE,EAAe,MAAM,qBAAqB,CAAC;AAoCtD,kDAAkD;AAClD,MAAM,CAAC,MAAM,uBAAuB,GAAqB,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;AAoBlG,oGAAoG;AACpG,MAAM,CAAC,MAAM,8BAA8B,GAAG,yDAAyD,CAAC;AAExG,iFAAiF;AACjF,MAAM,CAAC,MAAM,sCAAsC,GAAG,iEAAiE,CAAC;AAExH,4GAA4G;AAC5G,MAAM,CAAC,MAAM,sCAAsC,GAAG,iEAAiE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,OAAO;QACxB,YAAY,EAAE,OAAO,CAAC,YAAY;QAClC,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,SAAS,EAAE,OAAO,CAAC,SAAS;QAC5B,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,CAAC,UAAU,IAAI,EAAE,UAAU,EAAE,EAAE,MAAM,EAAE,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC;QAC7M,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;KACvE,CAAC,CAAC;AACL,CAAC"}
@@ -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"}