beamlit 0.0.57rc120__py3-none-any.whl → 0.0.58__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.
beamlit/agents/chat.py CHANGED
@@ -1,11 +1,12 @@
1
1
  from logging import getLogger
2
2
  from typing import Tuple, Union
3
3
 
4
+ from langchain_core.language_models import BaseChatModel
5
+
4
6
  from beamlit.api.models import get_model
5
7
  from beamlit.authentication import get_authentication_headers, new_client
6
8
  from beamlit.common.settings import get_settings
7
9
  from beamlit.models import Model
8
- from langchain_core.language_models import BaseChatModel
9
10
 
10
11
  from .voice.openai import OpenAIVoiceReactAgent
11
12
 
@@ -10,14 +10,15 @@ import inspect
10
10
  from logging import getLogger
11
11
  from typing import Callable
12
12
 
13
+ from langgraph.checkpoint.memory import MemorySaver
14
+ from langgraph.prebuilt import create_react_agent
15
+
13
16
  from beamlit.api.models import get_model, list_models
14
17
  from beamlit.authentication import new_client
15
18
  from beamlit.common.settings import Settings, init
16
19
  from beamlit.errors import UnexpectedStatus
17
20
  from beamlit.functions import get_functions
18
21
  from beamlit.models import Agent, AgentSpec, Metadata
19
- from langgraph.checkpoint.memory import MemorySaver
20
- from langgraph.prebuilt import create_react_agent
21
22
 
22
23
  from .chat import get_chat_model_full
23
24
  from .voice.openai import OpenAIVoiceReactAgent
beamlit/agents/thread.py CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  Defines threading capabilities for agents.
4
4
  """
5
- import jwt
6
5
  from fastapi import Request
7
6
 
8
7
 
@@ -7,21 +7,18 @@ It also includes utilities for creating authenticated clients and managing authe
7
7
  from dataclasses import dataclass
8
8
  from typing import Dict, Generator
9
9
 
10
- from httpx import Auth, Request, Response
11
-
12
10
  from beamlit.common.settings import Settings, get_settings
11
+ from httpx import Auth, Request, Response
13
12
 
14
13
  from ..client import AuthenticatedClient
15
14
  from .apikey import ApiKeyProvider
16
15
  from .clientcredentials import ClientCredentials
17
- from .credentials import (
18
- Credentials,
19
- current_context,
20
- load_credentials,
21
- load_credentials_from_settings,
22
- )
16
+ from .credentials import (Credentials, current_context, load_credentials,
17
+ load_credentials_from_settings)
23
18
  from .device_mode import BearerToken
24
19
 
20
+ global provider_singleton
21
+ provider_singleton = None
25
22
 
26
23
  class PublicProvider(Auth):
27
24
  """
@@ -144,6 +141,11 @@ def get_authentication_headers(settings: Settings) -> Dict[str, str]:
144
141
  Returns:
145
142
  Dict[str, str]: A dictionary of authentication headers.
146
143
  """
144
+ global provider_singleton
145
+
146
+ if provider_singleton:
147
+ return provider_singleton.get_headers()
148
+
147
149
  context = current_context()
148
150
  if context.workspace and not settings.authentication.client.credentials:
149
151
  credentials = load_credentials(context.workspace)
@@ -165,4 +167,5 @@ def get_authentication_headers(settings: Settings) -> Dict[str, str]:
165
167
 
166
168
  if provider is None:
167
169
  return None
170
+ provider_singleton = provider
168
171
  return provider.get_headers()
@@ -4,16 +4,13 @@ authentication for Beamlit. It manages token refreshing and authentication flows
4
4
  client credentials and refresh tokens.
5
5
  """
6
6
 
7
- import base64
8
- import json
9
7
  from dataclasses import dataclass
10
8
  from datetime import datetime, timedelta
11
9
  from typing import Generator, Optional
12
10
 
13
11
  import requests
14
- from httpx import Auth, Request, Response, post
15
-
16
12
  from beamlit.common.settings import get_settings
13
+ from httpx import Auth, Request, Response, post
17
14
 
18
15
 
19
16
  @dataclass
@@ -39,6 +36,7 @@ class ClientCredentials(Auth):
39
36
  base_url (str): The base URL for authentication.
40
37
  """
41
38
  self.credentials = credentials
39
+ self.expires_at = None
42
40
  self.workspace_name = workspace_name
43
41
  self.base_url = base_url
44
42
 
@@ -52,16 +50,15 @@ class ClientCredentials(Auth):
52
50
  Raises:
53
51
  Exception: If token refresh fails.
54
52
  """
55
- err = self.refresh_if_needed()
53
+ err = self.get_token()
56
54
  if err:
57
55
  raise err
