@maiaos/cli 0.1.0-canary.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +287 -0
- package/dist/bin/maia.NOTICES.txt +59 -0
- package/dist/bin/maia.cdx.json +145 -0
- package/dist/bin/maia.mjs +2 -0
- package/dist/bootstrap/index.d.ts +3 -0
- package/dist/bootstrap/index.js +3 -0
- package/dist/bootstrap/process.d.ts +5 -0
- package/dist/bootstrap/process.js +45 -0
- package/dist/bootstrap/run.d.ts +25 -0
- package/dist/bootstrap/run.js +95 -0
- package/dist/bootstrap/stdio.d.ts +4 -0
- package/dist/bootstrap/stdio.js +9 -0
- package/dist/cli/cli.d.ts +17 -0
- package/dist/cli/cli.js +481 -0
- package/dist/cli/environment.d.ts +8 -0
- package/dist/cli/environment.js +12 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +2 -0
- package/dist/cli/services.d.ts +4 -0
- package/dist/cli/services.js +4 -0
- package/dist/command-line/context.d.ts +178 -0
- package/dist/command-line/context.js +2 -0
- package/dist/command-line/index.d.ts +7 -0
- package/dist/command-line/index.js +6 -0
- package/dist/command-line/input/arguments.d.ts +55 -0
- package/dist/command-line/input/arguments.js +220 -0
- package/dist/command-line/input/index.d.ts +4 -0
- package/dist/command-line/input/index.js +4 -0
- package/dist/command-line/input/prompt.d.ts +8 -0
- package/dist/command-line/input/prompt.js +44 -0
- package/dist/command-line/input/stdin-stream.d.ts +4 -0
- package/dist/command-line/input/stdin-stream.js +3 -0
- package/dist/command-line/input/stdin.d.ts +11 -0
- package/dist/command-line/input/stdin.js +23 -0
- package/dist/command-line/json-decoder.d.ts +3 -0
- package/dist/command-line/json-decoder.js +3 -0
- package/dist/command-line/json.d.ts +3 -0
- package/dist/command-line/json.js +4 -0
- package/dist/command-line/output.d.ts +57 -0
- package/dist/command-line/output.js +94 -0
- package/dist/command-line/rows.d.ts +10 -0
- package/dist/command-line/rows.js +32 -0
- package/dist/command-line/two-phase.d.ts +57 -0
- package/dist/command-line/two-phase.js +148 -0
- package/dist/command-receipt/command.d.ts +4 -0
- package/dist/command-receipt/command.js +59 -0
- package/dist/command-receipt/compact-list.d.ts +20 -0
- package/dist/command-receipt/compact-list.js +29 -0
- package/dist/command-receipt/index.d.ts +3 -0
- package/dist/command-receipt/index.js +3 -0
- package/dist/command-tree/commands.d.ts +17 -0
- package/dist/command-tree/commands.js +41 -0
- package/dist/command-tree/completion.d.ts +6 -0
- package/dist/command-tree/completion.js +36 -0
- package/dist/command-tree/grammar.d.ts +18 -0
- package/dist/command-tree/grammar.js +160 -0
- package/dist/command-tree/help.d.ts +62 -0
- package/dist/command-tree/help.js +219 -0
- package/dist/command-tree/index.d.ts +8 -0
- package/dist/command-tree/index.js +6 -0
- package/dist/command-tree/local.d.ts +3 -0
- package/dist/command-tree/local.js +126 -0
- package/dist/command-tree/placeholder.d.ts +3 -0
- package/dist/command-tree/placeholder.js +4 -0
- package/dist/command-tree/row.d.ts +29 -0
- package/dist/command-tree/row.js +2 -0
- package/dist/command-tree/suggest.d.ts +3 -0
- package/dist/command-tree/suggest.js +81 -0
- package/dist/command-tree/tree.d.ts +34 -0
- package/dist/command-tree/tree.js +124 -0
- package/dist/connection/client.d.ts +692 -0
- package/dist/connection/client.js +28 -0
- package/dist/connection/commands.d.ts +15 -0
- package/dist/connection/commands.js +118 -0
- package/dist/connection/index.d.ts +7 -0
- package/dist/connection/index.js +7 -0
- package/dist/connection/input.d.ts +50 -0
- package/dist/connection/input.js +90 -0
- package/dist/connection/login.d.ts +13 -0
- package/dist/connection/login.js +69 -0
- package/dist/connection/output/format.d.ts +32 -0
- package/dist/connection/output/format.js +94 -0
- package/dist/connection/output/index.d.ts +2 -0
- package/dist/connection/output/index.js +2 -0
- package/dist/connection/resolve.d.ts +60 -0
- package/dist/connection/resolve.js +30 -0
- package/dist/connection/signin.d.ts +4 -0
- package/dist/connection/signin.js +32 -0
- package/dist/connection/system.d.ts +4 -0
- package/dist/connection/system.js +190 -0
- package/dist/connection/tree/index.d.ts +2 -0
- package/dist/connection/tree/index.js +2 -0
- package/dist/connection/tree/tree.d.ts +3 -0
- package/dist/connection/tree/tree.js +209 -0
- package/dist/container/client.d.ts +142 -0
- package/dist/container/client.js +11 -0
- package/dist/container/commands.d.ts +7 -0
- package/dist/container/commands.js +100 -0
- package/dist/container/index.d.ts +3 -0
- package/dist/container/index.js +3 -0
- package/dist/container/output/format.d.ts +11 -0
- package/dist/container/output/format.js +28 -0
- package/dist/container/output/index.d.ts +2 -0
- package/dist/container/output/index.js +2 -0
- package/dist/context/client.d.ts +7 -0
- package/dist/context/client.js +21 -0
- package/dist/context/commands.d.ts +3 -0
- package/dist/context/commands.js +27 -0
- package/dist/context/index.d.ts +3 -0
- package/dist/context/index.js +3 -0
- package/dist/development/cli.d.ts +3 -0
- package/dist/development/cli.js +44 -0
- package/dist/execution/client.d.ts +25 -0
- package/dist/execution/client.js +24 -0
- package/dist/execution/index.d.ts +3 -0
- package/dist/execution/index.js +3 -0
- package/dist/execution/relocation.d.ts +6 -0
- package/dist/execution/relocation.js +123 -0
- package/dist/execution/tree/index.d.ts +2 -0
- package/dist/execution/tree/index.js +2 -0
- package/dist/execution/tree/tree.d.ts +3 -0
- package/dist/execution/tree/tree.js +137 -0
- package/dist/hold/client.d.ts +137 -0
- package/dist/hold/client.js +12 -0
- package/dist/hold/commands.d.ts +5 -0
- package/dist/hold/commands.js +91 -0
- package/dist/hold/index.d.ts +3 -0
- package/dist/hold/index.js +3 -0
- package/dist/hold/output/format.d.ts +11 -0
- package/dist/hold/output/format.js +29 -0
- package/dist/hold/output/index.d.ts +2 -0
- package/dist/hold/output/index.js +2 -0
- package/dist/hold/tree/index.d.ts +2 -0
- package/dist/hold/tree/index.js +2 -0
- package/dist/hold/tree/tree.d.ts +3 -0
- package/dist/hold/tree/tree.js +96 -0
- package/dist/import/client.d.ts +14 -0
- package/dist/import/client.js +16 -0
- package/dist/import/commands.d.ts +5 -0
- package/dist/import/commands.js +76 -0
- package/dist/import/index.d.ts +3 -0
- package/dist/import/index.js +3 -0
- package/dist/import/input.d.ts +16 -0
- package/dist/import/input.js +92 -0
- package/dist/import/output.d.ts +6 -0
- package/dist/import/output.js +40 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/integration/client.d.ts +1284 -0
- package/dist/integration/client.js +24 -0
- package/dist/integration/commands.d.ts +10 -0
- package/dist/integration/commands.js +104 -0
- package/dist/integration/index.d.ts +3 -0
- package/dist/integration/index.js +3 -0
- package/dist/integration/output.d.ts +22 -0
- package/dist/integration/output.js +20 -0
- package/dist/local-node/call.d.ts +7 -0
- package/dist/local-node/call.js +13 -0
- package/dist/local-node/client.d.ts +67 -0
- package/dist/local-node/client.js +241 -0
- package/dist/local-node/index.d.ts +3 -0
- package/dist/local-node/index.js +3 -0
- package/dist/login/agent-provider.d.ts +20 -0
- package/dist/login/agent-provider.js +109 -0
- package/dist/login/commands.d.ts +4 -0
- package/dist/login/commands.js +93 -0
- package/dist/login/failure.d.ts +3 -0
- package/dist/login/failure.js +14 -0
- package/dist/login/gateway.d.ts +12 -0
- package/dist/login/gateway.js +71 -0
- package/dist/login/index.d.ts +3 -0
- package/dist/login/index.js +2 -0
- package/dist/login/menu.d.ts +4 -0
- package/dist/login/menu.js +105 -0
- package/dist/login/output/format.d.ts +16 -0
- package/dist/login/output/format.js +31 -0
- package/dist/login/output/index.d.ts +2 -0
- package/dist/login/output/index.js +2 -0
- package/dist/login/vendor-account.d.ts +95 -0
- package/dist/login/vendor-account.js +75 -0
- package/dist/login/vendor-input.d.ts +14 -0
- package/dist/login/vendor-input.js +36 -0
- package/dist/mcp/calls.d.ts +7 -0
- package/dist/mcp/calls.js +202 -0
- package/dist/mcp/commands.d.ts +9 -0
- package/dist/mcp/commands.js +21 -0
- package/dist/mcp/index.d.ts +2 -0
- package/dist/mcp/index.js +2 -0
- package/dist/mcp/server.d.ts +11 -0
- package/dist/mcp/server.js +57 -0
- package/dist/orchestration/client.d.ts +78 -0
- package/dist/orchestration/client.js +89 -0
- package/dist/orchestration/commands.d.ts +14 -0
- package/dist/orchestration/commands.js +312 -0
- package/dist/orchestration/index.d.ts +3 -0
- package/dist/orchestration/index.js +3 -0
- package/dist/orchestration/output/compact-aggregate.d.ts +121 -0
- package/dist/orchestration/output/compact-aggregate.js +110 -0
- package/dist/orchestration/output/compact-run-list.d.ts +20 -0
- package/dist/orchestration/output/compact-run-list.js +16 -0
- package/dist/orchestration/output/human.d.ts +80 -0
- package/dist/orchestration/output/human.js +252 -0
- package/dist/orchestration/output/index.d.ts +4 -0
- package/dist/orchestration/output/index.js +4 -0
- package/dist/orchestration/tree/index.d.ts +2 -0
- package/dist/orchestration/tree/index.js +2 -0
- package/dist/orchestration/tree/tree.d.ts +3 -0
- package/dist/orchestration/tree/tree.js +142 -0
- package/dist/port-lease/client.d.ts +160 -0
- package/dist/port-lease/client.js +11 -0
- package/dist/port-lease/commands.d.ts +6 -0
- package/dist/port-lease/commands.js +17 -0
- package/dist/port-lease/index.d.ts +3 -0
- package/dist/port-lease/index.js +3 -0
- package/dist/port-lease/input.d.ts +65 -0
- package/dist/port-lease/input.js +67 -0
- package/dist/port-lease/output/format.d.ts +11 -0
- package/dist/port-lease/output/format.js +24 -0
- package/dist/port-lease/output/index.d.ts +2 -0
- package/dist/port-lease/output/index.js +2 -0
- package/dist/presentation/client.d.ts +10 -0
- package/dist/presentation/client.js +9 -0
- package/dist/presentation/commands.d.ts +6 -0
- package/dist/presentation/commands.js +78 -0
- package/dist/presentation/index.d.ts +4 -0
- package/dist/presentation/index.js +3 -0
- package/dist/presentation/output/format.d.ts +11 -0
- package/dist/presentation/output/format.js +32 -0
- package/dist/presentation/output/index.d.ts +3 -0
- package/dist/presentation/output/index.js +2 -0
- package/dist/project-guard/client.d.ts +88 -0
- package/dist/project-guard/client.js +7 -0
- package/dist/project-guard/commands.d.ts +4 -0
- package/dist/project-guard/commands.js +39 -0
- package/dist/project-guard/index.d.ts +3 -0
- package/dist/project-guard/index.js +3 -0
- package/dist/project-guard/input.d.ts +18 -0
- package/dist/project-guard/input.js +47 -0
- package/dist/project-guard/output/format.d.ts +11 -0
- package/dist/project-guard/output/format.js +35 -0
- package/dist/project-guard/output/index.d.ts +2 -0
- package/dist/project-guard/output/index.js +2 -0
- package/dist/project-workspace/client.d.ts +86 -0
- package/dist/project-workspace/client.js +159 -0
- package/dist/project-workspace/commands.d.ts +30 -0
- package/dist/project-workspace/commands.js +700 -0
- package/dist/project-workspace/index.d.ts +5 -0
- package/dist/project-workspace/index.js +5 -0
- package/dist/project-workspace/metadata-client.d.ts +99 -0
- package/dist/project-workspace/metadata-client.js +8 -0
- package/dist/project-workspace/metadata-commands.d.ts +4 -0
- package/dist/project-workspace/metadata-commands.js +56 -0
- package/dist/project-workspace/output/human.d.ts +126 -0
- package/dist/project-workspace/output/human.js +103 -0
- package/dist/project-workspace/output/index.d.ts +3 -0
- package/dist/project-workspace/output/index.js +3 -0
- package/dist/project-workspace/output/metadata.d.ts +11 -0
- package/dist/project-workspace/output/metadata.js +17 -0
- package/dist/project-workspace/tree/index.d.ts +2 -0
- package/dist/project-workspace/tree/index.js +2 -0
- package/dist/project-workspace/tree/tree.d.ts +3 -0
- package/dist/project-workspace/tree/tree.js +197 -0
- package/dist/provider/client.d.ts +6 -0
- package/dist/provider/client.js +5 -0
- package/dist/provider/commands.d.ts +3 -0
- package/dist/provider/commands.js +38 -0
- package/dist/provider/index.d.ts +3 -0
- package/dist/provider/index.js +3 -0
- package/dist/reference/commands.d.ts +3 -0
- package/dist/reference/commands.js +39 -0
- package/dist/reference/index.d.ts +3 -0
- package/dist/reference/index.js +3 -0
- package/dist/reference/resolve.d.ts +29 -0
- package/dist/reference/resolve.js +294 -0
- package/dist/reference/tree/index.d.ts +2 -0
- package/dist/reference/tree/index.js +2 -0
- package/dist/reference/tree/tree.d.ts +3 -0
- package/dist/reference/tree/tree.js +17 -0
- package/dist/remote-node/client.d.ts +258 -0
- package/dist/remote-node/client.js +12 -0
- package/dist/remote-node/commands.d.ts +6 -0
- package/dist/remote-node/commands.js +264 -0
- package/dist/remote-node/connector.d.ts +59 -0
- package/dist/remote-node/connector.js +122 -0
- package/dist/remote-node/index.d.ts +4 -0
- package/dist/remote-node/index.js +4 -0
- package/dist/remote-node/reachability.d.ts +22 -0
- package/dist/remote-node/reachability.js +34 -0
- package/dist/remote-node/text.d.ts +9 -0
- package/dist/remote-node/text.js +64 -0
- package/dist/remote-node/tree/index.d.ts +2 -0
- package/dist/remote-node/tree/index.js +2 -0
- package/dist/remote-node/tree/tree.d.ts +3 -0
- package/dist/remote-node/tree/tree.js +51 -0
- package/dist/run-ledger/client.d.ts +358 -0
- package/dist/run-ledger/client.js +13 -0
- package/dist/run-ledger/commands.d.ts +8 -0
- package/dist/run-ledger/commands.js +19 -0
- package/dist/run-ledger/index.d.ts +3 -0
- package/dist/run-ledger/index.js +3 -0
- package/dist/run-ledger/input.d.ts +42 -0
- package/dist/run-ledger/input.js +107 -0
- package/dist/run-ledger/output/format.d.ts +11 -0
- package/dist/run-ledger/output/format.js +49 -0
- package/dist/run-ledger/output/index.d.ts +2 -0
- package/dist/run-ledger/output/index.js +2 -0
- package/dist/session/agent-permission.d.ts +63 -0
- package/dist/session/agent-permission.js +20 -0
- package/dist/session/approval/client.d.ts +117 -0
- package/dist/session/approval/client.js +7 -0
- package/dist/session/approval/commands.d.ts +7 -0
- package/dist/session/approval/commands.js +123 -0
- package/dist/session/approval/index.d.ts +3 -0
- package/dist/session/approval/index.js +3 -0
- package/dist/session/approval/output/format.d.ts +12 -0
- package/dist/session/approval/output/format.js +25 -0
- package/dist/session/approval/output/index.d.ts +2 -0
- package/dist/session/approval/output/index.js +2 -0
- package/dist/session/attach-client.d.ts +16 -0
- package/dist/session/attach-client.js +8 -0
- package/dist/session/attach-render.d.ts +16 -0
- package/dist/session/attach-render.js +154 -0
- package/dist/session/attach.d.ts +5 -0
- package/dist/session/attach.js +106 -0
- package/dist/session/client.d.ts +132 -0
- package/dist/session/client.js +128 -0
- package/dist/session/coding-client.d.ts +16 -0
- package/dist/session/coding-client.js +15 -0
- package/dist/session/coding-commands.d.ts +4 -0
- package/dist/session/coding-commands.js +50 -0
- package/dist/session/commands.d.ts +13 -0
- package/dist/session/commands.js +488 -0
- package/dist/session/create-tasks.d.ts +20 -0
- package/dist/session/create-tasks.js +110 -0
- package/dist/session/index.d.ts +9 -0
- package/dist/session/index.js +7 -0
- package/dist/session/interaction/client.d.ts +347 -0
- package/dist/session/interaction/client.js +15 -0
- package/dist/session/interaction/commands.d.ts +7 -0
- package/dist/session/interaction/commands.js +101 -0
- package/dist/session/interaction/index.d.ts +3 -0
- package/dist/session/interaction/index.js +3 -0
- package/dist/session/interaction/input.d.ts +15 -0
- package/dist/session/interaction/input.js +46 -0
- package/dist/session/interaction/output/format.d.ts +11 -0
- package/dist/session/interaction/output/format.js +3 -0
- package/dist/session/interaction/output/index.d.ts +2 -0
- package/dist/session/interaction/output/index.js +2 -0
- package/dist/session/output/diff.d.ts +3 -0
- package/dist/session/output/diff.js +30 -0
- package/dist/session/output/failure.d.ts +11 -0
- package/dist/session/output/failure.js +24 -0
- package/dist/session/output/human.d.ts +112 -0
- package/dist/session/output/human.js +71 -0
- package/dist/session/output/index.d.ts +6 -0
- package/dist/session/output/index.js +6 -0
- package/dist/session/output/observe.d.ts +4 -0
- package/dist/session/output/observe.js +46 -0
- package/dist/session/output/tasks.d.ts +19 -0
- package/dist/session/output/tasks.js +34 -0
- package/dist/session/rename.d.ts +3 -0
- package/dist/session/rename.js +37 -0
- package/dist/session/task-file.d.ts +5 -0
- package/dist/session/task-file.js +23 -0
- package/dist/session/tree/index.d.ts +2 -0
- package/dist/session/tree/index.js +2 -0
- package/dist/session/tree/tree.d.ts +3 -0
- package/dist/session/tree/tree.js +309 -0
- package/dist/session/turn/client.d.ts +25 -0
- package/dist/session/turn/client.js +40 -0
- package/dist/session/turn/commands.d.ts +6 -0
- package/dist/session/turn/commands.js +157 -0
- package/dist/session/turn/index.d.ts +4 -0
- package/dist/session/turn/index.js +3 -0
- package/dist/session/turn/output.d.ts +42 -0
- package/dist/session/turn/output.js +38 -0
- package/dist/status/client.d.ts +119 -0
- package/dist/status/client.js +5 -0
- package/dist/status/command.d.ts +4 -0
- package/dist/status/command.js +40 -0
- package/dist/status/doctor.d.ts +15 -0
- package/dist/status/doctor.js +111 -0
- package/dist/status/index.d.ts +5 -0
- package/dist/status/index.js +4 -0
- package/dist/status/output/compact.d.ts +31 -0
- package/dist/status/output/compact.js +46 -0
- package/dist/status/output/human.d.ts +7 -0
- package/dist/status/output/human.js +30 -0
- package/dist/status/output/index.d.ts +3 -0
- package/dist/status/output/index.js +3 -0
- package/dist/terminal/arguments.d.ts +13 -0
- package/dist/terminal/arguments.js +79 -0
- package/dist/terminal/client.d.ts +79 -0
- package/dist/terminal/client.js +68 -0
- package/dist/terminal/commands.d.ts +7 -0
- package/dist/terminal/commands.js +131 -0
- package/dist/terminal/control-commands.d.ts +10 -0
- package/dist/terminal/control-commands.js +212 -0
- package/dist/terminal/index.d.ts +4 -0
- package/dist/terminal/index.js +4 -0
- package/dist/terminal/output/compact-list.d.ts +147 -0
- package/dist/terminal/output/compact-list.js +152 -0
- package/dist/terminal/output/human.d.ts +59 -0
- package/dist/terminal/output/human.js +55 -0
- package/dist/terminal/output/index.d.ts +3 -0
- package/dist/terminal/output/index.js +3 -0
- package/dist/terminal/tree/index.d.ts +2 -0
- package/dist/terminal/tree/index.js +2 -0
- package/dist/terminal/tree/tree.d.ts +3 -0
- package/dist/terminal/tree/tree.js +104 -0
- package/guidance/maia-cli/SKILL.md +58 -0
- package/guidance/maia-orchestration/SKILL.md +54 -0
- package/package.json +76 -0
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { CliArgumentError, recoverStdin, } from "../command-line/index.js";
|
|
3
|
+
import { safeLoginError } from "./failure.js";
|
|
4
|
+
const defaultAccess = {
|
|
5
|
+
list: () => Effect.tryPromise({
|
|
6
|
+
catch: (error) => error,
|
|
7
|
+
try: () => import("@maiaos/agent").then((agent) => agent.listMaiaAgentProviders()),
|
|
8
|
+
}),
|
|
9
|
+
login: (input) => Effect.tryPromise({
|
|
10
|
+
catch: (error) => error,
|
|
11
|
+
try: () => import("@maiaos/agent").then((agent) => agent.loginMaiaAgentProvider(input)),
|
|
12
|
+
}),
|
|
13
|
+
};
|
|
14
|
+
const access = (context) => context.dependencies.agentProviders ?? defaultAccess;
|
|
15
|
+
const isSafeError = (error) => error instanceof CliArgumentError ||
|
|
16
|
+
(error instanceof Error && error.name === "MaiaLoginError");
|
|
17
|
+
const safely = (failure) => (error) => isSafeError(error) ? error : safeLoginError(failure);
|
|
18
|
+
const safeEffect = (effect, failure) => Effect.mapError(effect, safely(failure));
|
|
19
|
+
export const listAgentProviders = (context) => safeEffect(access(context).list(), "Maia could not read the Maia agent's model providers.");
|
|
20
|
+
const authLabel = (type) => type === "oauth" ? "subscription" : "API key";
|
|
21
|
+
const cancelled = () => new CliArgumentError("Sign-in cancelled.");
|
|
22
|
+
const chosen = (question, answer) => {
|
|
23
|
+
const choices = question.choices ?? [];
|
|
24
|
+
if (choices.length === 0)
|
|
25
|
+
return Effect.succeed(answer);
|
|
26
|
+
const choice = choices[Number(answer) - 1] ?? choices.find((item) => item.id === answer);
|
|
27
|
+
return choice === undefined
|
|
28
|
+
? Effect.fail(new CliArgumentError(`Choose a number from 1 to ${String(choices.length)}.`))
|
|
29
|
+
: Effect.succeed(choice.id);
|
|
30
|
+
};
|
|
31
|
+
const promptAnswer = (context, question) => context.io.prompt?.(`${question.message} `, {
|
|
32
|
+
secret: question.secret,
|
|
33
|
+
...(question.signal === undefined ? {} : { signal: question.signal }),
|
|
34
|
+
}) ?? Effect.undefined;
|
|
35
|
+
const askTerminal = (context, question) => Effect.gen(function* () {
|
|
36
|
+
context.io.stderr((question.choices ?? [])
|
|
37
|
+
.map((choice, index) => ` ${String(index + 1)}) ${choice.label}\n`)
|
|
38
|
+
.join(""));
|
|
39
|
+
const answer = yield* promptAnswer(context, question);
|
|
40
|
+
if (answer === undefined)
|
|
41
|
+
return yield* cancelled();
|
|
42
|
+
return yield* chosen(question, answer);
|
|
43
|
+
});
|
|
44
|
+
const terminalInteraction = (context) => ({
|
|
45
|
+
ask: (question) => Effect.runPromise(askTerminal(context, question)),
|
|
46
|
+
show: (text) => {
|
|
47
|
+
context.io.stderr(`${text}\n`);
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
const keyInteraction = (context, input) => ({
|
|
51
|
+
ask: (question) => question.secret
|
|
52
|
+
? Promise.resolve(input.key)
|
|
53
|
+
: Promise.reject(new CliArgumentError(`'${input.providerId}' needs more than an API key: run 'maia login ${input.providerId}' at a terminal.`)),
|
|
54
|
+
show: (text) => {
|
|
55
|
+
context.io.stderr(`${text}\n`);
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
const findProvider = (providers, providerId) => {
|
|
59
|
+
const provider = providers.find((item) => item.id === providerId);
|
|
60
|
+
return provider === undefined
|
|
61
|
+
? Effect.fail(new CliArgumentError(`Unknown login target '${providerId}'. Use claude, codex or a model provider; 'maia login' lists them.`))
|
|
62
|
+
: Effect.succeed(provider);
|
|
63
|
+
};
|
|
64
|
+
const askAuthType = (context, provider) => safeEffect(askTerminal(context, {
|
|
65
|
+
choices: provider.authTypes.map((type) => ({
|
|
66
|
+
id: type,
|
|
67
|
+
label: authLabel(type),
|
|
68
|
+
})),
|
|
69
|
+
message: `Sign ${provider.name} in with:`,
|
|
70
|
+
secret: false,
|
|
71
|
+
}), "Sign-in cancelled.").pipe(Effect.map((answer) => (answer === "oauth" ? "oauth" : "api_key")));
|
|
72
|
+
const stdinRefusal = (provider) => new CliArgumentError(`${provider.name} ${provider.stored === "oauth" ? "is signed in with a subscription" : "signs in with a subscription"}: run 'maia login ${provider.id}' at a terminal.`);
|
|
73
|
+
const authTypeFor = (context, provider, keyFromStdin) => {
|
|
74
|
+
if (keyFromStdin)
|
|
75
|
+
return provider.authTypes.includes("api_key") && provider.stored !== "oauth"
|
|
76
|
+
? Effect.succeed("api_key")
|
|
77
|
+
: Effect.fail(stdinRefusal(provider));
|
|
78
|
+
if (provider.stored !== undefined)
|
|
79
|
+
context.io.stderr(`This replaces the stored ${authLabel(provider.stored)} for ${provider.name}.\n`);
|
|
80
|
+
const [only, other] = provider.authTypes;
|
|
81
|
+
return only !== undefined && other === undefined
|
|
82
|
+
? Effect.succeed(only)
|
|
83
|
+
: askAuthType(context, provider);
|
|
84
|
+
};
|
|
85
|
+
const readKey = (context) => {
|
|
86
|
+
const stdin = context.io.stdin;
|
|
87
|
+
return stdin === undefined
|
|
88
|
+
? Effect.fail(new CliArgumentError("Standard input is unavailable."))
|
|
89
|
+
: recoverStdin(stdin({ label: "API key", maxBytes: 8 * 1024, maxChunks: 8 }), safely("Maia could not read the key from standard input."));
|
|
90
|
+
};
|
|
91
|
+
const interactionFor = (context, input) => input.keyFromStdin
|
|
92
|
+
? readKey(context).pipe(Effect.map((key) => keyInteraction(context, { key, providerId: input.providerId })))
|
|
93
|
+
: Effect.succeed(terminalInteraction(context));
|
|
94
|
+
const refuseWithoutTerminal = (provider) => Effect.fail(new CliArgumentError(`${provider.name} signs in at a terminal: run 'maia login ${provider.id}' in one, or pass an API key with --api-key-stdin.`));
|
|
95
|
+
export const signInAgentProvider = (context, input) => Effect.gen(function* () {
|
|
96
|
+
const providers = yield* listAgentProviders(context);
|
|
97
|
+
const provider = yield* findProvider(providers, input.providerId);
|
|
98
|
+
if (!input.keyFromStdin && !input.atTerminal)
|
|
99
|
+
return yield* refuseWithoutTerminal(provider);
|
|
100
|
+
const authType = yield* authTypeFor(context, provider, input.keyFromStdin);
|
|
101
|
+
const interaction = yield* interactionFor(context, input);
|
|
102
|
+
yield* safeEffect(access(context).login({
|
|
103
|
+
authType,
|
|
104
|
+
interaction,
|
|
105
|
+
providerId: provider.id,
|
|
106
|
+
}), `The ${provider.name} sign-in did not complete.`);
|
|
107
|
+
return provider;
|
|
108
|
+
});
|
|
109
|
+
//# sourceMappingURL=agent-provider.js.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type CommandContext, type CommandEffect } from "../command-line/index.js";
|
|
2
|
+
export declare const runLogin: (tokens: readonly string[], context: CommandContext) => CommandEffect;
|
|
3
|
+
export declare const runLoginGateway: (tokens: readonly string[], context: CommandContext) => CommandEffect;
|
|
4
|
+
//# sourceMappingURL=commands.d.ts.map
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { CliArgumentError, parseOptions, reportError, requirePositionals, unknownCommand, writeSuccess, } from "../command-line/index.js";
|
|
3
|
+
import { callNode, ConnectionNodeError, redactConnection, } from "../connection/index.js";
|
|
4
|
+
import { listAgentProviders, signInAgentProvider } from "./agent-provider.js";
|
|
5
|
+
import { loginFailureMessage } from "./failure.js";
|
|
6
|
+
import { gatewayLogin } from "./gateway.js";
|
|
7
|
+
import { runLoginMenu } from "./menu.js";
|
|
8
|
+
import { formatLoginList } from "./output/index.js";
|
|
9
|
+
import { signInHere, signInThroughNode, writeSignedIn, } from "./vendor-account.js";
|
|
10
|
+
import { readVendorLogin } from "./vendor-input.js";
|
|
11
|
+
const atTerminal = (context) => context.io.interactive === true && !context.json;
|
|
12
|
+
const parsed = (read) => Effect.try({
|
|
13
|
+
catch: (error) => error instanceof CliArgumentError
|
|
14
|
+
? error
|
|
15
|
+
: new CliArgumentError("Invalid login input."),
|
|
16
|
+
try: read,
|
|
17
|
+
});
|
|
18
|
+
const listLogins = (context) => Effect.all([
|
|
19
|
+
callNode(context.dependencies.listConnections, (list) => list({ limit: 100 })),
|
|
20
|
+
listAgentProviders(context),
|
|
21
|
+
]).pipe(Effect.map(([accounts, providers]) => {
|
|
22
|
+
writeSuccess({
|
|
23
|
+
accounts: accounts.items.map(redactConnection),
|
|
24
|
+
agentProviders: providers.filter((item) => item.stored !== undefined),
|
|
25
|
+
availableProviders: providers
|
|
26
|
+
.filter((item) => item.stored === undefined)
|
|
27
|
+
.map((item) => item.id),
|
|
28
|
+
command: "login.list",
|
|
29
|
+
}, context, formatLoginList);
|
|
30
|
+
return 0;
|
|
31
|
+
}));
|
|
32
|
+
const readAgentVendorLogin = (tokens, context) => {
|
|
33
|
+
const input = readVendorLogin(tokens);
|
|
34
|
+
if (!atTerminal(context) && input.name === undefined)
|
|
35
|
+
throw new CliArgumentError("Pass --name: without a terminal, running the command again must reach the same account.");
|
|
36
|
+
return input;
|
|
37
|
+
};
|
|
38
|
+
const vendorLogin = (tokens, context) => parsed(() => readAgentVendorLogin(tokens, context)).pipe(Effect.flatMap((input) => atTerminal(context)
|
|
39
|
+
? signInHere(context, input).pipe(Effect.map((connection) => writeSignedIn(context, connection)))
|
|
40
|
+
: signInThroughNode(context, input)));
|
|
41
|
+
const readProviderLogin = (tokens, context) => {
|
|
42
|
+
const options = parseOptions(tokens, new Set(), new Set(["--api-key-stdin"]));
|
|
43
|
+
requirePositionals(options.positionals, 1);
|
|
44
|
+
if (context.profile !== undefined)
|
|
45
|
+
throw new CliArgumentError("Model providers belong to the Maia agent, not a Node profile: run without --profile.");
|
|
46
|
+
return {
|
|
47
|
+
keyFromStdin: options.flags.has("--api-key-stdin"),
|
|
48
|
+
providerId: options.positionals[0] ?? "",
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
const providerLogin = (tokens, context) => parsed(() => readProviderLogin(tokens, context)).pipe(Effect.flatMap((input) => signInAgentProvider(context, {
|
|
52
|
+
...input,
|
|
53
|
+
atTerminal: atTerminal(context),
|
|
54
|
+
})), Effect.map((provider) => {
|
|
55
|
+
writeSuccess({ command: "login", providerId: provider.id }, context, ({ providerId }) => `${providerId} stored in Maia auth.json\n`);
|
|
56
|
+
return 0;
|
|
57
|
+
}));
|
|
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
|
+
const remoteLoginRefusal = (target, context) => context.node === undefined ||
|
|
60
|
+
target === "claude" ||
|
|
61
|
+
target === "codex" ||
|
|
62
|
+
target === "gateway"
|
|
63
|
+
? undefined
|
|
64
|
+
: new CliArgumentError("With --node, name the account to sign in there: maia --node <name> login <claude|codex|gateway>.");
|
|
65
|
+
const login = (tokens, context) => {
|
|
66
|
+
const target = tokens.length === 0 ? undefined : loginTarget(tokens);
|
|
67
|
+
const refusal = remoteLoginRefusal(target, context);
|
|
68
|
+
if (refusal !== undefined)
|
|
69
|
+
return Effect.fail(refusal);
|
|
70
|
+
if (target === undefined && tokens.length > 0)
|
|
71
|
+
return Effect.fail(unknownCommand());
|
|
72
|
+
if (target === undefined)
|
|
73
|
+
return atTerminal(context) ? runLoginMenu(context) : listLogins(context);
|
|
74
|
+
if (target === "gateway")
|
|
75
|
+
return gatewayLogin(tokens, context);
|
|
76
|
+
return target === "claude" || target === "codex"
|
|
77
|
+
? vendorLogin(tokens, context)
|
|
78
|
+
: providerLogin(tokens, context);
|
|
79
|
+
};
|
|
80
|
+
const reportFailure = (error, context) => {
|
|
81
|
+
if (error instanceof ConnectionNodeError)
|
|
82
|
+
return reportError(error.error, context);
|
|
83
|
+
return reportError({
|
|
84
|
+
code: error instanceof CliArgumentError
|
|
85
|
+
? "invalid_argument"
|
|
86
|
+
: "internal_error",
|
|
87
|
+
message: loginFailureMessage(error),
|
|
88
|
+
retryable: false,
|
|
89
|
+
}, context);
|
|
90
|
+
};
|
|
91
|
+
export const runLogin = (tokens, context) => login(tokens, context).pipe(Effect.catch((error) => Effect.sync(() => reportFailure(error, context))));
|
|
92
|
+
export const runLoginGateway = (tokens, context) => runLogin(["gateway", ...tokens], context);
|
|
93
|
+
//# sourceMappingURL=commands.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { CliArgumentError } from "../command-line/index.js";
|
|
2
|
+
import { ConnectionNodeError } from "../connection/index.js";
|
|
3
|
+
const SAFE_ERROR_NAME = "MaiaLoginError";
|
|
4
|
+
export const safeLoginError = (message) => Object.assign(new Error(message), { name: SAFE_ERROR_NAME });
|
|
5
|
+
export const loginFailureMessage = (error) => {
|
|
6
|
+
if (error instanceof ConnectionNodeError)
|
|
7
|
+
return error.error.message;
|
|
8
|
+
if (error instanceof CliArgumentError)
|
|
9
|
+
return error.message;
|
|
10
|
+
return error instanceof Error && error.name === SAFE_ERROR_NAME
|
|
11
|
+
? error.message
|
|
12
|
+
: "The sign-in did not complete.";
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=failure.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { type CommandContext } from "../command-line/index.js";
|
|
3
|
+
type GatewayLoginInput = {
|
|
4
|
+
readonly baseUrl: string;
|
|
5
|
+
readonly commandId?: string;
|
|
6
|
+
readonly maxConcurrentSessions?: number;
|
|
7
|
+
readonly name: string;
|
|
8
|
+
};
|
|
9
|
+
export declare const readGatewayLogin: (tokens: readonly string[]) => GatewayLoginInput;
|
|
10
|
+
export declare const gatewayLogin: (tokens: readonly string[], context: CommandContext) => Effect.Effect<number, unknown, import("effect/Crypto").Crypto>;
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=gateway.d.ts.map
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { connectionGatewayCreateParametersSchema, } from "@maiaos/sdk";
|
|
2
|
+
import { Effect } from "effect";
|
|
3
|
+
import { CliArgumentError, missingArgument, parseOptions, recoverStdin, requirePositionals, writeSuccess, } from "../command-line/index.js";
|
|
4
|
+
import { callNode, ConnectionNodeError, formatConnectionResult, redactConnectionResult, } from "../connection/index.js";
|
|
5
|
+
import { newCliIdentifier } from "../local-node/index.js";
|
|
6
|
+
const readSessionLimit = (value) => {
|
|
7
|
+
if (value === undefined)
|
|
8
|
+
return {};
|
|
9
|
+
if (!/^(?:[1-9]|1[0-6])$/u.test(value))
|
|
10
|
+
throw new CliArgumentError("Option '--max-sessions' must be an integer from 1 to 16.");
|
|
11
|
+
return { maxConcurrentSessions: Number(value) };
|
|
12
|
+
};
|
|
13
|
+
export const readGatewayLogin = (tokens) => {
|
|
14
|
+
const parsed = parseOptions(tokens, new Set(["--base-url", "--command-id", "--max-sessions", "--name"]), new Set(["--api-key-stdin"]));
|
|
15
|
+
requirePositionals(parsed.positionals, 1);
|
|
16
|
+
const commandId = parsed.options.get("--command-id");
|
|
17
|
+
const name = parsed.options.get("--name");
|
|
18
|
+
const baseUrl = parsed.options.get("--base-url");
|
|
19
|
+
if (parsed.positionals[0] !== "gateway" ||
|
|
20
|
+
name === undefined ||
|
|
21
|
+
baseUrl === undefined ||
|
|
22
|
+
!parsed.flags.has("--api-key-stdin"))
|
|
23
|
+
throw missingArgument();
|
|
24
|
+
if (/\/v1\/?$/u.test(baseUrl))
|
|
25
|
+
throw new CliArgumentError("Leave '/v1' out of '--base-url'; Maia adds it for each request.");
|
|
26
|
+
return {
|
|
27
|
+
baseUrl,
|
|
28
|
+
...(commandId === undefined ? {} : { commandId }),
|
|
29
|
+
name,
|
|
30
|
+
...readSessionLimit(parsed.options.get("--max-sessions")),
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
const INVALID_GATEWAY = "Invalid gateway: '--base-url' must be https, or http to a loopback host, without credentials, query, fragment, trailing slash or '/v1'; '--name' uses lower-case letters, digits and dashes; the key is one line of 8 to 4096 printable characters.";
|
|
34
|
+
const readKey = (context) => {
|
|
35
|
+
const stdin = context.io.stdin;
|
|
36
|
+
return stdin === undefined
|
|
37
|
+
? Effect.fail(new CliArgumentError("Standard input is unavailable."))
|
|
38
|
+
: recoverStdin(stdin({ label: "API key", maxBytes: 8 * 1024, maxChunks: 8 }), () => new CliArgumentError("Maia could not read the key from standard input."));
|
|
39
|
+
};
|
|
40
|
+
const gatewayParameters = (input, apiKey) => (input.commandId === undefined
|
|
41
|
+
? newCliIdentifier("command")
|
|
42
|
+
: Effect.succeed(input.commandId)).pipe(Effect.flatMap((commandId) => {
|
|
43
|
+
const parameters = connectionGatewayCreateParametersSchema.safeParse({
|
|
44
|
+
...input,
|
|
45
|
+
apiKey: apiKey.trim(),
|
|
46
|
+
commandId,
|
|
47
|
+
});
|
|
48
|
+
return parameters.success
|
|
49
|
+
? Effect.succeed(parameters.data)
|
|
50
|
+
: Effect.fail(new CliArgumentError(INVALID_GATEWAY));
|
|
51
|
+
}));
|
|
52
|
+
const readInput = (tokens) => Effect.try({
|
|
53
|
+
catch: (error) => error instanceof CliArgumentError
|
|
54
|
+
? error
|
|
55
|
+
: new CliArgumentError("Invalid login input."),
|
|
56
|
+
try: () => readGatewayLogin(tokens),
|
|
57
|
+
});
|
|
58
|
+
const withRetryHint = (error, commandId) => error instanceof ConnectionNodeError && error.error.code === "storage_failed"
|
|
59
|
+
? new ConnectionNodeError({
|
|
60
|
+
...error.error,
|
|
61
|
+
message: `${error.error.message} Retry: the same command with --command-id ${commandId}.`,
|
|
62
|
+
})
|
|
63
|
+
: error;
|
|
64
|
+
const createGateway = (context, parameters) => callNode(context.dependencies.createGatewayConnection, (create) => create(parameters)).pipe(Effect.mapError((error) => withRetryHint(error, parameters.commandId)));
|
|
65
|
+
export const gatewayLogin = (tokens, context) => readInput(tokens).pipe(Effect.flatMap((input) => readKey(context).pipe(Effect.flatMap((key) => gatewayParameters(input, key)))), Effect.flatMap((parameters) => createGateway(context, parameters)), Effect.map((result) => {
|
|
66
|
+
if (result.keyCustody === "kept" && !context.json)
|
|
67
|
+
context.io.stderr("The gateway already had a key; it keeps that key and ignored the one on stdin.\n");
|
|
68
|
+
writeSuccess({ command: result.method, result: redactConnectionResult(result) }, context, formatConnectionResult);
|
|
69
|
+
return 0;
|
|
70
|
+
}));
|
|
71
|
+
//# sourceMappingURL=gateway.js.map
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { CliArgumentError, } from "../command-line/index.js";
|
|
3
|
+
import { callNode, describeConnection, redactConnection, } from "../connection/index.js";
|
|
4
|
+
import { listAgentProviders, signInAgentProvider } from "./agent-provider.js";
|
|
5
|
+
import { loginFailureMessage } from "./failure.js";
|
|
6
|
+
import { describeAgentProvider, formatAccounts, formatSignedInProviders, } from "./output/index.js";
|
|
7
|
+
import { signInHere } from "./vendor-account.js";
|
|
8
|
+
import { nextFreeName, vendorExecutor, } from "./vendor-input.js";
|
|
9
|
+
const MENU = [
|
|
10
|
+
"",
|
|
11
|
+
" 1) Add a Codex account",
|
|
12
|
+
" 2) Add a Claude Code account",
|
|
13
|
+
" 3) Sign a worker account in again",
|
|
14
|
+
" 4) Sign the Maia agent in to a model provider",
|
|
15
|
+
" q) Quit",
|
|
16
|
+
"",
|
|
17
|
+
].join("\n");
|
|
18
|
+
const say = (context, text) => Effect.sync(() => {
|
|
19
|
+
context.io.stderr(`${text}\n`);
|
|
20
|
+
});
|
|
21
|
+
const ask = (context, question) => {
|
|
22
|
+
const prompt = context.io.prompt;
|
|
23
|
+
return prompt === undefined
|
|
24
|
+
? Effect.fail(new CliArgumentError("Sign-in cancelled."))
|
|
25
|
+
: prompt(question).pipe(Effect.flatMap((answer) => answer === undefined
|
|
26
|
+
? Effect.fail(new CliArgumentError("Sign-in cancelled."))
|
|
27
|
+
: Effect.succeed(answer)));
|
|
28
|
+
};
|
|
29
|
+
const listAccounts = (context) => callNode(context.dependencies.listConnections, (list) => list({ limit: 100 })).pipe(Effect.map((result) => ({
|
|
30
|
+
accounts: result.items,
|
|
31
|
+
})), Effect.catch((error) => say(context, `Worker accounts are unavailable: ${loginFailureMessage(error)}`).pipe(Effect.as({}))));
|
|
32
|
+
const showLogins = (context, logins) => Effect.sync(() => {
|
|
33
|
+
const accounts = logins.accounts === undefined
|
|
34
|
+
? ""
|
|
35
|
+
: formatAccounts(logins.accounts.map(redactConnection));
|
|
36
|
+
context.io.stderr(`${accounts}${formatSignedInProviders(logins.providers)}`);
|
|
37
|
+
});
|
|
38
|
+
const askName = (context, vendor, accounts) => {
|
|
39
|
+
const proposal = nextFreeName(vendor, new Set(accounts.map((account) => account.name)));
|
|
40
|
+
return ask(context, `Name [${proposal}]: `).pipe(Effect.map((answer) => (answer === "" ? proposal : answer)));
|
|
41
|
+
};
|
|
42
|
+
const addAccount = (context, vendor, accounts) => askName(context, vendor, accounts).pipe(Effect.flatMap((name) => {
|
|
43
|
+
const executor = vendorExecutor(vendor);
|
|
44
|
+
return executor === undefined
|
|
45
|
+
? Effect.void
|
|
46
|
+
: signInHere(context, {
|
|
47
|
+
deviceCode: false,
|
|
48
|
+
executor,
|
|
49
|
+
name,
|
|
50
|
+
vendor,
|
|
51
|
+
}).pipe(Effect.flatMap((connection) => say(context, `Signed in: ${describeConnection(redactConnection(connection))}`)));
|
|
52
|
+
}));
|
|
53
|
+
const signInAgain = (context, accounts) => ask(context, "Account name: ").pipe(Effect.flatMap((name) => {
|
|
54
|
+
const account = accounts.find((item) => item.name === name);
|
|
55
|
+
if (account === undefined)
|
|
56
|
+
return say(context, `No account is named '${name}'.`);
|
|
57
|
+
if (account.executor === "gateway")
|
|
58
|
+
return say(context, `'${name}' is a gateway; it signs in with its API key, not a vendor login.`);
|
|
59
|
+
const vendor = account.executor === "codex-cli" ? "codex" : "claude";
|
|
60
|
+
return signInHere(context, {
|
|
61
|
+
deviceCode: false,
|
|
62
|
+
executor: account.executor,
|
|
63
|
+
name: account.name,
|
|
64
|
+
vendor,
|
|
65
|
+
}).pipe(Effect.asVoid);
|
|
66
|
+
}));
|
|
67
|
+
const signInProvider = (context, providers) => say(context, providers
|
|
68
|
+
.map((provider, index) => ` ${String(index + 1)}) ${describeAgentProvider(provider)}`)
|
|
69
|
+
.join("\n")).pipe(Effect.andThen(ask(context, "Provider (number or id): ")), Effect.flatMap((answer) => {
|
|
70
|
+
const providerId = providers[Number(answer) - 1]?.id ?? answer;
|
|
71
|
+
return providerId === ""
|
|
72
|
+
? Effect.void
|
|
73
|
+
: signInAgentProvider(context, {
|
|
74
|
+
atTerminal: true,
|
|
75
|
+
keyFromStdin: false,
|
|
76
|
+
providerId,
|
|
77
|
+
}).pipe(Effect.flatMap((provider) => say(context, `The Maia agent is signed in to ${provider.name}.`)));
|
|
78
|
+
}));
|
|
79
|
+
const choose = (context, choice, logins) => {
|
|
80
|
+
const accounts = logins.accounts ?? [];
|
|
81
|
+
if (choice === "1")
|
|
82
|
+
return addAccount(context, "codex", accounts);
|
|
83
|
+
if (choice === "2")
|
|
84
|
+
return addAccount(context, "claude", accounts);
|
|
85
|
+
if (choice === "3")
|
|
86
|
+
return signInAgain(context, accounts);
|
|
87
|
+
return choice === "4"
|
|
88
|
+
? signInProvider(context, logins.providers)
|
|
89
|
+
: say(context, "Choose 1, 2, 3, 4 or q.");
|
|
90
|
+
};
|
|
91
|
+
const round = (context) => Effect.gen(function* () {
|
|
92
|
+
const logins = {
|
|
93
|
+
...(yield* listAccounts(context)),
|
|
94
|
+
providers: yield* listAgentProviders(context),
|
|
95
|
+
};
|
|
96
|
+
yield* showLogins(context, logins);
|
|
97
|
+
yield* say(context, MENU);
|
|
98
|
+
const choice = yield* ask(context, "> ").pipe(Effect.orElseSucceed(() => "q"));
|
|
99
|
+
if (choice === "q" || choice === "")
|
|
100
|
+
return 0;
|
|
101
|
+
yield* choose(context, choice, logins).pipe(Effect.catch((error) => say(context, loginFailureMessage(error))));
|
|
102
|
+
return yield* round(context);
|
|
103
|
+
});
|
|
104
|
+
export const runLoginMenu = (context) => round(context);
|
|
105
|
+
//# sourceMappingURL=menu.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { MaiaAgentProvider } from "@maiaos/agent";
|
|
2
|
+
import { type RedactedConnection } from "../../connection/output/index.js";
|
|
3
|
+
export type CliLoginListResult = {
|
|
4
|
+
readonly accounts: readonly RedactedConnection[];
|
|
5
|
+
readonly agentProviders: readonly MaiaAgentProvider[];
|
|
6
|
+
readonly availableProviders: readonly string[];
|
|
7
|
+
readonly command: "login.list";
|
|
8
|
+
};
|
|
9
|
+
export declare const isLoginListResult: (result: {
|
|
10
|
+
readonly command: string;
|
|
11
|
+
}) => result is CliLoginListResult;
|
|
12
|
+
export declare const describeAgentProvider: (provider: MaiaAgentProvider) => string;
|
|
13
|
+
export declare const formatAccounts: (accounts: readonly RedactedConnection[]) => string;
|
|
14
|
+
export declare const formatSignedInProviders: (providers: readonly MaiaAgentProvider[]) => string;
|
|
15
|
+
export declare const formatLoginList: (result: CliLoginListResult) => string;
|
|
16
|
+
//# sourceMappingURL=format.d.ts.map
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { describeConnection, } from "../../connection/output/index.js";
|
|
2
|
+
export const isLoginListResult = (result) => result.command === "login.list";
|
|
3
|
+
const authLabel = (type) => type === "oauth" ? "subscription" : "API key";
|
|
4
|
+
export const describeAgentProvider = (provider) => [
|
|
5
|
+
`${provider.name} (${provider.id})`,
|
|
6
|
+
provider.authTypes.map(authLabel).join(" or "),
|
|
7
|
+
...(provider.stored === undefined
|
|
8
|
+
? []
|
|
9
|
+
: [`signed in with ${authLabel(provider.stored)}`]),
|
|
10
|
+
].join(" ");
|
|
11
|
+
export const formatAccounts = (accounts) => accounts.length === 0
|
|
12
|
+
? "Worker accounts: none yet.\n"
|
|
13
|
+
: `Worker accounts (Maia Node)\n${accounts
|
|
14
|
+
.map((account) => ` ${describeConnection(account)}\n`)
|
|
15
|
+
.join("")}`;
|
|
16
|
+
export const formatSignedInProviders = (providers) => {
|
|
17
|
+
const signedIn = providers.filter((item) => item.stored !== undefined);
|
|
18
|
+
return signedIn.length === 0
|
|
19
|
+
? "Maia agent model providers: none signed in.\n"
|
|
20
|
+
: `Maia agent model providers (one credential each)\n${signedIn
|
|
21
|
+
.map((provider) => ` ${describeAgentProvider(provider)}\n`)
|
|
22
|
+
.join("")}`;
|
|
23
|
+
};
|
|
24
|
+
export const formatLoginList = (result) => [
|
|
25
|
+
formatAccounts(result.accounts),
|
|
26
|
+
formatSignedInProviders(result.agentProviders),
|
|
27
|
+
result.availableProviders.length === 0
|
|
28
|
+
? ""
|
|
29
|
+
: `Other model providers: ${result.availableProviders.join(", ")}\n`,
|
|
30
|
+
].join("");
|
|
31
|
+
//# sourceMappingURL=format.js.map
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import type { Connection } from "@maiaos/sdk";
|
|
2
|
+
import { Effect } from "effect";
|
|
3
|
+
import { type CommandContext } from "../command-line/index.js";
|
|
4
|
+
import { ConnectionNodeError } from "../connection/index.js";
|
|
5
|
+
import { type VendorLoginInput } from "./vendor-input.js";
|
|
6
|
+
export declare const signInHere: (context: CommandContext, input: VendorLoginInput) => Effect.Effect<{
|
|
7
|
+
readonly configRoot: {
|
|
8
|
+
readonly kind: "maia-managed";
|
|
9
|
+
readonly path: string;
|
|
10
|
+
} | {
|
|
11
|
+
readonly kind: "system-default";
|
|
12
|
+
};
|
|
13
|
+
readonly connectionId: string;
|
|
14
|
+
readonly createdAt: string;
|
|
15
|
+
readonly executor: "claude-code" | "codex-cli" | "gateway";
|
|
16
|
+
readonly gateway?: {
|
|
17
|
+
readonly baseUrl: string;
|
|
18
|
+
} | undefined;
|
|
19
|
+
readonly limitedUntil: string | null;
|
|
20
|
+
readonly maxConcurrentSessions: number;
|
|
21
|
+
readonly name: string;
|
|
22
|
+
readonly revision: string;
|
|
23
|
+
readonly schemaVersion: "maia.connection/v1";
|
|
24
|
+
readonly state: "disabled" | "enabled";
|
|
25
|
+
readonly updatedAt: string;
|
|
26
|
+
readonly usage?: {
|
|
27
|
+
readonly account?: {
|
|
28
|
+
readonly email?: string | undefined;
|
|
29
|
+
readonly plan?: string | undefined;
|
|
30
|
+
} | undefined;
|
|
31
|
+
readonly checkedAt: string;
|
|
32
|
+
readonly resetCredits?: {
|
|
33
|
+
readonly availableCount: number;
|
|
34
|
+
readonly nextCreditId?: string | undefined;
|
|
35
|
+
readonly nextExpiresAt?: string | undefined;
|
|
36
|
+
} | undefined;
|
|
37
|
+
readonly unavailable?: {
|
|
38
|
+
readonly message?: string | undefined;
|
|
39
|
+
readonly reason: "probe_failed" | "signed_out" | "unsupported";
|
|
40
|
+
} | undefined;
|
|
41
|
+
readonly windows: readonly {
|
|
42
|
+
readonly id: string;
|
|
43
|
+
readonly kind: "other" | "session" | "weekly";
|
|
44
|
+
readonly resetsAt?: string | undefined;
|
|
45
|
+
readonly usedPercent: number;
|
|
46
|
+
readonly windowMinutes?: number | undefined;
|
|
47
|
+
}[];
|
|
48
|
+
} | undefined;
|
|
49
|
+
} | {
|
|
50
|
+
readonly configRoot: {
|
|
51
|
+
readonly kind: "maia-managed";
|
|
52
|
+
readonly path: string;
|
|
53
|
+
} | {
|
|
54
|
+
readonly kind: "system-default";
|
|
55
|
+
};
|
|
56
|
+
readonly connectionId: string;
|
|
57
|
+
readonly createdAt: string;
|
|
58
|
+
readonly executor: "claude-code" | "codex-cli" | "gateway";
|
|
59
|
+
readonly gateway?: {
|
|
60
|
+
readonly baseUrl: string;
|
|
61
|
+
} | undefined;
|
|
62
|
+
readonly limitedUntil: string | null;
|
|
63
|
+
readonly maxConcurrentSessions: number;
|
|
64
|
+
readonly name: string;
|
|
65
|
+
readonly revision: string;
|
|
66
|
+
readonly schemaVersion: "maia.connection/v1";
|
|
67
|
+
readonly state: "disabled" | "enabled";
|
|
68
|
+
readonly updatedAt: string;
|
|
69
|
+
readonly usage?: {
|
|
70
|
+
readonly account?: {
|
|
71
|
+
readonly email?: string | undefined;
|
|
72
|
+
readonly plan?: string | undefined;
|
|
73
|
+
} | undefined;
|
|
74
|
+
readonly checkedAt: string;
|
|
75
|
+
readonly resetCredits?: {
|
|
76
|
+
readonly availableCount: number;
|
|
77
|
+
readonly nextCreditId?: string | undefined;
|
|
78
|
+
readonly nextExpiresAt?: string | undefined;
|
|
79
|
+
} | undefined;
|
|
80
|
+
readonly unavailable?: {
|
|
81
|
+
readonly message?: string | undefined;
|
|
82
|
+
readonly reason: "probe_failed" | "signed_out" | "unsupported";
|
|
83
|
+
} | undefined;
|
|
84
|
+
readonly windows: readonly {
|
|
85
|
+
readonly id: string;
|
|
86
|
+
readonly kind: "other" | "session" | "weekly";
|
|
87
|
+
readonly resetsAt?: string | undefined;
|
|
88
|
+
readonly usedPercent: number;
|
|
89
|
+
readonly windowMinutes?: number | undefined;
|
|
90
|
+
}[];
|
|
91
|
+
} | undefined;
|
|
92
|
+
}, ConnectionNodeError | Error, import("effect/Crypto").Crypto>;
|
|
93
|
+
export declare const writeSignedIn: (context: CommandContext, connection: Connection) => number;
|
|
94
|
+
export declare const signInThroughNode: (context: CommandContext, input: VendorLoginInput) => Effect.Effect<number, ConnectionNodeError | Error, import("effect/Crypto").Crypto>;
|
|
95
|
+
//# sourceMappingURL=vendor-account.d.ts.map
|