rasa-sdk 3.21.0.dev1__tar.gz → 3.21.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. {rasa_sdk-3.21.0.dev1 → rasa_sdk-3.21.1}/PKG-INFO +7 -8
  2. {rasa_sdk-3.21.0.dev1 → rasa_sdk-3.21.1}/pyproject.toml +8 -9
  3. rasa_sdk-3.21.1/rasa_sdk/cors.py +366 -0
  4. {rasa_sdk-3.21.0.dev1 → rasa_sdk-3.21.1}/rasa_sdk/endpoint.py +1 -16
  5. {rasa_sdk-3.21.0.dev1 → rasa_sdk-3.21.1}/rasa_sdk/tracing/instrumentation/attribute_extractors.py +6 -1
  6. {rasa_sdk-3.21.0.dev1 → rasa_sdk-3.21.1}/rasa_sdk/version.py +1 -1
  7. {rasa_sdk-3.21.0.dev1 → rasa_sdk-3.21.1}/LICENSE.txt +0 -0
  8. {rasa_sdk-3.21.0.dev1 → rasa_sdk-3.21.1}/README.md +0 -0
  9. {rasa_sdk-3.21.0.dev1 → rasa_sdk-3.21.1}/rasa_sdk/__init__.py +0 -0
  10. {rasa_sdk-3.21.0.dev1 → rasa_sdk-3.21.1}/rasa_sdk/__main__.py +0 -0
  11. {rasa_sdk-3.21.0.dev1 → rasa_sdk-3.21.1}/rasa_sdk/cli/__init__.py +0 -0
  12. {rasa_sdk-3.21.0.dev1 → rasa_sdk-3.21.1}/rasa_sdk/cli/arguments.py +0 -0
  13. {rasa_sdk-3.21.0.dev1 → rasa_sdk-3.21.1}/rasa_sdk/constants.py +0 -0
  14. {rasa_sdk-3.21.0.dev1 → rasa_sdk-3.21.1}/rasa_sdk/events.py +0 -0
  15. {rasa_sdk-3.21.0.dev1 → rasa_sdk-3.21.1}/rasa_sdk/exceptions.py +0 -0
  16. {rasa_sdk-3.21.0.dev1 → rasa_sdk-3.21.1}/rasa_sdk/executor.py +0 -0
  17. {rasa_sdk-3.21.0.dev1 → rasa_sdk-3.21.1}/rasa_sdk/forms.py +0 -0
  18. {rasa_sdk-3.21.0.dev1 → rasa_sdk-3.21.1}/rasa_sdk/grpc_errors.py +0 -0
  19. {rasa_sdk-3.21.0.dev1 → rasa_sdk-3.21.1}/rasa_sdk/grpc_py/__init__.py +0 -0
  20. {rasa_sdk-3.21.0.dev1 → rasa_sdk-3.21.1}/rasa_sdk/grpc_py/action_webhook_pb2.py +0 -0
  21. {rasa_sdk-3.21.0.dev1 → rasa_sdk-3.21.1}/rasa_sdk/grpc_py/action_webhook_pb2.pyi +0 -0
  22. {rasa_sdk-3.21.0.dev1 → rasa_sdk-3.21.1}/rasa_sdk/grpc_py/action_webhook_pb2_grpc.py +0 -0
  23. {rasa_sdk-3.21.0.dev1 → rasa_sdk-3.21.1}/rasa_sdk/grpc_server.py +0 -0
  24. {rasa_sdk-3.21.0.dev1 → rasa_sdk-3.21.1}/rasa_sdk/interfaces.py +0 -0
  25. {rasa_sdk-3.21.0.dev1 → rasa_sdk-3.21.1}/rasa_sdk/knowledge_base/__init__.py +0 -0
  26. {rasa_sdk-3.21.0.dev1 → rasa_sdk-3.21.1}/rasa_sdk/knowledge_base/actions.py +0 -0
  27. {rasa_sdk-3.21.0.dev1 → rasa_sdk-3.21.1}/rasa_sdk/knowledge_base/storage.py +0 -0
  28. {rasa_sdk-3.21.0.dev1 → rasa_sdk-3.21.1}/rasa_sdk/knowledge_base/utils.py +0 -0
  29. {rasa_sdk-3.21.0.dev1 → rasa_sdk-3.21.1}/rasa_sdk/plugin.py +0 -0
  30. {rasa_sdk-3.21.0.dev1 → rasa_sdk-3.21.1}/rasa_sdk/slots.py +0 -0
  31. {rasa_sdk-3.21.0.dev1 → rasa_sdk-3.21.1}/rasa_sdk/tracing/config.py +0 -0
  32. {rasa_sdk-3.21.0.dev1 → rasa_sdk-3.21.1}/rasa_sdk/tracing/endpoints.py +0 -0
  33. {rasa_sdk-3.21.0.dev1 → rasa_sdk-3.21.1}/rasa_sdk/tracing/instrumentation/instrumentation.py +0 -0
  34. {rasa_sdk-3.21.0.dev1 → rasa_sdk-3.21.1}/rasa_sdk/tracing/tracer_register.py +0 -0
  35. {rasa_sdk-3.21.0.dev1 → rasa_sdk-3.21.1}/rasa_sdk/tracing/utils.py +0 -0
  36. {rasa_sdk-3.21.0.dev1 → rasa_sdk-3.21.1}/rasa_sdk/types.py +0 -0
  37. {rasa_sdk-3.21.0.dev1 → rasa_sdk-3.21.1}/rasa_sdk/utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: rasa-sdk
