chainlit 2.0.0__py3-none-any.whl → 2.0.dev1__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 +57 -55
- chainlit/action.py +10 -12
- chainlit/{auth/__init__.py → auth.py} +34 -20
- chainlit/cache.py +1 -2
- chainlit/callbacks.py +7 -52
- chainlit/chat_context.py +2 -2
- chainlit/chat_settings.py +1 -3
- chainlit/cli/__init__.py +1 -14
- chainlit/config.py +69 -35
- chainlit/context.py +2 -3
- chainlit/copilot/dist/index.js +935 -8533
- chainlit/data/__init__.py +8 -96
- chainlit/data/acl.py +2 -3
- chainlit/data/base.py +1 -1
- chainlit/data/dynamodb.py +3 -5
- chainlit/data/literalai.py +6 -4
- chainlit/data/sql_alchemy.py +7 -8
- chainlit/data/storage_clients/azure.py +0 -1
- chainlit/data/storage_clients/base.py +0 -6
- chainlit/data/storage_clients/s3.py +3 -16
- chainlit/discord/app.py +1 -2
- chainlit/element.py +9 -13
- chainlit/emitter.py +21 -17
- chainlit/frontend/dist/assets/{DailyMotion-DgRzV5GZ.js → DailyMotion-D1ipkdPJ.js} +1 -1
- chainlit/frontend/dist/assets/{Facebook-C0vx6HWv.js → Facebook-d4TLeTik.js} +1 -1
- chainlit/frontend/dist/assets/{FilePlayer-CdhzeHPP.js → FilePlayer-BcU7tttX.js} +1 -1
- chainlit/frontend/dist/assets/{Kaltura-5iVmeUct.js → Kaltura-DdaRjZrh.js} +1 -1
- chainlit/frontend/dist/assets/{Mixcloud-C2zi77Ex.js → Mixcloud-BaJoMsaU.js} +1 -1
- chainlit/frontend/dist/assets/{Mux-Vkebogdf.js → Mux-DxPCM5d3.js} +1 -1
- chainlit/frontend/dist/assets/{Preview-DwY_sEIl.js → Preview-tUK_Z9pZ.js} +1 -1
- chainlit/frontend/dist/assets/{SoundCloud-CREBXAWo.js → SoundCloud-K8-lFZC6.js} +1 -1
- chainlit/frontend/dist/assets/{Streamable-B5Lu25uy.js → Streamable-hB-AQ54w.js} +1 -1
- chainlit/frontend/dist/assets/{Twitch-y9iKCcM1.js → Twitch-pmuNY0J5.js} +1 -1
- chainlit/frontend/dist/assets/{Vidyard-ClYvcuEu.js → Vidyard-BSUm6trV.js} +1 -1
- chainlit/frontend/dist/assets/{Vimeo-D6HvM2jt.js → Vimeo-JIPn71zS.js} +1 -1
- chainlit/frontend/dist/assets/Wistia-D75KkqOG.js +1 -0
- chainlit/frontend/dist/assets/{YouTube-D10tR6CJ.js → YouTube-CPlwqNm_.js} +1 -1
- chainlit/frontend/dist/assets/index-CuSbXjG5.js +1091 -0
- chainlit/frontend/dist/assets/index-CwmincdQ.css +1 -0
- chainlit/frontend/dist/assets/{react-plotly-BpxUS-ab.js → react-plotly-DALmanjC.js} +1 -1
- chainlit/frontend/dist/index.html +2 -2
- chainlit/haystack/callbacks.py +4 -5
- chainlit/input_widget.py +4 -6
- chainlit/langchain/callbacks.py +47 -56
- chainlit/langflow/__init__.py +0 -1
- chainlit/llama_index/callbacks.py +7 -7
- chainlit/message.py +7 -6
- chainlit/mistralai/__init__.py +2 -3
- chainlit/oauth_providers.py +3 -70
- chainlit/openai/__init__.py +2 -3
- chainlit/secret.py +1 -1
- chainlit/server.py +174 -474
- chainlit/session.py +5 -7
- chainlit/slack/app.py +2 -3
- chainlit/socket.py +103 -78
- chainlit/step.py +11 -11
- chainlit/sync.py +1 -2
- chainlit/teams/app.py +0 -1
- chainlit/types.py +4 -20
- chainlit/user.py +1 -2
- chainlit/utils.py +2 -3
- {chainlit-2.0.0.dist-info → chainlit-2.0.dev1.dist-info}/METADATA +38 -8
- chainlit-2.0.dev1.dist-info/RECORD +99 -0
- chainlit/auth/cookie.py +0 -123
- chainlit/auth/jwt.py +0 -37
- chainlit/data/chainlit_data_layer.py +0 -584
- chainlit/data/storage_clients/azure_blob.py +0 -80
- chainlit/data/storage_clients/gcs.py +0 -78
- chainlit/frontend/dist/assets/Dataframe-DVgwSMU2.js +0 -22
- chainlit/frontend/dist/assets/Wistia-Cu4zZ2Ci.js +0 -1
- chainlit/frontend/dist/assets/index-CI4qFOt5.js +0 -8665
- chainlit/frontend/dist/assets/index-CrrqM0nZ.css +0 -1
- chainlit/translations/nl-NL.json +0 -229
- chainlit-2.0.0.dist-info/RECORD +0 -106
- {chainlit-2.0.0.dist-info → chainlit-2.0.dev1.dist-info}/WHEEL +0 -0
- {chainlit-2.0.0.dist-info → chainlit-2.0.dev1.dist-info}/entry_points.txt +0 -0
chainlit/data/__init__.py
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import os
|
|
2
|
-
import warnings
|
|
3
2
|
from typing import Optional
|
|
4
3
|
|
|
5
4
|
from .base import BaseDataLayer
|
|
@@ -8,106 +7,19 @@ from .utils import (
|
|
|
8
7
|
)
|
|
9
8
|
|
|
10
9
|
_data_layer: Optional[BaseDataLayer] = None
|
|
11
|
-
_data_layer_initialized = False
|
|
12
10
|
|
|
13
11
|
|
|
14
12
|
def get_data_layer():
|
|
15
|
-
global _data_layer
|
|
13
|
+
global _data_layer
|
|
16
14
|
|
|
17
|
-
if not
|
|
18
|
-
if
|
|
19
|
-
|
|
15
|
+
if not _data_layer:
|
|
16
|
+
if api_key := os.environ.get("LITERAL_API_KEY"):
|
|
17
|
+
from .literalai import LiteralDataLayer
|
|
20
18
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
# support legacy LITERAL_SERVER variable as fallback
|
|
20
|
+
server = os.environ.get("LITERAL_API_URL") or os.environ.get(
|
|
21
|
+
"LITERAL_SERVER"
|
|
24
22
|
)
|
|
25
|
-
|
|
26
|
-
else:
|
|
27
|
-
from chainlit.config import config
|
|
28
|
-
|
|
29
|
-
if config.code.data_layer:
|
|
30
|
-
# When @data_layer is configured, call it to get data layer.
|
|
31
|
-
_data_layer = config.code.data_layer()
|
|
32
|
-
elif database_url := os.environ.get("DATABASE_URL"):
|
|
33
|
-
# Default to Chainlit data layer if DATABASE_URL specified.
|
|
34
|
-
from .chainlit_data_layer import ChainlitDataLayer
|
|
35
|
-
|
|
36
|
-
if os.environ.get("LITERAL_API_KEY"):
|
|
37
|
-
warnings.warn(
|
|
38
|
-
"Both LITERAL_API_KEY and DATABASE_URL specified. Ignoring Literal AI data layer and relying on data layer pointing to DATABASE_URL."
|
|
39
|
-
)
|
|
40
|
-
bucket_name = os.environ.get("BUCKET_NAME")
|
|
41
|
-
|
|
42
|
-
# AWS S3
|
|
43
|
-
aws_region = os.getenv("APP_AWS_REGION")
|
|
44
|
-
aws_access_key = os.getenv("APP_AWS_ACCESS_KEY")
|
|
45
|
-
aws_secret_key = os.getenv("APP_AWS_SECRET_KEY")
|
|
46
|
-
dev_aws_endpoint = os.getenv("DEV_AWS_ENDPOINT")
|
|
47
|
-
is_using_s3 = bool(aws_access_key and aws_secret_key and aws_region)
|
|
48
|
-
|
|
49
|
-
# Google Cloud Storage
|
|
50
|
-
gcs_project_id = os.getenv("APP_GCS_PROJECT_ID")
|
|
51
|
-
gcs_client_email = os.getenv("APP_GCS_CLIENT_EMAIL")
|
|
52
|
-
gcs_private_key = os.getenv("APP_GCS_PRIVATE_KEY")
|
|
53
|
-
is_using_gcs = bool(
|
|
54
|
-
gcs_project_id and gcs_client_email and gcs_private_key
|
|
55
|
-
)
|
|
56
|
-
|
|
57
|
-
# Azure Storage
|
|
58
|
-
azure_storage_account = os.getenv("APP_AZURE_STORAGE_ACCOUNT")
|
|
59
|
-
azure_storage_key = os.getenv("APP_AZURE_STORAGE_ACCESS_KEY")
|
|
60
|
-
is_using_azure = bool(azure_storage_account and azure_storage_key)
|
|
61
|
-
|
|
62
|
-
storage_client = None
|
|
63
|
-
|
|
64
|
-
if sum([is_using_s3, is_using_gcs, is_using_azure]) > 1:
|
|
65
|
-
warnings.warn(
|
|
66
|
-
"Multiple storage configurations detected. Please use only one."
|
|
67
|
-
)
|
|
68
|
-
elif is_using_s3:
|
|
69
|
-
from chainlit.data.storage_clients.s3 import S3StorageClient
|
|
70
|
-
|
|
71
|
-
storage_client = S3StorageClient(
|
|
72
|
-
bucket=bucket_name,
|
|
73
|
-
region_name=aws_region,
|
|
74
|
-
aws_access_key_id=aws_access_key,
|
|
75
|
-
aws_secret_access_key=aws_secret_key,
|
|
76
|
-
endpoint_url=dev_aws_endpoint,
|
|
77
|
-
)
|
|
78
|
-
elif is_using_gcs:
|
|
79
|
-
from chainlit.data.storage_clients.gcs import GCSStorageClient
|
|
80
|
-
|
|
81
|
-
storage_client = GCSStorageClient(
|
|
82
|
-
project_id=gcs_project_id,
|
|
83
|
-
client_email=gcs_client_email,
|
|
84
|
-
private_key=gcs_private_key,
|
|
85
|
-
bucket_name=bucket_name,
|
|
86
|
-
)
|
|
87
|
-
elif is_using_azure:
|
|
88
|
-
from chainlit.data.storage_clients.azure_blob import (
|
|
89
|
-
AzureBlobStorageClient,
|
|
90
|
-
)
|
|
91
|
-
|
|
92
|
-
storage_client = AzureBlobStorageClient(
|
|
93
|
-
container_name=bucket_name,
|
|
94
|
-
storage_account=azure_storage_account,
|
|
95
|
-
storage_key=azure_storage_key,
|
|
96
|
-
)
|
|
97
|
-
|
|
98
|
-
_data_layer = ChainlitDataLayer(
|
|
99
|
-
database_url=database_url, storage_client=storage_client
|
|
100
|
-
)
|
|
101
|
-
elif api_key := os.environ.get("LITERAL_API_KEY"):
|
|
102
|
-
# When LITERAL_API_KEY is defined, use Literal AI data layer
|
|
103
|
-
from .literalai import LiteralDataLayer
|
|
104
|
-
|
|
105
|
-
# support legacy LITERAL_SERVER variable as fallback
|
|
106
|
-
server = os.environ.get("LITERAL_API_URL") or os.environ.get(
|
|
107
|
-
"LITERAL_SERVER"
|
|
108
|
-
)
|
|
109
|
-
_data_layer = LiteralDataLayer(api_key=api_key, server=server)
|
|
110
|
-
|
|
111
|
-
_data_layer_initialized = True
|
|
23
|
+
_data_layer = LiteralDataLayer(api_key=api_key, server=server)
|
|
112
24
|
|
|
113
25
|
return _data_layer
|
chainlit/data/acl.py
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
from fastapi import HTTPException
|
|
2
|
-
|
|
3
1
|
from chainlit.data import get_data_layer
|
|
2
|
+
from fastapi import HTTPException
|
|
4
3
|
|
|
5
4
|
|
|
6
5
|
async def is_thread_author(username: str, thread_id: str):
|
|
@@ -9,7 +8,7 @@ async def is_thread_author(username: str, thread_id: str):
|
|
|
9
8
|
raise HTTPException(status_code=400, detail="Data layer not initialized")
|
|
10
9
|
|
|
11
10
|
thread_author = await data_layer.get_thread_author(thread_id)
|
|
12
|
-
|
|
11
|
+
|
|
13
12
|
if not thread_author:
|
|
14
13
|
raise HTTPException(status_code=404, detail="Thread not found")
|
|
15
14
|
|
chainlit/data/base.py
CHANGED
chainlit/data/dynamodb.py
CHANGED
|
@@ -11,7 +11,6 @@ import aiofiles
|
|
|
11
11
|
import aiohttp
|
|
12
12
|
import boto3 # type: ignore
|
|
13
13
|
from boto3.dynamodb.types import TypeDeserializer, TypeSerializer
|
|
14
|
-
|
|
15
14
|
from chainlit.context import context
|
|
16
15
|
from chainlit.data.base import BaseDataLayer
|
|
17
16
|
from chainlit.data.storage_clients.base import BaseStorageClient
|
|
@@ -30,9 +29,8 @@ from chainlit.types import (
|
|
|
30
29
|
from chainlit.user import PersistedUser, User
|
|
31
30
|
|
|
32
31
|
if TYPE_CHECKING:
|
|
33
|
-
from mypy_boto3_dynamodb import DynamoDBClient
|
|
34
|
-
|
|
35
32
|
from chainlit.element import Element
|
|
33
|
+
from mypy_boto3_dynamodb import DynamoDBClient
|
|
36
34
|
|
|
37
35
|
|
|
38
36
|
_logger = logger.getChild("DynamoDB")
|
|
@@ -404,7 +402,7 @@ class DynamoDBDataLayer(BaseDataLayer):
|
|
|
404
402
|
|
|
405
403
|
BATCH_ITEM_SIZE = 25 # pylint: disable=invalid-name
|
|
406
404
|
for i in range(0, len(delete_requests), BATCH_ITEM_SIZE):
|
|
407
|
-
chunk = delete_requests[i : i + BATCH_ITEM_SIZE]
|
|
405
|
+
chunk = delete_requests[i : i + BATCH_ITEM_SIZE] # noqa: E203
|
|
408
406
|
response = self.client.batch_write_item(
|
|
409
407
|
RequestItems={
|
|
410
408
|
self.table_name: chunk, # type: ignore
|
|
@@ -412,7 +410,7 @@ class DynamoDBDataLayer(BaseDataLayer):
|
|
|
412
410
|
)
|
|
413
411
|
|
|
414
412
|
backoff_time = 1
|
|
415
|
-
while response
|
|
413
|
+
while "UnprocessedItems" in response and response["UnprocessedItems"]:
|
|
416
414
|
backoff_time *= 2
|
|
417
415
|
# Cap the backoff time at 32 seconds & add jitter
|
|
418
416
|
delay = min(backoff_time, 32) + random.uniform(0, 1)
|
chainlit/data/literalai.py
CHANGED
|
@@ -94,6 +94,7 @@ class LiteralToChainlitConverter:
|
|
|
94
94
|
"input": input,
|
|
95
95
|
"output": output,
|
|
96
96
|
"showInput": metadata.get("showInput", False),
|
|
97
|
+
"indent": metadata.get("indent"),
|
|
97
98
|
"language": metadata.get("language"),
|
|
98
99
|
"isError": bool(step.error),
|
|
99
100
|
"waitForAnswer": metadata.get("waitForAnswer", False),
|
|
@@ -109,7 +110,6 @@ class LiteralToChainlitConverter:
|
|
|
109
110
|
"autoPlay": metadata.get("autoPlay", None),
|
|
110
111
|
"playerConfig": metadata.get("playerConfig", None),
|
|
111
112
|
"page": metadata.get("page"),
|
|
112
|
-
"props": metadata.get("props"),
|
|
113
113
|
"size": metadata.get("size"),
|
|
114
114
|
"type": metadata.get("type", "file"),
|
|
115
115
|
"forId": attachment.step_id,
|
|
@@ -349,9 +349,11 @@ class LiteralDataLayer(BaseDataLayer):
|
|
|
349
349
|
async def create_step(self, step_dict: "StepDict"):
|
|
350
350
|
metadata = dict(
|
|
351
351
|
step_dict.get("metadata", {}),
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
352
|
+
**{
|
|
353
|
+
"waitForAnswer": step_dict.get("waitForAnswer"),
|
|
354
|
+
"language": step_dict.get("language"),
|
|
355
|
+
"showInput": step_dict.get("showInput"),
|
|
356
|
+
},
|
|
355
357
|
)
|
|
356
358
|
|
|
357
359
|
step: LiteralStepDict = {
|
chainlit/data/sql_alchemy.py
CHANGED
|
@@ -7,11 +7,6 @@ from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union
|
|
|
7
7
|
|
|
8
8
|
import aiofiles
|
|
9
9
|
import aiohttp
|
|
10
|
-
from sqlalchemy import text
|
|
11
|
-
from sqlalchemy.exc import SQLAlchemyError
|
|
12
|
-
from sqlalchemy.ext.asyncio import AsyncEngine, AsyncSession, create_async_engine
|
|
13
|
-
from sqlalchemy.orm import sessionmaker
|
|
14
|
-
|
|
15
10
|
from chainlit.data.base import BaseDataLayer
|
|
16
11
|
from chainlit.data.storage_clients.base import BaseStorageClient
|
|
17
12
|
from chainlit.data.utils import queue_until_user_message
|
|
@@ -28,6 +23,10 @@ from chainlit.types import (
|
|
|
28
23
|
ThreadFilter,
|
|
29
24
|
)
|
|
30
25
|
from chainlit.user import PersistedUser, User
|
|
26
|
+
from sqlalchemy import text
|
|
27
|
+
from sqlalchemy.exc import SQLAlchemyError
|
|
28
|
+
from sqlalchemy.ext.asyncio import AsyncEngine, AsyncSession, create_async_engine
|
|
29
|
+
from sqlalchemy.orm import sessionmaker
|
|
31
30
|
|
|
32
31
|
if TYPE_CHECKING:
|
|
33
32
|
from chainlit.element import Element, ElementDict
|
|
@@ -168,7 +167,7 @@ class SQLAlchemyDataLayer(BaseDataLayer):
|
|
|
168
167
|
async def create_user(self, user: User) -> Optional[PersistedUser]:
|
|
169
168
|
if self.show_logger:
|
|
170
169
|
logger.info(f"SQLAlchemy: create_user, user_identifier={user.identifier}")
|
|
171
|
-
existing_user: Optional[PersistedUser] = await self.get_user(user.identifier)
|
|
170
|
+
existing_user: Optional["PersistedUser"] = await self.get_user(user.identifier)
|
|
172
171
|
user_dict: Dict[str, Any] = {
|
|
173
172
|
"identifier": str(user.identifier),
|
|
174
173
|
"metadata": json.dumps(user.metadata) or {},
|
|
@@ -439,7 +438,6 @@ class SQLAlchemyDataLayer(BaseDataLayer):
|
|
|
439
438
|
url=element_dict.get("url"),
|
|
440
439
|
objectKey=element_dict.get("objectKey"),
|
|
441
440
|
name=element_dict["name"],
|
|
442
|
-
props=element_dict.get("props"),
|
|
443
441
|
display=element_dict["display"],
|
|
444
442
|
size=element_dict.get("size"),
|
|
445
443
|
language=element_dict.get("language"),
|
|
@@ -578,6 +576,7 @@ class SQLAlchemyDataLayer(BaseDataLayer):
|
|
|
578
576
|
s."generation" AS step_generation,
|
|
579
577
|
s."showInput" AS step_showinput,
|
|
580
578
|
s."language" AS step_language,
|
|
579
|
+
s."indent" AS step_indent,
|
|
581
580
|
f."value" AS feedback_value,
|
|
582
581
|
f."comment" AS feedback_comment,
|
|
583
582
|
f."id" AS feedback_id
|
|
@@ -665,6 +664,7 @@ class SQLAlchemyDataLayer(BaseDataLayer):
|
|
|
665
664
|
generation=step_feedback.get("step_generation"),
|
|
666
665
|
showInput=step_feedback.get("step_showinput"),
|
|
667
666
|
language=step_feedback.get("step_language"),
|
|
667
|
+
indent=step_feedback.get("step_indent"),
|
|
668
668
|
feedback=feedback,
|
|
669
669
|
)
|
|
670
670
|
# Append the step to the steps list of the corresponding ThreadDict
|
|
@@ -688,7 +688,6 @@ class SQLAlchemyDataLayer(BaseDataLayer):
|
|
|
688
688
|
autoPlay=element.get("element_autoPlay"),
|
|
689
689
|
playerConfig=element.get("element_playerconfig"),
|
|
690
690
|
page=element.get("element_page"),
|
|
691
|
-
props=element.get("element_props"),
|
|
692
691
|
forId=element.get("element_forid"),
|
|
693
692
|
mime=element.get("element_mime"),
|
|
694
693
|
)
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
from abc import ABC, abstractmethod
|
|
2
2
|
from typing import Any, Dict, Union
|
|
3
3
|
|
|
4
|
-
EXPIRY_TIME = 3600
|
|
5
|
-
|
|
6
4
|
|
|
7
5
|
class BaseStorageClient(ABC):
|
|
8
6
|
"""Base class for non-text data persistence like Azure Data Lake, S3, Google Storage, etc."""
|
|
@@ -16,7 +14,3 @@ class BaseStorageClient(ABC):
|
|
|
16
14
|
overwrite: bool = True,
|
|
17
15
|
) -> Dict[str, Any]:
|
|
18
16
|
pass
|
|
19
|
-
|
|
20
|
-
@abstractmethod
|
|
21
|
-
async def get_read_url(self, object_key: str) -> str:
|
|
22
|
-
pass
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
from typing import Any, Dict, Union
|
|
2
2
|
|
|
3
3
|
import boto3 # type: ignore
|
|
4
|
-
|
|
5
|
-
from chainlit.data.storage_clients.base import EXPIRY_TIME, BaseStorageClient
|
|
4
|
+
from chainlit.data.storage_clients.base import BaseStorageClient
|
|
6
5
|
from chainlit.logger import logger
|
|
7
6
|
|
|
8
7
|
|
|
@@ -11,26 +10,14 @@ class S3StorageClient(BaseStorageClient):
|
|
|
11
10
|
Class to enable Amazon S3 storage provider
|
|
12
11
|
"""
|
|
13
12
|
|
|
14
|
-
def __init__(self, bucket: str
|
|
13
|
+
def __init__(self, bucket: str):
|
|
15
14
|
try:
|
|
16
15
|
self.bucket = bucket
|
|
17
|
-
self.client = boto3.client("s3"
|
|
16
|
+
self.client = boto3.client("s3")
|
|
18
17
|
logger.info("S3StorageClient initialized")
|
|
19
18
|
except Exception as e:
|
|
20
19
|
logger.warn(f"S3StorageClient initialization error: {e}")
|
|
21
20
|
|
|
22
|
-
async def get_read_url(self, object_key: str) -> str:
|
|
23
|
-
try:
|
|
24
|
-
url = self.client.generate_presigned_url(
|
|
25
|
-
"get_object",
|
|
26
|
-
Params={"Bucket": self.bucket, "Key": object_key},
|
|
27
|
-
ExpiresIn=EXPIRY_TIME,
|
|
28
|
-
)
|
|
29
|
-
return url
|
|
30
|
-
except Exception as e:
|
|
31
|
-
logger.warn(f"S3StorageClient, get_read_url error: {e}")
|
|
32
|
-
return object_key
|
|
33
|
-
|
|
34
21
|
async def upload_file(
|
|
35
22
|
self,
|
|
36
23
|
object_key: str,
|
chainlit/discord/app.py
CHANGED
|
@@ -12,8 +12,6 @@ if TYPE_CHECKING:
|
|
|
12
12
|
import discord
|
|
13
13
|
import filetype
|
|
14
14
|
import httpx
|
|
15
|
-
from discord.ui import Button, View
|
|
16
|
-
|
|
17
15
|
from chainlit.config import config
|
|
18
16
|
from chainlit.context import ChainlitContext, HTTPSession, context, context_var
|
|
19
17
|
from chainlit.data import get_data_layer
|
|
@@ -25,6 +23,7 @@ from chainlit.telemetry import trace
|
|
|
25
23
|
from chainlit.types import Feedback
|
|
26
24
|
from chainlit.user import PersistedUser, User
|
|
27
25
|
from chainlit.user_session import user_session
|
|
26
|
+
from discord.ui import Button, View
|
|
28
27
|
|
|
29
28
|
|
|
30
29
|
class FeedbackView(View):
|
chainlit/element.py
CHANGED
|
@@ -16,15 +16,13 @@ from typing import (
|
|
|
16
16
|
)
|
|
17
17
|
|
|
18
18
|
import filetype
|
|
19
|
-
from pydantic import Field
|
|
20
|
-
from pydantic.dataclasses import dataclass
|
|
21
|
-
from syncer import asyncio
|
|
22
|
-
|
|
23
19
|
from chainlit.context import context
|
|
24
20
|
from chainlit.data import get_data_layer
|
|
25
21
|
from chainlit.logger import logger
|
|
26
22
|
from chainlit.telemetry import trace_event
|
|
27
23
|
from chainlit.types import FileDict
|
|
24
|
+
from pydantic.dataclasses import Field, dataclass
|
|
25
|
+
from syncer import asyncio
|
|
28
26
|
|
|
29
27
|
mime_types = {
|
|
30
28
|
"text": "text/plain",
|
|
@@ -42,7 +40,7 @@ ElementType = Literal[
|
|
|
42
40
|
"file",
|
|
43
41
|
"plotly",
|
|
44
42
|
"dataframe",
|
|
45
|
-
"
|
|
43
|
+
"component",
|
|
46
44
|
]
|
|
47
45
|
ElementDisplay = Literal["inline", "side", "page"]
|
|
48
46
|
ElementSize = Literal["small", "medium", "large"]
|
|
@@ -60,7 +58,6 @@ class ElementDict(TypedDict):
|
|
|
60
58
|
size: Optional[ElementSize]
|
|
61
59
|
language: Optional[str]
|
|
62
60
|
page: Optional[int]
|
|
63
|
-
props: Optional[Dict]
|
|
64
61
|
autoPlay: Optional[bool]
|
|
65
62
|
playerConfig: Optional[dict]
|
|
66
63
|
forId: Optional[str]
|
|
@@ -118,7 +115,6 @@ class Element:
|
|
|
118
115
|
"display": self.display,
|
|
119
116
|
"objectKey": getattr(self, "object_key", None),
|
|
120
117
|
"size": getattr(self, "size", None),
|
|
121
|
-
"props": getattr(self, "props", None),
|
|
122
118
|
"page": getattr(self, "page", None),
|
|
123
119
|
"autoPlay": getattr(self, "auto_play", None),
|
|
124
120
|
"playerConfig": getattr(self, "player_config", None),
|
|
@@ -158,7 +154,7 @@ class Element:
|
|
|
158
154
|
try:
|
|
159
155
|
asyncio.create_task(data_layer.create_element(self))
|
|
160
156
|
except Exception as e:
|
|
161
|
-
logger.error(f"Failed to create element: {e
|
|
157
|
+
logger.error(f"Failed to create element: {str(e)}")
|
|
162
158
|
if not self.url and (not self.chainlit_key or self.updatable):
|
|
163
159
|
file_dict = await context.session.persist_file(
|
|
164
160
|
name=self.name,
|
|
@@ -356,7 +352,8 @@ class Plotly(Element):
|
|
|
356
352
|
content: str = ""
|
|
357
353
|
|
|
358
354
|
def __post_init__(self) -> None:
|
|
359
|
-
from plotly import graph_objects as go
|
|
355
|
+
from plotly import graph_objects as go
|
|
356
|
+
from plotly import io as pio
|
|
360
357
|
|
|
361
358
|
if not isinstance(self.figure, go.Figure):
|
|
362
359
|
raise TypeError("figure must be a plotly.graph_objects.Figure")
|
|
@@ -390,15 +387,14 @@ class Dataframe(Element):
|
|
|
390
387
|
|
|
391
388
|
|
|
392
389
|
@dataclass
|
|
393
|
-
class
|
|
394
|
-
"""Useful to send a custom
|
|
390
|
+
class Component(Element):
|
|
391
|
+
"""Useful to send a custom component to the UI."""
|
|
395
392
|
|
|
396
|
-
type: ClassVar[ElementType] = "
|
|
393
|
+
type: ClassVar[ElementType] = "component"
|
|
397
394
|
mime: str = "application/json"
|
|
398
395
|
props: Dict = Field(default_factory=dict)
|
|
399
396
|
|
|
400
397
|
def __post_init__(self) -> None:
|
|
401
398
|
self.content = json.dumps(self.props)
|
|
402
|
-
self.updatable = True
|
|
403
399
|
|
|
404
400
|
super().__post_init__()
|
chainlit/emitter.py
CHANGED
|
@@ -2,9 +2,6 @@ import asyncio
|
|
|
2
2
|
import uuid
|
|
3
3
|
from typing import Any, Dict, List, Literal, Optional, Union, cast
|
|
4
4
|
|
|
5
|
-
from literalai.helper import utc_now
|
|
6
|
-
from socketio.exceptions import TimeoutError
|
|
7
|
-
|
|
8
5
|
from chainlit.chat_context import chat_context
|
|
9
6
|
from chainlit.config import config
|
|
10
7
|
from chainlit.data import get_data_layer
|
|
@@ -19,10 +16,12 @@ from chainlit.types import (
|
|
|
19
16
|
FileDict,
|
|
20
17
|
FileReference,
|
|
21
18
|
MessagePayload,
|
|
22
|
-
OutputAudioChunk,
|
|
23
19
|
ThreadDict,
|
|
20
|
+
OutputAudioChunk
|
|
24
21
|
)
|
|
25
22
|
from chainlit.user import PersistedUser
|
|
23
|
+
from literalai.helper import utc_now
|
|
24
|
+
from socketio.exceptions import TimeoutError
|
|
26
25
|
|
|
27
26
|
|
|
28
27
|
class BaseChainlitEmitter:
|
|
@@ -53,15 +52,15 @@ class BaseChainlitEmitter:
|
|
|
53
52
|
async def send_element(self, element_dict: ElementDict):
|
|
54
53
|
"""Stub method to send an element to the UI."""
|
|
55
54
|
pass
|
|
56
|
-
|
|
55
|
+
|
|
57
56
|
async def update_audio_connection(self, state: Literal["on", "off"]):
|
|
58
57
|
"""Audio connection signaling."""
|
|
59
58
|
pass
|
|
60
|
-
|
|
59
|
+
|
|
61
60
|
async def send_audio_chunk(self, chunk: OutputAudioChunk):
|
|
62
61
|
"""Stub method to send an audio chunk to the UI."""
|
|
63
62
|
pass
|
|
64
|
-
|
|
63
|
+
|
|
65
64
|
async def send_audio_interrupt(self):
|
|
66
65
|
"""Stub method to interrupt the current audio response."""
|
|
67
66
|
pass
|
|
@@ -128,8 +127,10 @@ class BaseChainlitEmitter:
|
|
|
128
127
|
"""Stub method to set chat settings."""
|
|
129
128
|
pass
|
|
130
129
|
|
|
131
|
-
async def
|
|
132
|
-
|
|
130
|
+
async def send_action_response(
|
|
131
|
+
self, id: str, status: bool, response: Optional[str] = None
|
|
132
|
+
):
|
|
133
|
+
"""Send an action response to the UI."""
|
|
133
134
|
pass
|
|
134
135
|
|
|
135
136
|
|
|
@@ -176,7 +177,7 @@ class ChainlitEmitter(BaseChainlitEmitter):
|
|
|
176
177
|
async def send_audio_chunk(self, chunk: OutputAudioChunk):
|
|
177
178
|
"""Send an audio chunk to the UI."""
|
|
178
179
|
await self.emit("audio_chunk", chunk)
|
|
179
|
-
|
|
180
|
+
|
|
180
181
|
async def send_audio_interrupt(self):
|
|
181
182
|
"""Method to interrupt the current audio response."""
|
|
182
183
|
await self.emit("audio_interrupt", {})
|
|
@@ -282,9 +283,9 @@ class ChainlitEmitter(BaseChainlitEmitter):
|
|
|
282
283
|
# End the task temporarily so that the User can answer the prompt
|
|
283
284
|
await self.task_end()
|
|
284
285
|
|
|
285
|
-
final_res: Optional[
|
|
286
|
-
|
|
287
|
-
|
|
286
|
+
final_res: Optional[
|
|
287
|
+
Union["StepDict", "AskActionResponse", List["FileDict"]]
|
|
288
|
+
] = None
|
|
288
289
|
|
|
289
290
|
if user_res:
|
|
290
291
|
interaction: Union[str, None] = None
|
|
@@ -319,7 +320,7 @@ class ChainlitEmitter(BaseChainlitEmitter):
|
|
|
319
320
|
elif spec.type == "action":
|
|
320
321
|
action_res = cast(AskActionResponse, user_res)
|
|
321
322
|
final_res = action_res
|
|
322
|
-
interaction = action_res["
|
|
323
|
+
interaction = action_res["value"]
|
|
323
324
|
|
|
324
325
|
if not self.session.has_first_interaction and interaction:
|
|
325
326
|
self.session.has_first_interaction = True
|
|
@@ -385,6 +386,9 @@ class ChainlitEmitter(BaseChainlitEmitter):
|
|
|
385
386
|
def set_chat_settings(self, settings: Dict[str, Any]):
|
|
386
387
|
self.session.chat_settings = settings
|
|
387
388
|
|
|
388
|
-
def
|
|
389
|
-
|
|
390
|
-
|
|
389
|
+
def send_action_response(
|
|
390
|
+
self, id: str, status: bool, response: Optional[str] = None
|
|
391
|
+
):
|
|
392
|
+
return self.emit(
|
|
393
|
+
"action_response", {"id": id, "status": status, "response": response}
|
|
394
|
+
)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{g as P,r as v,u as D,a as O}from"./index-CuSbXjG5.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};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{g as _,r as g,u as P,a as m}from"./index-CuSbXjG5.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};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{g as b,r as _,u as O,a as A}from"./index-CuSbXjG5.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};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{g as y,r as f,u as _,a as m}from"./index-CuSbXjG5.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};
|