@@ -26,82 +26,67 @@ export function createDialogProviderOptions() {
2626 const sync = useSync ( )
2727 const dialog = useDialog ( )
2828 const sdk = useSDK ( )
29- const connected = createMemo ( ( ) => new Set ( sync . data . provider_next . connected ) )
3029 const options = createMemo ( ( ) => {
3130 return pipe (
3231 sync . data . provider_next . all ,
3332 sortBy ( ( x ) => PROVIDER_PRIORITY [ x . id ] ?? 99 ) ,
34- map ( ( provider ) => {
35- const isConnected = connected ( ) . has ( provider . id )
36- return {
37- title : provider . name ,
38- value : provider . id ,
39- description : {
40- opencode : "(Recommended)" ,
41- anthropic : "(Claude Max or API key)" ,
42- openai : "(ChatGPT Plus/Pro or API key)" ,
43- } [ provider . id ] ,
44- category : provider . id in PROVIDER_PRIORITY ? "Popular" : "Other" ,
45- footer : isConnected ? "Connected" : undefined ,
46- async onSelect ( ) {
47- const methods = sync . data . provider_auth [ provider . id ] ?? [
48- {
49- type : "api" ,
50- label : "API key" ,
51- } ,
52- ]
53- let index : number | null = 0
54- if ( methods . length > 1 ) {
55- index = await new Promise < number | null > ( ( resolve ) => {
56- dialog . replace (
57- ( ) => (
58- < DialogSelect
59- title = "Select auth method"
60- options = { methods . map ( ( x , index ) => ( {
61- title : x . label ,
62- value : index ,
63- } ) ) }
64- onSelect = { ( option ) => resolve ( option . value ) }
65- />
66- ) ,
67- ( ) => resolve ( null ) ,
68- )
69- } )
70- }
71- if ( index == null ) return
72- const method = methods [ index ]
73- if ( method . type === "oauth" ) {
74- const result = await sdk . client . provider . oauth . authorize ( {
75- providerID : provider . id ,
76- method : index ,
77- } )
78- if ( result . data ?. method === "code" ) {
79- dialog . replace ( ( ) => (
80- < CodeMethod
81- providerID = { provider . id }
82- title = { method . label }
83- index = { index }
84- authorization = { result . data ! }
85- />
86- ) )
87- }
88- if ( result . data ?. method === "auto" ) {
89- dialog . replace ( ( ) => (
90- < AutoMethod
91- providerID = { provider . id }
92- title = { method . label }
93- index = { index }
94- authorization = { result . data ! }
33+ map ( ( provider ) => ( {
34+ title : provider . name ,
35+ value : provider . id ,
36+ description : {
37+ opencode : "(Recommended)" ,
38+ anthropic : "(Claude Max or API key)" ,
39+ openai : "(ChatGPT Plus/Pro or API key)" ,
40+ } [ provider . id ] ,
41+ category : provider . id in PROVIDER_PRIORITY ? "Popular" : "Other" ,
42+ async onSelect ( ) {
43+ const methods = sync . data . provider_auth [ provider . id ] ?? [
44+ {
45+ type : "api" ,
46+ label : "API key" ,
47+ } ,
48+ ]
49+ let index : number | null = 0
50+ if ( methods . length > 1 ) {
51+ index = await new Promise < number | null > ( ( resolve ) => {
52+ dialog . replace (
53+ ( ) => (
54+ < DialogSelect
55+ title = "Select auth method"
56+ options = { methods . map ( ( x , index ) => ( {
57+ title : x . label ,
58+ value : index ,
59+ } ) ) }
60+ onSelect = { ( option ) => resolve ( option . value ) }
9561 />
96- ) )
97- }
62+ ) ,
63+ ( ) => resolve ( null ) ,
64+ )
65+ } )
66+ }
67+ if ( index == null ) return
68+ const method = methods [ index ]
69+ if ( method . type === "oauth" ) {
70+ const result = await sdk . client . provider . oauth . authorize ( {
71+ providerID : provider . id ,
72+ method : index ,
73+ } )
74+ if ( result . data ?. method === "code" ) {
75+ dialog . replace ( ( ) => (
76+ < CodeMethod providerID = { provider . id } title = { method . label } index = { index } authorization = { result . data ! } />
77+ ) )
9878 }
99- if ( method . type === "api" ) {
100- return dialog . replace ( ( ) => < ApiMethod providerID = { provider . id } title = { method . label } /> )
79+ if ( result . data ?. method === "auto" ) {
80+ dialog . replace ( ( ) => (
81+ < AutoMethod providerID = { provider . id } title = { method . label } index = { index } authorization = { result . data ! } />
82+ ) )
10183 }
102- } ,
103- }
104- } ) ,
84+ }
85+ if ( method . type === "api" ) {
86+ return dialog . replace ( ( ) => < ApiMethod providerID = { provider . id } title = { method . label } /> )
87+ }
88+ } ,
89+ } ) ) ,
10590 )
10691 } )
10792 return options
0 commit comments