3
- Version: 3.21.0.dev1
3
+ Version: 3.21.1
4
4
  Summary: Open source machine learning framework to automate text- and voice-based conversations: NLU, dialogue management, connect to Slack, Facebook, and more - Create chatbots and voice assistants
5
5
  License: Apache-2.0
6
6
  Keywords: nlp,machine-learning,machine-learning-library,bot,bots,botkit,rasa conversational-agents,conversational-ai,chatbot,chatbot-framework,bot-framework
@@ -18,16 +18,15 @@ Classifier: Programming Language :: Python :: 3.11
18
18
  Classifier: Programming Language :: Python :: 3.12
19
19
  Classifier: Programming Language :: Python :: 3.13
20
20
  Classifier: Topic :: Software Development :: Libraries
21
- Requires-Dist: Sanic-Cors (>=2.0.0,<3.0.0)
22
21
  Requires-Dist: coloredlogs (>=10,<16)
23
- Requires-Dist: grpcio (>=1.83.0,<1.84.0)
24
- Requires-Dist: grpcio-health-checking (>=1.83.0,<1.84.0)
22
+ Requires-Dist: grpcio (>=1.84.0,<1.85.0)
23
+ Requires-Dist: grpcio-health-checking (>=1.84.0,<1.85.0)
25
24
  Requires-Dist: grpcio-tools (>=1.83.0,<1.84.0) ; python_version < "3.14"
26
- Requires-Dist: opentelemetry-api (>=1.44.0,<1.45.0)
27
- Requires-Dist: opentelemetry-exporter-otlp (>=1.44.0,<1.45.0)
28
- Requires-Dist: opentelemetry-sdk (>=1.44.0,<1.45.0)
25
+ Requires-Dist: opentelemetry-api (>=1.45.0,<1.46.0)
26
+ Requires-Dist: opentelemetry-exporter-otlp (>=1.45.0,<1.46.0)
27
+ Requires-Dist: opentelemetry-sdk (>=1.45.0,<1.46.0)
29
28
  Requires-Dist: pluggy (>=1.0.0,<2.0.0)
30
- Requires-Dist: protobuf (>=7.35.1,<7.36.0)
29
+ Requires-Dist: protobuf (>=7.36.0,<7.37.0)
31
30
  Requires-Dist: pydantic (>=2.13.4,<2.14.0)
32
31
  Requires-Dist: ruamel.yaml (>=0.19.1,<0.20.0)
33
32
  Requires-Dist: sanic (>=25.12,<25.13)
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
4
4
 
5
5
  [tool.poetry]
6
6
  name = "rasa-sdk"
7
- version = "3.21.0.dev1"
7
+ version = "3.21.1"
8
8
  description = "Open source machine learning framework to automate text- and voice-based conversations: NLU, dialogue management, connect to Slack, Facebook, and more - Create chatbots and voice assistants"
9
9
  authors = [ "Rasa Technologies GmbH <hi@rasa.com>",]