58
-
59
56
  return {
60
57
  "X-Beamlit-Authorization": f"Bearer {self.credentials.access_token}",
61
58
  "X-Beamlit-Workspace": self.workspace_name,
62
59
  }
63
60
 
64
- def refresh_if_needed(self) -> Optional[Exception]:
61
+ def get_token(self) -> Optional[Exception]:
65
62
  """
66
63
  Checks if the access token needs to be refreshed and performs the refresh if necessary.
67
64
 
@@ -69,33 +66,23 @@ class ClientCredentials(Auth):
69
66
  Optional[Exception]: An exception if refreshing fails, otherwise None.
70
67
  """
71
68
  settings = get_settings()
72
- if self.credentials.client_credentials and not self.credentials.refresh_token:
69
+ if self.need_token():
73
70
  headers = {"Authorization": f"Basic {self.credentials.client_credentials}", "Content-Type": "application/json"}
74
71
  body = {"grant_type": "client_credentials"}
75
72
  response = requests.post(f"{settings.base_url}/oauth/token", headers=headers, json=body)
76
73
  response.raise_for_status()
77
- self.credentials.access_token = response.json()["access_token"]
78
- self.credentials.refresh_token = response.json()["refresh_token"]
79
- self.credentials.expires_in = response.json()["expires_in"]
80
-
81
- # Need to refresh token if expires in less than 10 minutes
82
- parts = self.credentials.access_token.split(".")
83
- if len(parts) != 3:
84
- return Exception("Invalid JWT token format")
85
- try:
86
- claims_bytes = base64.urlsafe_b64decode(parts[1] + "=" * (-len(parts[1]) % 4))
87
- claims = json.loads(claims_bytes)
88
- except Exception as e:
89
- return Exception(f"Failed to decode/parse JWT claims: {str(e)}")
90
-
91
- exp_time = datetime.fromtimestamp(claims["exp"])
92
- current_time = datetime.now()
93
- # Refresh if token expires in less than 10 minutes
94
- if current_time + timedelta(minutes=10) > exp_time:
95
- return self.do_refresh()
96
-
74
+ creds = response.json()
75
+ self.credentials.access_token = creds["access_token"]
76
+ self.credentials.refresh_token = creds["refresh_token"]
77
+ self.credentials.expires_in = creds["expires_in"]
78
+ self.expires_at = datetime.now() + timedelta(seconds=self.credentials.expires_in)
97
79
  return None
98
80
 
81
+ def need_token(self):
82
+ if not self.expires_at:
83
+ return True
84
+ return datetime.now() > self.expires_at - timedelta(minutes=10)
85
+
99
86
  def auth_flow(self, request: Request) -> Generator[Request, Response, None]:
