fix: patch auth flow (#180)
This commit is contained in:
@@ -54,14 +54,6 @@ export async function getClient() {
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Auto-cache: if LETTA_API_KEY is set in env but not in settings, write it to settings
|
||||
// Note: LETTA_BASE_URL is intentionally NOT cached - it should only come from env vars
|
||||
if (process.env.LETTA_API_KEY && !settings.env?.LETTA_API_KEY) {
|
||||
const updatedEnv = { ...settings.env };
|
||||
updatedEnv.LETTA_API_KEY = process.env.LETTA_API_KEY;
|
||||
settingsManager.updateSettings({ env: updatedEnv });
|
||||
}
|
||||
|
||||
return new Letta({
|
||||
apiKey,
|
||||
baseURL,
|
||||
|
||||
@@ -6,6 +6,7 @@ import { hostname } from "node:os";
|
||||
import { Box, Text, useApp, useInput } from "ink";
|
||||
import { useState } from "react";
|
||||
import { asciiLogo } from "../cli/components/AsciiArt.ts";
|
||||
import { colors } from "../cli/components/colors";
|
||||
import { settingsManager } from "../settings-manager";
|
||||
import { pollForToken, requestDeviceCode } from "./oauth";
|
||||
|
||||
@@ -124,8 +125,8 @@ export function SetupUI({ onComplete }: SetupUIProps) {
|
||||
if (mode === "device-code") {
|
||||
return (
|
||||
<Box flexDirection="column" padding={1}>
|
||||
<Text>{asciiLogo}</Text>
|
||||
<Text bold>Login to Letta Cloud</Text>
|
||||
<Text color={colors.welcome.accent}>{asciiLogo}</Text>
|
||||
<Text bold>Login to the Letta Developer Platform</Text>
|
||||
<Text> </Text>
|
||||
<Text dimColor>Opening browser for authorization...</Text>
|
||||
<Text> </Text>
|
||||
@@ -145,14 +146,15 @@ export function SetupUI({ onComplete }: SetupUIProps) {
|
||||
// Main menu
|
||||
return (
|
||||
<Box flexDirection="column" padding={1}>
|
||||
<Text>{asciiLogo}</Text>
|
||||
<Text color={colors.welcome.accent}>{asciiLogo}</Text>
|
||||
<Text bold>Welcome to Letta Code!</Text>
|
||||
<Text> </Text>
|
||||
<Text>Let's get you authenticated:</Text>
|
||||
<Text> </Text>
|
||||
<Box>
|
||||
<Text color={selectedOption === 0 ? "cyan" : undefined}>
|
||||
{selectedOption === 0 ? "→" : " "} Login to Letta Cloud
|
||||
{selectedOption === 0 ? "→" : " "} Login to the Letta Developer
|
||||
Platform
|
||||
</Text>
|
||||
</Box>
|
||||
<Box>
|
||||
|
||||
12
src/index.ts
12
src/index.ts
@@ -114,14 +114,6 @@ async function main() {
|
||||
// Silently ignore update failures
|
||||
});
|
||||
|
||||
// set LETTA_API_KEY from environment if available
|
||||
if (process.env.LETTA_API_KEY && !settings.env?.LETTA_API_KEY) {
|
||||
settings.env = settings.env || {};
|
||||
settings.env.LETTA_API_KEY = process.env.LETTA_API_KEY;
|
||||
|
||||
settingsManager.updateSettings({ env: settings.env });
|
||||
}
|
||||
|
||||
// Parse command-line arguments (Bun-idiomatic approach using parseArgs)
|
||||
let values: Record<string, unknown>;
|
||||
let positionals: string[];
|
||||
@@ -286,10 +278,12 @@ async function main() {
|
||||
LETTA_CLOUD_API_URL;
|
||||
|
||||
// Check if refresh token is missing for Letta Cloud (only when not using env var)
|
||||
// Skip this check if we already have an API key from env
|
||||
if (
|
||||
!isHeadless &&
|
||||
baseURL === LETTA_CLOUD_API_URL &&
|
||||
!settings.refreshToken
|
||||
!settings.refreshToken &&
|
||||
!apiKey
|
||||
) {
|
||||
// For interactive mode, show setup flow
|
||||
const { runSetup } = await import("./auth/setup");
|
||||
|
||||
Reference in New Issue
Block a user