10
10
  maintainers = [ "Tom Bocklisch <tom@rasa.com>",]
@@ -74,17 +74,16 @@ python = ">=3.10,<3.15"
74
74
  coloredlogs = ">=10,<16"
75
75
  sanic = "~25.12"
76
76
  typing-extensions = "~4.16.0"
77
- Sanic-Cors = "^2.0.0"
78
77
  "ruamel.yaml" = "~0.19.1"
79
78
  websockets = ">=10.0,<16"
80
79
  pluggy = "^1.0.0"
81
80
  pydantic = "~2.13.4"
82
- grpcio-health-checking = "~1.83.0"
83
- opentelemetry-sdk = "~1.44.0"
84
- opentelemetry-exporter-otlp = "~1.44.0"
85
- opentelemetry-api = "~1.44.0"
86
- grpcio = "~1.83.0"
87
- protobuf = "~7.35.1"
81
+ grpcio-health-checking = "~1.84.0"
82
+ opentelemetry-sdk = "~1.45.0"
83
+ opentelemetry-exporter-otlp = "~1.45.0"
84
+ opentelemetry-api = "~1.45.0"
85
+ grpcio = "~1.84.0"
86
+ protobuf = "~7.36.0"
88
87
 
89
88
  [tool.poetry.requires-plugins]
90
89
  poetry-plugin-export = ">=1.8"
@@ -112,7 +111,7 @@ questionary = ">=2.1.1,<3.0.0"
112
111
  towncrier = "~25.8.0"
113
112
  toml = "^0.10.0"
114
113
  semantic_version = "^2.8.5"
115
- mypy = "~2.3.0"
114
+ mypy = "~2.4.0"
116
115
  sanic-testing = "~24.6.0"
117
116
  ruff = "~0.15.14"
118
117
  pytest-asyncio = "^0.23.6"
