@maiaos/cli 0.1.0-canary.2 → 0.1.0-canary.20
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 +38 -265
- package/dist/address-space/address-space.d.ts +38 -0
- package/dist/address-space/address-space.js +130 -0
- package/dist/address-space/index.d.ts +2 -0
- package/dist/address-space/index.js +2 -0
- package/dist/agents/client.d.ts +171 -0
- package/dist/agents/client.js +8 -0
- package/dist/agents/commands.d.ts +7 -0
- package/dist/agents/commands.js +65 -0
- package/dist/agents/index.d.ts +3 -0
- package/dist/agents/index.js +3 -0
- package/dist/agents/input.d.ts +130 -0
- package/dist/agents/input.js +99 -0
- package/dist/agents/output/format.d.ts +8 -0
- package/dist/agents/output/format.js +47 -0
- package/dist/agents/output/index.d.ts +2 -0
- package/dist/agents/output/index.js +2 -0
- package/dist/agents/tree/index.d.ts +2 -0
- package/dist/agents/tree/index.js +2 -0
- package/dist/agents/tree/tree.d.ts +3 -0
- package/dist/agents/tree/tree.js +43 -0
- package/dist/bin/maia.cdx.json +37 -14
- package/dist/bin/maia.mjs +1 -1
- package/dist/bootstrap/exit.d.ts +14 -0
- package/dist/bootstrap/exit.js +42 -0
- package/dist/bootstrap/process.js +4 -26
- package/dist/bootstrap/run.js +5 -2
- package/dist/cli/cli.d.ts +2 -1
- package/dist/cli/cli.js +81 -16
- package/dist/command-line/context.d.ts +14 -4
- package/dist/command-line/context.js +1 -1
- package/dist/command-line/index.d.ts +6 -6
- package/dist/command-line/index.js +6 -5
- package/dist/command-line/input/arguments.d.ts +7 -0
- package/dist/command-line/input/arguments.js +22 -10
- package/dist/command-line/input/index.d.ts +2 -2
- package/dist/command-line/input/index.js +2 -2
- package/dist/command-line/input/stdin.d.ts +1 -0
- package/dist/command-line/input/stdin.js +1 -0
- package/dist/command-line/json.d.ts +1 -0
- package/dist/command-line/json.js +23 -0
- package/dist/command-line/output.d.ts +8 -1
- package/dist/command-line/output.js +33 -14
- package/dist/command-line/rows.d.ts +2 -0
- package/dist/command-line/rows.js +10 -1
- package/dist/command-line/two-phase.d.ts +5 -0
- package/dist/command-line/two-phase.js +33 -8
- package/dist/command-tree/help.d.ts +1 -1
- package/dist/command-tree/help.js +1 -0
- package/dist/command-tree/index.d.ts +2 -2
- package/dist/command-tree/index.js +1 -1
- package/dist/command-tree/local.js +12 -0
- package/dist/command-tree/placeholder.d.ts +1 -0
- package/dist/command-tree/placeholder.js +1 -0
- package/dist/command-tree/row.d.ts +2 -0
- package/dist/command-tree/tree.d.ts +3 -2
- package/dist/command-tree/tree.js +18 -2
- package/dist/connection/access/client.d.ts +13 -0
- package/dist/connection/access/client.js +19 -0
- package/dist/connection/access/commands.d.ts +6 -0
- package/dist/connection/access/commands.js +60 -0
- package/dist/connection/access/format.d.ts +8 -0
- package/dist/connection/access/format.js +61 -0
- package/dist/connection/access/index.d.ts +3 -0
- package/dist/connection/access/index.js +3 -0
- package/dist/connection/access/input.d.ts +53 -0
- package/dist/connection/access/input.js +83 -0
- package/dist/connection/client.d.ts +99 -1
- package/dist/connection/client.js +9 -1
- package/dist/connection/index.d.ts +2 -1
- package/dist/connection/index.js +2 -1
- package/dist/connection/system.d.ts +1 -0
- package/dist/connection/system.js +109 -5
- package/dist/connection/tree/tree.js +59 -8
- package/dist/container/output/format.js +1 -2
- package/dist/dashboard/cockpit-client.d.ts +6 -0
- package/dist/dashboard/cockpit-client.js +27 -0
- package/dist/dashboard/cockpits.d.ts +29 -0
- package/dist/dashboard/cockpits.js +65 -0
- package/dist/dashboard/dashboard.d.ts +7 -0
- package/dist/dashboard/dashboard.js +47 -0
- package/dist/dashboard/draw.d.ts +15 -0
- package/dist/dashboard/draw.js +30 -0
- package/dist/dashboard/frame.d.ts +4 -0
- package/dist/dashboard/frame.js +15 -0
- package/dist/dashboard/index.d.ts +2 -0
- package/dist/dashboard/index.js +2 -0
- package/dist/dashboard/modes.d.ts +5 -0
- package/dist/dashboard/modes.js +16 -0
- package/dist/dashboard/node-connection.d.ts +15 -0
- package/dist/dashboard/node-connection.js +51 -0
- package/dist/dashboard/pi-tui.d.ts +6 -0
- package/dist/dashboard/pi-tui.js +35 -0
- package/dist/dashboard/status-bar.d.ts +4 -0
- package/dist/dashboard/status-bar.js +60 -0
- package/dist/dashboard/terminal.d.ts +53 -0
- package/dist/dashboard/terminal.js +165 -0
- package/dist/dashboard/tree-model.d.ts +28 -0
- package/dist/dashboard/tree-model.js +97 -0
- package/dist/dashboard/tree.d.ts +10 -0
- package/dist/dashboard/tree.js +76 -0
- package/dist/fleet/fleet.d.ts +70 -0
- package/dist/fleet/fleet.js +91 -0
- package/dist/fleet/index.d.ts +2 -0
- package/dist/fleet/index.js +2 -0
- package/dist/hold/output/format.js +1 -5
- package/dist/hold/tree/tree.js +1 -0
- package/dist/import/commands.js +3 -4
- package/dist/import/output.js +1 -4
- package/dist/local-node/client.d.ts +9 -4
- package/dist/local-node/client.js +21 -9
- package/dist/local-node/index.d.ts +2 -1
- package/dist/local-node/index.js +2 -1
- package/dist/local-node/wait.d.ts +10 -0
- package/dist/local-node/wait.js +17 -0
- package/dist/login/commands.js +2 -1
- package/dist/mcp/calls.d.ts +1 -0
- package/dist/mcp/calls.js +37 -3
- package/dist/mcp/commands.d.ts +5 -2
- package/dist/mcp/commands.js +30 -4
- package/dist/mcp/routing.d.ts +24 -0
- package/dist/mcp/routing.js +188 -0
- package/dist/mcp/server.d.ts +13 -4
- package/dist/mcp/server.js +35 -12
- package/dist/presentation/output/format.js +4 -3
- package/dist/project-guard/commands.js +11 -2
- package/dist/project-workspace/commands.js +16 -6
- package/dist/project-workspace/output/human.d.ts +13 -0
- package/dist/project-workspace/output/human.js +17 -5
- package/dist/project-workspace/output/index.d.ts +1 -1
- package/dist/project-workspace/output/index.js +1 -1
- package/dist/project-workspace/output/metadata.js +1 -1
- package/dist/project-workspace/tree/tree.js +27 -12
- package/dist/reference/commands.js +4 -2
- package/dist/reference/index.d.ts +1 -1
- package/dist/reference/index.js +1 -1
- package/dist/reference/resolve.d.ts +2 -0
- package/dist/reference/resolve.js +28 -18
- package/dist/remote-node/client.d.ts +89 -9
- package/dist/remote-node/client.js +6 -1
- package/dist/remote-node/commands.d.ts +9 -0
- package/dist/remote-node/commands.js +96 -18
- package/dist/remote-node/connector.d.ts +12 -4
- package/dist/remote-node/connector.js +54 -26
- package/dist/remote-node/index.d.ts +2 -2
- package/dist/remote-node/index.js +2 -2
- package/dist/remote-node/reachability.d.ts +43 -1
- package/dist/remote-node/reachability.js +13 -3
- package/dist/remote-node/text.d.ts +2 -1
- package/dist/remote-node/text.js +74 -27
- package/dist/remote-node/tree/tree.js +21 -1
- package/dist/routine/client.d.ts +398 -0
- package/dist/routine/client.js +28 -0
- package/dist/routine/commands.d.ts +9 -0
- package/dist/routine/commands.js +109 -0
- package/dist/routine/index.d.ts +3 -0
- package/dist/routine/index.js +3 -0
- package/dist/routine/input.d.ts +28 -0
- package/dist/routine/input.js +44 -0
- package/dist/routine/output/format.d.ts +23 -0
- package/dist/routine/output/format.js +83 -0
- package/dist/routine/output/index.d.ts +2 -0
- package/dist/routine/output/index.js +2 -0
- package/dist/routine/tree/index.d.ts +2 -0
- package/dist/routine/tree/index.js +2 -0
- package/dist/routine/tree/tree.d.ts +3 -0
- package/dist/routine/tree/tree.js +70 -0
- package/dist/session/agent-permission.d.ts +2 -2
- package/dist/session/approval/commands.js +31 -9
- package/dist/session/approval/output/format.d.ts +11 -0
- package/dist/session/approval/output/format.js +8 -0
- package/dist/session/approval/output/index.d.ts +1 -1
- package/dist/session/approval/output/index.js +1 -1
- package/dist/session/attach-client.d.ts +1 -1
- package/dist/session/attach-client.js +12 -3
- package/dist/session/attach-render.js +15 -7
- package/dist/session/attach.js +17 -3
- package/dist/session/client.d.ts +12 -3
- package/dist/session/client.js +18 -17
- package/dist/session/commands.d.ts +1 -0
- package/dist/session/commands.js +120 -13
- package/dist/session/create-tasks.js +29 -11
- package/dist/session/index.d.ts +2 -2
- package/dist/session/index.js +2 -1
- package/dist/session/interaction/output/format.js +2 -1
- package/dist/session/output/diff.js +3 -10
- package/dist/session/output/failure.js +3 -10
- package/dist/session/output/human.d.ts +1 -0
- package/dist/session/output/human.js +21 -10
- package/dist/session/output/index.d.ts +2 -2
- package/dist/session/output/index.js +2 -2
- package/dist/session/output/tasks.d.ts +16 -1
- package/dist/session/output/tasks.js +41 -27
- package/dist/session/tree/tree.js +67 -8
- package/dist/session/turn/client.d.ts +4 -1
- package/dist/session/turn/client.js +22 -11
- package/dist/session/turn/commands.d.ts +2 -0
- package/dist/session/turn/commands.js +39 -11
- package/dist/session/turn/index.d.ts +3 -3
- package/dist/session/turn/index.js +1 -1
- package/dist/session/turn/output.d.ts +7 -2
- package/dist/session/turn/output.js +36 -13
- package/dist/status/client.d.ts +7 -2
- package/dist/status/command.js +3 -1
- package/dist/status/doctor.d.ts +5 -1
- package/dist/status/doctor.js +10 -4
- package/dist/status/output/compact.d.ts +1 -0
- package/dist/status/output/compact.js +3 -0
- package/dist/status/output/human.d.ts +1 -1
- package/dist/status/output/human.js +71 -14
- package/dist/team-workspace/ceremony.d.ts +19 -0
- package/dist/team-workspace/ceremony.js +141 -0
- package/dist/team-workspace/client.d.ts +58 -0
- package/dist/team-workspace/client.js +6 -0
- package/dist/team-workspace/commands.d.ts +3 -0
- package/dist/team-workspace/commands.js +85 -0
- package/dist/team-workspace/confirmation.d.ts +4 -0
- package/dist/team-workspace/confirmation.js +8 -0
- package/dist/team-workspace/dependencies.d.ts +8 -0
- package/dist/team-workspace/dependencies.js +2 -0
- package/dist/team-workspace/index.d.ts +6 -0
- package/dist/team-workspace/index.js +5 -0
- package/dist/team-workspace/launcher.d.ts +17 -0
- package/dist/team-workspace/launcher.js +30 -0
- package/dist/team-workspace/output.d.ts +15 -0
- package/dist/team-workspace/output.js +28 -0
- package/dist/team-workspace/terminal.d.ts +9 -0
- package/dist/team-workspace/terminal.js +46 -0
- package/dist/terminal/client.d.ts +4 -0
- package/dist/terminal/client.js +3 -0
- package/dist/terminal/commands.js +37 -25
- package/dist/terminal/control-commands.js +26 -9
- package/dist/terminal/keys.d.ts +12 -0
- package/dist/terminal/keys.js +62 -0
- package/dist/terminal/output/compact-list.d.ts +1 -0
- package/dist/terminal/output/compact-list.js +1 -0
- package/dist/terminal/output/human.d.ts +2 -19
- package/dist/terminal/output/human.js +6 -6
- package/dist/terminal/tree/tree.js +16 -16
- package/package.json +10 -8
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { LocalNodeRequestOptions, LocalNodeStatusResult, ProtocolError } from "@maiaos/sdk";
|
|
2
|
-
import type { DiscoveredNodeApiEffectConnection, LocalNodeEffectClient, NodeApiEffectDiscoveryOptions } from "@maiaos/sdk/node/effect";
|
|
2
|
+
import type { DiscoveredNodeApiEffectConnection, LocalNodeEffectClient, NodeApiEffectDiscoveryOptions, NodeBridge } from "@maiaos/sdk/node/effect";
|
|
3
3
|
import * as Crypto from "effect/Crypto";
|
|
4
4
|
import * as Effect from "effect/Effect";
|
|
5
|
-
import * as Schedule from "effect/Schedule";
|
|
6
5
|
export type CliMutationRecovery = {
|
|
7
6
|
readonly commandId: string;
|
|
7
|
+
readonly profile?: string;
|
|
8
8
|
};
|
|
9
9
|
export type CliNodeResult<TValue> = {
|
|
10
10
|
readonly error: ProtocolError;
|
|
@@ -14,12 +14,15 @@ export type CliNodeResult<TValue> = {
|
|
|
14
14
|
readonly ok: true;
|
|
15
15
|
readonly value: TValue;
|
|
16
16
|
};
|
|
17
|
-
export type CliNodeConnection = Pick<DiscoveredNodeApiEffectConnection, "client" | "status"
|
|
17
|
+
export type CliNodeConnection = Pick<DiscoveredNodeApiEffectConnection, "client" | "status"> & {
|
|
18
|
+
readonly attachSession?: NodeBridge["attachSession"];
|
|
19
|
+
};
|
|
18
20
|
export type CliNodeConnector = (options: NodeApiEffectDiscoveryOptions) => Effect.Effect<CliNodeConnection, unknown, Crypto.Crypto>;
|
|
19
21
|
export declare const newCliIdentifier: (prefix: "command" | "request") => Effect.Effect<string, never, Crypto.Crypto>;
|
|
20
22
|
export declare const commandIdentifier: (commandId: string | undefined) => Effect.Effect<string, never, Crypto.Crypto>;
|
|
21
23
|
export declare const fillCommandIdentifier: (input: unknown) => Effect.Effect<unknown, never, Crypto.Crypto>;
|
|
22
24
|
export declare const connectLocalNode: CliNodeConnector;
|
|
25
|
+
export declare const holdsSessionCredential: Effect.Effect<boolean>;
|
|
23
26
|
export declare const outcomeCanBeAmbiguous: (error: unknown) => boolean;
|
|
24
27
|
export declare const invalidNodeInput: <TValue>(schemaError?: unknown) => Effect.Effect<CliNodeResult<TValue>>;
|
|
25
28
|
export type ParameterSchema<TParameters> = {
|
|
@@ -36,6 +39,8 @@ export type CliNodeOperations = {
|
|
|
36
39
|
readonly asCoordinator: () => CliNodeOperations;
|
|
37
40
|
readonly asSession: () => CliNodeOperations;
|
|
38
41
|
readonly readStatus: Effect.Effect<LocalNodeStatusResult, unknown, Crypto.Crypto>;
|
|
42
|
+
readonly remote: boolean;
|
|
43
|
+
readonly runConnectionOperation: <TValue>(operation: (connection: CliNodeConnection) => Effect.Effect<TValue, unknown, Crypto.Crypto>) => CliNodeEffect<TValue>;
|
|
39
44
|
readonly runDiscoveryOperation: <TValue>(operation: (options: NodeApiEffectDiscoveryOptions) => Effect.Effect<TValue, unknown, Crypto.Crypto>, recovery?: CliMutationRecovery) => CliNodeEffect<TValue>;
|
|
40
45
|
readonly runNodeClientOperation: <TValue>(operation: (client: LocalNodeEffectClient, options: LocalNodeRequestOptions) => Effect.Effect<TValue, unknown>, recovery?: CliMutationRecovery) => CliNodeEffect<TValue>;
|
|
41
46
|
readonly runValidatedNodeOperation: <TParameters, TValue>(input: unknown, schema: ParameterSchema<TParameters>, operation: (client: LocalNodeEffectClient, parameters: TParameters, options: LocalNodeRequestOptions) => Effect.Effect<TValue, unknown>, recovery?: CliMutationRecovery) => CliNodeEffect<TValue>;
|
|
@@ -59,7 +64,7 @@ type LazyNodeDependencyInput<TModule, TClient> = {
|
|
|
59
64
|
readonly name: keyof TClient;
|
|
60
65
|
};
|
|
61
66
|
export declare const isBriefSaturation: (error: unknown) => boolean;
|
|
62
|
-
export declare const
|
|
67
|
+
export declare const retryBriefSaturation: <TValue, TError, TServices>(attempt: Effect.Effect<TValue, TError, TServices>, deadlineAt?: bigint) => Effect.Effect<TValue, TError, TServices>;
|
|
63
68
|
export declare const makeCliNodeOperations: (options?: CliNodeOperationsOptions) => CliNodeOperations;
|
|
64
69
|
export declare const discoveryOptionsFor: (profile: string | undefined) => Effect.Effect<NodeApiEffectDiscoveryOptions, unknown>;
|
|
65
70
|
export declare const runLazyNodeDependency: <TModule, TClient>(input: LazyNodeDependencyInput<TModule, TClient>) => Effect.Effect<unknown, unknown, Crypto.Crypto>;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { protocolErrorSchema } from "@maiaos/sdk";
|
|
2
2
|
import * as Cause from "effect/Cause";
|
|
3
|
+
import * as Clock from "effect/Clock";
|
|
3
4
|
import * as Config from "effect/Config";
|
|
4
5
|
import * as Crypto from "effect/Crypto";
|
|
5
6
|
import * as Data from "effect/Data";
|
|
7
|
+
import * as Duration from "effect/Duration";
|
|
6
8
|
import * as Effect from "effect/Effect";
|
|
7
9
|
import * as Option from "effect/Option";
|
|
8
10
|
import * as Predicate from "effect/Predicate";
|
|
@@ -68,6 +70,7 @@ const sessionAttachmentDenied = () => new CliLocalNodeError({
|
|
|
68
70
|
retryable: false,
|
|
69
71
|
},
|
|
70
72
|
});
|
|
73
|
+
export const holdsSessionCredential = Effect.map(Config.option(Config.String(SESSION_CREDENTIAL_VARIABLE)), Option.isSome).pipe(Effect.orElseSucceed(() => false));
|
|
71
74
|
const sessionLaunch = Effect.gen(function* () {
|
|
72
75
|
const credential = yield* Config.option(Config.String(SESSION_CREDENTIAL_VARIABLE));
|
|
73
76
|
const origin = yield* Config.option(Config.String(SESSION_NODE_ORIGIN_VARIABLE));
|
|
@@ -181,15 +184,21 @@ export const isBriefSaturation = (error) => {
|
|
|
181
184
|
return (parsed.data.code === "saturated" && parsed.data.saturation === "admission");
|
|
182
185
|
return maiaClientErrorCode(error) === "saturated";
|
|
183
186
|
};
|
|
184
|
-
|
|
187
|
+
const SATURATION_RETRY = Schedule.exponential("100 millis").pipe(Schedule.jittered);
|
|
185
188
|
const SATURATION_RETRIES = 4;
|
|
189
|
+
const DEADLINE_MARGIN_NANOS = 500000000n;
|
|
190
|
+
const endingBefore = (deadlineAt) => Schedule.fromStep(Effect.map(Schedule.toStep(SATURATION_RETRY), (step) => (now, input) => Effect.flatMap(step(now, input), ([output, backoff]) => Effect.flatMap(Clock.monotonicTimeNanos, (current) => current + Duration.toNanosUnsafe(backoff) + DEADLINE_MARGIN_NANOS >=
|
|
191
|
+
deadlineAt
|
|
192
|
+
? Cause.done(output)
|
|
193
|
+
: Effect.succeed([output, backoff])))));
|
|
194
|
+
export const retryBriefSaturation = (attempt, deadlineAt) => Effect.retry(attempt, {
|
|
195
|
+
schedule: deadlineAt === undefined ? SATURATION_RETRY : endingBefore(deadlineAt),
|
|
196
|
+
times: SATURATION_RETRIES,
|
|
197
|
+
while: isBriefSaturation,
|
|
198
|
+
});
|
|
186
199
|
const nodeClientOperation = (connect) => (operation, recovery) => completeOperation(Effect.gen(function* () {
|
|
187
200
|
const connection = yield* connect;
|
|
188
|
-
return yield* newCliIdentifier("request").pipe(Effect.flatMap((messageId) => operation(connection.client, { messageId }))
|
|
189
|
-
schedule: SATURATION_RETRY,
|
|
190
|
-
times: SATURATION_RETRIES,
|
|
191
|
-
while: isBriefSaturation,
|
|
192
|
-
}));
|
|
201
|
+
return yield* retryBriefSaturation(newCliIdentifier("request").pipe(Effect.flatMap((messageId) => operation(connection.client, { messageId }))));
|
|
193
202
|
}), recovery);
|
|
194
203
|
const validatedNodeOperation = (runNodeClientOperation) => (input, schema, operation, recovery) => {
|
|
195
204
|
const parameters = schema.safeParse(input);
|
|
@@ -208,6 +217,9 @@ const coordinatorOptions = (options) => ({
|
|
|
208
217
|
const boundSession = (options) => options.remote === true
|
|
209
218
|
? () => Effect.fail(sessionRemoteDenied())
|
|
210
219
|
: connectSession;
|
|
220
|
+
const discoveryOperation = (options, discoveryOptions, operation) => options.remote === true
|
|
221
|
+
? Effect.fail(remoteDiscoveryDenied())
|
|
222
|
+
: asSessionOr(Effect.flatMap(discoveryOptions, operation), () => Effect.fail(sessionAttachmentDenied()));
|
|
211
223
|
export const makeCliNodeOperations = (options = {}) => {
|
|
212
224
|
const discoveryOptions = discoveryOptionsOf(options.discoveryOptions);
|
|
213
225
|
const connector = options.connector ?? connectLocalNode;
|
|
@@ -217,9 +229,9 @@ export const makeCliNodeOperations = (options = {}) => {
|
|
|
217
229
|
asCoordinator: () => makeCliNodeOperations(coordinatorOptions(options)),
|
|
218
230
|
asSession: () => makeCliNodeOperations({ ...options, requireSession: true }),
|
|
219
231
|
readStatus: Effect.map(connect, (connection) => connection.status),
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
232
|
+
remote: options.remote === true,
|
|
233
|
+
runConnectionOperation: (operation) => completeOperation(Effect.flatMap(connect, operation)),
|
|
234
|
+
runDiscoveryOperation: (operation, recovery) => completeOperation(discoveryOperation(options, discoveryOptions, operation), recovery),
|
|
223
235
|
runNodeClientOperation,
|
|
224
236
|
runValidatedNodeOperation: validatedNodeOperation(runNodeClientOperation),
|
|
225
237
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export { type CliNodeCall, makeCallClient } from "./call.js";
|
|
2
|
-
export { type CliMutationRecovery, type CliNodeBinding, type CliNodeConnection, type CliNodeConnector, type CliNodeEffect, type CliNodeOperations, type CliNodeOperationsOptions, type CliNodeResult, commandIdentifier, connectLocalNode, discoveryOptionsFor, fillCommandIdentifier, invalidNodeInput, makeCliNodeOperations, newCliIdentifier, outcomeCanBeAmbiguous, type ParameterSchema, runLazyNodeDependency, } from "./client.js";
|
|
2
|
+
export { type CliMutationRecovery, type CliNodeBinding, type CliNodeConnection, type CliNodeConnector, type CliNodeEffect, type CliNodeOperations, type CliNodeOperationsOptions, type CliNodeResult, commandIdentifier, connectLocalNode, discoveryOptionsFor, fillCommandIdentifier, holdsSessionCredential, invalidNodeInput, makeCliNodeOperations, newCliIdentifier, outcomeCanBeAmbiguous, type ParameterSchema, retryBriefSaturation, runLazyNodeDependency, } from "./client.js";
|
|
3
|
+
export { repeatBoundedWait } from "./wait.js";
|
|
3
4
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/local-node/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export { makeCallClient } from "./call.js";
|
|
2
|
-
export { commandIdentifier, connectLocalNode, discoveryOptionsFor, fillCommandIdentifier, invalidNodeInput, makeCliNodeOperations, newCliIdentifier, outcomeCanBeAmbiguous, runLazyNodeDependency, } from "./client.js";
|
|
2
|
+
export { commandIdentifier, connectLocalNode, discoveryOptionsFor, fillCommandIdentifier, holdsSessionCredential, invalidNodeInput, makeCliNodeOperations, newCliIdentifier, outcomeCanBeAmbiguous, retryBriefSaturation, runLazyNodeDependency, } from "./client.js";
|
|
3
|
+
export { repeatBoundedWait } from "./wait.js";
|
|
3
4
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { CliNodeEffect } from "./client.js";
|
|
2
|
+
type BoundedWait<TValue> = {
|
|
3
|
+
readonly maxRequestMilliseconds: number;
|
|
4
|
+
readonly once: (waitMilliseconds: number) => CliNodeEffect<TValue>;
|
|
5
|
+
readonly satisfied: (value: TValue) => boolean;
|
|
6
|
+
readonly timeoutMilliseconds: number;
|
|
7
|
+
};
|
|
8
|
+
export declare const repeatBoundedWait: <TValue>(input: BoundedWait<TValue>) => CliNodeEffect<TValue>;
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=wait.d.ts.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as Clock from "effect/Clock";
|
|
2
|
+
import * as Effect from "effect/Effect";
|
|
3
|
+
const monotonicMilliseconds = Effect.map(Clock.monotonicTimeNanos, (nanos) => Number(nanos / 1000000n));
|
|
4
|
+
export const repeatBoundedWait = (input) => Effect.gen(function* () {
|
|
5
|
+
const deadline = (yield* monotonicMilliseconds) + input.timeoutMilliseconds;
|
|
6
|
+
const next = () => Effect.gen(function* () {
|
|
7
|
+
const remaining = deadline - (yield* monotonicMilliseconds);
|
|
8
|
+
const result = yield* input.once(Math.max(0, Math.min(input.maxRequestMilliseconds, remaining)));
|
|
9
|
+
if (!result.ok || input.satisfied(result.value))
|
|
10
|
+
return result;
|
|
11
|
+
return (yield* monotonicMilliseconds) >= deadline
|
|
12
|
+
? result
|
|
13
|
+
: yield* next();
|
|
14
|
+
});
|
|
15
|
+
return yield* next();
|
|
16
|
+
});
|
|
17
|
+
//# sourceMappingURL=wait.js.map
|
package/dist/login/commands.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
|
-
import { CliArgumentError, parseOptions, reportError, requirePositionals, unknownCommand, writeSuccess, } from "../command-line/index.js";
|
|
2
|
+
import { CliArgumentError, LOCAL_NODE, parseOptions, reportError, requirePositionals, unknownCommand, writeSuccess, } from "../command-line/index.js";
|
|
3
3
|
import { callNode, ConnectionNodeError, redactConnection, } from "../connection/index.js";
|
|
4
4
|
import { listAgentProviders, signInAgentProvider } from "./agent-provider.js";
|
|
5
5
|
import { loginFailureMessage } from "./failure.js";
|
|
@@ -57,6 +57,7 @@ const providerLogin = (tokens, context) => parsed(() => readProviderLogin(tokens
|
|
|
57
57
|
}));
|
|
58
58
|
const loginTarget = (tokens) => parseOptions(tokens, new Set(["--base-url", "--command-id", "--max-sessions", "--name"]), new Set(["--api-key-stdin", "--device-code"])).positionals[0];
|
|
59
59
|
const remoteLoginRefusal = (target, context) => context.node === undefined ||
|
|
60
|
+
context.node === LOCAL_NODE ||
|
|
60
61
|
target === "claude" ||
|
|
61
62
|
target === "codex" ||
|
|
62
63
|
target === "gateway"
|
package/dist/mcp/calls.d.ts
CHANGED
|
@@ -3,5 +3,6 @@ import { type LocalNodeRequestMethod } from "@maiaos/sdk";
|
|
|
3
3
|
import { type CliNodeEffect, type CliNodeOperations } from "../local-node/index.js";
|
|
4
4
|
export type CoordinatorCall = (node: CliNodeOperations, input: unknown) => CliNodeEffect<unknown>;
|
|
5
5
|
export declare const COORDINATOR_CALLS: ReadonlyMap<CoordinatorToolOperation, CoordinatorCall>;
|
|
6
|
+
export declare const callCoordinator: (node: CliNodeOperations) => (operation: CoordinatorToolOperation, input: unknown) => CliNodeEffect<unknown>;
|
|
6
7
|
export declare const WORKER_CALLS: ReadonlyMap<LocalNodeRequestMethod, CoordinatorCall>;
|
|
7
8
|
//# sourceMappingURL=calls.d.ts.map
|
package/dist/mcp/calls.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { approvalListParametersSchema, approvalShowParametersSchema, connectionDetectParametersSchema, connectionListParametersSchema, connectionModelsListParametersSchema, connectionShowParametersSchema, connectionUsageShowParametersSchema, containerIndexListParametersSchema, COORDINATOR_TOOL_OPERATIONS, discoverySessionsListParametersSchema, invocationContextShowParametersSchema, LOCAL_NODE_CALL_METHODS, localNodeRequestPayloadSchema, portLeaseAcquireParametersSchema, portLeaseListParametersSchema, portLeaseReleaseParametersSchema, portLeaseRenewParametersSchema, projectGuardShowParametersSchema, projectListParametersSchema, projectShowParametersSchema, receiptGetParametersSchema, runLedgerCreateParametersSchema, runLedgerListParametersSchema, runLedgerTaskDispatchParametersSchema, runLedgerTaskListParametersSchema, runLedgerTaskSettleParametersSchema, runLedgerTaskShowParametersSchema, sessionArchiveParametersSchema, sessionCreateParametersSchema, sessionDiffParametersSchema, sessionEventsListParametersSchema, sessionHistoryReadParametersSchema, sessionListParametersSchema, sessionObserveParametersSchema, sessionResumeParametersSchema, sessionShowParametersSchema, sessionStartParametersSchema, sessionStopParametersSchema, turnInterruptParametersSchema, turnSendParametersSchema, turnShowParametersSchema, turnWaitParametersSchema, workerToolDefinitions, workspaceListParametersSchema, workspaceShowParametersSchema, } from "@maiaos/sdk";
|
|
2
|
-
import { Predicate } from "effect";
|
|
1
|
+
import { agentsListParametersSchema, agentsShowParametersSchema, approvalListParametersSchema, approvalRespondParametersSchema, approvalShowParametersSchema, connectionDetectParametersSchema, connectionListParametersSchema, connectionModelsListParametersSchema, connectionShowParametersSchema, connectionUsageShowParametersSchema, containerIndexListParametersSchema, COORDINATOR_TOOL_OPERATIONS, discoverySessionsListParametersSchema, invocationContextShowParametersSchema, LOCAL_NODE_CALL_METHODS, localNodeRequestPayloadSchema, portLeaseAcquireParametersSchema, portLeaseListParametersSchema, portLeaseReleaseParametersSchema, portLeaseRenewParametersSchema, projectGuardShowParametersSchema, projectListParametersSchema, projectShowParametersSchema, receiptGetParametersSchema, routineListParametersSchema, routineShowParametersSchema, runLedgerCreateParametersSchema, runLedgerListParametersSchema, runLedgerTaskDispatchParametersSchema, runLedgerTaskListParametersSchema, runLedgerTaskSettleParametersSchema, runLedgerTaskShowParametersSchema, sessionArchiveParametersSchema, sessionCreateParametersSchema, sessionDiffParametersSchema, sessionEventsListParametersSchema, sessionHistoryReadParametersSchema, sessionInboxAckParametersSchema, sessionInboxCheckParametersSchema, sessionListParametersSchema, sessionMessageSendParametersSchema, sessionObserveParametersSchema, sessionResumeParametersSchema, sessionShowParametersSchema, sessionStartParametersSchema, sessionStopParametersSchema, turnCancelParametersSchema, turnInterruptParametersSchema, turnQueueListParametersSchema, turnSendParametersSchema, turnShowParametersSchema, turnWaitParametersSchema, workerToolDefinitions, workspaceListParametersSchema, workspaceShowParametersSchema, } from "@maiaos/sdk";
|
|
2
|
+
import { Effect, Predicate } from "effect";
|
|
3
3
|
import { invalidNodeInput, } from "../local-node/index.js";
|
|
4
4
|
const recoveryOf = (input) => Predicate.hasProperty(input, "commandId") &&
|
|
5
5
|
Predicate.isString(input.commandId)
|
|
@@ -27,6 +27,14 @@ const typedCall = (method) => (node, input) => {
|
|
|
27
27
|
};
|
|
28
28
|
export const COORDINATOR_CALLS = new Map([
|
|
29
29
|
...COORDINATOR_TOOL_OPERATIONS.filter(isCallBound).map((operation) => [operation, typedCall(operation)]),
|
|
30
|
+
[
|
|
31
|
+
"agents.list",
|
|
32
|
+
validated(agentsListParametersSchema, (client, parameters, options) => client.listAgents(parameters, options)),
|
|
33
|
+
],
|
|
34
|
+
[
|
|
35
|
+
"agents.show",
|
|
36
|
+
validated(agentsShowParametersSchema, (client, parameters, options) => client.showAgent(parameters, options)),
|
|
37
|
+
],
|
|
30
38
|
[
|
|
31
39
|
"approval.list",
|
|
32
40
|
validated(approvalListParametersSchema, (client, parameters, options) => client.listApprovals(parameters, options)),
|
|
@@ -96,6 +104,14 @@ export const COORDINATOR_CALLS = new Map([
|
|
|
96
104
|
"receipt.get",
|
|
97
105
|
validated(receiptGetParametersSchema, (client, parameters, options) => client.getReceipt(parameters, options)),
|
|
98
106
|
],
|
|
107
|
+
[
|
|
108
|
+
"routine.list",
|
|
109
|
+
validated(routineListParametersSchema, (client, parameters, options) => client.listRoutines(parameters, options)),
|
|
110
|
+
],
|
|
111
|
+
[
|
|
112
|
+
"routine.show",
|
|
113
|
+
validated(routineShowParametersSchema, (client, parameters, options) => client.showRoutine(parameters, options)),
|
|
114
|
+
],
|
|
99
115
|
[
|
|
100
116
|
"run.ledger.create",
|
|
101
117
|
validated(runLedgerCreateParametersSchema, (client, parameters, options) => client.createRunLedger(parameters, options)),
|
|
@@ -164,10 +180,18 @@ export const COORDINATOR_CALLS = new Map([
|
|
|
164
180
|
"session.stop",
|
|
165
181
|
validated(sessionStopParametersSchema, (client, parameters, options) => client.stopSession(parameters, options)),
|
|
166
182
|
],
|
|
183
|
+
[
|
|
184
|
+
"turn.cancel",
|
|
185
|
+
validated(turnCancelParametersSchema, (client, parameters, options) => client.cancelTurn(parameters, options)),
|
|
186
|
+
],
|
|
167
187
|
[
|
|
168
188
|
"turn.interrupt",
|
|
169
189
|
validated(turnInterruptParametersSchema, (client, parameters, options) => client.interruptTurn(parameters, options)),
|
|
170
190
|
],
|
|
191
|
+
[
|
|
192
|
+
"turn.queue.list",
|
|
193
|
+
validated(turnQueueListParametersSchema, (client, parameters, options) => client.listTurnQueue(parameters, options)),
|
|
194
|
+
],
|
|
171
195
|
[
|
|
172
196
|
"turn.send",
|
|
173
197
|
validated(turnSendParametersSchema, (client, parameters, options) => client.sendTurn(parameters, options)),
|
|
@@ -189,10 +213,20 @@ export const COORDINATOR_CALLS = new Map([
|
|
|
189
213
|
validated(workspaceShowParametersSchema, (client, parameters, options) => client.showWorkspace(parameters, options)),
|
|
190
214
|
],
|
|
191
215
|
]);
|
|
216
|
+
export const callCoordinator = (node) => (operation, input) => {
|
|
217
|
+
const call = COORDINATOR_CALLS.get(operation);
|
|
218
|
+
return call === undefined
|
|
219
|
+
? Effect.die(new Error(`No SDK call for ${operation}.`))
|
|
220
|
+
: call(node, input);
|
|
221
|
+
};
|
|
192
222
|
export const WORKER_CALLS = (() => {
|
|
193
223
|
const available = new Map(COORDINATOR_CALLS);
|
|
194
224
|
available.set("context.show", validated(invocationContextShowParametersSchema, (client, parameters, options) => client.showCurrentContext(parameters, options)));
|
|
195
|
-
|
|
225
|
+
available.set("approval.respond", validated(approvalRespondParametersSchema, (client, parameters, options) => client.respondToApproval(parameters, options)));
|
|
226
|
+
available.set("session.inbox.ack", validated(sessionInboxAckParametersSchema, (client, parameters, options) => client.acknowledgeSessionDelivery(parameters, options)));
|
|
227
|
+
available.set("session.inbox.check", validated(sessionInboxCheckParametersSchema, (client, parameters, options) => client.checkSessionInbox(parameters, options)));
|
|
228
|
+
available.set("session.message.send", validated(sessionMessageSendParametersSchema, (client, parameters, options) => client.sendSessionMessage(parameters, options)));
|
|
229
|
+
return new Map(workerToolDefinitions("orchestrator").map(({ operation }) => {
|
|
196
230
|
const call = available.get(operation);
|
|
197
231
|
if (call === undefined)
|
|
198
232
|
throw new Error(`No worker SDK call for ${operation}.`);
|
package/dist/mcp/commands.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
import type { CoordinatorToolOperation } from "@maiaos/sdk";
|
|
1
2
|
import * as Effect from "effect/Effect";
|
|
2
3
|
import { type CliServices, type CommandContext, type CommandEffect } from "../command-line/index.js";
|
|
3
|
-
import type { CliNodeOperations } from "../local-node/index.js";
|
|
4
|
+
import type { CliNodeEffect, CliNodeOperations } from "../local-node/index.js";
|
|
5
|
+
import type { ToolFleet } from "./server.js";
|
|
4
6
|
export type McpCliDependencies = {
|
|
5
|
-
readonly
|
|
7
|
+
readonly callCoordinatorTool: (operation: CoordinatorToolOperation, input: unknown) => CliNodeEffect<unknown>;
|
|
8
|
+
readonly serveMcp: (version: string, worker?: boolean, fleet?: ToolFleet) => Effect.Effect<number, unknown, CliServices>;
|
|
6
9
|
};
|
|
7
10
|
export declare const makeMcpClient: (node: CliNodeOperations) => McpCliDependencies;
|
|
8
11
|
export declare const runMcpCommand: (tokens: readonly string[], context: CommandContext) => CommandEffect;
|
package/dist/mcp/commands.js
CHANGED
|
@@ -1,21 +1,47 @@
|
|
|
1
1
|
import * as Config from "effect/Config";
|
|
2
2
|
import * as Effect from "effect/Effect";
|
|
3
3
|
import * as Option from "effect/Option";
|
|
4
|
-
import { requireNoArguments, } from "../command-line/index.js";
|
|
4
|
+
import { LOCAL_NODE, requireNoArguments, } from "../command-line/index.js";
|
|
5
|
+
import { refused } from "../fleet/index.js";
|
|
6
|
+
const coordinatorTool = (node) => (operation, input) => Effect.promise(() => import("./calls.js")).pipe(Effect.flatMap((module) => module.callCoordinator(node.asCoordinator())(operation, input)));
|
|
5
7
|
export const makeMcpClient = (node) => ({
|
|
6
|
-
|
|
8
|
+
callCoordinatorTool: coordinatorTool(node),
|
|
9
|
+
serveMcp: (version, worker = false, fleet) => Effect.promise(() => import("./server.js")).pipe(Effect.flatMap((module) => Effect.gen(function* () {
|
|
7
10
|
const credential = yield* Config.option(Config.String("MAIA_SESSION_CREDENTIAL"));
|
|
8
11
|
const origin = yield* Config.option(Config.String("MAIA_NODE_ORIGIN"));
|
|
9
12
|
const session = worker || Option.isSome(credential) || Option.isSome(origin);
|
|
10
|
-
return yield* module.serveCoordinatorMcp(session ? node.asSession() : node.asCoordinator(), version, {
|
|
13
|
+
return yield* module.serveCoordinatorMcp(session ? node.asSession() : node.asCoordinator(), version, {
|
|
14
|
+
worker: session,
|
|
15
|
+
...(session || fleet === undefined ? {} : { fleet }),
|
|
16
|
+
});
|
|
11
17
|
}))),
|
|
12
18
|
});
|
|
19
|
+
const fleetOf = ({ bindNode, dependencies, node, }) => {
|
|
20
|
+
const bound = new Map();
|
|
21
|
+
const bind = (name) => {
|
|
22
|
+
const known = bound.get(name);
|
|
23
|
+
if (known !== undefined)
|
|
24
|
+
return known;
|
|
25
|
+
const call = bindNode?.(name).callCoordinatorTool;
|
|
26
|
+
const reach = (operation, input) => call === undefined
|
|
27
|
+
? Effect.succeed(refused("internal_error", `Node ${name} has no coordinator tools.`))
|
|
28
|
+
: call(operation, input);
|
|
29
|
+
bound.set(name, reach);
|
|
30
|
+
return reach;
|
|
31
|
+
};
|
|
32
|
+
return {
|
|
33
|
+
bind: bindNode && bind,
|
|
34
|
+
chosen: node !== undefined,
|
|
35
|
+
listRemoteNodes: dependencies.listRemoteNodes,
|
|
36
|
+
node: node ?? LOCAL_NODE,
|
|
37
|
+
};
|
|
38
|
+
};
|
|
13
39
|
export const runMcpCommand = (tokens, context) => {
|
|
14
40
|
const worker = tokens[0] === "--worker";
|
|
15
41
|
requireNoArguments(worker ? tokens.slice(1) : tokens, "MCP");
|
|
16
42
|
const { serveMcp } = context.dependencies;
|
|
17
43
|
if (serveMcp === undefined)
|
|
18
44
|
return Effect.die(new Error("The MCP server is unavailable."));
|
|
19
|
-
return Effect.orDie(serveMcp(context.version, worker));
|
|
45
|
+
return Effect.orDie(serveMcp(context.version, worker, worker ? undefined : fleetOf(context)));
|
|
20
46
|
};
|
|
21
47
|
//# sourceMappingURL=commands.js.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { RouteKind } from "@maiaos/client-core/cockpit";
|
|
2
|
+
import { type CoordinatorToolOperation, type ProtocolError } from "@maiaos/sdk";
|
|
3
|
+
import { type Crypto, Effect } from "effect";
|
|
4
|
+
import { type Fleet } from "../fleet/index.js";
|
|
5
|
+
import { type CliNodeEffect, type CliNodeResult } from "../local-node/index.js";
|
|
6
|
+
export type ToolReach = (operation: CoordinatorToolOperation, input: unknown) => CliNodeEffect<unknown>;
|
|
7
|
+
export type ToolAnswer = CliNodeResult<unknown> | {
|
|
8
|
+
readonly error: ProtocolError;
|
|
9
|
+
readonly ok: false;
|
|
10
|
+
readonly result: unknown;
|
|
11
|
+
};
|
|
12
|
+
type ToolKind = Exclude<RouteKind, "terminal">;
|
|
13
|
+
type ToolRoute = {
|
|
14
|
+
readonly held?: {
|
|
15
|
+
readonly ids: (input: object) => unknown;
|
|
16
|
+
readonly kind: ToolKind;
|
|
17
|
+
};
|
|
18
|
+
readonly merged?: true;
|
|
19
|
+
};
|
|
20
|
+
export declare const TOOL_ROUTES: ReadonlyMap<CoordinatorToolOperation, ToolRoute>;
|
|
21
|
+
export declare const isRoutedTool: (operation: string) => operation is CoordinatorToolOperation;
|
|
22
|
+
export declare const routeToolCall: (fleet: Fleet<ToolReach>, operation: CoordinatorToolOperation, input: unknown) => Effect.Effect<ToolAnswer, never, Crypto.Crypto>;
|
|
23
|
+
export {};
|
|
24
|
+
//# sourceMappingURL=routing.d.ts.map
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { localNodeRequestPayloadSchema, } from "@maiaos/sdk";
|
|
2
|
+
import { Effect, Predicate, Result } from "effect";
|
|
3
|
+
import { askEach, failureOf, fleetNodes, holderIn, mergeLists, refused, routes, } from "../fleet/index.js";
|
|
4
|
+
import { invalidNodeInput, } from "../local-node/index.js";
|
|
5
|
+
const LOCAL = {};
|
|
6
|
+
const held = (kind, field, merged) => ({
|
|
7
|
+
held: {
|
|
8
|
+
ids: (input) => Predicate.hasProperty(input, field) ? input[field] : undefined,
|
|
9
|
+
kind,
|
|
10
|
+
},
|
|
11
|
+
...(merged === undefined ? {} : { merged }),
|
|
12
|
+
});
|
|
13
|
+
const HISTORY = {
|
|
14
|
+
held: {
|
|
15
|
+
ids: (input) => Predicate.hasProperty(input, "target") &&
|
|
16
|
+
Predicate.hasProperty(input.target, "sessionId") &&
|
|
17
|
+
Predicate.hasProperty(input.target, "kind") &&
|
|
18
|
+
input.target.kind === "session"
|
|
19
|
+
? input.target.sessionId
|
|
20
|
+
: undefined,
|
|
21
|
+
kind: "session",
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
export const TOOL_ROUTES = new Map([
|
|
25
|
+
["agents.list", LOCAL],
|
|
26
|
+
["agents.show", LOCAL],
|
|
27
|
+
["approval.list", held("session", "sessionId", true)],
|
|
28
|
+
["approval.show", held("approval", "approvalId")],
|
|
29
|
+
["connection.detect", LOCAL],
|
|
30
|
+
["connection.list", LOCAL],
|
|
31
|
+
["connection.models.list", LOCAL],
|
|
32
|
+
["connection.show", LOCAL],
|
|
33
|
+
["connection.usage.show", LOCAL],
|
|
34
|
+
["container.index.list", LOCAL],
|
|
35
|
+
["discovery.sessions.list", LOCAL],
|
|
36
|
+
["node.status", LOCAL],
|
|
37
|
+
["port.lease.acquire", LOCAL],
|
|
38
|
+
["port.lease.list", LOCAL],
|
|
39
|
+
["port.lease.release", LOCAL],
|
|
40
|
+
["port.lease.renew", LOCAL],
|
|
41
|
+
["project.guard.show", held("project", "projectId")],
|
|
42
|
+
["project.list", { merged: true }],
|
|
43
|
+
["project.show", held("project", "projectId")],
|
|
44
|
+
["receipt.get", held("command", "commandId")],
|
|
45
|
+
["reference.resolve", held("project", "projectId")],
|
|
46
|
+
["routine.list", held("project", "projectId", true)],
|
|
47
|
+
["routine.show", held("routine", "routineId")],
|
|
48
|
+
["run.ledger.create", LOCAL],
|
|
49
|
+
["run.ledger.list", LOCAL],
|
|
50
|
+
["run.ledger.task.dispatch", LOCAL],
|
|
51
|
+
["run.ledger.task.list", LOCAL],
|
|
52
|
+
["run.ledger.task.settle", LOCAL],
|
|
53
|
+
["run.ledger.task.show", LOCAL],
|
|
54
|
+
["session.archive", held("session", "sessionId")],
|
|
55
|
+
["session.create", held("workspace", "workspaceId")],
|
|
56
|
+
["session.diff", held("session", "sessionId")],
|
|
57
|
+
["session.events.list", held("session", "sessionId")],
|
|
58
|
+
["session.history.read", HISTORY],
|
|
59
|
+
["session.list", held("project", "projectId", true)],
|
|
60
|
+
["session.observe", held("session", "sessionIds", true)],
|
|
61
|
+
["session.rename", held("session", "sessionId")],
|
|
62
|
+
["session.resume", held("session", "sessionId")],
|
|
63
|
+
["session.show", held("session", "sessionId")],
|
|
64
|
+
["session.start", held("session", "sessionId")],
|
|
65
|
+
["session.stop", held("session", "sessionId")],
|
|
66
|
+
["turn.cancel", held("turn", "turnId")],
|
|
67
|
+
["turn.interrupt", held("turn", "turnId")],
|
|
68
|
+
["turn.queue.list", held("session", "sessionId")],
|
|
69
|
+
["turn.send", held("session", "sessionId")],
|
|
70
|
+
["turn.show", held("turn", "turnId")],
|
|
71
|
+
["turn.wait", held("turn", "turnIds")],
|
|
72
|
+
["workspace.list", held("project", "projectId")],
|
|
73
|
+
["workspace.show", held("workspace", "workspaceId")],
|
|
74
|
+
]);
|
|
75
|
+
const PROBES = {
|
|
76
|
+
approval: (approvalId) => ["approval.show", { approvalId }],
|
|
77
|
+
command: (commandId) => ["receipt.get", { commandId }],
|
|
78
|
+
project: (projectId) => ["project.show", { projectId }],
|
|
79
|
+
routine: (routineId) => ["routine.show", { routineId }],
|
|
80
|
+
session: (sessionId) => ["session.show", { sessionId }],
|
|
81
|
+
turn: (turnId) => ["turn.show", { turnId }],
|
|
82
|
+
workspace: (workspaceId) => ["workspace.show", { workspaceId }],
|
|
83
|
+
};
|
|
84
|
+
const CHOOSE_NODE = "serve that Node alone with 'maia --node <name> mcp'";
|
|
85
|
+
const heldIds = ({ ids, kind }, input) => {
|
|
86
|
+
const value = Predicate.isObject(input) ? ids(input) : undefined;
|
|
87
|
+
const named = [value].flat();
|
|
88
|
+
return named.length > 0 &&
|
|
89
|
+
named.every((id) => Predicate.isString(id) && routes({ id, kind }))
|
|
90
|
+
? [...new Set(named)]
|
|
91
|
+
: [];
|
|
92
|
+
};
|
|
93
|
+
const oneHolder = (ids) => (holders) => {
|
|
94
|
+
const names = [...new Set(holders.map(({ node }) => node))];
|
|
95
|
+
const [holder] = holders;
|
|
96
|
+
return holder !== undefined && names.length === 1
|
|
97
|
+
? { ok: true, value: holder }
|
|
98
|
+
: refused("invalid_argument", `${ids.join(", ")} are on different Nodes (${names.join(", ")}): call once per Node.`);
|
|
99
|
+
};
|
|
100
|
+
const holderOf = (nodes, kind, id) => Effect.flatMap(holderIn(nodes, { id, kind }, {
|
|
101
|
+
choose: CHOOSE_NODE,
|
|
102
|
+
probe: (reach) => reach(...PROBES[kind](id)),
|
|
103
|
+
}), (found) => Result.isSuccess(found)
|
|
104
|
+
? Effect.succeed(found.success)
|
|
105
|
+
: Effect.fail(found.failure.error));
|
|
106
|
+
const holderOfAll = (nodes, kind, ids) => Effect.forEach(ids, (id) => holderOf(nodes, kind, id)).pipe(Effect.match({
|
|
107
|
+
onFailure: (error) => ({ error, ok: false }),
|
|
108
|
+
onSuccess: oneHolder(ids),
|
|
109
|
+
}));
|
|
110
|
+
const pageOf = (node, result) => {
|
|
111
|
+
if (!result.ok)
|
|
112
|
+
return result;
|
|
113
|
+
const { value } = result;
|
|
114
|
+
return Predicate.hasProperty(value, "items") && Array.isArray(value.items)
|
|
115
|
+
? { ok: true, value: value }
|
|
116
|
+
: refused("internal_error", `Node ${node} answered a list without items.`);
|
|
117
|
+
};
|
|
118
|
+
const continues = (input) => Predicate.hasProperty(input, "afterCursor") &&
|
|
119
|
+
input.afterCursor !== undefined &&
|
|
120
|
+
input.afterCursor !== "0";
|
|
121
|
+
const observationOf = (result) => {
|
|
122
|
+
if (!result.ok)
|
|
123
|
+
return {};
|
|
124
|
+
const { value } = result;
|
|
125
|
+
return {
|
|
126
|
+
...(Predicate.hasProperty(value, "observedAt")
|
|
127
|
+
? { observedAt: value.observedAt }
|
|
128
|
+
: {}),
|
|
129
|
+
...(Predicate.hasProperty(value, "stallAfterSeconds")
|
|
130
|
+
? { stallAfterSeconds: value.stallAfterSeconds }
|
|
131
|
+
: {}),
|
|
132
|
+
};
|
|
133
|
+
};
|
|
134
|
+
const mergedAnswer = (operation) => (answers) => {
|
|
135
|
+
const lists = mergeLists(answers.map(({ node, result }) => ({
|
|
136
|
+
node,
|
|
137
|
+
result: pageOf(node, result),
|
|
138
|
+
})));
|
|
139
|
+
const merged = {
|
|
140
|
+
...lists,
|
|
141
|
+
method: operation,
|
|
142
|
+
nodes: lists.nodes.map((entry, index) => {
|
|
143
|
+
const answer = answers[index];
|
|
144
|
+
return answer === undefined
|
|
145
|
+
? entry
|
|
146
|
+
: { ...entry, ...observationOf(answer.result) };
|
|
147
|
+
}),
|
|
148
|
+
};
|
|
149
|
+
const failed = failureOf(merged.nodes);
|
|
150
|
+
return failed === undefined
|
|
151
|
+
? { ok: true, value: merged }
|
|
152
|
+
: { error: failed, ok: false, result: merged };
|
|
153
|
+
};
|
|
154
|
+
const mergedList = (nodes, operation, input) => continues(input)
|
|
155
|
+
? Effect.succeed(refused("invalid_argument", `A cursor pages one Node: ${CHOOSE_NODE} to page it.`))
|
|
156
|
+
: Effect.map(askEach(nodes, (reach) => reach(operation, input)), mergedAnswer(operation));
|
|
157
|
+
const routeAmong = (local, nodes, { held, merged }) => (operation, input) => {
|
|
158
|
+
const ids = held === undefined ? [] : heldIds(held, input);
|
|
159
|
+
if (held !== undefined && ids.length > 0)
|
|
160
|
+
return Effect.flatMap(holderOfAll(nodes, held.kind, ids), (holder) => holder.ok
|
|
161
|
+
? holder.value.reach(operation, input)
|
|
162
|
+
: Effect.succeed(holder));
|
|
163
|
+
return merged === undefined
|
|
164
|
+
? local.reach(operation, input)
|
|
165
|
+
: mergedList(nodes, operation, input);
|
|
166
|
+
};
|
|
167
|
+
const ROUTED = new Set(TOOL_ROUTES.keys());
|
|
168
|
+
export const isRoutedTool = (operation) => ROUTED.has(operation);
|
|
169
|
+
export const routeToolCall = (fleet, operation, input) => {
|
|
170
|
+
const route = TOOL_ROUTES.get(operation) ?? LOCAL;
|
|
171
|
+
const { local } = fleet;
|
|
172
|
+
if (route.held === undefined && route.merged === undefined)
|
|
173
|
+
return local.reach(operation, input);
|
|
174
|
+
const checked = localNodeRequestPayloadSchema.safeParse({
|
|
175
|
+
method: operation,
|
|
176
|
+
parameters: input,
|
|
177
|
+
});
|
|
178
|
+
if (!checked.success)
|
|
179
|
+
return invalidNodeInput(checked.error);
|
|
180
|
+
return Effect.flatMap(fleetNodes(fleet), (space) => {
|
|
181
|
+
if (!space.ok)
|
|
182
|
+
return Effect.succeed(space);
|
|
183
|
+
return space.value.length === 1
|
|
184
|
+
? local.reach(operation, input)
|
|
185
|
+
: routeAmong(local, space.value, route)(operation, input);
|
|
186
|
+
});
|
|
187
|
+
};
|
|
188
|
+
//# sourceMappingURL=routing.js.map
|
package/dist/mcp/server.d.ts
CHANGED
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
import { Cause, Crypto, Effect, Layer } from "effect";
|
|
2
|
-
import
|
|
2
|
+
import * as McpSchema from "effect/ai/McpSchema";
|
|
3
3
|
import type { Stdio } from "effect/Stdio";
|
|
4
|
-
import type {
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
import type { Fleet } from "../fleet/index.js";
|
|
5
|
+
import type { CliNodeOperations } from "../local-node/index.js";
|
|
6
|
+
import { type ToolAnswer, type ToolReach } from "./routing.js";
|
|
7
|
+
export type ToolFleet = Omit<Fleet<ToolReach>, "local"> & {
|
|
8
|
+
readonly node: string;
|
|
9
|
+
};
|
|
10
|
+
export declare const toolResult: (result: ToolAnswer) => McpSchema.CallToolResult;
|
|
11
|
+
export declare const coordinatorMcpLayer: (node: CliNodeOperations, version: string, { fleet, worker, }?: {
|
|
12
|
+
readonly fleet?: ToolFleet;
|
|
13
|
+
readonly worker?: boolean;
|
|
14
|
+
}) => Layer.Layer<never, Cause.IllegalArgumentError, Crypto.Crypto | Stdio>;
|
|
7
15
|
export declare const serveCoordinatorMcp: (node: CliNodeOperations, version: string, options?: {
|
|
16
|
+
readonly fleet?: ToolFleet;
|
|
8
17
|
readonly stdio?: Layer.Layer<Stdio>;
|
|
9
18
|
readonly worker?: boolean;
|
|
10
19
|
}) => Effect.Effect<number, never, Crypto.Crypto>;
|