@@ -2,17 +2,17 @@ import consola from "consola"
22import fs from "node:fs"
33import { FetchError } from "ofetch"
44
5- import { PATHS } from "~/lib/paths"
65import { CONFIG } from "~/lib/config"
6+ import { PATHS } from "~/lib/paths"
77import { getGitHubUser } from "~/services/github/get-user/service"
88
99import type { parseCli } from "./cli"
1010
1111import { getModels } from "../services/copilot/get-models/service"
1212import { getCopilotToken } from "../services/copilot/get-token/copilot-token"
1313import { getGitHubToken } from "../services/github/get-token/service"
14- import { CACHE } from "./cache"
1514import { initializeLogger } from "./logger"
15+ import { getGithubToken , saveGithubToken } from "./token-storage"
1616import { TOKENS } from "./tokens"
1717
1818interface InitStep {
@@ -22,26 +22,17 @@ interface InitStep {
2222
2323const initSteps : Array < InitStep > = [
2424 {
25- name : "Emulation check " ,
25+ name : "App directory " ,
2626 run : ( ) => {
27- if ( CONFIG . EMULATE_STREAMING ) {
28- consola . box ( "Streaming emulation is enabled." )
29- }
30- } ,
31- } ,
32- {
33- name : "Cache" ,
34- run : async ( ) => {
35- if ( ! fs . existsSync ( PATHS . CACHE_PATH ) ) {
27+ if ( ! fs . existsSync ( PATHS . APP_DIR ) ) {
3628 fs . mkdirSync ( PATHS . APP_DIR , { recursive : true } )
37- await CACHE . _write ( { } )
3829 }
3930 } ,
4031 } ,
4132 {
4233 name : "GitHub authentication" ,
4334 run : async ( ) => {
44- TOKENS . GITHUB_TOKEN = await getCachedGithubToken ( )
35+ TOKENS . GITHUB_TOKEN = await getGithubToken ( )
4536
4637 try {
4738 await logUser ( )
@@ -89,15 +80,10 @@ const initSteps: Array<InitStep> = [
8980 } ,
9081]
9182
92- async function getCachedGithubToken ( ) {
93- const cachedToken = await CACHE . get ( "github-token" )
94- return cachedToken ?. value
95- }
96-
9783async function initializeGithubToken ( ) {
9884 consola . start ( "Getting GitHub device code" )
9985 const token = await getGitHubToken ( )
100- await CACHE . set ( "github-token" , token . access_token )
86+ await saveGithubToken ( token . access_token )
10187 return token . access_token
10288}
10389
0 commit comments