@@ -0,0 +1,366 @@
1
+ r"""Cross-Origin Resource Sharing (CORS) support for the action server.
2
+
3
+ This module replaces the unmaintained ``sanic-cors`` package, which had no
4
+ release since 2022 and shipped CVE-2026-37737: its origin matching used
5
+ ``re.match``, which anchors only at the start of the string, so a configured
6
+ origin of ``https://.*\.example\.com`` also accepted
7
+ ``https://x.example.com.attacker.example``. Origins here are matched with
8
+ ``re.fullmatch`` instead.
9
+
10
+ Only the subset of CORS the action server actually exposes is implemented.
11
+ The action server runs without credentials, so ``Access-Control-Allow-Origin``
12
+ may be the wildcard when no ``Origin`` header is present; when one is present
13
+ it is echoed back, which is what ``sanic-cors`` did.
14
+
15
+ Preflight (``OPTIONS``) requests are answered directly from request middleware
16
+ and never reach a route handler. Sanic resolves the route *before* running
17
+ middleware, but a routing failure is passed to
18
+ ``Sanic.handle_exception(..., run_middleware=True)``, which falls back to the
19
+ app-level request middleware. That is why the middleware here is registered on
20
+ the app rather than on a blueprint: it is what lets a preflight to a
21
+ ``POST``-only route, or to an unknown path, still receive a ``200``.
22
+ """
23
+
24
+ from __future__ import annotations
25
+
26
+ import logging
27
+ import re
28
+ from typing import Any, List, Optional, Pattern, Text, Tuple, Union
29
+
30
+ from pydantic import BaseModel, ConfigDict
31
+ from sanic import Sanic
32
+ from sanic.request import Request
33
+ from sanic.response import HTTPResponse
34
+
35
+ logger = logging.getLogger(__name__)
36
+
37
+ ALLOW_ORIGIN_HEADER = "Access-Control-Allow-Origin"
38
+ ALLOW_METHODS_HEADER = "Access-Control-Allow-Methods"
39
+ ALLOW_HEADERS_HEADER = "Access-Control-Allow-Headers"
40
+ REQUEST_METHOD_HEADER = "Access-Control-Request-Method"
41
+ REQUEST_HEADERS_HEADER = "Access-Control-Request-Headers"
42
+ VARY_HEADER = "Vary"
43
+
44
+ WILDCARD = "*"
45
+
46
+ # The methods `sanic-cors` allowed by default, which the SDK never overrode.
47
+ ALLOWED_METHODS: Tuple[Text, ...] = (
48
+ "DELETE",
49
+ "GET",
50
+ "HEAD",
51
+ "OPTIONS",
52
+ "PATCH",
53
+ "POST",
54
+ "PUT",
55
+ )
56
+ ALLOWED_METHODS_VALUE = ", ".join(ALLOWED_METHODS)
57
+
58
+ # Characters that made `sanic-cors` treat a configured origin as a regular
59
+ # expression. `*` is handled separately, as a glob.
60
+ _REGEX_METACHARACTERS = frozenset("\\[]()+|^$?{}")
61
+
62
+ _APP_POLICY_ATTRIBUTE = "cors_policy"
63
+ _APP_REGISTERED_ATTRIBUTE = "cors_middleware_registered"
64
+ _REQUEST_APPLIED_ATTRIBUTE = "cors_applied"
65
+
66
+
67
+ class CorsPolicy(BaseModel):
68
+ """The set of origins the action server accepts cross-origin requests from."""
69
+
70
+ model_config = ConfigDict(frozen=True)
71
+
72
+ allow_all: bool = False
73
+ literals: Tuple[Text, ...] = ()
74
+ patterns: Tuple[Pattern[Text], ...] = ()
75
+
76
+ def matches(self, request_origin: Text) -> bool:
77
+ """Check whether a request's `Origin` header is allowed.
78
+
79
+ Args:
80
+ request_origin: The value of the request's `Origin` header.
81
+
82
+ Returns:
83
+ `True` if the origin is covered by this policy.
84
+ """
85
+ if self.allow_all:
86
+ return True
87
+ lowered = request_origin.lower()
88
+ if any(lowered == literal.lower() for literal in self.literals):
89
+ return True
90
+ # `fullmatch` rather than `match` is the fix for CVE-2026-37737.
91
+ return any(pattern.fullmatch(request_origin) for pattern in self.patterns)
92
+
93
+ @property
94
+ def origin_can_vary(self) -> bool:
95
+ """Whether the emitted `Access-Control-Allow-Origin` depends on the request."""
96
+ return self.allow_all or len(self.literals) > 1 or bool(self.patterns)
97
+
98
+ @property
99
+ def is_pattern_only(self) -> bool:
100
+ """Whether this policy is made up exclusively of patterns."""
101
+ return bool(self.patterns) and not self.literals and not self.allow_all
102
+
103
+
104
+ def _compile_glob(origin: Text) -> Pattern[Text]:
105
+ """Translate a glob-style origin into a fully anchored regular expression.
106
+
107
+ A `*` matches any run of characters that does not cross a `/`, so
108
+ `https://*.example.com` accepts `https://a.example.com` and
109
+ `https://a.b.example.com`, but neither
110
+ `https://a.example.com.attacker.example` nor
111
+ `https://attacker.example/.example.com`.
112
+
113
+ Args:
114
+ origin: A configured origin containing at least one `*`.
115
+
116
+ Returns:
117
+ The compiled, case-insensitive pattern.
118
+ """
119
+ parts = re.split(r"(\*)", origin)
120
+ pattern = "".join(
121
+ "[^/]*" if part == WILDCARD else re.escape(part) for part in parts
122
+ )
123
+ return re.compile(pattern, re.IGNORECASE)
124
+
125
+
126
+ def _compile_origin(origin: Text) -> Union[Text, Pattern[Text]]:
127
+ """Turn one configured origin into a literal or a compiled pattern.
128
+
129
+ Args:
130
+ origin: A single entry from the configured origins.
131
+
132
+ Returns:
133
+ The origin itself if it should be compared literally, otherwise a
134
+ compiled pattern to be matched with `re.fullmatch`.
135
+ """
136
+ if any(character in _REGEX_METACHARACTERS for character in origin):
137
+ # `sanic-cors` accepted raw regular expressions here, so keep honouring
138
+ # them -- anchored, unlike before.
139
+ try:
140
+ return re.compile(origin, re.IGNORECASE)
141
+ except re.error as error:
142
+ logger.warning(
143
+ "Could not compile the configured CORS origin '%s' as a regular "
144
+ "expression (%s). It will only be matched literally.",
145
+ origin,
146
+ error,
147
+ )
148
+ return origin
149
+ if WILDCARD in origin:
150
+ return _compile_glob(origin)
151
+ return origin
152
+
153
+
154
+ def build_policy(cors_origins: Union[Text, List[Text], None]) -> CorsPolicy:
155
+ """Build a `CorsPolicy` from a configured origin, or list of origins.
156
+
157
+ Args:
158
+ cors_origins: A single origin, a list of origins, or `None`. `"*"`
159
+ anywhere in the list allows every origin.
160
+
161
+ Returns:
162
+ The resulting policy. An empty or unset configuration yields a policy
163
+ that matches nothing.
164
+ """
165
+ if cors_origins is None:
166
+ configured: List[Text] = []
167
+ elif isinstance(cors_origins, str):
168
+ configured = [cors_origins]
169
+ else:
170
+ configured = [str(origin) for origin in cors_origins]
171
+
172
+ cleaned = [origin.strip() for origin in configured if origin and origin.strip()]
173
+ if WILDCARD in cleaned:
174
+ return CorsPolicy(allow_all=True)
175
+
176
+ literals: List[Text] = []
177
+ patterns: List[Pattern[Text]] = []
178
+ for origin in cleaned:
179
+ compiled = _compile_origin(origin)
180
+ if isinstance(compiled, str):
181
+ literals.append(compiled)
182
+ else:
183
+ patterns.append(compiled)
184
+ return CorsPolicy(literals=tuple(literals), patterns=tuple(patterns))
185
+
186
+
187
+ def _read_origin(request: Request) -> Tuple[Optional[Text], bool]:
188
+ """Read the request's `Origin` header.
189
+
190
+ Args:
191
+ request: The incoming request.
192
+
193
+ Returns:
194
+ A tuple of the origin (`None` when the header is absent or repeated)
195
+ and whether the header was malformed, i.e. sent more than once.
196
+ """
197
+ origins = request.headers.getall("origin", None)
198
+ if not origins:
199
+ return None, False
200
+ if len(origins) > 1:
201
+ # Browsers send at most one `Origin`. `sanic-cors` joined repeats with
202
+ # ", " and echoed the joined string back, which is never a valid origin.
203
+ logger.debug("Received %s Origin headers; refusing CORS.", len(origins))
204
+ return None, True
205
+ return origins[0], False
206
+
207
+
208
+ def _is_preflight(request: Request) -> bool:
209
+ """Check whether a request is a CORS preflight for an allowed method.
210
+
211
+ Only such a request gets the `Access-Control-Allow-Methods` and
212
+ `Access-Control-Allow-Headers` response headers. Every `OPTIONS` request is
213
+ short-circuited regardless -- see `_cors_request_middleware`.
214
+
215
+ Args:
216
+ request: The incoming request.
217
+
218
+ Returns:
219
+ `True` for an `OPTIONS` request carrying an allowed
220
+ `Access-Control-Request-Method`.
221
+ """
222
+ if request.method != "OPTIONS":
223
+ return False
224
+ requested_method = request.headers.get(REQUEST_METHOD_HEADER)
225
+ if not requested_method:
226
+ return False
227
+ return requested_method.strip().upper() in ALLOWED_METHODS
228
+
229
+
230
+ def _add_vary_origin(response: HTTPResponse) -> None:
231
+ """Append `Origin` to the response's `Vary` header without dropping values.
232
+
233
+ Args:
234
+ response: The response to amend.
235
+ """
236
+ existing = response.headers.get(VARY_HEADER)
237
+ if not existing:
238
+ response.headers[VARY_HEADER] = "Origin"
239
+ return
240
+ already_listed = {value.strip().lower() for value in existing.split(",")}
241
+ if "origin" not in already_listed:
242
+ response.headers[VARY_HEADER] = f"{existing}, Origin"
243
+
244
+
245
+ def _apply_cors_headers(
246
+ request: Request, response: HTTPResponse, policy: CorsPolicy
247
+ ) -> None:
248
+ """Add the CORS response headers this request and policy call for.
249
+
250
+ Args:
251
+ request: The incoming request.
252
+ response: The response to amend in place.
253
+ policy: The app's configured policy.
254
+ """
255
+ request_origin, malformed_origin = _read_origin(request)
256
+ if malformed_origin:
257
+ # Emit nothing at all, so the browser blocks the response.
258
+ return
259
+
260
+ if request_origin is not None:
261
+ if not policy.matches(request_origin):
262
+ return
263
+ response.headers[ALLOW_ORIGIN_HEADER] = request_origin
264
+ if policy.origin_can_vary:
265
+ _add_vary_origin(response)
266
+ elif policy.allow_all:
267
+ response.headers[ALLOW_ORIGIN_HEADER] = WILDCARD
268
+ elif policy.is_pattern_only:
269
+ # A pattern cannot be turned back into a concrete origin, so there is
270
+ # nothing to advertise to a client that did not send one.
271
+ return
272
+ elif policy.literals:
273
+ # No `Origin` header means this is not a cross-origin request at all,
274
+ # so the value is inert. `sanic-cors` emitted the last of the sorted
275
+ # literals here; kept as-is to avoid changing observable behaviour.
276
+ response.headers[ALLOW_ORIGIN_HEADER] = sorted(policy.literals)[-1]
277
+ if policy.origin_can_vary:
278
+ _add_vary_origin(response)
279
+ else:
280
+ return
281
+
282
+ if _is_preflight(request):
283
+ response.headers[ALLOW_METHODS_HEADER] = ALLOWED_METHODS_VALUE
284
+ requested_headers = request.headers.get(REQUEST_HEADERS_HEADER)
285
+ if requested_headers:
286
+ # The action server allowed any header, so echo back what was asked.
287
+ response.headers[ALLOW_HEADERS_HEADER] = ", ".join(
288
+ sorted(
289
+ header.strip()
290
+ for header in requested_headers.split(",")
291
+ if header.strip()
292
+ )
293
+ )
294
+
295
+
296
+ async def _cors_request_middleware(request: Request) -> Optional[HTTPResponse]:
297
+ """Answer CORS preflight requests before they reach a route handler.
298
+
299
+ Args:
300
+ request: The incoming request.
301
+
302
+ Returns:
303
+ An empty `200` response for any `OPTIONS` request, otherwise `None` so
304
+ that request handling continues as usual.
305
+ """
306
+ if request.method == "OPTIONS":
307
+ # Every `OPTIONS` request is answered here, whether or not it carries a
308
+ # usable `Access-Control-Request-Method`, and whether or not the route
309
+ # would have accepted the method. The action server declares no
310
+ # `OPTIONS` handlers of its own, so nothing is being shadowed.
311
+ return HTTPResponse(status=200)
312
+ return None
313
+
314
+
315
+ async def _cors_response_middleware(
316
+ request: Request, response: Optional[HTTPResponse]
317
+ ) -> None:
318
+ """Add CORS headers to an outgoing response.
319
+
320
+ Args:
321
+ request: The request the response belongs to.
322
+ response: The response to amend. `None` for websocket upgrades.
323
+ """
324
+ if response is None or not hasattr(response, "headers"):
325
+ return
326
+
327
+ policy: Optional[CorsPolicy] = getattr(request.app.ctx, _APP_POLICY_ATTRIBUTE, None)
328
+ if policy is None:
329
+ return
330
+
331
+ # Sanic can run response middleware twice on the error path, once from
332
+ # `handle_exception` and once from `Request.respond`.
333
+ if getattr(request.ctx, _REQUEST_APPLIED_ATTRIBUTE, False):
334
+ return
335
+ setattr(request.ctx, _REQUEST_APPLIED_ATTRIBUTE, True)
336
+
337
+ _apply_cors_headers(request, response, policy)
338
+
339
+
340
+ def configure_cors(
341
+ app: Sanic, cors_origins: Union[Text, List[Text], None] = ""
342
+ ) -> None:
343
+ """Configure CORS origins for the given app.
344
+
345
+ Safe to call more than once on the same app; the policy is replaced and the
346
+ middleware stays registered exactly once.
347
+
348
+ Args:
349
+ app: The Sanic app to add CORS handling to.
350
+ cors_origins: The allowed origins. `"*"` allows every origin; an empty
351
+ value disables cross-origin requests.
352
+ """
353
+ setattr(app.ctx, _APP_POLICY_ATTRIBUTE, build_policy(cors_origins))
354
+
355
+ if getattr(app.ctx, _APP_REGISTERED_ATTRIBUTE, False):
356
+ return
357
+ setattr(app.ctx, _APP_REGISTERED_ATTRIBUTE, True)
358
+
359
+ # Sanic annotates these inconsistently, and differently between versions:
360
+ # on 22.12 `on_request` is untyped, on 25.12 it is `on_response`. A
361
+ # `type: ignore` correct on one is flagged as unused on the other, and this
362
+ # module is backported to branches still on 22.12 - so go through a
363
+ # deliberately untyped reference instead.
364
+ middleware_registrar: Any = app
365
+ middleware_registrar.on_request(_cors_request_middleware)
366
+ middleware_registrar.on_response(_cors_response_middleware)
@@ -17,20 +17,14 @@ from sanic.worker.loader import AppLoader
17
17
  # - all `pkg_resources` deprecation warning from multiple dependencies
