iatoolkit 0.55.3__tar.gz → 0.56.0__tar.gz
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.
Potentially problematic release.
This version of iatoolkit might be problematic. Click here for more details.
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/PKG-INFO +1 -1
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/pyproject.toml +1 -1
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/base_company.py +1 -1
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/common/routes.py +23 -11
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/iatoolkit.py +3 -4
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/repositories/profile_repo.py +7 -3
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/services/auth_service.py +5 -2
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/services/dispatcher_service.py +2 -24
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/services/jwt_service.py +15 -24
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/services/profile_service.py +10 -8
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/static/js/chat_feedback.js +1 -1
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/static/js/chat_history.js +1 -1
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/static/js/chat_main.js +40 -14
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/templates/chat.html +7 -3
- iatoolkit-0.56.0/src/iatoolkit/templates/login_simulation.html +34 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/views/base_login_view.py +32 -4
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/views/external_login_view.py +42 -2
- iatoolkit-0.56.0/src/iatoolkit/views/login_simulation_view.py +81 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/views/login_view.py +27 -11
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit.egg-info/PKG-INFO +1 -1
- iatoolkit-0.55.3/src/iatoolkit/templates/login_simulation.html +0 -91
- iatoolkit-0.55.3/src/iatoolkit/views/login_simulation_view.py +0 -27
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/readme.md +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/requirements.txt +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/setup.cfg +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/__init__.py +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/cli_commands.py +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/common/__init__.py +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/common/exceptions.py +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/common/session_manager.py +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/common/util.py +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/company_registry.py +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/infra/__init__.py +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/infra/call_service.py +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/infra/connectors/__init__.py +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/infra/connectors/file_connector.py +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/infra/connectors/file_connector_factory.py +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/infra/connectors/google_cloud_storage_connector.py +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/infra/connectors/google_drive_connector.py +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/infra/connectors/local_file_connector.py +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/infra/connectors/s3_connector.py +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/infra/gemini_adapter.py +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/infra/google_chat_app.py +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/infra/llm_client.py +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/infra/llm_proxy.py +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/infra/llm_response.py +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/infra/mail_app.py +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/infra/openai_adapter.py +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/infra/redis_session_manager.py +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/repositories/__init__.py +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/repositories/database_manager.py +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/repositories/document_repo.py +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/repositories/llm_query_repo.py +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/repositories/models.py +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/repositories/tasks_repo.py +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/repositories/vs_repo.py +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/services/__init__.py +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/services/benchmark_service.py +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/services/branding_service.py +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/services/document_service.py +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/services/excel_service.py +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/services/file_processor_service.py +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/services/history_service.py +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/services/load_documents_service.py +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/services/mail_service.py +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/services/onboarding_service.py +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/services/prompt_manager_service.py +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/services/query_service.py +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/services/search_service.py +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/services/sql_service.py +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/services/tasks_service.py +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/services/user_feedback_service.py +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/services/user_session_context_service.py +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/static/images/fernando.jpeg +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/static/js/chat_filepond.js +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/static/js/chat_onboarding.js +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/static/styles/chat_iatoolkit.css +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/static/styles/chat_info.css +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/static/styles/chat_modal.css +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/static/styles/landing_page.css +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/static/styles/llm_output.css +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/static/styles/onboarding.css +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/system_prompts/format_styles.prompt +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/system_prompts/query_main.prompt +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/system_prompts/sql_rules.prompt +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/templates/_branding_styles.html +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/templates/_login_widget.html +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/templates/_navbar.html +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/templates/about.html +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/templates/base.html +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/templates/change_password.html +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/templates/chat_modals.html +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/templates/error.html +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/templates/forgot_password.html +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/templates/header.html +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/templates/index.html +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/templates/onboarding_shell.html +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/templates/signup.html +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/templates/test.html +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/views/__init__.py +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/views/change_password_view.py +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/views/chat_token_request_view.py +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/views/file_store_api_view.py +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/views/forgot_password_view.py +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/views/history_api_view.py +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/views/index_view.py +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/views/init_context_api_view.py +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/views/llmquery_api_view.py +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/views/llmquery_web_view.py +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/views/prompt_api_view.py +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/views/signup_view.py +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/views/tasks_review_view.py +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/views/tasks_view.py +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/views/user_feedback_api_view.py +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit/views/verify_user_view.py +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit.egg-info/SOURCES.txt +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit.egg-info/dependency_links.txt +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit.egg-info/requires.txt +0 -0
- {iatoolkit-0.55.3 → iatoolkit-0.56.0}/src/iatoolkit.egg-info/top_level.txt +0 -0
|
@@ -88,7 +88,7 @@ class BaseCompany(ABC):
|
|
|
88
88
|
|
|
89
89
|
@abstractmethod
|
|
90
90
|
# get context specific for this company
|
|
91
|
-
def get_user_info(self, user_identifier: str) ->
|
|
91
|
+
def get_user_info(self, user_identifier: str) -> dict:
|
|
92
92
|
raise NotImplementedError("La subclase debe implementar el método get_user_info()")
|
|
93
93
|
|
|
94
94
|
@abstractmethod
|
|
@@ -26,8 +26,6 @@ def register_views(injector, app):
|
|
|
26
26
|
from iatoolkit.views.tasks_view import TaskView
|
|
27
27
|
from iatoolkit.views.tasks_review_view import TaskReviewView
|
|
28
28
|
from iatoolkit.views.login_simulation_view import LoginSimulationView
|
|
29
|
-
from iatoolkit.views.login_view import LoginView, FinalizeContextView
|
|
30
|
-
from iatoolkit.views.external_login_view import ExternalLoginView
|
|
31
29
|
from iatoolkit.views.signup_view import SignupView
|
|
32
30
|
from iatoolkit.views.verify_user_view import VerifyAccountView
|
|
33
31
|
from iatoolkit.views.forgot_password_view import ForgotPasswordView
|
|
@@ -36,27 +34,41 @@ def register_views(injector, app):
|
|
|
36
34
|
from iatoolkit.views.user_feedback_api_view import UserFeedbackApiView
|
|
37
35
|
from iatoolkit.views.prompt_api_view import PromptApiView
|
|
38
36
|
from iatoolkit.views.chat_token_request_view import ChatTokenRequestView
|
|
37
|
+
from iatoolkit.views.login_view import LoginView, FinalizeContextView
|
|
38
|
+
from iatoolkit.views.external_login_view import ExternalLoginView, RedeemTokenApiView
|
|
39
39
|
|
|
40
40
|
# iatoolkit home page
|
|
41
41
|
app.add_url_rule('/<company_short_name>', view_func=IndexView.as_view('index'))
|
|
42
42
|
|
|
43
|
-
#
|
|
44
|
-
app.add_url_rule('/<company_short_name>/
|
|
45
|
-
view_func=InitContextApiView.as_view('init_context_api'))
|
|
43
|
+
# login for the iatoolkit integrated frontend
|
|
44
|
+
app.add_url_rule('/<company_short_name>/login', view_func=LoginView.as_view('login'))
|
|
46
45
|
|
|
47
|
-
# this
|
|
48
|
-
# only the first one should be used from an external app
|
|
46
|
+
# this is the login for external users
|
|
49
47
|
app.add_url_rule('/<company_short_name>/external_login',
|
|
50
48
|
view_func=ExternalLoginView.as_view('external_login'))
|
|
51
49
|
|
|
50
|
+
# this endpoint is called when onboarding_shell finish the context load
|
|
51
|
+
app.add_url_rule(
|
|
52
|
+
'/<company_short_name>/finalize',
|
|
53
|
+
view_func=FinalizeContextView.as_view('finalize_no_token')
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
app.add_url_rule(
|
|
57
|
+
'/<company_short_name>/finalize/<token>',
|
|
58
|
+
view_func=FinalizeContextView.as_view('finalize_with_token')
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
# this endpoint is called by the JS for changing the token for a session
|
|
62
|
+
app.add_url_rule('/<string:company_short_name>/api/redeem_token',
|
|
63
|
+
view_func = RedeemTokenApiView.as_view('redeem_token'))
|
|
64
|
+
|
|
52
65
|
# this endpoint is for requesting a chat token for external users
|
|
53
66
|
app.add_url_rule('/auth/chat_token',
|
|
54
67
|
view_func=ChatTokenRequestView.as_view('chat-token'))
|
|
55
68
|
|
|
56
|
-
#
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
app.add_url_rule('/<company_short_name>/finalize_context_load', view_func=FinalizeContextView.as_view('finalize_context_load'))
|
|
69
|
+
# init (reset) the company context (with api-key)
|
|
70
|
+
app.add_url_rule('/<company_short_name>/api/init_context_api',
|
|
71
|
+
view_func=InitContextApiView.as_view('init_context_api'))
|
|
60
72
|
|
|
61
73
|
# register new user, account verification and forgot password
|
|
62
74
|
app.add_url_rule('/<company_short_name>/signup',view_func=SignupView.as_view('signup'))
|
|
@@ -19,7 +19,7 @@ from werkzeug.middleware.proxy_fix import ProxyFix
|
|
|
19
19
|
from injector import Binder, singleton, Injector
|
|
20
20
|
from importlib.metadata import version as _pkg_version, PackageNotFoundError
|
|
21
21
|
|
|
22
|
-
IATOOLKIT_VERSION = "0.
|
|
22
|
+
IATOOLKIT_VERSION = "0.56.0"
|
|
23
23
|
|
|
24
24
|
# global variable for the unique instance of IAToolkit
|
|
25
25
|
_iatoolkit_instance: Optional['IAToolkit'] = None
|
|
@@ -155,10 +155,9 @@ class IAToolkit:
|
|
|
155
155
|
|
|
156
156
|
self.app.config.update({
|
|
157
157
|
'VERSION': self.version,
|
|
158
|
-
'SERVER_NAME': domain,
|
|
159
158
|
'SECRET_KEY': self._get_config_value('FLASK_SECRET_KEY', 'iatoolkit-default-secret'),
|
|
160
|
-
'SESSION_COOKIE_SAMESITE': "None"
|
|
161
|
-
'SESSION_COOKIE_SECURE':
|
|
159
|
+
'SESSION_COOKIE_SAMESITE': "None",
|
|
160
|
+
'SESSION_COOKIE_SECURE': True,
|
|
162
161
|
'SESSION_PERMANENT': False,
|
|
163
162
|
'SESSION_USE_SIGNER': True,
|
|
164
163
|
'JWT_SECRET_KEY': self._get_config_value('JWT_SECRET_KEY', 'iatoolkit-jwt-secret'),
|
|
@@ -72,10 +72,14 @@ class ProfileRepo:
|
|
|
72
72
|
def create_company(self, new_company: Company):
|
|
73
73
|
company = self.session.query(Company).filter_by(name=new_company.name).first()
|
|
74
74
|
if company:
|
|
75
|
-
company.parameters
|
|
76
|
-
|
|
77
|
-
company.
|
|
75
|
+
if company.parameters != new_company.parameters:
|
|
76
|
+
company.parameters = new_company.parameters
|
|
77
|
+
if company.branding != new_company.branding:
|
|
78
|
+
company.branding = new_company.branding
|
|
79
|
+
if company.onboarding_cards != new_company.onboarding_cards:
|
|
80
|
+
company.onboarding_cards = new_company.onboarding_cards
|
|
78
81
|
else:
|
|
82
|
+
# Si la compañía no existe, la añade a la sesión.
|
|
79
83
|
self.session.add(new_company)
|
|
80
84
|
company = new_company
|
|
81
85
|
|
|
@@ -7,6 +7,7 @@ from flask import request
|
|
|
7
7
|
from injector import inject
|
|
8
8
|
from iatoolkit.services.profile_service import ProfileService
|
|
9
9
|
from flask import request
|
|
10
|
+
import logging
|
|
10
11
|
|
|
11
12
|
|
|
12
13
|
class AuthService:
|
|
@@ -52,6 +53,7 @@ class AuthService:
|
|
|
52
53
|
if api_key:
|
|
53
54
|
api_key_entry = self.profile_service.get_active_api_key_entry(api_key)
|
|
54
55
|
if not api_key_entry:
|
|
56
|
+
logging.info(f"Invalid or inactive API Key {api_key}")
|
|
55
57
|
return {"success": False, "error": "Invalid or inactive API Key", "status_code": 401}
|
|
56
58
|
|
|
57
59
|
# obtain the company from the api_key_entry
|
|
@@ -61,7 +63,7 @@ class AuthService:
|
|
|
61
63
|
user_identifier = ''
|
|
62
64
|
if request.is_json:
|
|
63
65
|
data = request.get_json() or {}
|
|
64
|
-
user_identifier = data.get('
|
|
66
|
+
user_identifier = data.get('user_identifier', '')
|
|
65
67
|
|
|
66
68
|
return {
|
|
67
69
|
"success": True,
|
|
@@ -70,5 +72,6 @@ class AuthService:
|
|
|
70
72
|
}
|
|
71
73
|
|
|
72
74
|
# --- Failure: No valid credentials found ---
|
|
75
|
+
logging.info(f"Authentication required. No session cookie or API Key provided.")
|
|
73
76
|
return {"success": False, "error": "Authentication required. No session cookie or API Key provided.",
|
|
74
|
-
"status_code":
|
|
77
|
+
"status_code": 402}
|
|
@@ -178,35 +178,13 @@ class Dispatcher:
|
|
|
178
178
|
# source 2: external company user
|
|
179
179
|
company_instance = self.company_instances[company_name]
|
|
180
180
|
try:
|
|
181
|
-
|
|
181
|
+
external_user_profile = company_instance.get_user_info(user_identifier)
|
|
182
182
|
except Exception as e:
|
|
183
183
|
logging.exception(e)
|
|
184
184
|
raise IAToolkitException(IAToolkitException.ErrorType.EXTERNAL_SOURCE_ERROR,
|
|
185
185
|
f"Error en get_user_info de {company_name}: {str(e)}") from e
|
|
186
186
|
|
|
187
|
-
|
|
188
|
-
return self._normalize_user_data(raw_user_data)
|
|
189
|
-
|
|
190
|
-
def _normalize_user_data(self, raw_data: dict) -> dict:
|
|
191
|
-
"""
|
|
192
|
-
Asegura que los datos del usuario siempre tengan una estructura consistente.
|
|
193
|
-
"""
|
|
194
|
-
# default values
|
|
195
|
-
normalized_user = {
|
|
196
|
-
"id": raw_data.get("id", 0),
|
|
197
|
-
"username": raw_data.get("id", 0),
|
|
198
|
-
"user_email": raw_data.get("email", ""),
|
|
199
|
-
"user_fullname": raw_data.get("user_fullname", ""),
|
|
200
|
-
"is_local": False,
|
|
201
|
-
"extras": raw_data.get("extras", {})
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
# get the extras from the raw data, if any
|
|
205
|
-
extras = raw_data.get("extras", {})
|
|
206
|
-
if isinstance(extras, dict):
|
|
207
|
-
normalized_user.update(extras)
|
|
208
|
-
|
|
209
|
-
return normalized_user
|
|
187
|
+
return external_user_profile
|
|
210
188
|
|
|
211
189
|
def get_metadata_from_filename(self, company_name: str, filename: str) -> dict:
|
|
212
190
|
if company_name not in self.company_instances:
|
|
@@ -24,16 +24,18 @@ class JWTService:
|
|
|
24
24
|
raise RuntimeError(f"Configuración JWT esencial faltante: {e}")
|
|
25
25
|
|
|
26
26
|
def generate_chat_jwt(self,
|
|
27
|
-
company_id: int,
|
|
28
27
|
company_short_name: str,
|
|
29
|
-
|
|
28
|
+
user_identifier: str,
|
|
30
29
|
expires_delta_seconds: int) -> Optional[str]:
|
|
31
30
|
# generate a JWT for a chat session
|
|
32
31
|
try:
|
|
32
|
+
if not company_short_name or not user_identifier:
|
|
33
|
+
logging.error(f"Missing token ID: {company_short_name}/{user_identifier}")
|
|
34
|
+
return None
|
|
35
|
+
|
|
33
36
|
payload = {
|
|
34
|
-
'company_id': company_id,
|
|
35
37
|
'company_short_name': company_short_name,
|
|
36
|
-
'
|
|
38
|
+
'user_identifier': user_identifier,
|
|
37
39
|
'exp': time.time() + expires_delta_seconds,
|
|
38
40
|
'iat': time.time(),
|
|
39
41
|
'type': 'chat_session' # Identificador del tipo de token
|
|
@@ -41,10 +43,10 @@ class JWTService:
|
|
|
41
43
|
token = jwt.encode(payload, self.secret_key, algorithm=self.algorithm)
|
|
42
44
|
return token
|
|
43
45
|
except Exception as e:
|
|
44
|
-
logging.error(f"Error al generar JWT para
|
|
46
|
+
logging.error(f"Error al generar JWT para {company_short_name}/{user_identifier}: {e}")
|
|
45
47
|
return None
|
|
46
48
|
|
|
47
|
-
def validate_chat_jwt(self, token: str
|
|
49
|
+
def validate_chat_jwt(self, token: str) -> Optional[Dict[str, Any]]:
|
|
48
50
|
"""
|
|
49
51
|
Valida un JWT de sesión de chat.
|
|
50
52
|
Retorna el payload decodificado si es válido y coincide con la empresa, o None.
|
|
@@ -59,33 +61,22 @@ class JWTService:
|
|
|
59
61
|
logging.warning(f"Validación JWT fallida: tipo incorrecto '{payload.get('type')}'")
|
|
60
62
|
return None
|
|
61
63
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
f"Esperado: {expected_company_short_name}, Obtenido: {payload.get('company_short_name')}"
|
|
66
|
-
)
|
|
64
|
+
# user_identifier debe estar presente
|
|
65
|
+
if not payload.get('user_identifier'):
|
|
66
|
+
logging.warning(f"Validación JWT fallida: user_identifier ausente o vacío.")
|
|
67
67
|
return None
|
|
68
68
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
logging.warning(f"Validación JWT fallida: external_user_id ausente o vacío.")
|
|
72
|
-
return None
|
|
73
|
-
|
|
74
|
-
# company_id debe estar presente
|
|
75
|
-
if 'company_id' not in payload or not isinstance(payload['company_id'], int):
|
|
76
|
-
logging.warning(f"Validación JWT fallida: company_id ausente o tipo incorrecto.")
|
|
69
|
+
if not payload.get('company_short_name'):
|
|
70
|
+
logging.warning(f"Validación JWT fallida: company_short_name ausente.")
|
|
77
71
|
return None
|
|
78
72
|
|
|
79
73
|
logging.debug(
|
|
80
74
|
f"JWT validado exitosamente para company: {payload.get('company_short_name')}, user: {payload.get('external_user_id')}")
|
|
81
75
|
return payload
|
|
82
76
|
|
|
83
|
-
except jwt.ExpiredSignatureError:
|
|
84
|
-
logging.info(f"Validación JWT fallida: token expirado para {expected_company_short_name}")
|
|
85
|
-
return None
|
|
86
77
|
except jwt.InvalidTokenError as e:
|
|
87
|
-
logging.warning(f"Validación JWT fallida: token inválido
|
|
78
|
+
logging.warning(f"Validación JWT fallida: token inválido . Error: {e}")
|
|
88
79
|
return None
|
|
89
80
|
except Exception as e:
|
|
90
|
-
logging.error(f"Error inesperado durante validación de JWT
|
|
81
|
+
logging.error(f"Error inesperado durante validación de JWT : {e}")
|
|
91
82
|
return None
|
|
@@ -60,7 +60,6 @@ class ProfileService:
|
|
|
60
60
|
# the user_profile variables are used on the LLM templates also (see in query_main.prompt)
|
|
61
61
|
user_identifier = user.email # no longer de ID
|
|
62
62
|
user_profile = {
|
|
63
|
-
"id": user_identifier,
|
|
64
63
|
"user_email": user.email,
|
|
65
64
|
"user_fullname": f'{user.first_name} {user.last_name}',
|
|
66
65
|
"user_is_local": True,
|
|
@@ -78,8 +77,8 @@ class ProfileService:
|
|
|
78
77
|
"""
|
|
79
78
|
Public method for views to create a web session for an external user.
|
|
80
79
|
"""
|
|
81
|
-
# 1. Fetch the
|
|
82
|
-
|
|
80
|
+
# 1. Fetch the external user profile via Dispatcher.
|
|
81
|
+
external_user_profile = self.dispatcher.get_user_info(
|
|
83
82
|
company_name=company.short_name,
|
|
84
83
|
user_identifier=user_identifier
|
|
85
84
|
)
|
|
@@ -88,7 +87,7 @@ class ProfileService:
|
|
|
88
87
|
self.create_web_session(
|
|
89
88
|
company=company,
|
|
90
89
|
user_identifier=user_identifier,
|
|
91
|
-
user_profile=
|
|
90
|
+
user_profile=external_user_profile)
|
|
92
91
|
|
|
93
92
|
def create_web_session(self, company: Company, user_identifier: str, user_profile: dict):
|
|
94
93
|
"""
|
|
@@ -96,16 +95,19 @@ class ProfileService:
|
|
|
96
95
|
"""
|
|
97
96
|
user_profile['company_short_name'] = company.short_name
|
|
98
97
|
user_profile['user_identifier'] = user_identifier
|
|
99
|
-
user_profile['
|
|
98
|
+
user_profile['id'] = user_identifier
|
|
100
99
|
user_profile['company_id'] = company.id
|
|
101
100
|
user_profile['company'] = company.name
|
|
102
101
|
|
|
103
|
-
# user_profile
|
|
102
|
+
# save user_profile in Redis session
|
|
104
103
|
self.session_context.save_profile_data(company.short_name, user_identifier, user_profile)
|
|
105
104
|
|
|
106
|
-
# save
|
|
105
|
+
# save a min Flask session cookie for this user
|
|
106
|
+
self.set_session_for_user(company.short_name, user_identifier)
|
|
107
|
+
|
|
108
|
+
def set_session_for_user(self, company_short_name: str, user_identifier:str ):
|
|
109
|
+
SessionManager.set('company_short_name', company_short_name)
|
|
107
110
|
SessionManager.set('user_identifier', user_identifier)
|
|
108
|
-
SessionManager.set('company_short_name', company.short_name)
|
|
109
111
|
|
|
110
112
|
def get_current_session_info(self) -> dict:
|
|
111
113
|
"""
|
|
@@ -106,7 +106,7 @@ const sendFeedback = async function(message) {
|
|
|
106
106
|
};
|
|
107
107
|
try {
|
|
108
108
|
// Asumiendo que callLLMAPI está definido globalmente en otro archivo (ej. chat_main.js)
|
|
109
|
-
const responseData = await
|
|
109
|
+
const responseData = await callToolkit('/feedback', data, "POST");
|
|
110
110
|
return responseData;
|
|
111
111
|
} catch (error) {
|
|
112
112
|
console.error("Error al enviar feedback:", error);
|
|
@@ -40,7 +40,7 @@ $(document).ready(function () {
|
|
|
40
40
|
historyContent.hide();
|
|
41
41
|
|
|
42
42
|
try {
|
|
43
|
-
const responseData = await
|
|
43
|
+
const responseData = await callToolkit("/api/history", {}, "POST");
|
|
44
44
|
|
|
45
45
|
if (responseData && responseData.history) {
|
|
46
46
|
// Guardar datos globalmente
|
|
@@ -5,6 +5,13 @@ let abortController = null;
|
|
|
5
5
|
let selectedPrompt = null; // Will hold a lightweight prompt object
|
|
6
6
|
|
|
7
7
|
$(document).ready(function () {
|
|
8
|
+
// Gatilla el redeem sin esperar ni manejar respuesta aquí
|
|
9
|
+
if (window.redeemToken !== '') {
|
|
10
|
+
const url = `/api/redeem_token`;
|
|
11
|
+
// No await: dejamos que callToolkit maneje todo internamente
|
|
12
|
+
callToolkit(url, {'token': window.redeemToken}, "POST").catch(() => {});
|
|
13
|
+
}
|
|
14
|
+
|
|
8
15
|
// --- MAIN EVENT HANDLERS ---
|
|
9
16
|
$('#send-button').on('click', handleChatMessage);
|
|
10
17
|
$('#stop-button').on('click', abortCurrentRequest);
|
|
@@ -176,7 +183,7 @@ const handleChatMessage = async function () {
|
|
|
176
183
|
user_identifier: window.user_identifier
|
|
177
184
|
};
|
|
178
185
|
|
|
179
|
-
const responseData = await
|
|
186
|
+
const responseData = await callToolkit("/llm_query", data, "POST");
|
|
180
187
|
if (responseData && responseData.answer) {
|
|
181
188
|
const answerSection = $('<div>').addClass('answer-section llm-output').append(responseData.answer);
|
|
182
189
|
displayBotMessage(answerSection);
|
|
@@ -292,28 +299,39 @@ function resetSpecificDataInput() {
|
|
|
292
299
|
* @param {number} timeoutMs - Timeout in milliseconds.
|
|
293
300
|
* @returns {Promise<object|null>} The response data or null on error.
|
|
294
301
|
*/
|
|
295
|
-
const
|
|
302
|
+
const callToolkit = async function(apiPath, data, method, timeoutMs = 500000) {
|
|
296
303
|
const url = `${window.iatoolkit_base_url}/${window.companyShortName}${apiPath}`;
|
|
297
304
|
|
|
298
|
-
const headers = {"Content-Type": "application/json"};
|
|
299
|
-
if (window.sessionJWT) {
|
|
300
|
-
headers['X-Chat-Token'] = window.sessionJWT;
|
|
301
|
-
}
|
|
302
|
-
|
|
303
305
|
abortController = new AbortController();
|
|
304
306
|
const timeoutId = setTimeout(() => abortController.abort(), timeoutMs);
|
|
305
307
|
|
|
306
308
|
try {
|
|
307
|
-
const
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
309
|
+
const fetchOptions = {
|
|
310
|
+
method: method,
|
|
311
|
+
signal: abortController.signal,
|
|
312
|
+
credentials: 'include'
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
// Solo agrega body si el método lo soporta y hay datos
|
|
316
|
+
const methodUpper = (method || '').toUpperCase();
|
|
317
|
+
const canHaveBody = !['GET', 'HEAD'].includes(methodUpper);
|
|
318
|
+
if (canHaveBody && data !== undefined && data !== null) {
|
|
319
|
+
fetchOptions.body = JSON.stringify(data);
|
|
320
|
+
fetchOptions.headers = {"Content-Type": "application/json"};
|
|
321
|
+
|
|
322
|
+
}
|
|
323
|
+
const response = await fetch(url, fetchOptions);
|
|
324
|
+
|
|
314
325
|
clearTimeout(timeoutId);
|
|
315
326
|
|
|
316
327
|
if (!response.ok) {
|
|
328
|
+
if (response.status === 401) {
|
|
329
|
+
const errorMessage = `Tu sesión ha expirado. `;
|
|
330
|
+
const errorIcon = '<i class="bi bi-exclamation-triangle"></i>';
|
|
331
|
+
const infrastructureError = $('<div>').addClass('error-section').html(errorIcon + `<p>${errorMessage}</p>`);
|
|
332
|
+
displayBotMessage(infrastructureError);
|
|
333
|
+
return null;
|
|
334
|
+
}
|
|
317
335
|
try {
|
|
318
336
|
// Intentamos leer el error como JSON, que es el formato esperado de nuestra API.
|
|
319
337
|
const errorData = await response.json();
|
|
@@ -337,6 +355,14 @@ const callLLMAPI = async function(apiPath, data, method, timeoutMs = 500000) {
|
|
|
337
355
|
if (error.name === 'AbortError') {
|
|
338
356
|
throw error; // Re-throw to be handled by handleChatMessage
|
|
339
357
|
} else {
|
|
358
|
+
// Log detallado en consola
|
|
359
|
+
console.error('Error de red en callToolkit:', {
|
|
360
|
+
url,
|
|
361
|
+
method,
|
|
362
|
+
error,
|
|
363
|
+
message: error?.message,
|
|
364
|
+
stack: error?.stack,
|
|
365
|
+
});
|
|
340
366
|
const friendlyMessage = "Ocurrió un error de red. Por favor, inténtalo de nuevo en unos momentos.";
|
|
341
367
|
const errorIcon = '<i class="bi bi-exclamation-triangle"></i>';
|
|
342
368
|
const commError = $('<div>').addClass('error-section').html(errorIcon + `<p>${friendlyMessage}</p>`);
|
|
@@ -111,8 +111,11 @@
|
|
|
111
111
|
data-custom-fields='{{ prompt.custom_fields | tojson }}'>
|
|
112
112
|
{{ prompt.description }}
|
|
113
113
|
</a>
|
|
114
|
-
</li>
|
|
115
|
-
{%
|
|
114
|
+
</li>
|
|
115
|
+
{% endfor %}
|
|
116
|
+
{% if not loop.last %}
|
|
117
|
+
<li><hr class="dropdown-divider"></li>
|
|
118
|
+
{% endif %}
|
|
116
119
|
{% endfor %}
|
|
117
120
|
{% endif %}
|
|
118
121
|
</ul>
|
|
@@ -180,10 +183,11 @@
|
|
|
180
183
|
// --- Global Configuration from Backend ---
|
|
181
184
|
window.companyShortName = "{{ company_short_name }}";
|
|
182
185
|
window.user_identifier = "{{ user_identifier }}";
|
|
186
|
+
window.redeemToken = "{{ redeem_token }}";
|
|
183
187
|
window.iatoolkit_base_url = "{{ iatoolkit_base_url }}";
|
|
184
188
|
window.availablePrompts = {{ prompts.message | tojson }};
|
|
185
|
-
window.sendButtonColor = "{{ branding.send_button_color }}";
|
|
186
189
|
window.onboardingCards = {{ onboarding_cards | tojson }};
|
|
190
|
+
window.sendButtonColor = "{{ branding.send_button_color }}";
|
|
187
191
|
</script>
|
|
188
192
|
|
|
189
193
|
<!-- Carga de los scripts JS externos después de definir las variables globales -->
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{% extends "base.html" %}
|
|
2
|
+
|
|
3
|
+
{% block title %}Prueba de Login para {{ company_short_name }}{% endblock %}
|
|
4
|
+
|
|
5
|
+
{% block content %}
|
|
6
|
+
<div class="container-fluid">
|
|
7
|
+
<div class="row flex-fill mt-5 justify-content-center">
|
|
8
|
+
<div class="col-12 col-lg-6">
|
|
9
|
+
<div class="border rounded p-4 p-md-5 shadow-sm bg-light">
|
|
10
|
+
<h3 class="text-muted fw-semibold text-start mb-3">
|
|
11
|
+
Login Externo para <span style="color:#0d6efd;">{{ company_short_name }}</span>
|
|
12
|
+
</h3>
|
|
13
|
+
<div class="text-center mb-4">
|
|
14
|
+
<p class="text-muted widget-intro-text">
|
|
15
|
+
Este formulario simula el inicio de una sesión externa. Al enviar, serás redirigido a la URL de login final.
|
|
16
|
+
</p>
|
|
17
|
+
</div>
|
|
18
|
+
|
|
19
|
+
<!-- Formulario HTML estándar que hace un POST a la misma URL -->
|
|
20
|
+
<form method="POST" action="">
|
|
21
|
+
<div class="mb-3">
|
|
22
|
+
<label for="external_user_id" class="form-label d-block">External user ID</label>
|
|
23
|
+
<input type="text" id="external_user_id" name="external_user_id" class="form-control" required>
|
|
24
|
+
</div>
|
|
25
|
+
<button type="submit" class="btn btn-primary">
|
|
26
|
+
Redirigir a External Login
|
|
27
|
+
</button>
|
|
28
|
+
</form>
|
|
29
|
+
</div>
|
|
30
|
+
</div>
|
|
31
|
+
</div>
|
|
32
|
+
</div>
|
|
33
|
+
{% endblock %}
|
|
34
|
+
|
|
@@ -12,6 +12,7 @@ from iatoolkit.services.query_service import QueryService
|
|
|
12
12
|
from iatoolkit.services.branding_service import BrandingService
|
|
13
13
|
from iatoolkit.services.onboarding_service import OnboardingService
|
|
14
14
|
from iatoolkit.services.prompt_manager_service import PromptService
|
|
15
|
+
from iatoolkit.services.jwt_service import JWTService
|
|
15
16
|
|
|
16
17
|
|
|
17
18
|
class BaseLoginView(MethodView):
|
|
@@ -22,16 +23,20 @@ class BaseLoginView(MethodView):
|
|
|
22
23
|
@inject
|
|
23
24
|
def __init__(self,
|
|
24
25
|
profile_service: ProfileService,
|
|
26
|
+
jwt_service: JWTService,
|
|
25
27
|
branding_service: BrandingService,
|
|
26
28
|
prompt_service: PromptService,
|
|
27
29
|
onboarding_service: OnboardingService,
|
|
28
|
-
query_service: QueryService
|
|
30
|
+
query_service: QueryService
|
|
31
|
+
):
|
|
29
32
|
self.profile_service = profile_service
|
|
33
|
+
self.jwt_service = jwt_service
|
|
30
34
|
self.branding_service = branding_service
|
|
31
35
|
self.prompt_service = prompt_service
|
|
32
36
|
self.onboarding_service = onboarding_service
|
|
33
37
|
self.query_service = query_service
|
|
34
38
|
|
|
39
|
+
|
|
35
40
|
def _handle_login_path(self, company_short_name: str, user_identifier: str, company):
|
|
36
41
|
"""
|
|
37
42
|
Centralized logic to decide between the fast path and the slow path.
|
|
@@ -43,13 +48,33 @@ class BaseLoginView(MethodView):
|
|
|
43
48
|
prep_result = self.query_service.prepare_context(
|
|
44
49
|
company_short_name=company_short_name, user_identifier=user_identifier
|
|
45
50
|
)
|
|
51
|
+
|
|
52
|
+
# generate continuation token for external login
|
|
53
|
+
redeem_token = ''
|
|
54
|
+
if self.__class__.__name__ == 'ExternalLoginView':
|
|
55
|
+
redeem_token = self.jwt_service.generate_chat_jwt(
|
|
56
|
+
company_short_name=company_short_name,
|
|
57
|
+
user_identifier=user_identifier,
|
|
58
|
+
expires_delta_seconds=300
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
if not redeem_token:
|
|
62
|
+
return "Error al generar el redeem_token para login externo.", 500
|
|
63
|
+
|
|
46
64
|
if prep_result.get('rebuild_needed'):
|
|
47
65
|
# --- SLOW PATH: Render the loading shell ---
|
|
48
66
|
onboarding_cards = self.onboarding_service.get_onboarding_cards(company)
|
|
49
67
|
|
|
50
68
|
# callback url to call when the context finish loading
|
|
51
|
-
|
|
52
|
-
|
|
69
|
+
if redeem_token:
|
|
70
|
+
target_url = url_for('finalize_with_token',
|
|
71
|
+
company_short_name=company_short_name,
|
|
72
|
+
token=redeem_token,
|
|
73
|
+
_external=True)
|
|
74
|
+
else:
|
|
75
|
+
target_url = url_for('finalize_no_token',
|
|
76
|
+
company_short_name=company_short_name,
|
|
77
|
+
_external=True)
|
|
53
78
|
return render_template(
|
|
54
79
|
"onboarding_shell.html",
|
|
55
80
|
iframe_src_url=target_url,
|
|
@@ -62,7 +87,10 @@ class BaseLoginView(MethodView):
|
|
|
62
87
|
onboarding_cards = self.onboarding_service.get_onboarding_cards(company)
|
|
63
88
|
return render_template(
|
|
64
89
|
"chat.html",
|
|
90
|
+
company_short_name=company_short_name,
|
|
91
|
+
user_identifier=user_identifier,
|
|
65
92
|
branding=branding_data,
|
|
66
93
|
prompts=prompts,
|
|
67
|
-
onboarding_cards=onboarding_cards
|
|
94
|
+
onboarding_cards=onboarding_cards,
|
|
95
|
+
redeem_token=redeem_token
|
|
68
96
|
)
|