@@ -26,67 +26,72 @@ 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 ) )
2930 const options = createMemo ( ( ) => {
3031 return pipe (
3132 sync . data . provider_next . all ,
3233 sortBy ( ( x ) => PROVIDER_PRIORITY [ x . id ] ?? 99 ) ,
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 ) }
61- />
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- ) )
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+ } )
7870 }
79- if ( result . data ?. method === "auto" ) {
80- dialog . replace ( ( ) => (
81- < AutoMethod providerID = { provider . id } title = { method . label } index = { index } authorization = { result . data ! } />
82- ) )
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 providerID = { provider . id } title = { method . label } index = { index } authorization = { result . data ! } />
81+ ) )
82+ }
83+ if ( result . data ?. method === "auto" ) {
84+ dialog . replace ( ( ) => (
85+ < AutoMethod providerID = { provider . id } title = { method . label } index = { index } authorization = { result . data ! } />
86+ ) )
87+ }
8388 }
84- }
85- if ( method . type === "api" ) {
86- return dialog . replace ( ( ) => < ApiMethod providerID = { provider . id } title = { method . label } /> )
87- }
88- } ,
89- } ) ) ,
89+ if ( method . type === "api" ) {
90+ return dialog . replace ( ( ) => < ApiMethod providerID = { provider . id } title = { method . label } /> )
91+ }
92+ } ,
93+ }
94+ } ) ,
9095 )
9196 } )
9297 return options
0 commit comments