18
18
  # - google rcp warnings (`pkg_resources.namespaces`)
19
19
  # - open telemetry (`pkg_resources`)
20
- # - sanic-cors (`distutils Version classes...`)
21
20
  with warnings.catch_warnings():
22
21
  warnings.filterwarnings(
23
22
  "ignore", category=DeprecationWarning, message=".*pkg_resources.*"
24
23
  )
25
- warnings.filterwarnings(
26
- "ignore",
27
- category=DeprecationWarning,
28
- message="distutils Version classes are deprecated",
29
- )
30
- from sanic_cors import CORS
31
24
  from sanic.request import Request
32
25
  from rasa_sdk import utils
33
26
  from rasa_sdk.cli.arguments import add_endpoint_arguments
27
+ from rasa_sdk.cors import configure_cors
34
28
  from rasa_sdk.constants import (
35
29
  DEFAULT_ENDPOINTS_PATH,
36
30
  DEFAULT_KEEP_ALIVE_TIMEOUT,
@@ -52,15 +46,6 @@ with warnings.catch_warnings():
52
46
  logger = logging.getLogger(__name__)
53
47
 
54
48
 
55
- def configure_cors(
56
- app: Sanic, cors_origins: Union[Text, List[Text], None] = ""
57
- ) -> None:
58
- """Configure CORS origins for the given app."""
59
- CORS(
60
- app, resources={r"/*": {"origins": cors_origins or ""}}, automatic_options=True
61
- )
62
-
63
-
64
49
  def create_ssl_config(
65
50
  ssl_certificate: Optional[Text],
66
51
  ssl_keyfile: Optional[Text],
@@ -1,6 +1,7 @@
1
+ import asyncio
1
2
  import json
2
3
 
3
- from typing import Any, Dict, Text, List
4
+ from typing import Any, Dict, Text, List, Optional
4
5
  from rasa_sdk.executor import ActionExecutor, CollectingDispatcher
5
6
  from rasa_sdk.forms import ValidationAction
6
7
  from rasa_sdk.types import ActionCall, DomainDict
@@ -18,11 +19,15 @@ from rasa_sdk import Tracker
18
19
  def extract_attrs_for_action_executor(
19
20
  self: ActionExecutor,
20
21
  action_call: ActionCall,
22
+ sink: Optional[asyncio.Queue] = None,
23
+ dispatcher: Optional[CollectingDispatcher] = None,
21
24
  ) -> Dict[Text, Any]:
22
25
  """Extract the attributes for `ActionExecutor.run`.
23
26
 
24
27
  :param self: The `ActionExecutor` on which `run` is called.
25
28
  :param action_call: The `ActionCall` argument.
29
+ :param sink: The streaming output queue argument. Not used for attributes.
30
+ :param dispatcher: The dispatcher argument. Not used for attributes.
26
31
  :return: A dictionary containing the attributes.
27
32
  """
28
33
  attributes = {"sender_id": action_call.get("sender_id", "None")}
@@ -1,3 +1,3 @@
1
1
  # this file will automatically be changed,
2
2
  # do not add anything but the version number here!
3
- __version__ = "3.21.0.dev1"
3
+ __version__ = "3.21.1"
File without changes
File without changes