100
87
  """
101
88
  Processes the authentication flow by ensuring tokens are valid and adding necessary headers.
beamlit/deploy/deploy.py CHANGED
@@ -14,13 +14,21 @@ from pathlib import Path
14
14
  from typing import Literal
15
15
 
16
16
  import yaml
17
+
17
18
  from beamlit.api.agents import get_agent
18
19
  from beamlit.authentication import new_client
19
20
  from beamlit.client import AuthenticatedClient
20
21
  from beamlit.common import slugify
21
22
  from beamlit.common.settings import Settings, get_settings, init
22
- from beamlit.models import (Agent, AgentSpec, Flavor, Function, FunctionSpec,
23
- Metadata, MetadataLabels)
23
+ from beamlit.models import (
24
+ Agent,
25
+ AgentSpec,
26
+ Flavor,
27
+ Function,
28
+ FunctionSpec,
29
+ Metadata,
30
+ MetadataLabels,
31
+ )
24
32
 
25
33
  from .format import arg_to_dict
26
34
  from .parser import Resource, get_description, get_parameters, get_resources
@@ -12,13 +12,14 @@ import pydantic
12
12
  import pydantic_core
13
13
  import requests
14
14
  import typing_extensions as t
15
+ from langchain_core.tools.base import BaseTool, BaseToolkit, ToolException
16
+ from mcp import ClientSession
17
+ from mcp.types import CallToolResult, ListToolsResult
18
+
15
19
  from beamlit.authentication import get_authentication_headers
16
20
  from beamlit.authentication.authentication import AuthenticatedClient
17
21
  from beamlit.common.settings import get_settings
18
22
  from beamlit.functions.mcp.client import websocket_client
19
- from langchain_core.tools.base import BaseTool, BaseToolkit, ToolException
20
- from mcp import ClientSession
21
- from mcp.types import CallToolResult, ListToolsResult
22
23
 
23
24
  from .utils import create_schema_model
24
25
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: beamlit
3
- Version: 0.0.57rc120
3
+ Version: 0.0.58
4
4
  Summary: Add your description here
5
5
  Author-email: cploujoux <ch.ploujoux@gmail.com>
6
6
  License-File: LICENSE
@@ -6,9 +6,9 @@ beamlit/run.py,sha256=YMI8iTPB1M9gd_1FG958tw-Prf9EwIcca4jK4igi7MM,4448
6
6
  beamlit/types.py,sha256=E1hhDh_zXfsSQ0NCt9-uw90_Mr5iIlsdfnfvxv5HarU,1005
7
7
  beamlit/agents/__init__.py,sha256=bWsFaXUbAps3IsL3Prti89m1s714vICXodbQi77h3vY,206
8
8
  beamlit/agents/chain.py,sha256=JsinjAYBr3oaM4heouZaiaV2jMmi779LHAMtD_4P59s,4867
9
- beamlit/agents/chat.py,sha256=_g86rpzeDS5XTHTu8N2mTUP0LjMG7rY4iZUjrdKT0ZE,8942
10
- beamlit/agents/decorator.py,sha256=wgdbgJ65LfmhldGWxG8PBYU_7datnVpqKRzom6Ok3GU,8337
11
- beamlit/agents/thread.py,sha256=QecahZCH8_U91cvCw2X6cYn9N1liVXVl3u3lFxVDdNg,798
9
+ beamlit/agents/chat.py,sha256=elnJbS28aSRXwmIsAlS0guVK7swRpbY61yFL1QVeGbI,8943
10
+ beamlit/agents/decorator.py,sha256=VtFtMu8rNIS5fAUr39MnUIW8EGrY_84fUnkz2859yK4,8338
11
+ beamlit/agents/thread.py,sha256=kMLqMlWZIHNJdsQHvtlh3C99LuMsS0XrMks-vJaV9U4,787
12
12
  beamlit/agents/voice/openai.py,sha256=-RDBwl16i4TbUhFo5-77Ci3zmI3Y8U2yf2MmvXR2haQ,9479
13
13
  beamlit/agents/voice/utils.py,sha256=tQidyM40Ewuy12wKqpvJLvfJgneQ0sZf50dqnerPGHg,836
14
14
  beamlit/api/__init__.py,sha256=zTSiG_ujSjAqWPyc435YXaX9XTlpMjiJWBbV-f-YtdA,45
@@ -114,8 +114,8 @@ beamlit/api/workspaces/update_workspace.py,sha256=qa5DV2UJSUYuB_ibALb4E9ghKpT1Ha
114
114
  beamlit/api/workspaces/update_workspace_user_role.py,sha256=Yn9iuJ4tKtauzBiJyU4-wYUMS9g98X2Om8zs7UkzrY8,4917
115
115
  beamlit/authentication/__init__.py,sha256=wiXqRbc7E-ulrH_ueA9duOGFvXeo7-RvhSD1XbFogMo,1020
116
116
  beamlit/authentication/apikey.py,sha256=Q3Kz4Zbc_Lr6lYwiwiLo6AhggKcdqsd6xJjDi-nERiI,1557
117
- beamlit/authentication/authentication.py,sha256=u1DLlF2XKwkvQCjdBSTVp23pgC1eN4U_9EaRx4BszVM,5613
118
- beamlit/authentication/clientcredentials.py,sha256=_TY3op9afFh2wUiIdOc7sL8ehgz5EiVKoUYL4FFLfPk,5734
117
+ beamlit/authentication/authentication.py,sha256=OgqS6YciBnh0MomeEaL2YuZt1fHPOfQUkRhsIu6tcvk,5812
118
+ beamlit/authentication/clientcredentials.py,sha256=a3KNT3x3c2izS1EQXbL-bO9Xm-6T16qY7cLf97eE8u8,5198
119
119
  beamlit/authentication/credentials.py,sha256=Xb2Ajj-72FdU1l_pI8OMDRSXruCJHUQjME1NxTBmkTU,8713
120
120
  beamlit/authentication/device_mode.py,sha256=gBJqJpWQXEG8gZbWXhlvQyk8FfHH95-aqURUnudil-4,6526
121
121
  beamlit/common/__init__.py,sha256=saX5X3hRCJ9erSlXuSkZ2VGgquvpgdcofAU_9sM4bCE,354
@@ -127,7 +127,7 @@ beamlit/common/settings.py,sha256=9LshW8yVXmX9ZeNhfYH-nBnQV5nKSpi1RTZDNUOxe2s,52
127
127
  beamlit/common/slugify.py,sha256=QPJqa1VrSjRle931RN37t24rUjAbyZEg1UFAp2fLgac,679
128
128
  beamlit/common/utils.py,sha256=eG201z9gMRnhoHkaZGNtfFUbCzfg_Y59JR4ciMgidW8,1465
129
129
  beamlit/deploy/__init__.py,sha256=uRsI_-gTbbki59LlvubeTfG6wfI3o2XqZODW0QXA-Ao,292
130
- beamlit/deploy/deploy.py,sha256=xt6MY8J3jxMEEA9NCCZXYiy9eGQ5NxdPK0u_z3wW24w,11650
130
+ beamlit/deploy/deploy.py,sha256=AP1FjmoqE3tdKcNKtRZLojTaJ1PR73hwrk6ORRSgRmQ,11654
131
131
  beamlit/deploy/format.py,sha256=W3ESUHyFv-iZDjVnHOf9YFDDXZSXYIFFbwCoL1GInE0,1162
132
132
  beamlit/deploy/parser.py,sha256=gjRUhOVtfKnc1UNc_FhXsEfj9zrMNuq8W93pNsJBpo0,7586
133
133
  beamlit/functions/__init__.py,sha256=Mnoqpa1dm7TXwjodBbF_40JyD78aXsOYWmqjDSnA1lU,317
@@ -135,7 +135,7 @@ beamlit/functions/common.py,sha256=v4nmLP9Wotpb5e6hV30XbItgZjr5lwXcF0EOotxRngI,1
135
135
  beamlit/functions/decorator.py,sha256=iQbLwUo0K83DFJ3ub8O5jKtkbSINnku6GZcKJ9h7-5E,2292
136
136
  beamlit/functions/local/local.py,sha256=F7b_xYDytJIZc0fM1sYMtJgfBCF1cLjquQm83VchTLs,1891
137
137
  beamlit/functions/mcp/client.py,sha256=enLo0dzWMBHJEQf6as3UWM8tN3CjUN1YO3UPn67DLac,4072
138
- beamlit/functions/mcp/mcp.py,sha256=wejtA256-aMYEgUjfFQibD2-D2UJIySTVIfphPr_tuo,6039
138
+ beamlit/functions/mcp/mcp.py,sha256=voZYIbsHipSCEKXmnU_3uYKa_cfT1M2mv5t1pEwUkkE,6040
139
139
  beamlit/functions/mcp/utils.py,sha256=V7bah6cymdtjJ_LJUrNcHDeApDHA6uXvaGVeFJGKj2U,1850
140
140
  beamlit/functions/remote/remote.py,sha256=bkDUFiZI8YokqX8Fo76AnKLZF9PcjcDBr37hhxLevs8,6728
141
141
  beamlit/models/__init__.py,sha256=042wT7sG_YUmJJAb9edrui-DesMxLjOGVvnEtqc92CY,8916
@@ -254,8 +254,8 @@ beamlit/serve/app.py,sha256=5XZci-R95Zjl97wMtQd1BRtonnkJJ2AeoTVFPKGAOfA,4283
254
254
  beamlit/serve/middlewares/__init__.py,sha256=O7fyfE1DIYmajFY9WWdzxCgeAQWZzJfeUjzHGbpWaAk,309
255
255
  beamlit/serve/middlewares/accesslog.py,sha256=lcu33j4epFSHRBaeTpyt8deNb3kaM3K91-andw4fp80,1112
256
256
  beamlit/serve/middlewares/processtime.py,sha256=3x5w1yQexB0xFNKK6fgLbINxT-eLLunfZ6UDV0bIIF4,944
257
- beamlit-0.0.57rc120.dist-info/METADATA,sha256=TxuRw5IiySfgjmt-GvjfTpk06r4YpjgY0d64VqMiSfY,3547
258
- beamlit-0.0.57rc120.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
259
- beamlit-0.0.57rc120.dist-info/entry_points.txt,sha256=zxhgdn7SP-Otk4rEv7LMPAAa9w4TUCLbu9TJi9-K3xg,115
260
- beamlit-0.0.57rc120.dist-info/licenses/LICENSE,sha256=p5PNQvpvyDT_0aYBDgmV1fFI_vAD2aSV0wWG7VTgRis,1069
261
- beamlit-0.0.57rc120.dist-info/RECORD,,
257
+ beamlit-0.0.58.dist-info/METADATA,sha256=1JuqbE0ek155mK2KttjVURNzVtGu6efMKMX_4aj59FU,3542
258
+ beamlit-0.0.58.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
259
+ beamlit-0.0.58.dist-info/entry_points.txt,sha256=zxhgdn7SP-Otk4rEv7LMPAAa9w4TUCLbu9TJi9-K3xg,115
260
+ beamlit-0.0.58.dist-info/licenses/LICENSE,sha256=p5PNQvpvyDT_0aYBDgmV1fFI_vAD2aSV0wWG7VTgRis,1069
261
+ beamlit-0.0.58.dist-info/RECORD,,