llms-py 2.0.25__py3-none-any.whl → 2.0.27__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
llms/ui/ai.mjs CHANGED
@@ -6,12 +6,13 @@ const headers = { 'Accept': 'application/json' }
6
6
  const prefsKey = 'llms.prefs'
7
7
 
8
8
  export const o = {
9
- version: '2.0.25',
9
+ version: '2.0.27',
10
10
  base,
11
11
  prefsKey,
12
12
  welcome: 'Welcome to llms.py',
13
13
  auth: null,
14
14
  requiresAuth: false,
15
+ authType: 'apikey', // 'oauth' or 'apikey' - controls which SignIn component to use
15
16
  headers,
16
17
 
17
18
  resolveUrl(url){
@@ -50,26 +51,88 @@ export const o = {
50
51
  this.auth = auth
51
52
  if (auth?.apiKey) {
52
53
  this.headers.Authorization = `Bearer ${auth.apiKey}`
53
- } else if (this.headers.Authorization) {
54
+ //localStorage.setItem('llms:auth', JSON.stringify({ apiKey: auth.apiKey }))
55
+ } else if (auth?.sessionToken) {
56
+ this.headers['X-Session-Token'] = auth.sessionToken
57
+ localStorage.setItem('llms:auth', JSON.stringify({ sessionToken: auth.sessionToken }))
58
+ } else {
59
+ if (this.headers.Authorization) {
60
+ delete this.headers.Authorization
61
+ }
62
+ if (this.headers['X-Session-Token']) {
63
+ delete this.headers['X-Session-Token']
64
+ }
65
+ }
66
+ },
67
+ async signOut() {
68
+ if (this.auth?.sessionToken) {
69
+ // Call logout endpoint for OAuth sessions
70
+ try {
71
+ await this.post('/auth/logout', {
72
+ headers: {
73
+ 'X-Session-Token': this.auth.sessionToken
74
+ }
75
+ })
76
+ } catch (error) {
77
+ console.error('Logout error:', error)
78
+ }
79
+ }
80
+ this.auth = null
81
+ if (this.headers.Authorization) {
54
82
  delete this.headers.Authorization
55
83
  }
84
+ if (this.headers['X-Session-Token']) {
85
+ delete this.headers['X-Session-Token']
86
+ }
87
+ localStorage.removeItem('llms:auth')
56
88
  },
57
89
  async init() {
58
90
  // Load models and prompts
59
91
  const { initDB } = useThreadStore()
60
- const [_, configRes, modelsRes, authRes] = await Promise.all([
92
+ const [_, configRes, modelsRes] = await Promise.all([
61
93
  initDB(),
62
94
  this.getConfig(),
63
95
  this.getModels(),
64
- this.getAuth(),
65
96
  ])
66
97
  const config = await configRes.json()
67
98
  const models = await modelsRes.json()
68
- const auth = this.requiresAuth
99
+
100
+ // Update auth settings from server config
101
+ if (config.requiresAuth != null) {
102
+ this.requiresAuth = config.requiresAuth
103
+ }
104
+ if (config.authType != null) {
105
+ this.authType = config.authType
106
+ }
107
+
108
+ // Try to restore session from localStorage
109
+ if (this.requiresAuth) {
110
+ const storedAuth = localStorage.getItem('llms:auth')
111
+ if (storedAuth) {
112
+ try {
113
+ const authData = JSON.parse(storedAuth)
114
+ if (authData.sessionToken) {
115
+ this.headers['X-Session-Token'] = authData.sessionToken
116
+ }
117
+ // else if (authData.apiKey) {
118
+ // this.headers.Authorization = `Bearer ${authData.apiKey}`
119
+ // }
120
+ } catch (e) {
121
+ console.error('Failed to restore auth from localStorage:', e)
122
+ localStorage.removeItem('llms:auth')
123
+ }
124
+ }
125
+ }
126
+
127
+ // Get auth status
128
+ const authRes = await this.getAuth()
129
+ const auth = this.requiresAuth
69
130
  ? await authRes.json()
70
131
  : null
71
132
  if (auth?.responseStatus?.errorCode) {
72
133
  console.error(auth.responseStatus.errorCode, auth.responseStatus.message)
134
+ // Clear invalid session from localStorage
135
+ localStorage.removeItem('llms:auth')
73
136
  } else {
74
137
  this.signIn(auth)
75
138
  }