candura 0.2.4.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.
- candura/core/__init__.py +16 -0
- candura/core/agentic/__init__.py +43 -0
- candura/core/agentic/agentic.md +1014 -0
- candura/core/agentic/chassi/__init__.py +20 -0
- candura/core/agentic/chassi/admission.py +156 -0
- candura/core/agentic/chassi/agent.py +232 -0
- candura/core/agentic/chassi/agent_runner.py +204 -0
- candura/core/agentic/chassi/binder.py +93 -0
- candura/core/agentic/chassi/budget.py +106 -0
- candura/core/agentic/chassi/contract.py +101 -0
- candura/core/agentic/chassi/execution.py +88 -0
- candura/core/agentic/chassi/harness.py +207 -0
- candura/core/agentic/chassi/report.py +180 -0
- candura/core/agentic/conversations/__init__.py +58 -0
- candura/core/agentic/conversations/closing.py +72 -0
- candura/core/agentic/conversations/dedupe.py +230 -0
- candura/core/agentic/conversations/locks.py +243 -0
- candura/core/agentic/conversations/models.py +323 -0
- candura/core/agentic/conversations/notify.py +369 -0
- candura/core/agentic/conversations/notify_values.py +92 -0
- candura/core/agentic/conversations/queries.py +73 -0
- candura/core/agentic/conversations/repository.py +371 -0
- candura/core/agentic/conversations/store.py +103 -0
- candura/core/agentic/definition.py +322 -0
- candura/core/agentic/loader.py +308 -0
- candura/core/agentic/loop/__init__.py +175 -0
- candura/core/agentic/loop/catalog/__init__.py +23 -0
- candura/core/agentic/loop/catalog/commands.py +78 -0
- candura/core/agentic/loop/catalog/intention.py +39 -0
- candura/core/agentic/loop/catalog/intents.py +288 -0
- candura/core/agentic/loop/catalog/slot_text.py +106 -0
- candura/core/agentic/loop/conversation.py +296 -0
- candura/core/agentic/loop/delivery/__init__.py +8 -0
- candura/core/agentic/loop/delivery/builder.py +37 -0
- candura/core/agentic/loop/delivery/context.py +41 -0
- candura/core/agentic/loop/delivery/stage.py +26 -0
- candura/core/agentic/loop/evaluation/__init__.py +8 -0
- candura/core/agentic/loop/evaluation/builder.py +36 -0
- candura/core/agentic/loop/evaluation/context.py +107 -0
- candura/core/agentic/loop/evaluation/stage.py +35 -0
- candura/core/agentic/loop/execution/__init__.py +44 -0
- candura/core/agentic/loop/execution/agentic.py +62 -0
- candura/core/agentic/loop/execution/builder.py +45 -0
- candura/core/agentic/loop/execution/builtin.py +87 -0
- candura/core/agentic/loop/execution/content.py +66 -0
- candura/core/agentic/loop/execution/context.py +259 -0
- candura/core/agentic/loop/execution/engine.py +179 -0
- candura/core/agentic/loop/execution/plan.py +93 -0
- candura/core/agentic/loop/execution/stage.py +150 -0
- candura/core/agentic/loop/execution/trace.py +285 -0
- candura/core/agentic/loop/interpretation/__init__.py +27 -0
- candura/core/agentic/loop/interpretation/agent.py +193 -0
- candura/core/agentic/loop/interpretation/builder.py +86 -0
- candura/core/agentic/loop/interpretation/commands.py +31 -0
- candura/core/agentic/loop/interpretation/context.py +40 -0
- candura/core/agentic/loop/interpretation/interpreter.py +193 -0
- candura/core/agentic/loop/interpretation/pipeline.py +96 -0
- candura/core/agentic/loop/interpretation/query_context.py +95 -0
- candura/core/agentic/loop/interpretation/stage.py +65 -0
- candura/core/agentic/loop/panel.py +44 -0
- candura/core/agentic/loop/planning/__init__.py +29 -0
- candura/core/agentic/loop/planning/builder.py +74 -0
- candura/core/agentic/loop/planning/context.py +135 -0
- candura/core/agentic/loop/planning/decision.py +71 -0
- candura/core/agentic/loop/planning/router.py +148 -0
- candura/core/agentic/loop/planning/stage.py +120 -0
- candura/core/agentic/loop/presentation/__init__.py +35 -0
- candura/core/agentic/loop/presentation/builder.py +78 -0
- candura/core/agentic/loop/presentation/content.py +123 -0
- candura/core/agentic/loop/presentation/context.py +80 -0
- candura/core/agentic/loop/presentation/formatter.py +81 -0
- candura/core/agentic/loop/presentation/render.py +259 -0
- candura/core/agentic/loop/presentation/stage.py +87 -0
- candura/core/agentic/loop/reception/__init__.py +20 -0
- candura/core/agentic/loop/reception/builder.py +88 -0
- candura/core/agentic/loop/reception/context.py +111 -0
- candura/core/agentic/loop/reception/stage.py +55 -0
- candura/core/agentic/loop/reception/transcription.py +132 -0
- candura/core/agentic/loop/setup.py +138 -0
- candura/core/agentic/loop/stages.py +79 -0
- candura/core/agentic/media.py +31 -0
- candura/core/agentic/memory.py +31 -0
- candura/core/agentic/prompt.py +397 -0
- candura/core/agentic/prompt_capture.py +270 -0
- candura/core/agentic/prompt_sources.py +164 -0
- candura/core/agentic/runtime/__init__.py +5 -0
- candura/core/agentic/runtime/admission.py +71 -0
- candura/core/agentic/runtime/async_runtime.py +81 -0
- candura/core/agentic/runtime/execution_rule.py +40 -0
- candura/core/agentic/runtime/execution_scope.py +287 -0
- candura/core/agentic/runtime/hydration.py +82 -0
- candura/core/agentic/runtime/identity.py +130 -0
- candura/core/agentic/runtime/output_hook.py +218 -0
- candura/core/agentic/runtime/resolver.py +128 -0
- candura/core/agentic/runtime/runtime.py +210 -0
- candura/core/agentic/session.py +35 -0
- candura/core/clock.py +176 -0
- candura/core/config/__init__.py +24 -0
- candura/core/config/config.md +216 -0
- candura/core/config/config.py +187 -0
- candura/core/config/dotenv_source.py +57 -0
- candura/core/config/errors.py +13 -0
- candura/core/config/keys.py +190 -0
- candura/core/config/prefix.py +53 -0
- candura/core/config/profile.py +44 -0
- candura/core/config/timezone.py +49 -0
- candura/core/context/__init__.py +41 -0
- candura/core/context/activity.py +87 -0
- candura/core/context/agentic_view.py +131 -0
- candura/core/context/blackboard.py +303 -0
- candura/core/context/candura_context.py +190 -0
- candura/core/context/carrier.py +312 -0
- candura/core/context/content.py +124 -0
- candura/core/context/context.md +640 -0
- candura/core/context/exclusions.py +57 -0
- candura/core/context/execution_fields.py +167 -0
- candura/core/context/executions.py +360 -0
- candura/core/context/factory.py +34 -0
- candura/core/context/frame.py +34 -0
- candura/core/context/history.py +391 -0
- candura/core/context/identity.py +172 -0
- candura/core/context/labels.py +50 -0
- candura/core/context/lake_executions.py +208 -0
- candura/core/context/model.py +355 -0
- candura/core/context/opened_tenants.py +87 -0
- candura/core/context/otel.py +24 -0
- candura/core/context/outcomes.py +115 -0
- candura/core/context/retention.py +31 -0
- candura/core/context/scope.py +119 -0
- candura/core/context/snapshot.py +63 -0
- candura/core/context/tenant_store.py +182 -0
- candura/core/context/tenant_view.py +85 -0
- candura/core/context/tenants.py +140 -0
- candura/core/context/threads.py +24 -0
- candura/core/context/transport.py +40 -0
- candura/core/context/usage.py +154 -0
- candura/core/context/zone.py +99 -0
- candura/core/current.py +111 -0
- candura/core/facade.py +103 -0
- candura/core/internals/bridge/__init__.py +7 -0
- candura/core/internals/bridge/cache.py +181 -0
- candura/core/internals/bridge/clock.py +26 -0
- candura/core/internals/bridge/errors.py +103 -0
- candura/core/internals/bridge/evbus.py +171 -0
- candura/core/internals/bridge/kernel.py +244 -0
- candura/core/internals/bridge/lake.py +400 -0
- candura/core/internals/bridge/lake_fake.py +400 -0
- candura/core/internals/bridge/lake_ops_fake.py +80 -0
- candura/core/internals/bridge/lake_pull_fake.py +179 -0
- candura/core/internals/bridge/lake_records_fake.py +207 -0
- candura/core/internals/bridge/module.md +252 -0
- candura/core/internals/bridge/processes.py +296 -0
- candura/core/internals/bridge/reflection.py +76 -0
- candura/core/internals/bridge/registry.py +107 -0
- candura/core/internals/bridge/telemetry.py +205 -0
- candura/core/internals/extras.py +82 -0
- candura/core/internals/keyed_locks.py +167 -0
- candura/core/internals/lake/__init__.py +11 -0
- candura/core/internals/lake/upcasting.py +58 -0
- candura/core/internals/materialization.py +104 -0
- candura/core/internals/model_schema.py +132 -0
- candura/core/internals/namespaces/_guards.py +35 -0
- candura/core/internals/namespaces/addons.py +147 -0
- candura/core/internals/namespaces/agentic.py +225 -0
- candura/core/internals/namespaces/agentic_factories.py +298 -0
- candura/core/internals/namespaces/blobs.py +29 -0
- candura/core/internals/namespaces/caches.py +56 -0
- candura/core/internals/namespaces/candura.py +339 -0
- candura/core/internals/namespaces/channels.py +60 -0
- candura/core/internals/namespaces/config.py +147 -0
- candura/core/internals/namespaces/contexts.py +90 -0
- candura/core/internals/namespaces/conversations.py +229 -0
- candura/core/internals/namespaces/credits.py +241 -0
- candura/core/internals/namespaces/dispatchers.py +34 -0
- candura/core/internals/namespaces/executions.py +152 -0
- candura/core/internals/namespaces/identity.py +303 -0
- candura/core/internals/namespaces/internals.py +314 -0
- candura/core/internals/namespaces/kernel.py +252 -0
- candura/core/internals/namespaces/lake.py +344 -0
- candura/core/internals/namespaces/life.py +158 -0
- candura/core/internals/namespaces/loop.py +273 -0
- candura/core/internals/namespaces/modules.py +201 -0
- candura/core/internals/namespaces/node.py +320 -0
- candura/core/internals/namespaces/processes.py +253 -0
- candura/core/internals/namespaces/projection.py +53 -0
- candura/core/internals/namespaces/public.py +83 -0
- candura/core/internals/namespaces/repository.py +147 -0
- candura/core/internals/namespaces/root_factories.py +120 -0
- candura/core/internals/namespaces/shutdown.py +102 -0
- candura/core/internals/namespaces/task_rounds.py +389 -0
- candura/core/internals/namespaces/task_runs.py +189 -0
- candura/core/internals/namespaces/task_trace.py +73 -0
- candura/core/internals/namespaces/tasks.py +332 -0
- candura/core/internals/namespaces/telemetry.py +287 -0
- candura/core/internals/pipeline/__init__.py +6 -0
- candura/core/internals/pipeline/middleware.py +91 -0
- candura/core/internals/reflection/__init__.py +126 -0
- candura/core/internals/reflection/boot_catalog.py +180 -0
- candura/core/internals/reflection/naming.py +27 -0
- candura/core/internals/reflection/reflection.md +179 -0
- candura/core/internals/reflection/rule_registry.py +172 -0
- candura/core/internals/reflection/runtime.py +400 -0
- candura/core/internals/reflection/static_reflection.py +379 -0
- candura/core/internals/reflection/try_result.py +148 -0
- candura/core/internals/resolution/__init__.py +7 -0
- candura/core/internals/resolution/chain.py +89 -0
- candura/core/internals/resolution/contract.py +45 -0
- candura/core/internals/settling.py +86 -0
- candura/core/internals/telemetry/__init__.py +52 -0
- candura/core/internals/telemetry/_runtime_view.py +48 -0
- candura/core/internals/telemetry/appenders.py +156 -0
- candura/core/internals/telemetry/bridge_otel.py +87 -0
- candura/core/internals/telemetry/categories.py +91 -0
- candura/core/internals/telemetry/config.py +80 -0
- candura/core/internals/telemetry/config_keys.py +53 -0
- candura/core/internals/telemetry/contexts.py +66 -0
- candura/core/internals/telemetry/exceptions.py +61 -0
- candura/core/internals/telemetry/formatters/__init__.py +7 -0
- candura/core/internals/telemetry/formatters/json.py +53 -0
- candura/core/internals/telemetry/formatters/readable.py +95 -0
- candura/core/internals/telemetry/hooks.py +129 -0
- candura/core/internals/telemetry/identity.py +29 -0
- candura/core/internals/telemetry/layouts.py +51 -0
- candura/core/internals/telemetry/levels.py +62 -0
- candura/core/internals/telemetry/logger.py +150 -0
- candura/core/internals/telemetry/native_logs.py +96 -0
- candura/core/internals/telemetry/otel_setup.py +83 -0
- candura/core/internals/telemetry/port.py +111 -0
- candura/core/internals/telemetry/queues.py +72 -0
- candura/core/internals/telemetry/records.py +192 -0
- candura/core/internals/telemetry/resolver.py +29 -0
- candura/core/internals/telemetry/runtime.py +395 -0
- candura/core/internals/telemetry/signals.py +173 -0
- candura/core/internals/telemetry/stdlib_bridge.py +151 -0
- candura/core/internals/telemetry/telemetry.md +153 -0
- candura/core/internals/telemetry/tenant_policy.py +326 -0
- candura/core/internals/testing.py +122 -0
- candura/core/loggers.py +26 -0
- candura/core/models/__init__.py +81 -0
- candura/core/models/base.py +140 -0
- candura/core/models/channel/__init__.py +28 -0
- candura/core/models/channel/channel.md +52 -0
- candura/core/models/channel/identity.py +54 -0
- candura/core/models/channel/inbound.py +81 -0
- candura/core/models/channel/notify.py +45 -0
- candura/core/models/channel/outbound.py +86 -0
- candura/core/models/cloudevents.py +83 -0
- candura/core/models/credit/__init__.py +68 -0
- candura/core/models/credit/candu.py +245 -0
- candura/core/models/credit/credit.md +99 -0
- candura/core/models/credit/entries.py +208 -0
- candura/core/models/credit/prices.py +198 -0
- candura/core/models/credit/reports.py +130 -0
- candura/core/models/db/__init__.py +39 -0
- candura/core/models/db/changes.py +85 -0
- candura/core/models/db/codec.py +42 -0
- candura/core/models/db/db_dsl.py +328 -0
- candura/core/models/db/indexes.py +102 -0
- candura/core/models/db/purge.py +25 -0
- candura/core/models/db/versions.py +98 -0
- candura/core/models/envelope.py +87 -0
- candura/core/models/error/__init__.py +23 -0
- candura/core/models/error/agentic.py +221 -0
- candura/core/models/error/analytics.py +24 -0
- candura/core/models/error/base.py +34 -0
- candura/core/models/error/cache.py +23 -0
- candura/core/models/error/composition.py +11 -0
- candura/core/models/error/context.py +147 -0
- candura/core/models/error/credit.py +126 -0
- candura/core/models/error/eventbus.py +73 -0
- candura/core/models/error/exports.py +369 -0
- candura/core/models/error/identity.py +200 -0
- candura/core/models/error/kernel.py +165 -0
- candura/core/models/error/lake.py +127 -0
- candura/core/models/error/loop.py +119 -0
- candura/core/models/error/module.py +217 -0
- candura/core/models/error/nodes.py +337 -0
- candura/core/models/error/operation.py +117 -0
- candura/core/models/error/packaging.py +35 -0
- candura/core/models/error/reflection.py +326 -0
- candura/core/models/error/registry.py +60 -0
- candura/core/models/error/report.py +51 -0
- candura/core/models/error/repository.py +359 -0
- candura/core/models/error/safe.py +86 -0
- candura/core/models/error/sandbox.py +23 -0
- candura/core/models/error/storage.py +54 -0
- candura/core/models/error/telegram.py +206 -0
- candura/core/models/error/view.py +241 -0
- candura/core/models/events/__init__.py +23 -0
- candura/core/models/events/changes.py +60 -0
- candura/core/models/events/registry.py +56 -0
- candura/core/models/factory.py +106 -0
- candura/core/models/identity/__init__.py +137 -0
- candura/core/models/identity/audit.py +227 -0
- candura/core/models/identity/authority.py +49 -0
- candura/core/models/identity/destinations.py +101 -0
- candura/core/models/identity/identity.md +157 -0
- candura/core/models/identity/keys.py +74 -0
- candura/core/models/identity/models.py +397 -0
- candura/core/models/identity/policy.py +106 -0
- candura/core/models/identity/principals.py +145 -0
- candura/core/models/identity/schemes.py +142 -0
- candura/core/models/identity/schemes_builtin.py +229 -0
- candura/core/models/identity/sessions.py +362 -0
- candura/core/models/identity/tenant_status.py +53 -0
- candura/core/models/identity/tokens.py +226 -0
- candura/core/models/identity/web.py +116 -0
- candura/core/models/lake/__init__.py +28 -0
- candura/core/models/lake/dedupe.py +20 -0
- candura/core/models/lake/spec.py +61 -0
- candura/core/models/lake/stream.py +56 -0
- candura/core/models/lake/table.py +124 -0
- candura/core/models/meta/__init__.py +158 -0
- candura/core/models/meta/categories.py +28 -0
- candura/core/models/meta/code/__init__.py +54 -0
- candura/core/models/meta/code/boot_rules.py +59 -0
- candura/core/models/meta/code/dispatch.py +301 -0
- candura/core/models/meta/code/dispatch_execution.py +145 -0
- candura/core/models/meta/code/files.py +86 -0
- candura/core/models/meta/code/mclass.py +391 -0
- candura/core/models/meta/code/mclass_runtime.py +44 -0
- candura/core/models/meta/code/mclass_source.py +65 -0
- candura/core/models/meta/code/resolver.py +54 -0
- candura/core/models/meta/code/source.py +226 -0
- candura/core/models/meta/code/type_cache.py +58 -0
- candura/core/models/meta/content_policy.py +116 -0
- candura/core/models/meta/db_field.py +258 -0
- candura/core/models/meta/document_version.py +59 -0
- candura/core/models/meta/knowledge_names.py +123 -0
- candura/core/models/meta/meta.md +621 -0
- candura/core/models/meta/meta_agent_run.py +100 -0
- candura/core/models/meta/meta_agentic.py +82 -0
- candura/core/models/meta/meta_base.py +253 -0
- candura/core/models/meta/meta_cache.py +177 -0
- candura/core/models/meta/meta_components.py +386 -0
- candura/core/models/meta/meta_db.py +34 -0
- candura/core/models/meta/meta_evbus.py +80 -0
- candura/core/models/meta/meta_executions.py +373 -0
- candura/core/models/meta/meta_harness.py +353 -0
- candura/core/models/meta/meta_kernel.py +193 -0
- candura/core/models/meta/meta_lake.py +385 -0
- candura/core/models/meta/meta_model.py +64 -0
- candura/core/models/meta/meta_node.py +101 -0
- candura/core/models/meta/meta_outcome.py +144 -0
- candura/core/models/meta/meta_usage.py +52 -0
- candura/core/models/meta/query_nodes.py +134 -0
- candura/core/models/meta/scope.py +35 -0
- candura/core/models/sdk.py +17 -0
- candura/core/models/tasks.py +196 -0
- candura/core/models/telemetry.py +174 -0
- candura/core/models/uri.py +326 -0
- candura/core/modules/__init__.py +11 -0
- candura/core/modules/addons/__init__.py +41 -0
- candura/core/modules/addons/decorator.py +157 -0
- candura/core/modules/addons/native/__init__.py +21 -0
- candura/core/modules/addons/native/mclass/__init__.py +10 -0
- candura/core/modules/addons/native/mclass/execution.py +256 -0
- candura/core/modules/addons/native/mclass/factory.py +44 -0
- candura/core/modules/addons/native/mclass/instance_proxy.py +146 -0
- candura/core/modules/addons/native/mclass/invoker.py +124 -0
- candura/core/modules/addons/native/mclass/meta_class.py +332 -0
- candura/core/modules/addons/native/mclass/native_rules.py +29 -0
- candura/core/modules/addons/native/mclass/rules/__init__.py +27 -0
- candura/core/modules/addons/native/mclass/rules/dynamic.py +34 -0
- candura/core/modules/addons/native/mclass/rules/predicate.py +31 -0
- candura/core/modules/addons/native/mclass/rules/target.py +40 -0
- candura/core/modules/addons/native/mclass/rules/try_dispatch.py +36 -0
- candura/core/modules/addons/native/memoization.py +207 -0
- candura/core/modules/addons/native/remote.py +188 -0
- candura/core/modules/addons/native/tracing.py +156 -0
- candura/core/modules/addons/proxy.py +334 -0
- candura/core/modules/base/__init__.py +30 -0
- candura/core/modules/base/accessor.py +79 -0
- candura/core/modules/base/accessors/rules/__init__.py +18 -0
- candura/core/modules/base/accessors/rules/dotted.py +29 -0
- candura/core/modules/base/accessors/rules/scoped.py +24 -0
- candura/core/modules/base/addon.py +11 -0
- candura/core/modules/base/addon_base.py +237 -0
- candura/core/modules/base/addon_dynamic.py +188 -0
- candura/core/modules/base/container/__init__.py +8 -0
- candura/core/modules/base/container/addons.py +192 -0
- candura/core/modules/base/container/core.py +236 -0
- candura/core/modules/base/container/lifecycle.py +379 -0
- candura/core/modules/base/container/navigation.py +46 -0
- candura/core/modules/base/container/resolution.py +162 -0
- candura/core/modules/base/contract.py +315 -0
- candura/core/modules/base/engine.py +78 -0
- candura/core/modules/base/events.py +233 -0
- candura/core/modules/base/from_markers.py +381 -0
- candura/core/modules/base/from_resolution.py +167 -0
- candura/core/modules/base/injection/__init__.py +20 -0
- candura/core/modules/base/injection/decorator.py +62 -0
- candura/core/modules/base/injection/strategies/__init__.py +20 -0
- candura/core/modules/base/injection/strategies/agentic_strategy.py +58 -0
- candura/core/modules/base/injection/strategies/application_strategy.py +33 -0
- candura/core/modules/base/injection/strategies/base.py +25 -0
- candura/core/modules/base/injection/strategies/module_strategy.py +34 -0
- candura/core/modules/base/injection/strategies/orchestrator.py +34 -0
- candura/core/modules/base/injection/strategies/resolver.py +58 -0
- candura/core/modules/base/provider_changes.py +82 -0
- candura/core/modules/modules.md +926 -0
- candura/core/modules/native/agentics/__init__.py +27 -0
- candura/core/modules/native/agentics/engines/__init__.py +10 -0
- candura/core/modules/native/agentics/engines/cache.py +100 -0
- candura/core/modules/native/agentics/engines/pydantic/__init__.py +11 -0
- candura/core/modules/native/agentics/engines/pydantic/measure.py +60 -0
- candura/core/modules/native/agentics/engines/pydantic/model_resolution.py +125 -0
- candura/core/modules/native/agentics/engines/pydantic/module.md +62 -0
- candura/core/modules/native/agentics/engines/pydantic/module.py +356 -0
- candura/core/modules/native/agentics/engines/pydantic/runner.py +298 -0
- candura/core/modules/native/agentics/module.md +35 -0
- candura/core/modules/native/agentics/orch/__init__.py +7 -0
- candura/core/modules/native/agentics/orch/module.md +69 -0
- candura/core/modules/native/agentics/orch/module.py +169 -0
- candura/core/modules/native/cache/__init__.py +29 -0
- candura/core/modules/native/cache/contract.py +91 -0
- candura/core/modules/native/cache/definition.py +320 -0
- candura/core/modules/native/cache/module.md +105 -0
- candura/core/modules/native/cache/schemas.py +47 -0
- candura/core/modules/native/cache/zone.py +165 -0
- candura/core/modules/native/credit/__init__.py +71 -0
- candura/core/modules/native/credit/budget.py +200 -0
- candura/core/modules/native/credit/config_keys.py +52 -0
- candura/core/modules/native/credit/contract.py +113 -0
- candura/core/modules/native/credit/definition.py +369 -0
- candura/core/modules/native/credit/events.py +144 -0
- candura/core/modules/native/credit/fold.py +256 -0
- candura/core/modules/native/credit/ids.py +45 -0
- candura/core/modules/native/credit/in_flight.py +90 -0
- candura/core/modules/native/credit/ledger.py +256 -0
- candura/core/modules/native/credit/module.md +195 -0
- candura/core/modules/native/credit/operations.py +238 -0
- candura/core/modules/native/credit/periods.py +36 -0
- candura/core/modules/native/credit/price_book.py +129 -0
- candura/core/modules/native/credit/pricing.py +360 -0
- candura/core/modules/native/credit/projection.py +310 -0
- candura/core/modules/native/credit/recount.py +177 -0
- candura/core/modules/native/credit/turn_debit.py +75 -0
- candura/core/modules/native/credit/usage.py +94 -0
- candura/core/modules/native/db/__init__.py +10 -0
- candura/core/modules/native/db/base.py +278 -0
- candura/core/modules/native/db/codec.py +381 -0
- candura/core/modules/native/db/module.md +131 -0
- candura/core/modules/native/db/providers/contract.py +150 -0
- candura/core/modules/native/db/providers/inmemory/__init__.py +6 -0
- candura/core/modules/native/db/providers/inmemory/definition.py +296 -0
- candura/core/modules/native/db/repository/__init__.py +29 -0
- candura/core/modules/native/db/repository/changes.py +116 -0
- candura/core/modules/native/db/repository/contract.py +348 -0
- candura/core/modules/native/db/repository/definition.py +228 -0
- candura/core/modules/native/db/repository/execution_rule.py +212 -0
- candura/core/modules/native/db/repository/marker.py +86 -0
- candura/core/modules/native/db/repository/module.md +152 -0
- candura/core/modules/native/db/repository/purge.py +161 -0
- candura/core/modules/native/db/repository/query.py +184 -0
- candura/core/modules/native/db/repository/repository.py +388 -0
- candura/core/modules/native/db/repository/scope.py +54 -0
- candura/core/modules/native/db/repository/stamps.py +134 -0
- candura/core/modules/native/db/repository/versioning.py +134 -0
- candura/core/modules/native/eventbus/__init__.py +12 -0
- candura/core/modules/native/eventbus/codec.py +307 -0
- candura/core/modules/native/eventbus/config_keys.py +36 -0
- candura/core/modules/native/eventbus/contract.py +107 -0
- candura/core/modules/native/eventbus/definition.py +376 -0
- candura/core/modules/native/eventbus/drainer.py +165 -0
- candura/core/modules/native/eventbus/execution_rule.py +91 -0
- candura/core/modules/native/eventbus/inspection.py +89 -0
- candura/core/modules/native/eventbus/loops.py +183 -0
- candura/core/modules/native/eventbus/module.md +92 -0
- candura/core/modules/native/eventbus/packet.py +39 -0
- candura/core/modules/native/eventbus/replies.py +133 -0
- candura/core/modules/native/eventbus/subscription.py +65 -0
- candura/core/modules/native/identity/__init__.py +60 -0
- candura/core/modules/native/identity/attempts.py +80 -0
- candura/core/modules/native/identity/audit.py +385 -0
- candura/core/modules/native/identity/config_keys.py +61 -0
- candura/core/modules/native/identity/contract.py +75 -0
- candura/core/modules/native/identity/definition.py +306 -0
- candura/core/modules/native/identity/enrollment.py +302 -0
- candura/core/modules/native/identity/events.py +104 -0
- candura/core/modules/native/identity/invite_entry.py +191 -0
- candura/core/modules/native/identity/invite_uses.py +153 -0
- candura/core/modules/native/identity/invites.py +351 -0
- candura/core/modules/native/identity/module.md +208 -0
- candura/core/modules/native/identity/policy.py +143 -0
- candura/core/modules/native/identity/process_tenants.py +97 -0
- candura/core/modules/native/identity/resolver.py +245 -0
- candura/core/modules/native/identity/sessions.py +311 -0
- candura/core/modules/native/identity/tenant_status.py +36 -0
- candura/core/modules/native/identity/tenants.py +370 -0
- candura/core/modules/native/lake/__init__.py +27 -0
- candura/core/modules/native/lake/analytics/__init__.py +7 -0
- candura/core/modules/native/lake/analytics/_polars.py +19 -0
- candura/core/modules/native/lake/analytics/config_keys.py +23 -0
- candura/core/modules/native/lake/analytics/contract.py +55 -0
- candura/core/modules/native/lake/analytics/decoder.py +247 -0
- candura/core/modules/native/lake/analytics/definition.py +174 -0
- candura/core/modules/native/lake/analytics/frames.py +129 -0
- candura/core/modules/native/lake/analytics/live.py +57 -0
- candura/core/modules/native/lake/analytics/local.py +357 -0
- candura/core/modules/native/lake/analytics/module.md +83 -0
- candura/core/modules/native/lake/analytics/router.py +93 -0
- candura/core/modules/native/lake/analytics/sources.py +99 -0
- candura/core/modules/native/lake/boot.py +162 -0
- candura/core/modules/native/lake/closing.py +77 -0
- candura/core/modules/native/lake/config_keys.py +154 -0
- candura/core/modules/native/lake/contract.py +249 -0
- candura/core/modules/native/lake/counters.py +84 -0
- candura/core/modules/native/lake/definition.py +400 -0
- candura/core/modules/native/lake/discovery.py +158 -0
- candura/core/modules/native/lake/events.py +114 -0
- candura/core/modules/native/lake/lifecycle.py +136 -0
- candura/core/modules/native/lake/module.md +237 -0
- candura/core/modules/native/lake/processes.py +95 -0
- candura/core/modules/native/lake/pull.py +151 -0
- candura/core/modules/native/lake/purge.py +95 -0
- candura/core/modules/native/lake/reading.py +75 -0
- candura/core/modules/native/lake/reconcile.py +377 -0
- candura/core/modules/native/lake/settings.py +58 -0
- candura/core/modules/native/lake/tenants.py +134 -0
- candura/core/modules/native/lake/tier.py +28 -0
- candura/core/modules/native/lake/watermarks.py +196 -0
- candura/core/modules/native/loop/__init__.py +27 -0
- candura/core/modules/native/loop/_turn.py +302 -0
- candura/core/modules/native/loop/assembly.py +122 -0
- candura/core/modules/native/loop/contract.py +169 -0
- candura/core/modules/native/loop/definition.py +109 -0
- candura/core/modules/native/loop/extensions.md +325 -0
- candura/core/modules/native/loop/module.md +200 -0
- candura/core/modules/native/loop/module.py +192 -0
- candura/core/modules/native/loop/ports.py +241 -0
- candura/core/modules/native/loop/rules.py +90 -0
- candura/core/modules/native/loop/testing.py +281 -0
- candura/core/modules/native/loop/turn_delta.py +246 -0
- candura/core/modules/native/registry/__init__.py +20 -0
- candura/core/modules/native/registry/contract.py +142 -0
- candura/core/modules/native/registry/definition.py +222 -0
- candura/core/modules/native/registry/entry.py +23 -0
- candura/core/modules/native/registry/module.md +401 -0
- candura/core/modules/native/registry/resolver.py +135 -0
- candura/core/modules/native/storage/__init__.py +20 -0
- candura/core/modules/native/storage/base.py +65 -0
- candura/core/modules/native/storage/contract.py +36 -0
- candura/core/modules/native/storage/definition.py +90 -0
- candura/core/modules/native/storage/module.md +63 -0
- candura/core/modules/native/storage/selection.py +63 -0
- candura/core/nodes/__init__.py +94 -0
- candura/core/nodes/base/__init__.py +23 -0
- candura/core/nodes/base/binding.py +306 -0
- candura/core/nodes/base/channel.py +137 -0
- candura/core/nodes/base/channel_identity.py +173 -0
- candura/core/nodes/base/coercion.py +107 -0
- candura/core/nodes/base/endpoint.py +381 -0
- candura/core/nodes/base/endpoint_checks.py +59 -0
- candura/core/nodes/base/host.py +86 -0
- candura/core/nodes/base/identity.py +44 -0
- candura/core/nodes/base/lifecycle.py +77 -0
- candura/core/nodes/base/messaging.py +380 -0
- candura/core/nodes/base/node.py +371 -0
- candura/core/nodes/base/outbox.py +278 -0
- candura/core/nodes/base/paths.py +213 -0
- candura/core/nodes/base/pipeline.py +398 -0
- candura/core/nodes/base/registration.py +81 -0
- candura/core/nodes/base/response.py +160 -0
- candura/core/nodes/base/server.py +376 -0
- candura/core/nodes/base/subjects.py +75 -0
- candura/core/nodes/base/websocket.py +117 -0
- candura/core/nodes/definition.py +84 -0
- candura/core/nodes/internals/__init__.py +5 -0
- candura/core/nodes/internals/adapters/__init__.py +49 -0
- candura/core/nodes/internals/adapters/asgi.py +325 -0
- candura/core/nodes/internals/adapters/base.py +263 -0
- candura/core/nodes/internals/adapters/engine.py +244 -0
- candura/core/nodes/internals/adapters/infra.py +141 -0
- candura/core/nodes/internals/adapters/lifespan.py +135 -0
- candura/core/nodes/internals/adapters/litestar.py +230 -0
- candura/core/nodes/internals/adapters/routing.py +337 -0
- candura/core/nodes/internals/adapters/websocket.py +280 -0
- candura/core/nodes/internals/delivery/__init__.py +26 -0
- candura/core/nodes/internals/delivery/bus_binding.py +132 -0
- candura/core/nodes/internals/delivery/channels.py +87 -0
- candura/core/nodes/internals/delivery/envelope.py +43 -0
- candura/core/nodes/internals/delivery/idempotency.py +347 -0
- candura/core/nodes/internals/delivery/policy.py +229 -0
- candura/core/nodes/internals/delivery/remote.py +251 -0
- candura/core/nodes/internals/delivery/turn_completion.py +160 -0
- candura/core/nodes/internals/http/__init__.py +5 -0
- candura/core/nodes/internals/http/access_log.py +76 -0
- candura/core/nodes/internals/http/cors.py +149 -0
- candura/core/nodes/internals/http/guard.py +47 -0
- candura/core/nodes/internals/http/identity_middleware.py +284 -0
- candura/core/nodes/internals/http/identity_resolver.py +263 -0
- candura/core/nodes/internals/http/problems.py +123 -0
- candura/core/nodes/internals/http/routes.py +25 -0
- candura/core/nodes/internals/http/security.py +170 -0
- candura/core/nodes/internals/http/table.py +368 -0
- candura/core/nodes/internals/mcp/__init__.py +20 -0
- candura/core/nodes/internals/mcp/adapter.py +162 -0
- candura/core/nodes/internals/mcp/catalog.py +209 -0
- candura/core/nodes/internals/telemetry/__init__.py +2 -0
- candura/core/nodes/internals/telemetry/debit.py +101 -0
- candura/core/nodes/internals/telemetry/execution_rule.py +260 -0
- candura/core/nodes/internals/telemetry/resources.py +66 -0
- candura/core/nodes/internals/telemetry/scope.py +57 -0
- candura/core/nodes/internals/telemetry/shutdown.py +127 -0
- candura/core/nodes/internals/telemetry/startup.py +81 -0
- candura/core/nodes/native/admin/__init__.py +145 -0
- candura/core/nodes/native/admin/agents.py +145 -0
- candura/core/nodes/native/admin/credit_handlers.py +171 -0
- candura/core/nodes/native/admin/credit_models.py +130 -0
- candura/core/nodes/native/admin/events.py +92 -0
- candura/core/nodes/native/admin/execution_models.py +105 -0
- candura/core/nodes/native/admin/execution_queries.py +350 -0
- candura/core/nodes/native/admin/handler_rules.py +56 -0
- candura/core/nodes/native/admin/handlers.py +139 -0
- candura/core/nodes/native/admin/identity_panel.py +92 -0
- candura/core/nodes/native/admin/identity_tenants.py +399 -0
- candura/core/nodes/native/admin/loop_target.py +156 -0
- candura/core/nodes/native/admin/metric_costs.py +76 -0
- candura/core/nodes/native/admin/models.py +367 -0
- candura/core/nodes/native/admin/module.md +98 -0
- candura/core/nodes/native/admin/node.py +194 -0
- candura/core/nodes/native/admin/observation_handlers.py +198 -0
- candura/core/nodes/native/admin/operator_handlers.py +211 -0
- candura/core/nodes/native/admin/operator_models.py +132 -0
- candura/core/nodes/native/admin/panel_models.py +65 -0
- candura/core/nodes/native/admin/queries.py +174 -0
- candura/core/nodes/native/admin/server_info.py +75 -0
- candura/core/nodes/native/admin/stream.py +143 -0
- candura/core/nodes/native/admin/targets.py +289 -0
- candura/core/nodes/native/admin/task_models.py +43 -0
- candura/core/nodes/native/admin/task_queries.py +153 -0
- candura/core/nodes/native/admin/tenant_creation.py +220 -0
- candura/core/nodes/native/admin/tenant_handlers.py +114 -0
- candura/core/nodes/native/admin/tenants.py +178 -0
- candura/core/nodes/native/admin/tenants_view.py +61 -0
- candura/core/nodes/native/admin/usage_accounts.py +203 -0
- candura/core/nodes/native/admin/usage_models.py +83 -0
- candura/core/nodes/native/admin/usage_report.py +216 -0
- candura/core/nodes/native/admin/usage_report_models.py +95 -0
- candura/core/nodes/native/dataadmin/__init__.py +56 -0
- candura/core/nodes/native/dataadmin/db.py +323 -0
- candura/core/nodes/native/dataadmin/events.py +54 -0
- candura/core/nodes/native/dataadmin/filters.py +89 -0
- candura/core/nodes/native/dataadmin/guard.py +87 -0
- candura/core/nodes/native/dataadmin/handlers.py +287 -0
- candura/core/nodes/native/dataadmin/inflight.py +60 -0
- candura/core/nodes/native/dataadmin/lake.py +237 -0
- candura/core/nodes/native/dataadmin/models.py +268 -0
- candura/core/nodes/native/dataadmin/module.md +59 -0
- candura/core/nodes/native/dataadmin/node.py +84 -0
- candura/core/nodes/native/dataadmin/sandbox.py +260 -0
- candura/core/nodes/native/identity/__init__.py +26 -0
- candura/core/nodes/native/identity/module.md +130 -0
- candura/core/nodes/native/identity/node.py +339 -0
- candura/core/nodes/native/identity/pages.py +114 -0
- candura/core/nodes/native/identity/request.py +97 -0
- candura/core/nodes/native/operation/__init__.py +53 -0
- candura/core/nodes/native/operation/audit.py +110 -0
- candura/core/nodes/native/operation/catalog.py +105 -0
- candura/core/nodes/native/operation/channels.py +15 -0
- candura/core/nodes/native/operation/config_keys.py +30 -0
- candura/core/nodes/native/operation/contract.py +30 -0
- candura/core/nodes/native/operation/guards.py +59 -0
- candura/core/nodes/native/operation/module.md +51 -0
- candura/core/nodes/native/operation/moments.py +110 -0
- candura/core/nodes/native/operation/tenants.py +66 -0
- candura/core/nodes/native/operation/values.py +41 -0
- candura/core/nodes/native/simul/__init__.py +38 -0
- candura/core/nodes/native/simul/events.py +30 -0
- candura/core/nodes/native/simul/guard.py +86 -0
- candura/core/nodes/native/simul/module.md +41 -0
- candura/core/nodes/native/simul/node.py +169 -0
- candura/core/nodes/native/simul/port.py +151 -0
- candura/core/nodes/native/tasks/__init__.py +22 -0
- candura/core/nodes/native/tasks/keys.py +213 -0
- candura/core/nodes/native/tasks/models.py +173 -0
- candura/core/nodes/native/tasks/module.md +209 -0
- candura/core/nodes/native/tasks/node.py +247 -0
- candura/core/nodes/native/tasks/runner.py +169 -0
- candura/core/nodes/native/telegram/__init__.py +83 -0
- candura/core/nodes/native/telegram/aiogram_adapter.py +341 -0
- candura/core/nodes/native/telegram/attachments.py +52 -0
- candura/core/nodes/native/telegram/blobs.py +23 -0
- candura/core/nodes/native/telegram/bot_identity.py +81 -0
- candura/core/nodes/native/telegram/confirmation.py +133 -0
- candura/core/nodes/native/telegram/definition.py +112 -0
- candura/core/nodes/native/telegram/egress.py +279 -0
- candura/core/nodes/native/telegram/fake.py +232 -0
- candura/core/nodes/native/telegram/fake_webhook.py +205 -0
- candura/core/nodes/native/telegram/gateway.py +91 -0
- candura/core/nodes/native/telegram/guards.py +277 -0
- candura/core/nodes/native/telegram/ingress.py +347 -0
- candura/core/nodes/native/telegram/models.py +74 -0
- candura/core/nodes/native/telegram/module.md +169 -0
- candura/core/nodes/native/telegram/module.py +142 -0
- candura/core/nodes/native/telegram/normalize.py +85 -0
- candura/core/nodes/native/telegram/render.py +168 -0
- candura/core/nodes/native/telegram/settings.py +325 -0
- candura/core/nodes/native/telegram/source.py +204 -0
- candura/core/nodes/native/telegram/testing/__init__.py +37 -0
- candura/core/nodes/native/telegram/testing/chat.py +77 -0
- candura/core/nodes/native/telegram/testing/config.py +102 -0
- candura/core/nodes/native/telegram/testing/fake_chat.py +96 -0
- candura/core/nodes/native/telegram/testing/markdown.py +69 -0
- candura/core/nodes/native/telegram/testing/module.md +38 -0
- candura/core/nodes/native/telegram/testing/user_driver.py +239 -0
- candura/core/nodes/native/telegram/texts.py +70 -0
- candura/core/nodes/native/telegram/typing.py +87 -0
- candura/core/nodes/native/telegram/web_identity.py +204 -0
- candura/core/nodes/native/telegram/webhook.py +238 -0
- candura/core/nodes/nodes.md +873 -0
- candura/extensions/__init__.py +7 -0
- candura/extensions/a2ui/__init__.py +121 -0
- candura/extensions/a2ui/asgi.py +82 -0
- candura/extensions/a2ui/catalog/__init__.py +31 -0
- candura/extensions/a2ui/catalog/candura/v1/catalog.json +410 -0
- candura/extensions/a2ui/catalog/candura/v1/examples/Badge.json +16 -0
- candura/extensions/a2ui/catalog/candura/v1/examples/Chart.json +46 -0
- candura/extensions/a2ui/catalog/candura/v1/examples/Link.json +12 -0
- candura/extensions/a2ui/catalog/candura/v1/examples/Markdown.json +12 -0
- candura/extensions/a2ui/catalog/candura/v1/examples/ParamBar.json +16 -0
- candura/extensions/a2ui/catalog/candura/v1/examples/Stat.json +14 -0
- candura/extensions/a2ui/catalog/candura/v1/examples/Table.json +22 -0
- candura/extensions/a2ui/catalog/candura/v1/examples/Timeline.json +17 -0
- candura/extensions/a2ui/catalog/candura/v1/examples/WeekGrid.json +29 -0
- candura/extensions/a2ui/catalog/candura/v1/rules.txt +29 -0
- candura/extensions/a2ui/catalog/catalog.py +96 -0
- candura/extensions/a2ui/codec.py +386 -0
- candura/extensions/a2ui/config_keys.py +102 -0
- candura/extensions/a2ui/contract.py +198 -0
- candura/extensions/a2ui/definition.py +304 -0
- candura/extensions/a2ui/delivery.py +346 -0
- candura/extensions/a2ui/destination.py +97 -0
- candura/extensions/a2ui/devtools/__init__.py +29 -0
- candura/extensions/a2ui/devtools/guard.py +42 -0
- candura/extensions/a2ui/devtools/node.py +159 -0
- candura/extensions/a2ui/devtools/preview.py +292 -0
- candura/extensions/a2ui/devtools/simulate.py +332 -0
- candura/extensions/a2ui/enter.py +131 -0
- candura/extensions/a2ui/events.py +169 -0
- candura/extensions/a2ui/handlers.py +191 -0
- candura/extensions/a2ui/internals/__init__.py +5 -0
- candura/extensions/a2ui/internals/bundle.py +276 -0
- candura/extensions/a2ui/internals/reader.py +184 -0
- candura/extensions/a2ui/internals/schema.py +180 -0
- candura/extensions/a2ui/internals/webapp.py +259 -0
- candura/extensions/a2ui/links.py +252 -0
- candura/extensions/a2ui/materializer.py +143 -0
- candura/extensions/a2ui/models/__init__.py +60 -0
- candura/extensions/a2ui/models/address.py +51 -0
- candura/extensions/a2ui/models/document.py +99 -0
- candura/extensions/a2ui/models/params.py +152 -0
- candura/extensions/a2ui/models/records.py +161 -0
- candura/extensions/a2ui/models/request.py +48 -0
- candura/extensions/a2ui/models/values.py +103 -0
- candura/extensions/a2ui/models/view.py +165 -0
- candura/extensions/a2ui/models/web.py +63 -0
- candura/extensions/a2ui/module.md +137 -0
- candura/extensions/a2ui/node.py +339 -0
- candura/extensions/a2ui/param_bar.py +138 -0
- candura/extensions/a2ui/presentation.py +158 -0
- candura/extensions/a2ui/profiles.py +150 -0
- candura/extensions/a2ui/publications.py +296 -0
- candura/extensions/a2ui/registry.py +35 -0
- candura/extensions/a2ui/renderer.py +122 -0
- candura/extensions/a2ui/runner.py +94 -0
- candura/extensions/a2ui/runtime.py +281 -0
- candura/extensions/a2ui/services.py +179 -0
- candura/extensions/a2ui/settings.py +111 -0
- candura/extensions/a2ui/support.py +72 -0
- candura/extensions/a2ui/system/__init__.py +50 -0
- candura/extensions/a2ui/system/providers.py +59 -0
- candura/extensions/a2ui/system/publicacoes.a2ui.jsonl +5 -0
- candura/extensions/a2ui/view_store.py +145 -0
- candura/extensions/db/__init__.py +2 -0
- candura/extensions/db/firestore/__init__.py +6 -0
- candura/extensions/db/firestore/changes.py +74 -0
- candura/extensions/db/firestore/config_keys.py +26 -0
- candura/extensions/db/firestore/definition.py +346 -0
- candura/extensions/db/firestore/filters.py +125 -0
- candura/extensions/db/firestore/indexes.py +239 -0
- candura/extensions/db/firestore/layout.py +90 -0
- candura/extensions/db/firestore/limits.py +119 -0
- candura/extensions/db/firestore/memory.py +182 -0
- candura/extensions/db/firestore/module.md +38 -0
- candura/extensions/db/firestore/purge.py +136 -0
- candura/extensions/db/firestore/query_shape.py +127 -0
- candura/extensions/db/firestore/transport.py +70 -0
- candura/extensions/db/firestore/versioned.py +290 -0
- candura/extensions/db/surrealdb/__init__.py +6 -0
- candura/extensions/db/surrealdb/admin.py +86 -0
- candura/extensions/db/surrealdb/connection.py +225 -0
- candura/extensions/db/surrealdb/definition.py +399 -0
- candura/extensions/db/surrealdb/layout.py +152 -0
- candura/extensions/db/surrealdb/module.md +47 -0
- candura/extensions/db/surrealdb/versioned.py +69 -0
- candura/extensions/gcp/gcs/__init__.py +6 -0
- candura/extensions/gcp/gcs/definition.py +152 -0
- candura/extensions/gcp/gcs/module.md +35 -0
- candura/extensions/nodes/__init__.py +2 -0
- candura/extensions/nodes/adapters/__init__.py +6 -0
- candura/extensions/nodes/adapters/fastapi/__init__.py +8 -0
- candura/extensions/nodes/adapters/fastapi/context.py +80 -0
- candura/extensions/nodes/adapters/fastapi/module.md +22 -0
- candura/extensions/nodes/adapters/fastapi/server.py +355 -0
- candura/extensions/report/__init__.py +21 -0
- candura/extensions/report/contract.py +55 -0
- candura/extensions/report/definition.py +130 -0
- candura/extensions/report/engine.py +72 -0
- candura/extensions/report/markdown.py +171 -0
- candura/extensions/report/models.py +123 -0
- candura/extensions/report/module.md +68 -0
- candura/extensions/report/pdf_renderer.py +107 -0
- candura/extensions/report/theme.py +52 -0
- candura/extensions/report/themes/candura/fonts/Inter-Bold.ttf +0 -0
- candura/extensions/report/themes/candura/fonts/Inter-ExtraBold.ttf +0 -0
- candura/extensions/report/themes/candura/fonts/Inter-Italic.ttf +0 -0
- candura/extensions/report/themes/candura/fonts/Inter-Medium.ttf +0 -0
- candura/extensions/report/themes/candura/fonts/Inter-Regular.ttf +0 -0
- candura/extensions/report/themes/candura/fonts/Inter-SemiBold.ttf +0 -0
- candura/extensions/report/themes/candura/fonts/OFL.txt +92 -0
- candura/extensions/report/themes/candura/template.html.j2 +49 -0
- candura/extensions/report/themes/candura/theme.css +196 -0
- candura/extensions/sandbox/lua/__init__.py +20 -0
- candura/extensions/sandbox/lua/environment.py +172 -0
- candura/extensions/sandbox/lua/extensions/collection.lua +35 -0
- candura/extensions/sandbox/lua/extensions/context.lua +61 -0
- candura/extensions/sandbox/lua/extensions/core.lua +108 -0
- candura/extensions/sandbox/lua/extensions/env.lua +125 -0
- candura/extensions/sandbox/lua/extensions/guard.lua +50 -0
- candura/extensions/sandbox/lua/extensions/util.lua +60 -0
- candura/extensions/sandbox/lua/loader.py +65 -0
- candura/extensions/sandbox/lua/process.py +195 -0
- candura/extensions/sandbox/lua/sandbox.py +119 -0
- candura/extensions/sandbox/module.md +23 -0
- candura-0.2.4.dev1.dist-info/METADATA +95 -0
- candura-0.2.4.dev1.dist-info/RECORD +841 -0
- candura-0.2.4.dev1.dist-info/WHEEL +5 -0
- candura-0.2.4.dev1.dist-info/licenses/LICENSE +202 -0
- candura-0.2.4.dev1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
# candura/core/nodes/native/telegram/module.py
|
|
2
|
+
"""`TelegramGatewayModule` (REQ-SDK-15): o gateway da Bot API como módulo do container do SDK.
|
|
3
|
+
|
|
4
|
+
`sdk.node.Telegram(...)` usa o gateway registrado; sem ele, cria o `AiogramGateway` com o token da configuração e o
|
|
5
|
+
registra. Nos testes, `CanduraTestSdk(modules=[TelegramGatewayModule(FakeTelegramGateway())])` substitui o canal, como a
|
|
6
|
+
engine de LLM é substituída. Cada bot tem o seu gateway (REQ-CLI-31): o do prefixo `BODYSTRENGTH` é o módulo
|
|
7
|
+
`TelegramGatewayBodystrength` (`TelegramGatewayModule.for_prefix("BODYSTRENGTH", gateway)`), uma subclasse com o
|
|
8
|
+
`name` de classe próprio (REQ-ND-13-07).
|
|
9
|
+
|
|
10
|
+
O módulo guarda também a identidade conferida do bot (`identity`, REQ-ND-14-10): o ingress do bot a confere no
|
|
11
|
+
`on_start`; quem emite um convite confere antes de gravar (`telegram_invite_check(sdk, prefix=...)`), e
|
|
12
|
+
`telegram_invite_link(sdk, código, prefix=...)` monta o link pelo resultado.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
from typing import TYPE_CHECKING, Any, ClassVar, List, Optional
|
|
18
|
+
|
|
19
|
+
from candura.core.config import prefix_camel
|
|
20
|
+
from candura.core.current import DEFAULT_NAMESPACE
|
|
21
|
+
from candura.core.models.error import TelegramError
|
|
22
|
+
from candura.core.modules.base.contract import Module
|
|
23
|
+
|
|
24
|
+
from .bot_identity import TelegramBotIdentity
|
|
25
|
+
from .gateway import TelegramGateway
|
|
26
|
+
from .settings import configured_username, telegram_keys
|
|
27
|
+
|
|
28
|
+
if TYPE_CHECKING:
|
|
29
|
+
from candura.core.internals.namespaces.candura import SdkPublic
|
|
30
|
+
|
|
31
|
+
GATEWAY_MODULE = "TelegramGateway"
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def gateway_module_name(prefix: str = "") -> str:
|
|
35
|
+
"""O nome do módulo do gateway do bot: `TelegramGateway` sem prefixo, `TelegramGateway<Prefixo>` com ele
|
|
36
|
+
(`MEU_BOT` → `TelegramGatewayMeuBot`)."""
|
|
37
|
+
return f"{GATEWAY_MODULE}{prefix_camel(prefix)}"
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class TelegramGatewayModule(Module[TelegramGateway]):
|
|
41
|
+
"""Módulo que expõe uma instância de `TelegramGateway` como interface.
|
|
42
|
+
|
|
43
|
+
Padrão: Adapter (porta da Bot API exposta pelo container); `for_prefix` é o Factory Method do gateway de um bot.
|
|
44
|
+
"""
|
|
45
|
+
|
|
46
|
+
namespace: ClassVar[str | None] = DEFAULT_NAMESPACE
|
|
47
|
+
name: ClassVar[str] = GATEWAY_MODULE
|
|
48
|
+
description: ClassVar[str] = "Gateway da Bot API do Telegram (produção: Aiogram; testes: FakeTelegramGateway)."
|
|
49
|
+
contract: ClassVar[type] = TelegramGateway
|
|
50
|
+
prefix: ClassVar[str] = ""
|
|
51
|
+
"""O prefixo do bot (`for_prefix`): a `IdentityTenantPort` acha por ele o único bot do servidor."""
|
|
52
|
+
|
|
53
|
+
def __init__(self, gateway: Any) -> None:
|
|
54
|
+
super().__init__()
|
|
55
|
+
self.gateway = gateway
|
|
56
|
+
self.identity = TelegramBotIdentity()
|
|
57
|
+
"""A identidade do bot conferida pelo ingress (`getMe`), lida pelos convites."""
|
|
58
|
+
|
|
59
|
+
@classmethod
|
|
60
|
+
def for_prefix(cls, prefix: str, gateway: Any) -> "TelegramGatewayModule":
|
|
61
|
+
"""O módulo do gateway do bot do `prefix`: sem prefixo, este módulo (`TelegramGateway`); com ele, uma subclasse
|
|
62
|
+
cujo `name` de classe é `TelegramGateway<Prefixo>`, para conviver com os gateways de outros bots no mesmo SDK.
|
|
63
|
+
A subclasse continua `isinstance` desta, e o container a encontra pelo nome.
|
|
64
|
+
|
|
65
|
+
Raises:
|
|
66
|
+
TelegramError: prefixo inválido (as mesmas regras das chaves, `telegram_keys`).
|
|
67
|
+
"""
|
|
68
|
+
if not prefix:
|
|
69
|
+
return cls(gateway)
|
|
70
|
+
telegram_keys(prefix) # valida o prefixo
|
|
71
|
+
camel = prefix_camel(prefix)
|
|
72
|
+
attributes = {"name": gateway_module_name(prefix), "prefix": prefix, "__module__": cls.__module__}
|
|
73
|
+
bot_module = type(f"TelegramGateway{camel}Module", (cls,), attributes)
|
|
74
|
+
return bot_module(gateway)
|
|
75
|
+
|
|
76
|
+
def get_interface(self) -> TelegramGateway:
|
|
77
|
+
"""Retorna a instância do gateway encapsulada pelo módulo."""
|
|
78
|
+
return self.gateway
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def registered_gateway(sdk: "SdkPublic", prefix: str = "") -> Optional[TelegramGatewayModule]:
|
|
82
|
+
"""O módulo do gateway do bot do `prefix` registrado no SDK, pelo nome composto do prefixo; `None` sem ele. A
|
|
83
|
+
presença é consultada por `mod.has`, sem exceção como fluxo (REQ-ND-14-02).
|
|
84
|
+
|
|
85
|
+
Raises:
|
|
86
|
+
TelegramError: o módulo com o nome do gateway do bot não é um `TelegramGatewayModule` (não guarda a
|
|
87
|
+
conferência do bot, que o ingress e os convites leem).
|
|
88
|
+
"""
|
|
89
|
+
name = gateway_module_name(prefix)
|
|
90
|
+
if not sdk.internals.mod.has(name):
|
|
91
|
+
return None
|
|
92
|
+
module = sdk.internals.mod.get(name)
|
|
93
|
+
if not isinstance(module, TelegramGatewayModule):
|
|
94
|
+
raise TelegramError(f"O módulo '{name}' não é um TelegramGatewayModule: o bot não tem o gateway.")
|
|
95
|
+
return module
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def registered_prefixes(sdk: "SdkPublic") -> List[str]:
|
|
99
|
+
"""Os prefixos dos bots com o gateway registrado no SDK (`""` é o bot sem prefixo), em ordem e sem repetição."""
|
|
100
|
+
return sorted({module.prefix for module in sdk.internals.mod.all() if isinstance(module, TelegramGatewayModule)})
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def bot_identity(sdk: "SdkPublic", prefix: str = "") -> TelegramBotIdentity:
|
|
104
|
+
"""A identidade do bot do `prefix` no SDK: a do módulo do gateway (a que o ingress confere); sem o módulo, uma
|
|
105
|
+
ainda não conferida."""
|
|
106
|
+
module = registered_gateway(sdk, prefix)
|
|
107
|
+
return module.identity if module is not None else TelegramBotIdentity()
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def telegram_invite_check(sdk: "SdkPublic", *, prefix: str = "") -> None:
|
|
111
|
+
"""Confere, antes de emitir (gravar) um convite do bot do `prefix`, que o ingress não recusou a chave do usuário
|
|
112
|
+
do bot (`TelegramBotIdentity.check`); sem efeito quando não recusou.
|
|
113
|
+
|
|
114
|
+
Raises:
|
|
115
|
+
TelegramBotMismatchError: o ingress recusou o usuário configurado (o link levaria a outro bot).
|
|
116
|
+
TelegramError: o módulo com o nome do gateway do bot não é um `TelegramGatewayModule`.
|
|
117
|
+
"""
|
|
118
|
+
bot_identity(sdk, prefix).check()
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def telegram_invite_link(sdk: "SdkPublic", payload: str, *, prefix: str = "") -> Optional[str]:
|
|
122
|
+
"""O link de convite do bot do `prefix` (`https://t.me/<usuário>?start=<payload>`, com `*_TELEGRAM_BOT_USERNAME`),
|
|
123
|
+
pela conferência do ingress (`TelegramBotIdentity.invite_link`): `None` sem a chave ou com ela recusada, nunca o
|
|
124
|
+
link de outro bot. Quem emite o convite confere antes (`telegram_invite_check`).
|
|
125
|
+
|
|
126
|
+
Raises:
|
|
127
|
+
TelegramError: `payload` fora do que o Telegram aceita no `start`, ou o módulo com o nome do gateway do bot não
|
|
128
|
+
é um `TelegramGatewayModule`.
|
|
129
|
+
"""
|
|
130
|
+
return bot_identity(sdk, prefix).invite_link(configured_username(sdk.internals.config, prefix), payload)
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
__all__ = [
|
|
134
|
+
"GATEWAY_MODULE",
|
|
135
|
+
"TelegramGatewayModule",
|
|
136
|
+
"bot_identity",
|
|
137
|
+
"gateway_module_name",
|
|
138
|
+
"registered_gateway",
|
|
139
|
+
"registered_prefixes",
|
|
140
|
+
"telegram_invite_check",
|
|
141
|
+
"telegram_invite_link",
|
|
142
|
+
]
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# candura/core/nodes/native/telegram/normalize.py
|
|
2
|
+
"""Normalização de um update do Telegram em `InboundMessage` neutra (REQ-TGM-05, REQ-ND-13-14), sem I/O.
|
|
3
|
+
|
|
4
|
+
Comandos (`/cmd args`, inclusive `/cmd@bot`) viram `command`/`args` pelo parser canônico (`parse_command`, o mesmo de
|
|
5
|
+
`LoopRequest.of_text`); o anexo chega já gravado (`attachments.store_attachment`).
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from typing import List, Optional, Sequence, Tuple
|
|
11
|
+
|
|
12
|
+
from candura.core.models.channel import AttachmentRef, ChannelIdentity, InboundMessage
|
|
13
|
+
from candura.core.nodes.base.channel import parse_command
|
|
14
|
+
|
|
15
|
+
from .models import CHANNEL, TelegramUpdate
|
|
16
|
+
from .settings import TelegramSettings
|
|
17
|
+
|
|
18
|
+
START_COMMAND = "start"
|
|
19
|
+
"""O comando do link de entrada do Telegram: `https://t.me/<bot>?start=<código>` chega como `/start <código>`."""
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def telegram_command(text: Optional[str], bot_username: Optional[str] = None) -> Tuple[Optional[str], List[str]]:
|
|
23
|
+
"""O comando pelo parser canônico, com o pré-passo do `@bot`: `/treino@outro_bot` não é para este bot → texto."""
|
|
24
|
+
addressed, args = parse_command(text)
|
|
25
|
+
command, _, target = (addressed or "").partition("@")
|
|
26
|
+
if not command or (target and bot_username and target.lower() != bot_username.lower()):
|
|
27
|
+
return None, []
|
|
28
|
+
return command, args
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def message_id_of(bot_name: str, update: TelegramUpdate) -> str:
|
|
32
|
+
"""Id estável da mensagem (`event_id` dos consumidores): o mesmo em toda reentrega do update."""
|
|
33
|
+
return f"tg:{bot_name}:{update.update_id}"
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def inbound_message(
|
|
37
|
+
update: TelegramUpdate,
|
|
38
|
+
identity: ChannelIdentity,
|
|
39
|
+
*,
|
|
40
|
+
settings: TelegramSettings,
|
|
41
|
+
attachments: Sequence[AttachmentRef] = (),
|
|
42
|
+
bot_username: Optional[str] = None,
|
|
43
|
+
) -> InboundMessage:
|
|
44
|
+
"""`InboundMessage` do update (já aprovado pelas pré-condições) com os anexos já gravados; função pura. O chat é
|
|
45
|
+
privado pelo `chat.type` do update (REQ-LOOP-24-01)."""
|
|
46
|
+
command, args = telegram_command(update.text, bot_username)
|
|
47
|
+
return InboundMessage(
|
|
48
|
+
message_id=message_id_of(settings.bot_name, update),
|
|
49
|
+
channel=CHANNEL,
|
|
50
|
+
chat_id=str(update.chat_id),
|
|
51
|
+
identity=identity,
|
|
52
|
+
text=update.text,
|
|
53
|
+
command=command,
|
|
54
|
+
args=args,
|
|
55
|
+
attachments=list(attachments),
|
|
56
|
+
reply_to=settings.outbound_subject,
|
|
57
|
+
private=update.private,
|
|
58
|
+
**({"received_at": update.date} if update.date else {}),
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def carries_start_args(message: InboundMessage) -> bool:
|
|
63
|
+
"""A mensagem é um `/start` com argumentos: o comando normalizado, ou o texto cujo primeiro termo é `/start` ou
|
|
64
|
+
`/start@<qualquer bot>` (o de outro bot não vira comando aqui, e o código iria inteiro ao barramento)."""
|
|
65
|
+
if message.command == START_COMMAND and message.args:
|
|
66
|
+
return True
|
|
67
|
+
parts = (message.text or "").split(maxsplit=1)
|
|
68
|
+
return len(parts) == 2 and parts[0].split("@", 1)[0].lower() == f"/{START_COMMAND}"
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def without_invite_code(message: InboundMessage) -> InboundMessage:
|
|
72
|
+
"""A mensagem do `/start` com argumentos sem eles: `command="start"`, sem `args` e o texto `/start`. Com o
|
|
73
|
+
resolvedor padrão da Identity, o ingress a publica assim (o código do convite, aceito ou não, num chat privado ou
|
|
74
|
+
num grupo), e o código não chega ao histórico da conversa, ao lake, ao intérprete nem ao log."""
|
|
75
|
+
return message.model_copy(update={"text": f"/{START_COMMAND}", "command": START_COMMAND, "args": []})
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
__all__ = [
|
|
79
|
+
"START_COMMAND",
|
|
80
|
+
"carries_start_args",
|
|
81
|
+
"inbound_message",
|
|
82
|
+
"message_id_of",
|
|
83
|
+
"telegram_command",
|
|
84
|
+
"without_invite_code",
|
|
85
|
+
]
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
# candura/core/nodes/native/telegram/render.py
|
|
2
|
+
"""Texto para o Telegram (REQ-TGM-09): markdown simples → MarkdownV2 escapado, e divisão de textos longos.
|
|
3
|
+
|
|
4
|
+
O egress recebe markdown (`**negrito**`, `_itálico_`, `` `código` ``, blocos ```` ``` ````, `[texto](url)`, títulos `#`)
|
|
5
|
+
e o converte para MarkdownV2, escapando todo o resto: um `.`, `-` ou `(` solto não derruba a mensagem. A Bot API limita
|
|
6
|
+
cada mensagem a 4096 caracteres; `split_text` divide em quebras naturais (parágrafo, linha, espaço) medindo o texto
|
|
7
|
+
**já escapado**, e nunca separa um bloco de código aberto.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
import re
|
|
13
|
+
from typing import Callable, List, NamedTuple, Tuple
|
|
14
|
+
|
|
15
|
+
MAX_MESSAGE_CHARS = 4096
|
|
16
|
+
MAX_CAPTION_CHARS = 1024
|
|
17
|
+
|
|
18
|
+
_SPECIAL = re.compile(r"([_*\[\]()~`>#+\-=|{}.!\\])")
|
|
19
|
+
_CODE_SPECIAL = re.compile(r"([`\\])")
|
|
20
|
+
_URL_SPECIAL = re.compile(r"([)\\])")
|
|
21
|
+
_HEADING = re.compile(r"^#{1,6}[ \t]+(.+?)[ \t]*$", re.MULTILINE)
|
|
22
|
+
_TOKEN = re.compile(
|
|
23
|
+
r"```(?P<block>.*?)```"
|
|
24
|
+
r"|`(?P<code>[^`\n]+)`"
|
|
25
|
+
r"|\*\*(?P<bold>[^*\n]+?)\*\*"
|
|
26
|
+
r"|(?<![\w*])\*(?P<star>[^*\n]+?)\*(?![\w*])"
|
|
27
|
+
r"|(?<![\w])_(?P<italic>[^_\n]+?)_(?![\w])"
|
|
28
|
+
r"|\[(?P<label>[^\]\n]+)\]\((?P<url>[^)\s]+)\)",
|
|
29
|
+
re.DOTALL,
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def escape_text(text: str) -> str:
|
|
34
|
+
"""Escapa os caracteres especiais do MarkdownV2 em texto comum."""
|
|
35
|
+
return _SPECIAL.sub(r"\\\1", text)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _block(raw: str) -> str:
|
|
39
|
+
return "```" + _CODE_SPECIAL.sub(r"\\\1", raw) + "```"
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def to_markdown_v2(markdown: str) -> str:
|
|
43
|
+
"""Markdown simples → MarkdownV2 válido; tudo que não é marcação reconhecida vira texto escapado."""
|
|
44
|
+
text = _HEADING.sub(r"**\1**", markdown)
|
|
45
|
+
out: List[str] = []
|
|
46
|
+
cursor = 0
|
|
47
|
+
for match in _TOKEN.finditer(text):
|
|
48
|
+
out.append(escape_text(text[cursor : match.start()]))
|
|
49
|
+
cursor = match.end()
|
|
50
|
+
kind = match.lastgroup
|
|
51
|
+
if kind == "block":
|
|
52
|
+
out.append(_block(match["block"]))
|
|
53
|
+
elif kind == "code":
|
|
54
|
+
out.append("`" + _CODE_SPECIAL.sub(r"\\\1", match["code"]) + "`")
|
|
55
|
+
elif kind in ("bold", "star"):
|
|
56
|
+
out.append("*" + escape_text(match[kind]) + "*")
|
|
57
|
+
elif kind == "italic":
|
|
58
|
+
out.append("_" + escape_text(match["italic"]) + "_")
|
|
59
|
+
else: # link
|
|
60
|
+
out.append("[" + escape_text(match["label"]) + "](" + _URL_SPECIAL.sub(r"\\\1", match["url"]) + ")")
|
|
61
|
+
out.append(escape_text(text[cursor:]))
|
|
62
|
+
return "".join(out)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def _cut(rest: str, measure: Callable[[str], int], limit: int) -> int:
|
|
66
|
+
"""Maior prefixo de `rest` que cabe em `limit` (medido), preferindo parágrafo, linha e depois espaço.
|
|
67
|
+
|
|
68
|
+
O texto escapado nunca é menor que o original, então só os primeiros `limit` caracteres podem caber.
|
|
69
|
+
"""
|
|
70
|
+
window = rest[:limit]
|
|
71
|
+
size = len(window)
|
|
72
|
+
if len(rest) == size and measure(rest) <= limit:
|
|
73
|
+
return size
|
|
74
|
+
while size > 1 and measure(window[:size]) > limit:
|
|
75
|
+
size -= 1
|
|
76
|
+
if size == len(rest):
|
|
77
|
+
return size
|
|
78
|
+
for separator in ("\n\n", "\n", " "):
|
|
79
|
+
position = window.rfind(separator, 0, size)
|
|
80
|
+
if position > size // 4:
|
|
81
|
+
return position + len(separator)
|
|
82
|
+
return size
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
class TextSpan(NamedTuple):
|
|
86
|
+
"""Uma parte do texto a enviar: onde ela começa no texto original (`start`), se reabre um bloco de código cortado
|
|
87
|
+
na anterior (`reopened`), o texto cru (o markdown com o bloco fechado e reaberto, ou o texto puro) e o escapado
|
|
88
|
+
(igual ao cru no texto puro)."""
|
|
89
|
+
|
|
90
|
+
start: int
|
|
91
|
+
reopened: bool
|
|
92
|
+
raw: str
|
|
93
|
+
escaped: str
|
|
94
|
+
|
|
95
|
+
def rest(self, source: str) -> str:
|
|
96
|
+
"""O texto original desta parte até o fim, com o bloco reaberto: o que a reentrega de uma entrega parcial
|
|
97
|
+
manda, sem juntar partes nem mudar o que havia entre elas."""
|
|
98
|
+
return ("```\n" if self.reopened else "") + source[self.start :]
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def _spans(text: str, limit: int, measure: Callable[[str], int]) -> List[Tuple[int, str]]:
|
|
102
|
+
"""As partes de `split_text` com o deslocamento de cada uma em `text` (depois das quebras que a divisão tira)."""
|
|
103
|
+
spans: List[Tuple[int, str]] = []
|
|
104
|
+
start, rest = 0, text
|
|
105
|
+
while rest:
|
|
106
|
+
size = _cut(rest, measure, limit)
|
|
107
|
+
if size < len(rest):
|
|
108
|
+
part, following = rest[:size].rstrip(), rest[size:]
|
|
109
|
+
rest = following.lstrip("\n ")
|
|
110
|
+
consumed = size + len(following) - len(rest)
|
|
111
|
+
else:
|
|
112
|
+
part, rest, consumed = rest, "", len(rest)
|
|
113
|
+
if part.strip():
|
|
114
|
+
spans.append((start, part))
|
|
115
|
+
start += consumed
|
|
116
|
+
return spans
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def split_text(text: str, limit: int = MAX_MESSAGE_CHARS, measure: Callable[[str], int] = len) -> List[str]:
|
|
120
|
+
"""Divide `text` em partes que cabem em `limit` (pela `measure`), em quebras naturais; sem partes vazias."""
|
|
121
|
+
return [part for _, part in _spans(text, limit, measure)]
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def plain_spans(text: str, limit: int = MAX_MESSAGE_CHARS) -> List[TextSpan]:
|
|
125
|
+
"""As partes do texto puro (`split_text`), com o deslocamento de cada uma (`TextSpan`)."""
|
|
126
|
+
return [TextSpan(start, False, part, part) for start, part in _spans(text, limit, len)]
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def markdown_spans(markdown: str, limit: int = MAX_MESSAGE_CHARS) -> List[TextSpan]:
|
|
130
|
+
"""As partes do markdown prontas para envio (`TextSpan`), cada uma com a versão escapada dentro do `limit`.
|
|
131
|
+
|
|
132
|
+
A divisão mede o texto escapado. Uma divisão que cortaria um bloco ```` ``` ```` ao meio o fecha na parte e o
|
|
133
|
+
reabre na seguinte. Guardar o markdown de cada parte permite reenviar só as restantes como texto puro.
|
|
134
|
+
"""
|
|
135
|
+
spans: List[TextSpan] = []
|
|
136
|
+
reopen = False
|
|
137
|
+
margin = len("```\n") + len("\n```") # reabertura e fechamento de um bloco de código cortado
|
|
138
|
+
for start, part in _spans(markdown, limit - margin, lambda piece: len(to_markdown_v2(piece))):
|
|
139
|
+
reopened = reopen
|
|
140
|
+
body = ("```\n" if reopened else "") + part
|
|
141
|
+
reopen = body.count("```") % 2 == 1
|
|
142
|
+
closed = body + "\n```" if reopen else body
|
|
143
|
+
spans.append(TextSpan(start, reopened, closed, to_markdown_v2(closed)))
|
|
144
|
+
return spans
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
def markdown_parts(markdown: str, limit: int = MAX_MESSAGE_CHARS) -> List[Tuple[str, str]]:
|
|
148
|
+
"""Partes `(markdown, MarkdownV2)` de `markdown_spans`, sem o deslocamento."""
|
|
149
|
+
return [(span.raw, span.escaped) for span in markdown_spans(markdown, limit)]
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
def markdown_chunks(markdown: str, limit: int = MAX_MESSAGE_CHARS) -> List[str]:
|
|
153
|
+
"""Só as partes em MarkdownV2 de `markdown_parts`."""
|
|
154
|
+
return [escaped for _, escaped in markdown_parts(markdown, limit)]
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
__all__ = [
|
|
158
|
+
"MAX_CAPTION_CHARS",
|
|
159
|
+
"MAX_MESSAGE_CHARS",
|
|
160
|
+
"TextSpan",
|
|
161
|
+
"escape_text",
|
|
162
|
+
"markdown_chunks",
|
|
163
|
+
"markdown_parts",
|
|
164
|
+
"markdown_spans",
|
|
165
|
+
"plain_spans",
|
|
166
|
+
"split_text",
|
|
167
|
+
"to_markdown_v2",
|
|
168
|
+
]
|