MCPcopy Create free account
hub / github.com/apache/maka / connectRuntimeHostCli

Function connectRuntimeHostCli

packages/cli/src/runtime-host-cli-context.ts:59–144  ·  view source on GitHub ↗
(
  input: {
    readonly rootPath: string;
    readonly surface: ClientSurface;
    readonly profileId?: string;
    readonly clientDataRoot?: string;
  },
  overrides: Partial<RuntimeHostCliContextDeps> = {},
)

Source from the content-addressed store, hash-verified

57}
58
59export async function connectRuntimeHostCli(
60 input: {
61 readonly rootPath: string;
62 readonly surface: ClientSurface;
63 readonly profileId?: string;
64 readonly clientDataRoot?: string;
65 },
66 overrides: Partial<RuntimeHostCliContextDeps> = {},
67): Promise<RuntimeHostCliConnectionContext> {
68 const deps: RuntimeHostCliContextDeps = {
69 connectOrSpawn: connectOrSpawnRuntimeHost,
70 connectRemoteProfile: connectRemoteRuntimeHostProfile,
71 readConnectionCatalog: readRuntimeHostConnectionCatalog,
72 loadClientInstanceId: loadOrCreateRuntimeHostClientInstanceId,
73 executionCandidateEntrypoint: new URL(
74 import.meta.resolve('@maka/runtime-host/execution-candidate-main'),
75 ),
76 ...overrides,
77 };
78 const resolvedProfile = await resolveHostProfile(input, deps);
79 const profile = resolvedProfile.profile;
80 const clientInstanceId =
81 profile.kind === 'local'
82 ? randomUUID()
83 : await deps.loadClientInstanceId(
84 join(input.clientDataRoot ?? resolveMakaClientDataRoot(), 'runtime-host-client.json'),
85 );
86 const connectInput = {
87 rootPath: input.rootPath,
88 surface: input.surface,
89 protocol: { min: RUNTIME_HOST_PROTOCOL_VERSION, max: RUNTIME_HOST_PROTOCOL_VERSION },
90 clientInstanceId,
91 compositionId: INTERACTIVE_RUNTIME_HOST_COMPOSITION_ID,
92 candidateEntrypoint: deps.executionCandidateEntrypoint,
93 } as const;
94 const connect = async (
95 signal?: AbortSignal,
96 sshInteraction: 'batch' | 'inherit' = 'batch',
97 ): Promise<RuntimeHostConnection> => {
98 if (profile.kind === 'remote') {
99 return deps.connectRemoteProfile({
100 profile,
101 credential: resolvedProfile.credential!,
102 surface: input.surface,
103 clientInstanceId,
104 sshInteraction,
105 ...(signal ? { signal } : {}),
106 });
107 }
108 const connected = await deps.connectOrSpawn({
109 ...connectInput,
110 ...(signal ? { signal } : {}),
111 });
112 if (connected.kind === 'incompatible') {
113 throw new RuntimeHostCliConflictError(connected.handshake);
114 }
115 if (connected.kind === 'upgrade_required') {
116 throw new RuntimeHostPermanentReconnectError(

Calls 6

resolveHostProfileFunction · 0.85
connectFunction · 0.70
resolveMethod · 0.65
closeMethod · 0.65

Tested by

no test coverage detected