diff --git a/src/ensureAuthenticated.ts b/src/ensureAuthenticated.ts new file mode 100644 index 0000000..681a49c --- /dev/null +++ b/src/ensureAuthenticated.ts @@ -0,0 +1,14 @@ +import { type SimpleLogger } from "@lmstudio/lms-common"; +import { type LMStudioClient } from "@lmstudio/sdk"; +import chalk from "chalk"; + +export async function ensureAuthenticated(client: LMStudioClient, logger: SimpleLogger) { + await client.repository.ensureAuthenticated({ + onAuthenticationUrl: url => { + logger.info("Authentication required. Please visit the following URL to authenticate:"); + logger.info(); + logger.info(chalk.greenBright(` ${url}`)); + logger.info(); + }, + }); +} diff --git a/src/subcommands/pull.ts b/src/subcommands/pull.ts index 8fcab63..37c5562 100644 --- a/src/subcommands/pull.ts +++ b/src/subcommands/pull.ts @@ -4,6 +4,7 @@ import { command, positional, string, type Type } from "cmd-ts"; import { resolve } from "path"; import { createClient, createClientArgs } from "../createClient.js"; import { createDownloadPbUpdater } from "../downloadPbUpdater.js"; +import { ensureAuthenticated } from "../ensureAuthenticated.js"; import { exists } from "../exists.js"; import { createLogger, logLevelArgs } from "../logLevel.js"; import { optionalPositional } from "../optionalPositional.js"; @@ -51,6 +52,7 @@ export const pull = command({ handler: async args => { const logger = createLogger(args); const client = await createClient(logger, args); + await ensureAuthenticated(client, logger); const { owner, name } = args.artifactIdentifier; let path = args.path; let autoNamed: boolean; diff --git a/src/subcommands/push.ts b/src/subcommands/push.ts index 5261e99..ed5b8bc 100644 --- a/src/subcommands/push.ts +++ b/src/subcommands/push.ts @@ -1,6 +1,7 @@ import { command } from "cmd-ts"; import { cwd } from "process"; import { createClient, createClientArgs } from "../createClient.js"; +import { ensureAuthenticated } from "../ensureAuthenticated.js"; import { findProjectFolderOrExit } from "../findProjectFolder.js"; import { createLogger, logLevelArgs } from "../logLevel.js"; @@ -14,6 +15,7 @@ export const push = command({ handler: async args => { const logger = createLogger(args); const client = await createClient(logger, args); + await ensureAuthenticated(client, logger); const projectPath = await findProjectFolderOrExit(logger, cwd()); await client.repository.pushArtifact({ path: projectPath,