chainlit 1.2.0rc0__py3-none-any.whl → 1.3.0__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.
Potentially problematic release.
This version of chainlit might be problematic. Click here for more details.
- chainlit/__init__.py +0 -10
- chainlit/auth.py +9 -7
- chainlit/callbacks.py +0 -32
- chainlit/cli/__init__.py +2 -0
- chainlit/config.py +7 -11
- chainlit/context.py +4 -6
- chainlit/copilot/dist/index.js +298 -307
- chainlit/data/__init__.py +11 -6
- chainlit/data/dynamodb.py +7 -3
- chainlit/data/literalai.py +168 -59
- chainlit/data/sql_alchemy.py +89 -15
- chainlit/element.py +2 -1
- chainlit/emitter.py +0 -7
- chainlit/frontend/dist/assets/DailyMotion-CwoOhIL8.js +1 -0
- chainlit/frontend/dist/assets/Facebook-BhnGXlzq.js +1 -0
- chainlit/frontend/dist/assets/FilePlayer-CPSVT6fz.js +1 -0
- chainlit/frontend/dist/assets/Kaltura-COYaLzsL.js +1 -0
- chainlit/frontend/dist/assets/Mixcloud-JdadNiQ5.js +1 -0
- chainlit/frontend/dist/assets/Mux-CBN7RO2u.js +1 -0
- chainlit/frontend/dist/assets/Preview-CxAFvvjV.js +1 -0
- chainlit/frontend/dist/assets/SoundCloud-JlgmASWm.js +1 -0
- chainlit/frontend/dist/assets/Streamable-CUWgr6Zw.js +1 -0
- chainlit/frontend/dist/assets/Twitch-BiN1HEDM.js +1 -0
- chainlit/frontend/dist/assets/Vidyard-qhPmrhDm.js +1 -0
- chainlit/frontend/dist/assets/Vimeo-CrZVSCaT.js +1 -0
- chainlit/frontend/dist/assets/Wistia-C891KrBP.js +1 -0
- chainlit/frontend/dist/assets/YouTube-DKjw5Hbn.js +1 -0
- chainlit/frontend/dist/assets/index-DLRdQOIx.js +723 -0
- chainlit/frontend/dist/assets/{react-plotly-55648373.js → react-plotly-Dpmqg5Sy.js} +94 -94
- chainlit/frontend/dist/index.html +2 -3
- chainlit/haystack/callbacks.py +1 -3
- chainlit/input_widget.py +0 -22
- chainlit/langchain/callbacks.py +1 -2
- chainlit/message.py +1 -1
- chainlit/mistralai/__init__.py +0 -1
- chainlit/oauth_providers.py +46 -3
- chainlit/openai/__init__.py +3 -5
- chainlit/server.py +20 -32
- chainlit/session.py +5 -36
- chainlit/socket.py +2 -51
- chainlit/step.py +13 -20
- chainlit/translations/en-US.json +0 -6
- chainlit/types.py +1 -1
- chainlit/user_session.py +0 -4
- {chainlit-1.2.0rc0.dist-info → chainlit-1.3.0.dist-info}/METADATA +17 -9
- chainlit-1.3.0.dist-info/RECORD +96 -0
- chainlit/assistant.py +0 -16
- chainlit/assistant_settings.py +0 -35
- chainlit/frontend/dist/assets/DailyMotion-aa368b7e.js +0 -1
- chainlit/frontend/dist/assets/Facebook-0335db46.js +0 -1
- chainlit/frontend/dist/assets/FilePlayer-8d04256c.js +0 -1
- chainlit/frontend/dist/assets/Kaltura-67c9dd31.js +0 -1
- chainlit/frontend/dist/assets/Mixcloud-6bbaccf5.js +0 -1
- chainlit/frontend/dist/assets/Mux-c2bcb757.js +0 -1
- chainlit/frontend/dist/assets/Preview-210f3955.js +0 -1
- chainlit/frontend/dist/assets/SoundCloud-a0276b84.js +0 -1
- chainlit/frontend/dist/assets/Streamable-a007323d.js +0 -1
- chainlit/frontend/dist/assets/Twitch-e6a88aa3.js +0 -1
- chainlit/frontend/dist/assets/Vidyard-dfb88a35.js +0 -1
- chainlit/frontend/dist/assets/Vimeo-3baa13d9.js +0 -1
- chainlit/frontend/dist/assets/Wistia-e52f7bef.js +0 -1
- chainlit/frontend/dist/assets/YouTube-1715f22b.js +0 -1
- chainlit/frontend/dist/assets/index-bfdd8585.js +0 -729
- chainlit/translations/fr-FR.json +0 -236
- chainlit-1.2.0rc0.dist-info/RECORD +0 -99
- /chainlit/copilot/dist/assets/{logo_dark-2a3cf740.svg → logo_dark-IkGJ_IwC.svg} +0 -0
- /chainlit/copilot/dist/assets/{logo_light-b078e7bc.svg → logo_light-Bb_IPh6r.svg} +0 -0
- /chainlit/frontend/dist/assets/{index-aaf974a9.css → index-CwmincdQ.css} +0 -0
- /chainlit/frontend/dist/assets/{logo_dark-2a3cf740.svg → logo_dark-IkGJ_IwC.svg} +0 -0
- /chainlit/frontend/dist/assets/{logo_light-b078e7bc.svg → logo_light-Bb_IPh6r.svg} +0 -0
- {chainlit-1.2.0rc0.dist-info → chainlit-1.3.0.dist-info}/WHEEL +0 -0
- {chainlit-1.2.0rc0.dist-info → chainlit-1.3.0.dist-info}/entry_points.txt +0 -0
chainlit/data/__init__.py
CHANGED
|
@@ -2,7 +2,6 @@ import os
|
|
|
2
2
|
from typing import Optional
|
|
3
3
|
|
|
4
4
|
from .base import BaseDataLayer
|
|
5
|
-
from .literalai import LiteralDataLayer
|
|
6
5
|
from .utils import (
|
|
7
6
|
queue_until_user_message as queue_until_user_message, # TODO: Consider deprecating re-export.; Redundant alias tells type checkers to STFU.
|
|
8
7
|
)
|
|
@@ -10,11 +9,17 @@ from .utils import (
|
|
|
10
9
|
_data_layer: Optional[BaseDataLayer] = None
|
|
11
10
|
|
|
12
11
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
server = os.environ.get("LITERAL_API_URL") or os.environ.get("LITERAL_SERVER")
|
|
16
|
-
_data_layer = LiteralDataLayer(api_key=api_key, server=server)
|
|
12
|
+
def get_data_layer():
|
|
13
|
+
global _data_layer
|
|
17
14
|
|
|
15
|
+
if not _data_layer:
|
|
16
|
+
if api_key := os.environ.get("LITERAL_API_KEY"):
|
|
17
|
+
from .literalai import LiteralDataLayer
|
|
18
|
+
|
|
19
|
+
# support legacy LITERAL_SERVER variable as fallback
|
|
20
|
+
server = os.environ.get("LITERAL_API_URL") or os.environ.get(
|
|
21
|
+
"LITERAL_SERVER"
|
|
22
|
+
)
|
|
23
|
+
_data_layer = LiteralDataLayer(api_key=api_key, server=server)
|
|
18
24
|
|
|
19
|
-
def get_data_layer():
|
|
20
25
|
return _data_layer
|
chainlit/data/dynamodb.py
CHANGED
|
@@ -93,6 +93,10 @@ class DynamoDBDataLayer(BaseDataLayer):
|
|
|
93
93
|
ExpressionAttributeValues=self._serialize_item(expression_attribute_values),
|
|
94
94
|
)
|
|
95
95
|
|
|
96
|
+
@property
|
|
97
|
+
def context(self):
|
|
98
|
+
return context
|
|
99
|
+
|
|
96
100
|
async def get_user(self, identifier: str) -> Optional["PersistedUser"]:
|
|
97
101
|
_logger.info("DynamoDB: get_user identifier=%s", identifier)
|
|
98
102
|
|
|
@@ -241,7 +245,7 @@ class DynamoDBDataLayer(BaseDataLayer):
|
|
|
241
245
|
if not element.mime:
|
|
242
246
|
element.mime = "application/octet-stream"
|
|
243
247
|
|
|
244
|
-
context_user = context.session.user
|
|
248
|
+
context_user = self.context.session.user
|
|
245
249
|
user_folder = getattr(context_user, "id", "unknown")
|
|
246
250
|
file_object_key = f"{user_folder}/{element.thread_id}/{element.id}"
|
|
247
251
|
|
|
@@ -293,7 +297,7 @@ class DynamoDBDataLayer(BaseDataLayer):
|
|
|
293
297
|
|
|
294
298
|
@queue_until_user_message()
|
|
295
299
|
async def delete_element(self, element_id: str, thread_id: Optional[str] = None):
|
|
296
|
-
thread_id = context.session.thread_id
|
|
300
|
+
thread_id = self.context.session.thread_id
|
|
297
301
|
_logger.info(
|
|
298
302
|
"DynamoDB: delete_element thread=%s element=%s", thread_id, element_id
|
|
299
303
|
)
|
|
@@ -349,7 +353,7 @@ class DynamoDBDataLayer(BaseDataLayer):
|
|
|
349
353
|
|
|
350
354
|
@queue_until_user_message()
|
|
351
355
|
async def delete_step(self, step_id: str):
|
|
352
|
-
thread_id = context.session.thread_id
|
|
356
|
+
thread_id = self.context.session.thread_id
|
|
353
357
|
_logger.info("DynamoDB: delete_feedback thread=%s step=%s", thread_id, step_id)
|
|
354
358
|
|
|
355
359
|
self.client.delete_item(
|
chainlit/data/literalai.py
CHANGED
|
@@ -1,10 +1,30 @@
|
|
|
1
1
|
import json
|
|
2
|
-
from typing import
|
|
2
|
+
from typing import Dict, List, Literal, Optional, Union, cast
|
|
3
3
|
|
|
4
4
|
import aiofiles
|
|
5
|
+
from httpx import HTTPStatusError, RequestError
|
|
6
|
+
from literalai import (
|
|
7
|
+
Attachment as LiteralAttachment,
|
|
8
|
+
Score as LiteralScore,
|
|
9
|
+
Step as LiteralStep,
|
|
10
|
+
Thread as LiteralThread,
|
|
11
|
+
)
|
|
12
|
+
from literalai.observability.filter import threads_filters as LiteralThreadsFilters
|
|
13
|
+
from literalai.observability.step import StepDict as LiteralStepDict
|
|
14
|
+
|
|
5
15
|
from chainlit.data.base import BaseDataLayer
|
|
6
16
|
from chainlit.data.utils import queue_until_user_message
|
|
17
|
+
from chainlit.element import Audio, Element, ElementDict, File, Image, Pdf, Text, Video
|
|
7
18
|
from chainlit.logger import logger
|
|
19
|
+
from chainlit.step import (
|
|
20
|
+
FeedbackDict,
|
|
21
|
+
Step,
|
|
22
|
+
StepDict,
|
|
23
|
+
StepType,
|
|
24
|
+
TrueStepType,
|
|
25
|
+
check_add_step_in_cot,
|
|
26
|
+
stub_step,
|
|
27
|
+
)
|
|
8
28
|
from chainlit.types import (
|
|
9
29
|
Feedback,
|
|
10
30
|
PageInfo,
|
|
@@ -14,50 +34,19 @@ from chainlit.types import (
|
|
|
14
34
|
ThreadFilter,
|
|
15
35
|
)
|
|
16
36
|
from chainlit.user import PersistedUser, User
|
|
17
|
-
from httpx import HTTPStatusError, RequestError
|
|
18
|
-
from literalai import Attachment
|
|
19
|
-
from literalai import Score as LiteralScore
|
|
20
|
-
from literalai import Step as LiteralStep
|
|
21
|
-
from literalai.filter import threads_filters as LiteralThreadsFilters
|
|
22
|
-
from literalai.step import StepDict as LiteralStepDict
|
|
23
|
-
|
|
24
|
-
if TYPE_CHECKING:
|
|
25
|
-
from chainlit.element import Element, ElementDict
|
|
26
|
-
from chainlit.step import FeedbackDict, StepDict
|
|
27
37
|
|
|
28
38
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
39
|
+
class LiteralToChainlitConverter:
|
|
40
|
+
@classmethod
|
|
41
|
+
def steptype_to_steptype(cls, step_type: Optional[StepType]) -> TrueStepType:
|
|
42
|
+
if step_type in ["user_message", "assistant_message", "system_message"]:
|
|
43
|
+
return "undefined"
|
|
44
|
+
return cast(TrueStepType, step_type or "undefined")
|
|
35
45
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
metadata = attachment.metadata or {}
|
|
41
|
-
return {
|
|
42
|
-
"chainlitKey": None,
|
|
43
|
-
"display": metadata.get("display", "side"),
|
|
44
|
-
"language": metadata.get("language"),
|
|
45
|
-
"autoPlay": metadata.get("autoPlay", None),
|
|
46
|
-
"playerConfig": metadata.get("playerConfig", None),
|
|
47
|
-
"page": metadata.get("page"),
|
|
48
|
-
"size": metadata.get("size"),
|
|
49
|
-
"type": metadata.get("type", "file"),
|
|
50
|
-
"forId": attachment.step_id,
|
|
51
|
-
"id": attachment.id or "",
|
|
52
|
-
"mime": attachment.mime,
|
|
53
|
-
"name": attachment.name or "",
|
|
54
|
-
"objectKey": attachment.object_key,
|
|
55
|
-
"url": attachment.url,
|
|
56
|
-
"threadId": attachment.thread_id,
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
def score_to_feedback_dict(
|
|
60
|
-
self, score: Optional[LiteralScore]
|
|
46
|
+
@classmethod
|
|
47
|
+
def score_to_feedbackdict(
|
|
48
|
+
cls,
|
|
49
|
+
score: Optional[LiteralScore],
|
|
61
50
|
) -> "Optional[FeedbackDict]":
|
|
62
51
|
if not score:
|
|
63
52
|
return None
|
|
@@ -68,7 +57,8 @@ class LiteralDataLayer(BaseDataLayer):
|
|
|
68
57
|
"comment": score.comment,
|
|
69
58
|
}
|
|
70
59
|
|
|
71
|
-
|
|
60
|
+
@classmethod
|
|
61
|
+
def step_to_stepdict(cls, step: LiteralStep) -> "StepDict":
|
|
72
62
|
metadata = step.metadata or {}
|
|
73
63
|
input = (step.input or {}).get("content") or (
|
|
74
64
|
json.dumps(step.input) if step.input and step.input != {} else ""
|
|
@@ -95,7 +85,7 @@ class LiteralDataLayer(BaseDataLayer):
|
|
|
95
85
|
"id": step.id or "",
|
|
96
86
|
"threadId": step.thread_id or "",
|
|
97
87
|
"parentId": step.parent_id,
|
|
98
|
-
"feedback":
|
|
88
|
+
"feedback": cls.score_to_feedbackdict(user_feedback),
|
|
99
89
|
"start": step.start_time,
|
|
100
90
|
"end": step.end_time,
|
|
101
91
|
"type": step.type or "undefined",
|
|
@@ -110,6 +100,116 @@ class LiteralDataLayer(BaseDataLayer):
|
|
|
110
100
|
"waitForAnswer": metadata.get("waitForAnswer", False),
|
|
111
101
|
}
|
|
112
102
|
|
|
103
|
+
@classmethod
|
|
104
|
+
def attachment_to_elementdict(cls, attachment: LiteralAttachment) -> ElementDict:
|
|
105
|
+
metadata = attachment.metadata or {}
|
|
106
|
+
return {
|
|
107
|
+
"chainlitKey": None,
|
|
108
|
+
"display": metadata.get("display", "side"),
|
|
109
|
+
"language": metadata.get("language"),
|
|
110
|
+
"autoPlay": metadata.get("autoPlay", None),
|
|
111
|
+
"playerConfig": metadata.get("playerConfig", None),
|
|
112
|
+
"page": metadata.get("page"),
|
|
113
|
+
"size": metadata.get("size"),
|
|
114
|
+
"type": metadata.get("type", "file"),
|
|
115
|
+
"forId": attachment.step_id,
|
|
116
|
+
"id": attachment.id or "",
|
|
117
|
+
"mime": attachment.mime,
|
|
118
|
+
"name": attachment.name or "",
|
|
119
|
+
"objectKey": attachment.object_key,
|
|
120
|
+
"url": attachment.url,
|
|
121
|
+
"threadId": attachment.thread_id,
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
@classmethod
|
|
125
|
+
def attachment_to_element(
|
|
126
|
+
cls, attachment: LiteralAttachment, thread_id: Optional[str] = None
|
|
127
|
+
) -> Element:
|
|
128
|
+
metadata = attachment.metadata or {}
|
|
129
|
+
element_type = metadata.get("type", "file")
|
|
130
|
+
|
|
131
|
+
element_class = {
|
|
132
|
+
"file": File,
|
|
133
|
+
"image": Image,
|
|
134
|
+
"audio": Audio,
|
|
135
|
+
"video": Video,
|
|
136
|
+
"text": Text,
|
|
137
|
+
"pdf": Pdf,
|
|
138
|
+
}.get(element_type, Element)
|
|
139
|
+
|
|
140
|
+
assert thread_id or attachment.thread_id
|
|
141
|
+
|
|
142
|
+
element = element_class(
|
|
143
|
+
name=attachment.name or "",
|
|
144
|
+
display=metadata.get("display", "side"),
|
|
145
|
+
language=metadata.get("language"),
|
|
146
|
+
size=metadata.get("size"),
|
|
147
|
+
url=attachment.url,
|
|
148
|
+
mime=attachment.mime,
|
|
149
|
+
thread_id=thread_id or attachment.thread_id,
|
|
150
|
+
)
|
|
151
|
+
element.id = attachment.id or ""
|
|
152
|
+
element.for_id = attachment.step_id
|
|
153
|
+
element.object_key = attachment.object_key
|
|
154
|
+
return element
|
|
155
|
+
|
|
156
|
+
@classmethod
|
|
157
|
+
def step_to_step(cls, step: LiteralStep) -> Step:
|
|
158
|
+
chainlit_step = Step(
|
|
159
|
+
name=step.name or "",
|
|
160
|
+
type=cls.steptype_to_steptype(step.type),
|
|
161
|
+
id=step.id,
|
|
162
|
+
parent_id=step.parent_id,
|
|
163
|
+
thread_id=step.thread_id or None,
|
|
164
|
+
)
|
|
165
|
+
chainlit_step.start = step.start_time
|
|
166
|
+
chainlit_step.end = step.end_time
|
|
167
|
+
chainlit_step.created_at = step.created_at
|
|
168
|
+
chainlit_step.input = step.input.get("content", "") if step.input else ""
|
|
169
|
+
chainlit_step.output = step.output.get("content", "") if step.output else ""
|
|
170
|
+
chainlit_step.is_error = bool(step.error)
|
|
171
|
+
chainlit_step.metadata = step.metadata or {}
|
|
172
|
+
chainlit_step.tags = step.tags
|
|
173
|
+
chainlit_step.generation = step.generation
|
|
174
|
+
|
|
175
|
+
if step.attachments:
|
|
176
|
+
chainlit_step.elements = [
|
|
177
|
+
cls.attachment_to_element(attachment, chainlit_step.thread_id)
|
|
178
|
+
for attachment in step.attachments
|
|
179
|
+
]
|
|
180
|
+
|
|
181
|
+
return chainlit_step
|
|
182
|
+
|
|
183
|
+
@classmethod
|
|
184
|
+
def thread_to_threaddict(cls, thread: LiteralThread) -> ThreadDict:
|
|
185
|
+
return {
|
|
186
|
+
"id": thread.id,
|
|
187
|
+
"createdAt": getattr(thread, "created_at", ""),
|
|
188
|
+
"name": thread.name,
|
|
189
|
+
"userId": thread.participant_id,
|
|
190
|
+
"userIdentifier": thread.participant_identifier,
|
|
191
|
+
"tags": thread.tags,
|
|
192
|
+
"metadata": thread.metadata,
|
|
193
|
+
"steps": [cls.step_to_stepdict(step) for step in thread.steps]
|
|
194
|
+
if thread.steps
|
|
195
|
+
else [],
|
|
196
|
+
"elements": [
|
|
197
|
+
cls.attachment_to_elementdict(attachment)
|
|
198
|
+
for step in thread.steps
|
|
199
|
+
for attachment in step.attachments
|
|
200
|
+
]
|
|
201
|
+
if thread.steps
|
|
202
|
+
else [],
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
class LiteralDataLayer(BaseDataLayer):
|
|
207
|
+
def __init__(self, api_key: str, server: Optional[str]):
|
|
208
|
+
from literalai import AsyncLiteralClient
|
|
209
|
+
|
|
210
|
+
self.client = AsyncLiteralClient(api_key=api_key, url=server)
|
|
211
|
+
logger.info("Chainlit data layer initialized")
|
|
212
|
+
|
|
113
213
|
async def build_debug_url(self) -> str:
|
|
114
214
|
try:
|
|
115
215
|
project_id = await self.client.api.get_my_project_id()
|
|
@@ -239,7 +339,7 @@ class LiteralDataLayer(BaseDataLayer):
|
|
|
239
339
|
attachment = await self.client.api.get_attachment(id=element_id)
|
|
240
340
|
if not attachment:
|
|
241
341
|
return None
|
|
242
|
-
return
|
|
342
|
+
return LiteralToChainlitConverter.attachment_to_elementdict(attachment)
|
|
243
343
|
|
|
244
344
|
@queue_until_user_message()
|
|
245
345
|
async def delete_element(self, element_id: str, thread_id: Optional[str] = None):
|
|
@@ -339,32 +439,41 @@ class LiteralDataLayer(BaseDataLayer):
|
|
|
339
439
|
filters=literal_filters,
|
|
340
440
|
order_by={"column": "createdAt", "direction": "DESC"},
|
|
341
441
|
)
|
|
442
|
+
|
|
443
|
+
chainlit_threads = [
|
|
444
|
+
*map(LiteralToChainlitConverter.thread_to_threaddict, literal_response.data)
|
|
445
|
+
]
|
|
446
|
+
|
|
342
447
|
return PaginatedResponse(
|
|
343
448
|
pageInfo=PageInfo(
|
|
344
|
-
hasNextPage=literal_response.
|
|
345
|
-
startCursor=literal_response.
|
|
346
|
-
endCursor=literal_response.
|
|
449
|
+
hasNextPage=literal_response.page_info.has_next_page,
|
|
450
|
+
startCursor=literal_response.page_info.start_cursor,
|
|
451
|
+
endCursor=literal_response.page_info.end_cursor,
|
|
347
452
|
),
|
|
348
|
-
data=
|
|
453
|
+
data=chainlit_threads,
|
|
349
454
|
)
|
|
350
455
|
|
|
351
|
-
async def get_thread(self, thread_id: str) ->
|
|
352
|
-
from chainlit.step import check_add_step_in_cot, stub_step
|
|
353
|
-
|
|
456
|
+
async def get_thread(self, thread_id: str) -> Optional[ThreadDict]:
|
|
354
457
|
thread = await self.client.api.get_thread(id=thread_id)
|
|
355
458
|
if not thread:
|
|
356
459
|
return None
|
|
357
|
-
|
|
358
|
-
|
|
460
|
+
|
|
461
|
+
elements: List[ElementDict] = []
|
|
462
|
+
steps: List[StepDict] = []
|
|
359
463
|
if thread.steps:
|
|
360
464
|
for step in thread.steps:
|
|
361
465
|
for attachment in step.attachments:
|
|
362
|
-
elements.append(
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
466
|
+
elements.append(
|
|
467
|
+
LiteralToChainlitConverter.attachment_to_elementdict(attachment)
|
|
468
|
+
)
|
|
469
|
+
|
|
470
|
+
chainlit_step = LiteralToChainlitConverter.step_to_step(step)
|
|
471
|
+
if check_add_step_in_cot(chainlit_step):
|
|
472
|
+
steps.append(
|
|
473
|
+
LiteralToChainlitConverter.step_to_stepdict(step)
|
|
474
|
+
) # TODO: chainlit_step.to_dict()
|
|
366
475
|
else:
|
|
367
|
-
steps.append(stub_step(
|
|
476
|
+
steps.append(stub_step(chainlit_step))
|
|
368
477
|
|
|
369
478
|
return {
|
|
370
479
|
"createdAt": thread.created_at or "",
|
chainlit/data/sql_alchemy.py
CHANGED
|
@@ -7,7 +7,7 @@ from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union
|
|
|
7
7
|
|
|
8
8
|
import aiofiles
|
|
9
9
|
import aiohttp
|
|
10
|
-
|
|
10
|
+
|
|
11
11
|
from chainlit.data.base import BaseDataLayer, BaseStorageClient
|
|
12
12
|
from chainlit.data.utils import queue_until_user_message
|
|
13
13
|
from chainlit.element import ElementDict
|
|
@@ -84,6 +84,9 @@ class SQLAlchemyDataLayer(BaseDataLayer):
|
|
|
84
84
|
if result.returns_rows:
|
|
85
85
|
json_result = [dict(row._mapping) for row in result.fetchall()]
|
|
86
86
|
clean_json_result = self.clean_result(json_result)
|
|
87
|
+
assert isinstance(clean_json_result, list) or isinstance(
|
|
88
|
+
clean_json_result, int
|
|
89
|
+
)
|
|
87
90
|
return clean_json_result
|
|
88
91
|
else:
|
|
89
92
|
return result.rowcount
|
|
@@ -118,7 +121,47 @@ class SQLAlchemyDataLayer(BaseDataLayer):
|
|
|
118
121
|
result = await self.execute_sql(query=query, parameters=parameters)
|
|
119
122
|
if result and isinstance(result, list):
|
|
120
123
|
user_data = result[0]
|
|
121
|
-
|
|
124
|
+
|
|
125
|
+
# SQLite returns JSON as string, we most convert it. (#1137)
|
|
126
|
+
metadata = user_data.get("metadata", {})
|
|
127
|
+
if isinstance(metadata, str):
|
|
128
|
+
metadata = json.loads(metadata)
|
|
129
|
+
|
|
130
|
+
assert isinstance(metadata, dict)
|
|
131
|
+
assert isinstance(user_data["id"], str)
|
|
132
|
+
assert isinstance(user_data["identifier"], str)
|
|
133
|
+
assert isinstance(user_data["createdAt"], str)
|
|
134
|
+
|
|
135
|
+
return PersistedUser(
|
|
136
|
+
id=user_data["id"],
|
|
137
|
+
identifier=user_data["identifier"],
|
|
138
|
+
createdAt=user_data["createdAt"],
|
|
139
|
+
metadata=metadata,
|
|
140
|
+
)
|
|
141
|
+
return None
|
|
142
|
+
|
|
143
|
+
async def _get_user_identifer_by_id(self, user_id: str) -> str:
|
|
144
|
+
if self.show_logger:
|
|
145
|
+
logger.info(f"SQLAlchemy: _get_user_identifer_by_id, user_id={user_id}")
|
|
146
|
+
query = "SELECT identifier FROM users WHERE id = :user_id"
|
|
147
|
+
parameters = {"user_id": user_id}
|
|
148
|
+
result = await self.execute_sql(query=query, parameters=parameters)
|
|
149
|
+
|
|
150
|
+
assert result
|
|
151
|
+
assert isinstance(result, list)
|
|
152
|
+
|
|
153
|
+
return result[0]["identifier"]
|
|
154
|
+
|
|
155
|
+
async def _get_user_id_by_thread(self, thread_id: str) -> Optional[str]:
|
|
156
|
+
if self.show_logger:
|
|
157
|
+
logger.info(f"SQLAlchemy: _get_user_id_by_thread, thread_id={thread_id}")
|
|
158
|
+
query = """SELECT "userId" FROM threads WHERE id = :thread_id"""
|
|
159
|
+
parameters = {"thread_id": thread_id}
|
|
160
|
+
result = await self.execute_sql(query=query, parameters=parameters)
|
|
161
|
+
if result:
|
|
162
|
+
assert isinstance(result, list)
|
|
163
|
+
return result[0]["userId"]
|
|
164
|
+
|
|
122
165
|
return None
|
|
123
166
|
|
|
124
167
|
async def create_user(self, user: User) -> Optional[PersistedUser]:
|
|
@@ -179,10 +222,11 @@ class SQLAlchemyDataLayer(BaseDataLayer):
|
|
|
179
222
|
):
|
|
180
223
|
if self.show_logger:
|
|
181
224
|
logger.info(f"SQLAlchemy: update_thread, thread_id={thread_id}")
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
225
|
+
|
|
226
|
+
user_identifier = None
|
|
227
|
+
if user_id:
|
|
228
|
+
user_identifier = await self._get_user_identifer_by_id(user_id)
|
|
229
|
+
|
|
186
230
|
data = {
|
|
187
231
|
"id": thread_id,
|
|
188
232
|
"createdAt": (
|
|
@@ -294,8 +338,7 @@ class SQLAlchemyDataLayer(BaseDataLayer):
|
|
|
294
338
|
async def create_step(self, step_dict: "StepDict"):
|
|
295
339
|
if self.show_logger:
|
|
296
340
|
logger.info(f"SQLAlchemy: create_step, step_id={step_dict.get('id')}")
|
|
297
|
-
|
|
298
|
-
raise ValueError("No authenticated user in context")
|
|
341
|
+
|
|
299
342
|
step_dict["showInput"] = (
|
|
300
343
|
str(step_dict.get("showInput", "")).lower()
|
|
301
344
|
if "showInput" in step_dict
|
|
@@ -373,12 +416,45 @@ class SQLAlchemyDataLayer(BaseDataLayer):
|
|
|
373
416
|
return True
|
|
374
417
|
|
|
375
418
|
###### Elements ######
|
|
419
|
+
async def get_element(
|
|
420
|
+
self, thread_id: str, element_id: str
|
|
421
|
+
) -> Optional["ElementDict"]:
|
|
422
|
+
if self.show_logger:
|
|
423
|
+
logger.info(
|
|
424
|
+
f"SQLAlchemy: get_element, thread_id={thread_id}, element_id={element_id}"
|
|
425
|
+
)
|
|
426
|
+
query = """SELECT * FROM elements WHERE "threadId" = :thread_id AND "id" = :element_id"""
|
|
427
|
+
parameters = {"thread_id": thread_id, "element_id": element_id}
|
|
428
|
+
element: Union[List[Dict[str, Any]], int, None] = await self.execute_sql(
|
|
429
|
+
query=query, parameters=parameters
|
|
430
|
+
)
|
|
431
|
+
if isinstance(element, list) and element:
|
|
432
|
+
element_dict: Dict[str, Any] = element[0]
|
|
433
|
+
return ElementDict(
|
|
434
|
+
id=element_dict["id"],
|
|
435
|
+
threadId=element_dict.get("threadId"),
|
|
436
|
+
type=element_dict["type"],
|
|
437
|
+
chainlitKey=element_dict.get("chainlitKey"),
|
|
438
|
+
url=element_dict.get("url"),
|
|
439
|
+
objectKey=element_dict.get("objectKey"),
|
|
440
|
+
name=element_dict["name"],
|
|
441
|
+
display=element_dict["display"],
|
|
442
|
+
size=element_dict.get("size"),
|
|
443
|
+
language=element_dict.get("language"),
|
|
444
|
+
page=element_dict.get("page"),
|
|
445
|
+
autoPlay=element_dict.get("autoPlay"),
|
|
446
|
+
playerConfig=element_dict.get("playerConfig"),
|
|
447
|
+
forId=element_dict.get("forId"),
|
|
448
|
+
mime=element_dict.get("mime"),
|
|
449
|
+
)
|
|
450
|
+
else:
|
|
451
|
+
return None
|
|
452
|
+
|
|
376
453
|
@queue_until_user_message()
|
|
377
454
|
async def create_element(self, element: "Element"):
|
|
378
455
|
if self.show_logger:
|
|
379
456
|
logger.info(f"SQLAlchemy: create_element, element_id = {element.id}")
|
|
380
|
-
|
|
381
|
-
raise ValueError("No authenticated user in context")
|
|
457
|
+
|
|
382
458
|
if not self.storage_provider:
|
|
383
459
|
logger.warn(
|
|
384
460
|
"SQLAlchemy: create_element error. No blob_storage_client is configured!"
|
|
@@ -406,10 +482,8 @@ class SQLAlchemyDataLayer(BaseDataLayer):
|
|
|
406
482
|
if content is None:
|
|
407
483
|
raise ValueError("Content is None, cannot upload file")
|
|
408
484
|
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
user_folder = getattr(context_user, "id", "unknown")
|
|
412
|
-
file_object_key = f"{user_folder}/{element.id}" + (
|
|
485
|
+
user_id: str = await self._get_user_id_by_thread(element.thread_id) or "unknown"
|
|
486
|
+
file_object_key = f"{user_id}/{element.id}" + (
|
|
413
487
|
f"/{element.name}" if element.name else ""
|
|
414
488
|
)
|
|
415
489
|
|
|
@@ -581,7 +655,7 @@ class SQLAlchemyDataLayer(BaseDataLayer):
|
|
|
581
655
|
step_feedback.get("step_input", "")
|
|
582
656
|
if step_feedback.get("step_showinput")
|
|
583
657
|
not in [None, "false"]
|
|
584
|
-
else
|
|
658
|
+
else ""
|
|
585
659
|
),
|
|
586
660
|
output=step_feedback.get("step_output", ""),
|
|
587
661
|
createdAt=step_feedback.get("step_createdat"),
|
chainlit/element.py
CHANGED
|
@@ -57,6 +57,8 @@ class ElementDict(TypedDict):
|
|
|
57
57
|
|
|
58
58
|
@dataclass
|
|
59
59
|
class Element:
|
|
60
|
+
# Thread id
|
|
61
|
+
thread_id: str = Field(default_factory=lambda: context.session.thread_id)
|
|
60
62
|
# The type of the element. This will be used to determine how to display the element in the UI.
|
|
61
63
|
type: ClassVar[ElementType]
|
|
62
64
|
# Name of the element, this will be used to reference the element in the UI.
|
|
@@ -88,7 +90,6 @@ class Element:
|
|
|
88
90
|
trace_event(f"init {self.__class__.__name__}")
|
|
89
91
|
self.persisted = False
|
|
90
92
|
self.updatable = False
|
|
91
|
-
self.thread_id = context.session.thread_id
|
|
92
93
|
|
|
93
94
|
if not self.url and not self.path and not self.content:
|
|
94
95
|
raise ValueError("Must provide url, path or content to instantiate element")
|
chainlit/emitter.py
CHANGED
|
@@ -114,10 +114,6 @@ class BaseChainlitEmitter:
|
|
|
114
114
|
"""Stub method to set chat settings."""
|
|
115
115
|
pass
|
|
116
116
|
|
|
117
|
-
async def set_assistant_settings(self, settings: dict):
|
|
118
|
-
"""Stub method to send assistant settings to the UI."""
|
|
119
|
-
pass
|
|
120
|
-
|
|
121
117
|
async def send_action_response(
|
|
122
118
|
self, id: str, status: bool, response: Optional[str] = None
|
|
123
119
|
):
|
|
@@ -365,9 +361,6 @@ class ChainlitEmitter(BaseChainlitEmitter):
|
|
|
365
361
|
def set_chat_settings(self, settings: Dict[str, Any]):
|
|
366
362
|
self.session.chat_settings = settings
|
|
367
363
|
|
|
368
|
-
def set_assistant_settings(self, settings: Dict[str, Any]):
|
|
369
|
-
self.session.assistant_settings = settings
|
|
370
|
-
|
|
371
364
|
def send_action_response(
|
|
372
365
|
self, id: str, status: bool, response: Optional[str] = None
|
|
373
366
|
):
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{g as P,r as v,u as D,a as O}from"./index-DLRdQOIx.js";function b(t,e){for(var r=0;r<e.length;r++){const o=e[r];if(typeof o!="string"&&!Array.isArray(o)){for(const a in o)if(a!=="default"&&!(a in t)){const i=Object.getOwnPropertyDescriptor(o,a);i&&Object.defineProperty(t,a,i.get?i:{enumerable:!0,get:()=>o[a]})}}}return Object.freeze(Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}))}var M=Object.create,s=Object.defineProperty,w=Object.getOwnPropertyDescriptor,S=Object.getOwnPropertyNames,j=Object.getPrototypeOf,T=Object.prototype.hasOwnProperty,E=(t,e,r)=>e in t?s(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,A=(t,e)=>{for(var r in e)s(t,r,{get:e[r],enumerable:!0})},h=(t,e,r,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of S(e))!T.call(t,a)&&a!==r&&s(t,a,{get:()=>e[a],enumerable:!(o=w(e,a))||o.enumerable});return t},L=(t,e,r)=>(r=t!=null?M(j(t)):{},h(!t||!t.__esModule?s(r,"default",{value:t,enumerable:!0}):r,t)),C=t=>h(s({},"__esModule",{value:!0}),t),n=(t,e,r)=>(E(t,typeof e!="symbol"?e+"":e,r),r),d={};A(d,{default:()=>p});var _=C(d),c=L(v),l=D,f=O;const N="https://api.dmcdn.net/all.js",x="DM",K="dmAsyncInit";class p extends c.Component{constructor(){super(...arguments),n(this,"callPlayer",l.callPlayer),n(this,"onDurationChange",()=>{const e=this.getDuration();this.props.onDuration(e)}),n(this,"mute",()=>{this.callPlayer("setMuted",!0)}),n(this,"unmute",()=>{this.callPlayer("setMuted",!1)}),n(this,"ref",e=>{this.container=e})}componentDidMount(){this.props.onMount&&this.props.onMount(this)}load(e){const{controls:r,config:o,onError:a,playing:i}=this.props,[,y]=e.match(f.MATCH_URL_DAILYMOTION);if(this.player){this.player.load(y,{start:(0,l.parseStartTime)(e),autoplay:i});return}(0,l.getSDK)(N,x,K,u=>u.player).then(u=>{if(!this.container)return;const g=u.player;this.player=new g(this.container,{width:"100%",height:"100%",video:y,params:{controls:r,autoplay:this.props.playing,mute:this.props.muted,start:(0,l.parseStartTime)(e),origin:window.location.origin,...o.params},events:{apiready:this.props.onReady,seeked:()=>this.props.onSeek(this.player.currentTime),video_end:this.props.onEnded,durationchange:this.onDurationChange,pause:this.props.onPause,playing:this.props.onPlay,waiting:this.props.onBuffer,error:m=>a(m)}})},a)}play(){this.callPlayer("play")}pause(){this.callPlayer("pause")}stop(){}seekTo(e,r=!0){this.callPlayer("seek",e),r||this.pause()}setVolume(e){this.callPlayer("setVolume",e)}getDuration(){return this.player.duration||null}getCurrentTime(){return this.player.currentTime}getSecondsLoaded(){return this.player.bufferedTime}render(){const{display:e}=this.props,r={width:"100%",height:"100%",display:e};return c.default.createElement("div",{style:r},c.default.createElement("div",{ref:this.ref}))}}n(p,"displayName","DailyMotion");n(p,"canPlay",f.canPlay.dailymotion);n(p,"loopOnEnded",!0);const R=P(_),I=b({__proto__:null,default:R},[_]);export{I as D};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{g as _,r as g,u as P,a as m}from"./index-DLRdQOIx.js";function v(t,e){for(var r=0;r<e.length;r++){const a=e[r];if(typeof a!="string"&&!Array.isArray(a)){for(const s in a)if(s!=="default"&&!(s in t)){const p=Object.getOwnPropertyDescriptor(a,s);p&&Object.defineProperty(t,s,p.get?p:{enumerable:!0,get:()=>a[s]})}}}return Object.freeze(Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}))}var O=Object.create,i=Object.defineProperty,D=Object.getOwnPropertyDescriptor,E=Object.getOwnPropertyNames,S=Object.getPrototypeOf,j=Object.prototype.hasOwnProperty,I=(t,e,r)=>e in t?i(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,k=(t,e)=>{for(var r in e)i(t,r,{get:e[r],enumerable:!0})},h=(t,e,r,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of E(e))!j.call(t,s)&&s!==r&&i(t,s,{get:()=>e[s],enumerable:!(a=D(e,s))||a.enumerable});return t},w=(t,e,r)=>(r=t!=null?O(S(t)):{},h(!t||!t.__esModule?i(r,"default",{value:t,enumerable:!0}):r,t)),F=t=>h(i({},"__esModule",{value:!0}),t),o=(t,e,r)=>(I(t,typeof e!="symbol"?e+"":e,r),r),b={};k(b,{default:()=>l});var d=F(b),u=w(g),n=P,x=m;const c="https://connect.facebook.net/en_US/sdk.js",y="FB",f="fbAsyncInit",L="facebook-player-";class l extends u.Component{constructor(){super(...arguments),o(this,"callPlayer",n.callPlayer),o(this,"playerID",this.props.config.playerId||`${L}${(0,n.randomString)()}`),o(this,"mute",()=>{this.callPlayer("mute")}),o(this,"unmute",()=>{this.callPlayer("unmute")})}componentDidMount(){this.props.onMount&&this.props.onMount(this)}load(e,r){if(r){(0,n.getSDK)(c,y,f).then(a=>a.XFBML.parse());return}(0,n.getSDK)(c,y,f).then(a=>{a.init({appId:this.props.config.appId,xfbml:!0,version:this.props.config.version}),a.Event.subscribe("xfbml.render",s=>{this.props.onLoaded()}),a.Event.subscribe("xfbml.ready",s=>{s.type==="video"&&s.id===this.playerID&&(this.player=s.instance,this.player.subscribe("startedPlaying",this.props.onPlay),this.player.subscribe("paused",this.props.onPause),this.player.subscribe("finishedPlaying",this.props.onEnded),this.player.subscribe("startedBuffering",this.props.onBuffer),this.player.subscribe("finishedBuffering",this.props.onBufferEnd),this.player.subscribe("error",this.props.onError),this.props.muted?this.callPlayer("mute"):this.callPlayer("unmute"),this.props.onReady(),document.getElementById(this.playerID).querySelector("iframe").style.visibility="visible")})})}play(){this.callPlayer("play")}pause(){this.callPlayer("pause")}stop(){}seekTo(e,r=!0){this.callPlayer("seek",e),r||this.pause()}setVolume(e){this.callPlayer("setVolume",e)}getDuration(){return this.callPlayer("getDuration")}getCurrentTime(){return this.callPlayer("getCurrentPosition")}getSecondsLoaded(){return null}render(){const{attributes:e}=this.props.config,r={width:"100%",height:"100%"};return u.default.createElement("div",{style:r,id:this.playerID,className:"fb-video","data-href":this.props.url,"data-autoplay":this.props.playing?"true":"false","data-allowfullscreen":"true","data-controls":this.props.controls?"true":"false",...e})}}o(l,"displayName","Facebook");o(l,"canPlay",x.canPlay.facebook);o(l,"loopOnEnded",!0);const M=_(d),B=v({__proto__:null,default:M},[d]);export{B as F};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{g as b,r as _,u as O,a as A}from"./index-DLRdQOIx.js";function R(s,e){for(var t=0;t<e.length;t++){const i=e[t];if(typeof i!="string"&&!Array.isArray(i)){for(const n in i)if(n!=="default"&&!(n in s)){const l=Object.getOwnPropertyDescriptor(i,n);l&&Object.defineProperty(s,n,l.get?l:{enumerable:!0,get:()=>i[n]})}}}return Object.freeze(Object.defineProperty(s,Symbol.toStringTag,{value:"Module"}))}var I=Object.create,u=Object.defineProperty,D=Object.getOwnPropertyDescriptor,w=Object.getOwnPropertyNames,M=Object.getPrototypeOf,k=Object.prototype.hasOwnProperty,U=(s,e,t)=>e in s?u(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,N=(s,e)=>{for(var t in e)u(s,t,{get:e[t],enumerable:!0})},E=(s,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of w(e))!k.call(s,n)&&n!==t&&u(s,n,{get:()=>e[n],enumerable:!(i=D(e,n))||i.enumerable});return s},j=(s,e,t)=>(t=s!=null?I(M(s)):{},E(!s||!s.__esModule?u(t,"default",{value:s,enumerable:!0}):t,s)),H=s=>E(u({},"__esModule",{value:!0}),s),r=(s,e,t)=>(U(s,typeof e!="symbol"?e+"":e,t),t),m={};N(m,{default:()=>P});var g=H(m),d=j(_),a=O,c=A;const y=typeof navigator<"u",F=y&&navigator.platform==="MacIntel"&&navigator.maxTouchPoints>1,v=y&&(/iPad|iPhone|iPod/.test(navigator.userAgent)||F)&&!window.MSStream,V=y&&/^((?!chrome|android).)*safari/i.test(navigator.userAgent)&&!window.MSStream,T="https://cdn.jsdelivr.net/npm/hls.js@VERSION/dist/hls.min.js",C="Hls",B="https://cdnjs.cloudflare.com/ajax/libs/dashjs/VERSION/dash.all.min.js",x="dashjs",K="https://cdn.jsdelivr.net/npm/flv.js@VERSION/dist/flv.min.js",G="flvjs",X=/www\.dropbox\.com\/.+/,f=/https:\/\/watch\.cloudflarestream\.com\/([a-z0-9]+)/,W="https://videodelivery.net/{id}/manifest/video.m3u8";class P extends d.Component{constructor(){super(...arguments),r(this,"onReady",(...e)=>this.props.onReady(...e)),r(this,"onPlay",(...e)=>this.props.onPlay(...e)),r(this,"onBuffer",(...e)=>this.props.onBuffer(...e)),r(this,"onBufferEnd",(...e)=>this.props.onBufferEnd(...e)),r(this,"onPause",(...e)=>this.props.onPause(...e)),r(this,"onEnded",(...e)=>this.props.onEnded(...e)),r(this,"onError",(...e)=>this.props.onError(...e)),r(this,"onPlayBackRateChange",e=>this.props.onPlaybackRateChange(e.target.playbackRate)),r(this,"onEnablePIP",(...e)=>this.props.onEnablePIP(...e)),r(this,"onDisablePIP",e=>{const{onDisablePIP:t,playing:i}=this.props;t(e),i&&this.play()}),r(this,"onPresentationModeChange",e=>{if(this.player&&(0,a.supportsWebKitPresentationMode)(this.player)){const{webkitPresentationMode:t}=this.player;t==="picture-in-picture"?this.onEnablePIP(e):t==="inline"&&this.onDisablePIP(e)}}),r(this,"onSeek",e=>{this.props.onSeek(e.target.currentTime)}),r(this,"mute",()=>{this.player.muted=!0}),r(this,"unmute",()=>{this.player.muted=!1}),r(this,"renderSourceElement",(e,t)=>typeof e=="string"?d.default.createElement("source",{key:t,src:e}):d.default.createElement("source",{key:t,...e})),r(this,"renderTrack",(e,t)=>d.default.createElement("track",{key:t,...e})),r(this,"ref",e=>{this.player&&(this.prevPlayer=this.player),this.player=e})}componentDidMount(){this.props.onMount&&this.props.onMount(this),this.addListeners(this.player);const e=this.getSource(this.props.url);e&&(this.player.src=e),(v||this.props.config.forceDisableHls)&&this.player.load()}componentDidUpdate(e){this.shouldUseAudio(this.props)!==this.shouldUseAudio(e)&&(this.removeListeners(this.prevPlayer,e.url),this.addListeners(this.player)),this.props.url!==e.url&&!(0,a.isMediaStream)(this.props.url)&&!(this.props.url instanceof Array)&&(this.player.srcObject=null)}componentWillUnmount(){this.player.removeAttribute("src"),this.removeListeners(this.player),this.hls&&this.hls.destroy()}addListeners(e){const{url:t,playsinline:i}=this.props;e.addEventListener("play",this.onPlay),e.addEventListener("waiting",this.onBuffer),e.addEventListener("playing",this.onBufferEnd),e.addEventListener("pause",this.onPause),e.addEventListener("seeked",this.onSeek),e.addEventListener("ended",this.onEnded),e.addEventListener("error",this.onError),e.addEventListener("ratechange",this.onPlayBackRateChange),e.addEventListener("enterpictureinpicture",this.onEnablePIP),e.addEventListener("leavepictureinpicture",this.onDisablePIP),e.addEventListener("webkitpresentationmodechanged",this.onPresentationModeChange),this.shouldUseHLS(t)||e.addEventListener("canplay",this.onReady),i&&(e.setAttribute("playsinline",""),e.setAttribute("webkit-playsinline",""),e.setAttribute("x5-playsinline",""))}removeListeners(e,t){e.removeEventListener("canplay",this.onReady),e.removeEventListener("play",this.onPlay),e.removeEventListener("waiting",this.onBuffer),e.removeEventListener("playing",this.onBufferEnd),e.removeEventListener("pause",this.onPause),e.removeEventListener("seeked",this.onSeek),e.removeEventListener("ended",this.onEnded),e.removeEventListener("error",this.onError),e.removeEventListener("ratechange",this.onPlayBackRateChange),e.removeEventListener("enterpictureinpicture",this.onEnablePIP),e.removeEventListener("leavepictureinpicture",this.onDisablePIP),e.removeEventListener("webkitpresentationmodechanged",this.onPresentationModeChange),this.shouldUseHLS(t)||e.removeEventListener("canplay",this.onReady)}shouldUseAudio(e){return e.config.forceVideo||e.config.attributes.poster?!1:c.AUDIO_EXTENSIONS.test(e.url)||e.config.forceAudio}shouldUseHLS(e){return V&&this.props.config.forceSafariHLS||this.props.config.forceHLS?!0:v||this.props.config.forceDisableHls?!1:c.HLS_EXTENSIONS.test(e)||f.test(e)}shouldUseDASH(e){return c.DASH_EXTENSIONS.test(e)||this.props.config.forceDASH}shouldUseFLV(e){return c.FLV_EXTENSIONS.test(e)||this.props.config.forceFLV}load(e){const{hlsVersion:t,hlsOptions:i,dashVersion:n,flvVersion:l}=this.props.config;if(this.hls&&this.hls.destroy(),this.dash&&this.dash.reset(),this.shouldUseHLS(e)&&(0,a.getSDK)(T.replace("VERSION",t),C).then(o=>{if(this.hls=new o(i),this.hls.on(o.Events.MANIFEST_PARSED,()=>{this.props.onReady()}),this.hls.on(o.Events.ERROR,(h,p)=>{this.props.onError(h,p,this.hls,o)}),f.test(e)){const h=e.match(f)[1];this.hls.loadSource(W.replace("{id}",h))}else this.hls.loadSource(e);this.hls.attachMedia(this.player),this.props.onLoaded()}),this.shouldUseDASH(e)&&(0,a.getSDK)(B.replace("VERSION",n),x).then(o=>{this.dash=o.MediaPlayer().create(),this.dash.initialize(this.player,e,this.props.playing),this.dash.on("error",this.props.onError),parseInt(n)<3?this.dash.getDebug().setLogToBrowserConsole(!1):this.dash.updateSettings({debug:{logLevel:o.Debug.LOG_LEVEL_NONE}}),this.props.onLoaded()}),this.shouldUseFLV(e)&&(0,a.getSDK)(K.replace("VERSION",l),G).then(o=>{this.flv=o.createPlayer({type:"flv",url:e}),this.flv.attachMediaElement(this.player),this.flv.on(o.Events.ERROR,(h,p)=>{this.props.onError(h,p,this.flv,o)}),this.flv.load(),this.props.onLoaded()}),e instanceof Array)this.player.load();else if((0,a.isMediaStream)(e))try{this.player.srcObject=e}catch{this.player.src=window.URL.createObjectURL(e)}}play(){const e=this.player.play();e&&e.catch(this.props.onError)}pause(){this.player.pause()}stop(){this.player.removeAttribute("src"),this.dash&&this.dash.reset()}seekTo(e,t=!0){this.player.currentTime=e,t||this.pause()}setVolume(e){this.player.volume=e}enablePIP(){this.player.requestPictureInPicture&&document.pictureInPictureElement!==this.player?this.player.requestPictureInPicture():(0,a.supportsWebKitPresentationMode)(this.player)&&this.player.webkitPresentationMode!=="picture-in-picture"&&this.player.webkitSetPresentationMode("picture-in-picture")}disablePIP(){document.exitPictureInPicture&&document.pictureInPictureElement===this.player?document.exitPictureInPicture():(0,a.supportsWebKitPresentationMode)(this.player)&&this.player.webkitPresentationMode!=="inline"&&this.player.webkitSetPresentationMode("inline")}setPlaybackRate(e){try{this.player.playbackRate=e}catch(t){this.props.onError(t)}}getDuration(){if(!this.player)return null;const{duration:e,seekable:t}=this.player;return e===1/0&&t.length>0?t.end(t.length-1):e}getCurrentTime(){return this.player?this.player.currentTime:null}getSecondsLoaded(){if(!this.player)return null;const{buffered:e}=this.player;if(e.length===0)return 0;const t=e.end(e.length-1),i=this.getDuration();return t>i?i:t}getSource(e){const t=this.shouldUseHLS(e),i=this.shouldUseDASH(e),n=this.shouldUseFLV(e);if(!(e instanceof Array||(0,a.isMediaStream)(e)||t||i||n))return X.test(e)?e.replace("www.dropbox.com","dl.dropboxusercontent.com"):e}render(){const{url:e,playing:t,loop:i,controls:n,muted:l,config:o,width:h,height:p}=this.props,L=this.shouldUseAudio(this.props)?"audio":"video",S={width:h==="auto"?h:"100%",height:p==="auto"?p:"100%"};return d.default.createElement(L,{ref:this.ref,src:this.getSource(e),style:S,preload:"auto",autoPlay:t||void 0,controls:n,muted:l,loop:i,...o.attributes},e instanceof Array&&e.map(this.renderSourceElement),o.tracks.map(this.renderTrack))}}r(P,"displayName","FilePlayer");r(P,"canPlay",c.canPlay.file);const z=b(g),J=R({__proto__:null,default:z},[g]);export{J as F};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{g as y,r as f,u as _,a as m}from"./index-DLRdQOIx.js";function P(r,e){for(var t=0;t<e.length;t++){const o=e[t];if(typeof o!="string"&&!Array.isArray(o)){for(const a in o)if(a!=="default"&&!(a in r)){const l=Object.getOwnPropertyDescriptor(o,a);l&&Object.defineProperty(r,a,l.get?l:{enumerable:!0,get:()=>o[a]})}}}return Object.freeze(Object.defineProperty(r,Symbol.toStringTag,{value:"Module"}))}var g=Object.create,n=Object.defineProperty,b=Object.getOwnPropertyDescriptor,v=Object.getOwnPropertyNames,O=Object.getPrototypeOf,w=Object.prototype.hasOwnProperty,j=(r,e,t)=>e in r?n(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,L=(r,e)=>{for(var t in e)n(r,t,{get:e[t],enumerable:!0})},c=(r,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of v(e))!w.call(r,a)&&a!==t&&n(r,a,{get:()=>e[a],enumerable:!(o=b(e,a))||o.enumerable});return r},K=(r,e,t)=>(t=r!=null?g(O(r)):{},c(!r||!r.__esModule?n(t,"default",{value:r,enumerable:!0}):t,r)),D=r=>c(n({},"__esModule",{value:!0}),r),s=(r,e,t)=>(j(r,typeof e!="symbol"?e+"":e,t),t),d={};L(d,{default:()=>i});var h=D(d),u=K(f),p=_,M=m;const S="https://cdn.embed.ly/player-0.1.0.min.js",T="playerjs";class i extends u.Component{constructor(){super(...arguments),s(this,"callPlayer",p.callPlayer),s(this,"duration",null),s(this,"currentTime",null),s(this,"secondsLoaded",null),s(this,"mute",()=>{this.callPlayer("mute")}),s(this,"unmute",()=>{this.callPlayer("unmute")}),s(this,"ref",e=>{this.iframe=e})}componentDidMount(){this.props.onMount&&this.props.onMount(this)}load(e){(0,p.getSDK)(S,T).then(t=>{this.iframe&&(this.player=new t.Player(this.iframe),this.player.on("ready",()=>{setTimeout(()=>{this.player.isReady=!0,this.player.setLoop(this.props.loop),this.props.muted&&this.player.mute(),this.addListeners(this.player,this.props),this.props.onReady()},500)}))},this.props.onError)}addListeners(e,t){e.on("play",t.onPlay),e.on("pause",t.onPause),e.on("ended",t.onEnded),e.on("error",t.onError),e.on("timeupdate",({duration:o,seconds:a})=>{this.duration=o,this.currentTime=a})}play(){this.callPlayer("play")}pause(){this.callPlayer("pause")}stop(){}seekTo(e,t=!0){this.callPlayer("setCurrentTime",e),t||this.pause()}setVolume(e){this.callPlayer("setVolume",e)}setLoop(e){this.callPlayer("setLoop",e)}getDuration(){return this.duration}getCurrentTime(){return this.currentTime}getSecondsLoaded(){return this.secondsLoaded}render(){const e={width:"100%",height:"100%"};return u.default.createElement("iframe",{ref:this.ref,src:this.props.url,frameBorder:"0",scrolling:"no",style:e,allow:"encrypted-media; autoplay; fullscreen;",referrerPolicy:"no-referrer-when-downgrade"})}}s(i,"displayName","Kaltura");s(i,"canPlay",M.canPlay.kaltura);const E=y(h),N=P({__proto__:null,default:E},[h]);export{N as K};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{g as _,r as f,u as m,a as g}from"./index-DLRdQOIx.js";function v(t,e){for(var r=0;r<e.length;r++){const s=e[r];if(typeof s!="string"&&!Array.isArray(s)){for(const o in s)if(o!=="default"&&!(o in t)){const n=Object.getOwnPropertyDescriptor(s,o);n&&Object.defineProperty(t,o,n.get?n:{enumerable:!0,get:()=>s[o]})}}}return Object.freeze(Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}))}var P=Object.create,i=Object.defineProperty,O=Object.getOwnPropertyDescriptor,b=Object.getOwnPropertyNames,M=Object.getPrototypeOf,w=Object.prototype.hasOwnProperty,x=(t,e,r)=>e in t?i(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,j=(t,e)=>{for(var r in e)i(t,r,{get:e[r],enumerable:!0})},c=(t,e,r,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of b(e))!w.call(t,o)&&o!==r&&i(t,o,{get:()=>e[o],enumerable:!(s=O(e,o))||s.enumerable});return t},D=(t,e,r)=>(r=t!=null?P(M(t)):{},c(!t||!t.__esModule?i(r,"default",{value:t,enumerable:!0}):r,t)),S=t=>c(i({},"__esModule",{value:!0}),t),a=(t,e,r)=>(x(t,typeof e!="symbol"?e+"":e,r),r),d={};j(d,{default:()=>l});var h=S(d),p=D(f),u=m,y=g;const E="https://widget.mixcloud.com/media/js/widgetApi.js",L="Mixcloud";class l extends p.Component{constructor(){super(...arguments),a(this,"callPlayer",u.callPlayer),a(this,"duration",null),a(this,"currentTime",null),a(this,"secondsLoaded",null),a(this,"mute",()=>{}),a(this,"unmute",()=>{}),a(this,"ref",e=>{this.iframe=e})}componentDidMount(){this.props.onMount&&this.props.onMount(this)}load(e){(0,u.getSDK)(E,L).then(r=>{this.player=r.PlayerWidget(this.iframe),this.player.ready.then(()=>{this.player.events.play.on(this.props.onPlay),this.player.events.pause.on(this.props.onPause),this.player.events.ended.on(this.props.onEnded),this.player.events.error.on(this.props.error),this.player.events.progress.on((s,o)=>{this.currentTime=s,this.duration=o}),this.props.onReady()})},this.props.onError)}play(){this.callPlayer("play")}pause(){this.callPlayer("pause")}stop(){}seekTo(e,r=!0){this.callPlayer("seek",e),r||this.pause()}setVolume(e){}getDuration(){return this.duration}getCurrentTime(){return this.currentTime}getSecondsLoaded(){return null}render(){const{url:e,config:r}=this.props,s=e.match(y.MATCH_URL_MIXCLOUD)[1],o={width:"100%",height:"100%"},n=(0,u.queryString)({...r.options,feed:`/${s}/`});return p.default.createElement("iframe",{key:s,ref:this.ref,style:o,src:`https://www.mixcloud.com/widget/iframe/?${n}`,frameBorder:"0",allow:"autoplay"})}}a(l,"displayName","Mixcloud");a(l,"canPlay",y.canPlay.mixcloud);a(l,"loopOnEnded",!0);const T=_(h),N=v({__proto__:null,default:T},[h]);export{N as M};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{g as m,_ as E,r as g,a as _}from"./index-DLRdQOIx.js";function b(r,e){for(var t=0;t<e.length;t++){const i=e[t];if(typeof i!="string"&&!Array.isArray(i)){for(const s in i)if(s!=="default"&&!(s in r)){const o=Object.getOwnPropertyDescriptor(i,s);o&&Object.defineProperty(r,s,o.get?o:{enumerable:!0,get:()=>i[s]})}}}return Object.freeze(Object.defineProperty(r,Symbol.toStringTag,{value:"Module"}))}var L=Object.create,u=Object.defineProperty,I=Object.getOwnPropertyDescriptor,k=Object.getOwnPropertyNames,O=Object.getPrototypeOf,x=Object.prototype.hasOwnProperty,M=(r,e,t)=>e in r?u(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,R=(r,e)=>{for(var t in e)u(r,t,{get:e[t],enumerable:!0})},f=(r,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of k(e))!x.call(r,s)&&s!==t&&u(r,s,{get:()=>e[s],enumerable:!(i=I(e,s))||i.enumerable});return r},w=(r,e,t)=>(t=r!=null?L(O(r)):{},f(!r||!r.__esModule?u(t,"default",{value:r,enumerable:!0}):t,r)),D=r=>f(u({},"__esModule",{value:!0}),r),n=(r,e,t)=>(M(r,typeof e!="symbol"?e+"":e,t),t),y={};R(y,{default:()=>l});var P=D(y),v=w(g),p=_;const j="https://cdn.jsdelivr.net/npm/@mux/mux-player@VERSION/dist/mux-player.mjs";class l extends v.Component{constructor(){super(...arguments),n(this,"onReady",(...e)=>this.props.onReady(...e)),n(this,"onPlay",(...e)=>this.props.onPlay(...e)),n(this,"onBuffer",(...e)=>this.props.onBuffer(...e)),n(this,"onBufferEnd",(...e)=>this.props.onBufferEnd(...e)),n(this,"onPause",(...e)=>this.props.onPause(...e)),n(this,"onEnded",(...e)=>this.props.onEnded(...e)),n(this,"onError",(...e)=>this.props.onError(...e)),n(this,"onPlayBackRateChange",e=>this.props.onPlaybackRateChange(e.target.playbackRate)),n(this,"onEnablePIP",(...e)=>this.props.onEnablePIP(...e)),n(this,"onSeek",e=>{this.props.onSeek(e.target.currentTime)}),n(this,"onDurationChange",()=>{const e=this.getDuration();this.props.onDuration(e)}),n(this,"mute",()=>{this.player.muted=!0}),n(this,"unmute",()=>{this.player.muted=!1}),n(this,"ref",e=>{this.player=e})}componentDidMount(){this.props.onMount&&this.props.onMount(this),this.addListeners(this.player);const e=this.getPlaybackId(this.props.url);e&&(this.player.playbackId=e)}componentWillUnmount(){this.player.playbackId=null,this.removeListeners(this.player)}addListeners(e){const{playsinline:t}=this.props;e.addEventListener("play",this.onPlay),e.addEventListener("waiting",this.onBuffer),e.addEventListener("playing",this.onBufferEnd),e.addEventListener("pause",this.onPause),e.addEventListener("seeked",this.onSeek),e.addEventListener("ended",this.onEnded),e.addEventListener("error",this.onError),e.addEventListener("ratechange",this.onPlayBackRateChange),e.addEventListener("enterpictureinpicture",this.onEnablePIP),e.addEventListener("leavepictureinpicture",this.onDisablePIP),e.addEventListener("webkitpresentationmodechanged",this.onPresentationModeChange),e.addEventListener("canplay",this.onReady),t&&e.setAttribute("playsinline","")}removeListeners(e){e.removeEventListener("canplay",this.onReady),e.removeEventListener("play",this.onPlay),e.removeEventListener("waiting",this.onBuffer),e.removeEventListener("playing",this.onBufferEnd),e.removeEventListener("pause",this.onPause),e.removeEventListener("seeked",this.onSeek),e.removeEventListener("ended",this.onEnded),e.removeEventListener("error",this.onError),e.removeEventListener("ratechange",this.onPlayBackRateChange),e.removeEventListener("enterpictureinpicture",this.onEnablePIP),e.removeEventListener("leavepictureinpicture",this.onDisablePIP),e.removeEventListener("canplay",this.onReady)}async load(e){var t;const{onError:i,config:s}=this.props;if(!((t=globalThis.customElements)!=null&&t.get("mux-player")))try{const a=j.replace("VERSION",s.version);await E(()=>import(`${a}`),[]),this.props.onLoaded()}catch(a){i(a)}const[,o]=e.match(p.MATCH_URL_MUX);this.player.playbackId=o}play(){const e=this.player.play();e&&e.catch(this.props.onError)}pause(){this.player.pause()}stop(){this.player.playbackId=null}seekTo(e,t=!0){this.player.currentTime=e,t||this.pause()}setVolume(e){this.player.volume=e}enablePIP(){this.player.requestPictureInPicture&&document.pictureInPictureElement!==this.player&&this.player.requestPictureInPicture()}disablePIP(){document.exitPictureInPicture&&document.pictureInPictureElement===this.player&&document.exitPictureInPicture()}setPlaybackRate(e){try{this.player.playbackRate=e}catch(t){this.props.onError(t)}}getDuration(){if(!this.player)return null;const{duration:e,seekable:t}=this.player;return e===1/0&&t.length>0?t.end(t.length-1):e}getCurrentTime(){return this.player?this.player.currentTime:null}getSecondsLoaded(){if(!this.player)return null;const{buffered:e}=this.player;if(e.length===0)return 0;const t=e.end(e.length-1),i=this.getDuration();return t>i?i:t}getPlaybackId(e){const[,t]=e.match(p.MATCH_URL_MUX);return t}render(){const{url:e,playing:t,loop:i,controls:s,muted:o,config:a,width:h,height:c}=this.props,d={width:h==="auto"?h:"100%",height:c==="auto"?c:"100%"};return s===!1&&(d["--controls"]="none"),v.default.createElement("mux-player",{ref:this.ref,"playback-id":this.getPlaybackId(e),style:d,preload:"auto",autoPlay:t||void 0,muted:o?"":void 0,loop:i?"":void 0,...a.attributes})}}n(l,"displayName","Mux");n(l,"canPlay",p.canPlay.mux);const C=m(P),B=b({__proto__:null,default:C},[P]);export{B as M};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{g as y,r as v}from"./index-DLRdQOIx.js";function w(r,e){for(var t=0;t<e.length;t++){const n=e[t];if(typeof n!="string"&&!Array.isArray(n)){for(const a in n)if(a!=="default"&&!(a in r)){const o=Object.getOwnPropertyDescriptor(n,a);o&&Object.defineProperty(r,a,o.get?o:{enumerable:!0,get:()=>n[a]})}}}return Object.freeze(Object.defineProperty(r,Symbol.toStringTag,{value:"Module"}))}var P=Object.create,s=Object.defineProperty,O=Object.getOwnPropertyDescriptor,x=Object.getOwnPropertyNames,I=Object.getPrototypeOf,j=Object.prototype.hasOwnProperty,E=(r,e,t)=>e in r?s(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,S=(r,e)=>{for(var t in e)s(r,t,{get:e[t],enumerable:!0})},_=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of x(e))!j.call(r,a)&&a!==t&&s(r,a,{get:()=>e[a],enumerable:!(n=O(e,a))||n.enumerable});return r},C=(r,e,t)=>(t=r!=null?P(I(r)):{},_(!r||!r.__esModule?s(t,"default",{value:r,enumerable:!0}):t,r)),N=r=>_(s({},"__esModule",{value:!0}),r),p=(r,e,t)=>(E(r,typeof e!="symbol"?e+"":e,t),t),g={};S(g,{default:()=>k});var m=N(g),i=C(v);const u="64px",d={};class k extends i.Component{constructor(){super(...arguments),p(this,"mounted",!1),p(this,"state",{image:null}),p(this,"handleKeyPress",e=>{(e.key==="Enter"||e.key===" ")&&this.props.onClick()})}componentDidMount(){this.mounted=!0,this.fetchImage(this.props)}componentDidUpdate(e){const{url:t,light:n}=this.props;(e.url!==t||e.light!==n)&&this.fetchImage(this.props)}componentWillUnmount(){this.mounted=!1}fetchImage({url:e,light:t,oEmbedUrl:n}){if(!i.default.isValidElement(t)){if(typeof t=="string"){this.setState({image:t});return}if(d[e]){this.setState({image:d[e]});return}return this.setState({image:null}),window.fetch(n.replace("{url}",e)).then(a=>a.json()).then(a=>{if(a.thumbnail_url&&this.mounted){const o=a.thumbnail_url.replace("height=100","height=480").replace("-d_295x166","-d_640");this.setState({image:o}),d[e]=o}})}}render(){const{light:e,onClick:t,playIcon:n,previewTabIndex:a,previewAriaLabel:o}=this.props,{image:f}=this.state,l=i.default.isValidElement(e),h={display:"flex",alignItems:"center",justifyContent:"center"},c={preview:{width:"100%",height:"100%",backgroundImage:f&&!l?`url(${f})`:void 0,backgroundSize:"cover",backgroundPosition:"center",cursor:"pointer",...h},shadow:{background:"radial-gradient(rgb(0, 0, 0, 0.3), rgba(0, 0, 0, 0) 60%)",borderRadius:u,width:u,height:u,position:l?"absolute":void 0,...h},playIcon:{borderStyle:"solid",borderWidth:"16px 0 16px 26px",borderColor:"transparent transparent transparent white",marginLeft:"7px"}},b=i.default.createElement("div",{style:c.shadow,className:"react-player__shadow"},i.default.createElement("div",{style:c.playIcon,className:"react-player__play-icon"}));return i.default.createElement("div",{style:c.preview,className:"react-player__preview",onClick:t,tabIndex:a,onKeyPress:this.handleKeyPress,...o?{"aria-label":o}:{}},l?e:null,n||b)}}const D=y(m),A=w({__proto__:null,default:D},[m]);export{A as P};
|