metaobjects 0.9.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- metaobjects/__init__.py +75 -0
- metaobjects/agent_context/__init__.py +55 -0
- metaobjects/agent_context/_content/README.md +14 -0
- metaobjects/agent_context/_content/servers/csharp.meta.json +5 -0
- metaobjects/agent_context/_content/servers/java.meta.json +5 -0
- metaobjects/agent_context/_content/servers/kotlin.meta.json +5 -0
- metaobjects/agent_context/_content/servers/python.meta.json +5 -0
- metaobjects/agent_context/_content/servers/typescript.meta.json +5 -0
- metaobjects/agent_context/_content/skills/metaobjects-authoring/SKILL.md +301 -0
- metaobjects/agent_context/_content/skills/metaobjects-codegen/SKILL.md +99 -0
- metaobjects/agent_context/_content/skills/metaobjects-codegen/references/csharp.md +87 -0
- metaobjects/agent_context/_content/skills/metaobjects-codegen/references/java.md +94 -0
- metaobjects/agent_context/_content/skills/metaobjects-codegen/references/kotlin.md +110 -0
- metaobjects/agent_context/_content/skills/metaobjects-codegen/references/typescript.md +135 -0
- metaobjects/agent_context/_content/skills/metaobjects-prompts/SKILL.md +148 -0
- metaobjects/agent_context/_content/skills/metaobjects-prompts/references/csharp.md +110 -0
- metaobjects/agent_context/_content/skills/metaobjects-prompts/references/java.md +108 -0
- metaobjects/agent_context/_content/skills/metaobjects-prompts/references/kotlin.md +130 -0
- metaobjects/agent_context/_content/skills/metaobjects-prompts/references/python.md +116 -0
- metaobjects/agent_context/_content/skills/metaobjects-prompts/references/typescript.md +150 -0
- metaobjects/agent_context/_content/skills/metaobjects-runtime-ui/SKILL.md +130 -0
- metaobjects/agent_context/_content/skills/metaobjects-runtime-ui/references/java.md +96 -0
- metaobjects/agent_context/_content/skills/metaobjects-runtime-ui/references/kotlin.md +99 -0
- metaobjects/agent_context/_content/skills/metaobjects-runtime-ui/references/react.md +86 -0
- metaobjects/agent_context/_content/skills/metaobjects-runtime-ui/references/tanstack.md +119 -0
- metaobjects/agent_context/_content/skills/metaobjects-runtime-ui/references/typescript.md +92 -0
- metaobjects/agent_context/_content/skills/metaobjects-verify/SKILL.md +107 -0
- metaobjects/agent_context/_content/skills/metaobjects-verify/references/migration.md +72 -0
- metaobjects/agent_context/_content/templates/always-on.md.mustache +27 -0
- metaobjects/agent_context/assemble.py +133 -0
- metaobjects/agent_context/content_root.py +54 -0
- metaobjects/agent_context/scaffold.py +191 -0
- metaobjects/agent_context/types.py +44 -0
- metaobjects/attr_class_map.py +23 -0
- metaobjects/cli.py +696 -0
- metaobjects/codegen/__init__.py +0 -0
- metaobjects/codegen/config.py +11 -0
- metaobjects/codegen/constants.py +13 -0
- metaobjects/codegen/extract_delegate_emitter.py +384 -0
- metaobjects/codegen/extract_schema_emitter.py +139 -0
- metaobjects/codegen/format.py +31 -0
- metaobjects/codegen/fr010_field_mapping.py +220 -0
- metaobjects/codegen/generator.py +62 -0
- metaobjects/codegen/generator_registry.py +163 -0
- metaobjects/codegen/generators/__init__.py +0 -0
- metaobjects/codegen/generators/entity_model.py +263 -0
- metaobjects/codegen/generators/extractor_generator.py +317 -0
- metaobjects/codegen/generators/filter_allowlist_generator.py +309 -0
- metaobjects/codegen/generators/m2m_codegen.py +192 -0
- metaobjects/codegen/generators/output_parser_generator.py +272 -0
- metaobjects/codegen/generators/output_prompt_generator.py +192 -0
- metaobjects/codegen/generators/payload_vo_generator.py +672 -0
- metaobjects/codegen/generators/render_helper_generator.py +451 -0
- metaobjects/codegen/generators/router_generator.py +635 -0
- metaobjects/codegen/generators/template_generator.py +70 -0
- metaobjects/codegen/generators/tph_plan.py +120 -0
- metaobjects/codegen/generators/trace_helper_generator.py +336 -0
- metaobjects/codegen/instance_artifacts.py +15 -0
- metaobjects/codegen/output_format_spec_emitter.py +79 -0
- metaobjects/codegen/overwrite_policy.py +27 -0
- metaobjects/codegen/runner.py +110 -0
- metaobjects/codegen/runtime/__init__.py +6 -0
- metaobjects/codegen/runtime/filter_parser.py +193 -0
- metaobjects/codegen/type_map.py +84 -0
- metaobjects/core_types.py +809 -0
- metaobjects/datatype.py +19 -0
- metaobjects/documentation/__init__.py +28 -0
- metaobjects/documentation/doc_constants.py +20 -0
- metaobjects/documentation/doc_provider.py +20 -0
- metaobjects/documentation/doc_schema.py +24 -0
- metaobjects/errors.py +124 -0
- metaobjects/loader/__init__.py +0 -0
- metaobjects/loader/merge.py +287 -0
- metaobjects/loader/meta_data_loader.py +245 -0
- metaobjects/loader/sources/__init__.py +24 -0
- metaobjects/loader/sources/directory_source.py +50 -0
- metaobjects/loader/sources/file_source.py +41 -0
- metaobjects/loader/sources/meta_data_source.py +67 -0
- metaobjects/loader/sources/uri_source.py +56 -0
- metaobjects/loader/validate_discriminator.py +181 -0
- metaobjects/loader/validate_field_readonly.py +146 -0
- metaobjects/loader/validate_source_parameter_ref.py +159 -0
- metaobjects/loader/validate_source_physical_names.py +140 -0
- metaobjects/loader/validation_passes.py +1513 -0
- metaobjects/meta/__init__.py +1 -0
- metaobjects/meta/core/__init__.py +0 -0
- metaobjects/meta/core/attr/__init__.py +0 -0
- metaobjects/meta/core/attr/attr_constants.py +31 -0
- metaobjects/meta/core/attr/meta_attr.py +136 -0
- metaobjects/meta/core/field/__init__.py +0 -0
- metaobjects/meta/core/field/field_constants.py +105 -0
- metaobjects/meta/core/field/meta_field.py +76 -0
- metaobjects/meta/core/identity/__init__.py +0 -0
- metaobjects/meta/core/identity/identity_constants.py +19 -0
- metaobjects/meta/core/identity/meta_identity.py +8 -0
- metaobjects/meta/core/object/__init__.py +0 -0
- metaobjects/meta/core/object/meta_object.py +65 -0
- metaobjects/meta/core/object/meta_object_aware.py +43 -0
- metaobjects/meta/core/object/object_class_registry.py +56 -0
- metaobjects/meta/core/object/object_constants.py +13 -0
- metaobjects/meta/core/object/object_extract.py +400 -0
- metaobjects/meta/core/object/value_object.py +70 -0
- metaobjects/meta/core/relationship/__init__.py +0 -0
- metaobjects/meta/core/relationship/derive_m2m_fields.py +180 -0
- metaobjects/meta/core/relationship/meta_relationship.py +54 -0
- metaobjects/meta/core/relationship/relationship_constants.py +51 -0
- metaobjects/meta/core/validator/__init__.py +0 -0
- metaobjects/meta/core/validator/validator_constants.py +18 -0
- metaobjects/meta/meta_data.py +206 -0
- metaobjects/meta/meta_root.py +8 -0
- metaobjects/meta/persistence/__init__.py +0 -0
- metaobjects/meta/persistence/db/__init__.py +1 -0
- metaobjects/meta/persistence/db/db_constants.py +41 -0
- metaobjects/meta/persistence/db/db_provider.py +60 -0
- metaobjects/meta/persistence/origin/__init__.py +0 -0
- metaobjects/meta/persistence/origin/meta_origin.py +8 -0
- metaobjects/meta/persistence/origin/origin_constants.py +20 -0
- metaobjects/meta/persistence/source/__init__.py +0 -0
- metaobjects/meta/persistence/source/meta_source.py +137 -0
- metaobjects/meta/persistence/source/source_constants.py +115 -0
- metaobjects/meta/presentation/__init__.py +0 -0
- metaobjects/meta/presentation/layout/__init__.py +0 -0
- metaobjects/meta/presentation/layout/layout_constants.py +13 -0
- metaobjects/meta/presentation/layout/meta_layout.py +8 -0
- metaobjects/meta/presentation/view/__init__.py +0 -0
- metaobjects/meta/presentation/view/meta_view.py +8 -0
- metaobjects/meta/presentation/view/view_constants.py +22 -0
- metaobjects/meta/template/__init__.py +0 -0
- metaobjects/meta/template/meta_template.py +46 -0
- metaobjects/meta/template/template_constants.py +112 -0
- metaobjects/meta/template/template_provider.py +43 -0
- metaobjects/parser.py +380 -0
- metaobjects/parser_yaml.py +82 -0
- metaobjects/provider.py +111 -0
- metaobjects/py.typed +0 -0
- metaobjects/registry.py +210 -0
- metaobjects/registry_manifest.py +223 -0
- metaobjects/render/__init__.py +74 -0
- metaobjects/render/email_document.py +14 -0
- metaobjects/render/escapers.py +109 -0
- metaobjects/render/extract/__init__.py +59 -0
- metaobjects/render/extract/coerce.py +279 -0
- metaobjects/render/extract/extract.py +211 -0
- metaobjects/render/extract/extract_map.py +61 -0
- metaobjects/render/extract/json_forgiving_reader.py +203 -0
- metaobjects/render/extract/locate.py +65 -0
- metaobjects/render/extract/normalize.py +96 -0
- metaobjects/render/extract/strip.py +20 -0
- metaobjects/render/extract/types.py +332 -0
- metaobjects/render/extract/xml_forgiving_reader.py +162 -0
- metaobjects/render/filesystem_provider.py +51 -0
- metaobjects/render/prompt/__init__.py +32 -0
- metaobjects/render/prompt/output_format_renderer.py +340 -0
- metaobjects/render/prompt/output_format_spec.py +28 -0
- metaobjects/render/prompt/prompt_field.py +29 -0
- metaobjects/render/prompt/prompt_overrides.py +29 -0
- metaobjects/render/prompt/prompt_style.py +38 -0
- metaobjects/render/renderer.py +358 -0
- metaobjects/render/verify.py +266 -0
- metaobjects/runtime/__init__.py +39 -0
- metaobjects/runtime/llm_recorder.py +210 -0
- metaobjects/runtime/n2m_resolver.py +155 -0
- metaobjects/runtime/object_manager.py +715 -0
- metaobjects/runtime/tph.py +50 -0
- metaobjects/serializer_json.py +172 -0
- metaobjects/shared/__init__.py +0 -0
- metaobjects/shared/base_types.py +16 -0
- metaobjects/shared/separators.py +4 -0
- metaobjects/shared/structural.py +9 -0
- metaobjects/source/__init__.py +79 -0
- metaobjects/source/error_source.py +266 -0
- metaobjects/source/json_path.py +106 -0
- metaobjects/source/semantic_diff.py +98 -0
- metaobjects/source/yaml_positions.py +174 -0
- metaobjects/super_resolve.py +128 -0
- metaobjects/yaml_desugar.py +481 -0
- metaobjects-0.9.0.dist-info/METADATA +97 -0
- metaobjects-0.9.0.dist-info/RECORD +181 -0
- metaobjects-0.9.0.dist-info/WHEEL +4 -0
- metaobjects-0.9.0.dist-info/entry_points.txt +2 -0
- metaobjects-0.9.0.dist-info/licenses/LICENSE +189 -0
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"""Source subtype vocabulary (colocated).
|
|
2
|
+
|
|
3
|
+
Source v2 (ADR-0007): paradigm subtype ``rdb`` with @table/@kind/@role/@schema attrs.
|
|
4
|
+
Read-only-ness is derived from @kind (view/materializedView/storedProc/tableFunction
|
|
5
|
+
are read-only; table — the default — is writable). Multiple sources per object are
|
|
6
|
+
allowed (write-through CQRS) but exactly one must have role == "primary".
|
|
7
|
+
|
|
8
|
+
FR-016 / ADR-0018 — per-kind physical-name aliases. The source's logical name is the
|
|
9
|
+
bare structural ``name`` field every MetaData node carries (NOT an @-attr; ``@name``
|
|
10
|
+
would collide with ``ERR_RESERVED_ATTR``). The physical SQL name is one of the
|
|
11
|
+
kind-aware aliases (@table / @view / @materializedView / @proc / @function), all
|
|
12
|
+
filling the same internal slot. See :data:`PHYSICAL_NAME_ATTR_BY_KIND` and
|
|
13
|
+
:meth:`MetaSource.physical_name` for the four-step resolution rule.
|
|
14
|
+
"""
|
|
15
|
+
from ....shared.base_types import SUBTYPE_BASE
|
|
16
|
+
|
|
17
|
+
# --- Source v2 paradigm subtype --------------------------------------------
|
|
18
|
+
SOURCE_SUBTYPE_RDB = "rdb"
|
|
19
|
+
|
|
20
|
+
SOURCE_SUBTYPES = (SUBTYPE_BASE, SOURCE_SUBTYPE_RDB)
|
|
21
|
+
|
|
22
|
+
# --- Per-kind physical-name aliases (FR-016 / ADR-0018) --------------------
|
|
23
|
+
# One canonical attr key per rdb @kind. The single internal physical-name "slot"
|
|
24
|
+
# on the source is filled by whichever alias matches @kind; the canonical
|
|
25
|
+
# serializer emits the kind-matching alias regardless of which spelling was on
|
|
26
|
+
# input.
|
|
27
|
+
#: Physical SQL table name. Canonical attr for ``@kind: "table"`` (default).
|
|
28
|
+
SOURCE_ATTR_TABLE = "table"
|
|
29
|
+
#: Physical SQL view name. Canonical attr for ``@kind: "view"``.
|
|
30
|
+
SOURCE_ATTR_VIEW = "view"
|
|
31
|
+
#: Physical SQL materialized-view name. Canonical attr for ``@kind: "materializedView"``.
|
|
32
|
+
SOURCE_ATTR_MATERIALIZED_VIEW = "materializedView"
|
|
33
|
+
#: Physical SQL stored-procedure name. Canonical attr for ``@kind: "storedProc"``.
|
|
34
|
+
SOURCE_ATTR_PROC = "proc"
|
|
35
|
+
#: Physical SQL table-function name. Canonical attr for ``@kind: "tableFunction"``.
|
|
36
|
+
SOURCE_ATTR_FUNCTION = "function"
|
|
37
|
+
|
|
38
|
+
# --- Source attrs ----------------------------------------------------------
|
|
39
|
+
SOURCE_ATTR_KIND = "kind"
|
|
40
|
+
SOURCE_ATTR_ROLE = "role"
|
|
41
|
+
SOURCE_ATTR_SCHEMA = "schema"
|
|
42
|
+
# @parameterRef — name/FQN of an object.value describing the input shape of a
|
|
43
|
+
# stored-proc / table-function source. Cross-port (FR-015). Mirrors TS
|
|
44
|
+
# SOURCE_ATTR_PARAMETER_REF.
|
|
45
|
+
SOURCE_ATTR_PARAMETER_REF = "parameterRef"
|
|
46
|
+
|
|
47
|
+
# --- @kind values + read-only derivation ------------------------------------
|
|
48
|
+
SOURCE_KIND_TABLE = "table"
|
|
49
|
+
SOURCE_KIND_VIEW = "view"
|
|
50
|
+
SOURCE_KIND_MATERIALIZED_VIEW = "materializedView"
|
|
51
|
+
SOURCE_KIND_STORED_PROC = "storedProc"
|
|
52
|
+
SOURCE_KIND_TABLE_FUNCTION = "tableFunction"
|
|
53
|
+
|
|
54
|
+
SOURCE_RDB_KINDS = (
|
|
55
|
+
SOURCE_KIND_TABLE,
|
|
56
|
+
SOURCE_KIND_VIEW,
|
|
57
|
+
SOURCE_KIND_MATERIALIZED_VIEW,
|
|
58
|
+
SOURCE_KIND_STORED_PROC,
|
|
59
|
+
SOURCE_KIND_TABLE_FUNCTION,
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
# @kind default when omitted (writable table).
|
|
63
|
+
DEFAULT_SOURCE_KIND = SOURCE_KIND_TABLE
|
|
64
|
+
|
|
65
|
+
# Kinds whose source is read-only (codegen emits read-only model/queries/routes).
|
|
66
|
+
SOURCE_READ_ONLY_KINDS = frozenset({
|
|
67
|
+
SOURCE_KIND_VIEW,
|
|
68
|
+
SOURCE_KIND_MATERIALIZED_VIEW,
|
|
69
|
+
SOURCE_KIND_STORED_PROC,
|
|
70
|
+
SOURCE_KIND_TABLE_FUNCTION,
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
# --- FR-016 / ADR-0018 — @kind → canonical physical-name attr key ----------
|
|
74
|
+
#: Drives the four-step physical-name resolution rule on :class:`MetaSource`
|
|
75
|
+
#: and the canonical-serializer per-kind rewrite. The single internal
|
|
76
|
+
#: physical-name "slot" on a source is the value of whichever alias matches
|
|
77
|
+
#: the source's @kind.
|
|
78
|
+
PHYSICAL_NAME_ATTR_BY_KIND: dict[str, str] = {
|
|
79
|
+
SOURCE_KIND_TABLE: SOURCE_ATTR_TABLE,
|
|
80
|
+
SOURCE_KIND_VIEW: SOURCE_ATTR_VIEW,
|
|
81
|
+
SOURCE_KIND_MATERIALIZED_VIEW: SOURCE_ATTR_MATERIALIZED_VIEW,
|
|
82
|
+
SOURCE_KIND_STORED_PROC: SOURCE_ATTR_PROC,
|
|
83
|
+
SOURCE_KIND_TABLE_FUNCTION: SOURCE_ATTR_FUNCTION,
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
#: Every kind-aware physical-name alias key, ordered for deterministic
|
|
87
|
+
#: iteration (matches the SOURCE_RDB_KINDS order). Used by the validation pass
|
|
88
|
+
#: and by :meth:`MetaSource.physical_name`.
|
|
89
|
+
ALL_PHYSICAL_NAME_ALIASES: tuple[str, ...] = (
|
|
90
|
+
SOURCE_ATTR_TABLE,
|
|
91
|
+
SOURCE_ATTR_VIEW,
|
|
92
|
+
SOURCE_ATTR_MATERIALIZED_VIEW,
|
|
93
|
+
SOURCE_ATTR_PROC,
|
|
94
|
+
SOURCE_ATTR_FUNCTION,
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
# --- @role values + default -------------------------------------------------
|
|
98
|
+
SOURCE_ROLE_PRIMARY = "primary"
|
|
99
|
+
SOURCE_ROLE_REPLICA = "replica"
|
|
100
|
+
SOURCE_ROLE_INDEX = "index"
|
|
101
|
+
SOURCE_ROLE_CACHE = "cache"
|
|
102
|
+
SOURCE_ROLE_PUBLISH = "publish"
|
|
103
|
+
SOURCE_ROLE_MIRROR = "mirror"
|
|
104
|
+
|
|
105
|
+
SOURCE_ROLES = (
|
|
106
|
+
SOURCE_ROLE_PRIMARY,
|
|
107
|
+
SOURCE_ROLE_REPLICA,
|
|
108
|
+
SOURCE_ROLE_INDEX,
|
|
109
|
+
SOURCE_ROLE_CACHE,
|
|
110
|
+
SOURCE_ROLE_PUBLISH,
|
|
111
|
+
SOURCE_ROLE_MIRROR,
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
# @role default when omitted (system of record).
|
|
115
|
+
DEFAULT_SOURCE_ROLE = SOURCE_ROLE_PRIMARY
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"""Layout subtype vocabulary (colocated)."""
|
|
2
|
+
from ....shared.base_types import SUBTYPE_BASE
|
|
3
|
+
|
|
4
|
+
LAYOUT_SUBTYPE_DATA_GRID = "dataGrid"
|
|
5
|
+
LAYOUT_SUBTYPES = (SUBTYPE_BASE, LAYOUT_SUBTYPE_DATA_GRID)
|
|
6
|
+
|
|
7
|
+
# layout.dataGrid attrs
|
|
8
|
+
LAYOUT_ATTR_COLUMNS = "columns"
|
|
9
|
+
LAYOUT_ATTR_DEFAULT_SORT_FIELD = "defaultSortField"
|
|
10
|
+
LAYOUT_ATTR_DEFAULT_SORT_ORDER = "defaultSortOrder"
|
|
11
|
+
LAYOUT_ATTR_PAGE_SIZE = "pageSize"
|
|
12
|
+
LAYOUT_ATTR_FILTERABLE = "filterable"
|
|
13
|
+
LAYOUT_ATTR_FILTER = "filter"
|
|
File without changes
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"""View subtype vocabulary (colocated).
|
|
2
|
+
|
|
3
|
+
The view's subType IS the UI control type.
|
|
4
|
+
|
|
5
|
+
SP-G Phase1 Unit3 (B-2): the 11 generic web-presentation control kinds
|
|
6
|
+
(text/textarea/date/month/hotlink/dropdown/radio/checkbox/number/password/
|
|
7
|
+
hidden/web) are TS-web-presentation-only — they have NO backend / codegen /
|
|
8
|
+
render consumer in Python, so they are dead vocab here and were DEREGISTERED.
|
|
9
|
+
They remain registered in TypeScript (the web client + TS form codegen require
|
|
10
|
+
them for authoring). Only ``base`` + ``currency`` (the cross-port currency
|
|
11
|
+
``@locale`` wire contract) are registered cross-port.
|
|
12
|
+
"""
|
|
13
|
+
from ....shared.base_types import SUBTYPE_BASE
|
|
14
|
+
|
|
15
|
+
VIEW_SUBTYPE_CURRENCY = "currency"
|
|
16
|
+
VIEW_SUBTYPES = (
|
|
17
|
+
SUBTYPE_BASE,
|
|
18
|
+
VIEW_SUBTYPE_CURRENCY,
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
# view.currency attrs — @locale (BCP 47). Only on view.currency; defaults to "en-US".
|
|
22
|
+
VIEW_ATTR_LOCALE = "locale"
|
|
File without changes
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"""MetaTemplate — template.* metatype (FR-004).
|
|
2
|
+
|
|
3
|
+
Cross-port parity with Java's `MetaTemplate` / `PromptTemplate` / `OutputTemplate`
|
|
4
|
+
and C#'s `MetaObjects.Render` template tier.
|
|
5
|
+
"""
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
from collections.abc import Sequence
|
|
9
|
+
|
|
10
|
+
from ..meta_data import MetaData
|
|
11
|
+
from . import template_constants as tc
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class MetaTemplate(MetaData):
|
|
15
|
+
"""Concrete container for `template.prompt` / `template.output`.
|
|
16
|
+
|
|
17
|
+
Own-only accessors — read each attr off the node itself, never the super
|
|
18
|
+
chain (the loader's effective-attr walk is for codegen, not validation).
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
def payload_ref(self) -> str | None:
|
|
22
|
+
v = self.attr(tc.TEMPLATE_ATTR_PAYLOAD_REF)
|
|
23
|
+
return v if isinstance(v, str) and v else None
|
|
24
|
+
|
|
25
|
+
def text_ref(self) -> str | None:
|
|
26
|
+
v = self.attr(tc.TEMPLATE_ATTR_TEXT_REF)
|
|
27
|
+
return v if isinstance(v, str) and v else None
|
|
28
|
+
|
|
29
|
+
def response_ref(self) -> str | None:
|
|
30
|
+
v = self.attr(tc.TEMPLATE_ATTR_RESPONSE_REF)
|
|
31
|
+
return v if isinstance(v, str) and v else None
|
|
32
|
+
|
|
33
|
+
def format_(self) -> str:
|
|
34
|
+
v = self.attr(tc.TEMPLATE_ATTR_FORMAT)
|
|
35
|
+
return v if isinstance(v, str) and v else tc.TEMPLATE_FORMAT_DEFAULT
|
|
36
|
+
|
|
37
|
+
def required_slots(self) -> Sequence[str] | None:
|
|
38
|
+
v = self.attr(tc.TEMPLATE_ATTR_REQUIRED_SLOTS)
|
|
39
|
+
if isinstance(v, str):
|
|
40
|
+
return tuple(s.strip() for s in v.split(",") if s.strip())
|
|
41
|
+
if isinstance(v, (list, tuple)):
|
|
42
|
+
return tuple(str(x) for x in v)
|
|
43
|
+
return None
|
|
44
|
+
|
|
45
|
+
def is_prompt(self) -> bool:
|
|
46
|
+
return self.sub_type == tc.TEMPLATE_SUBTYPE_PROMPT
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"""Template subtype vocabulary (FR-004 cross-language prompt construction)."""
|
|
2
|
+
from ...shared.base_types import SUBTYPE_BASE
|
|
3
|
+
|
|
4
|
+
TEMPLATE_SUBTYPE_PROMPT = "prompt"
|
|
5
|
+
TEMPLATE_SUBTYPE_OUTPUT = "output"
|
|
6
|
+
# template.toolcall — ADR-0011: LLM tool-call envelope (no renderable body —
|
|
7
|
+
# the body IS the structured output schema resolved via @payloadRef).
|
|
8
|
+
TEMPLATE_SUBTYPE_TOOLCALL = "toolcall"
|
|
9
|
+
TEMPLATE_SUBTYPES = (
|
|
10
|
+
SUBTYPE_BASE,
|
|
11
|
+
TEMPLATE_SUBTYPE_PROMPT,
|
|
12
|
+
TEMPLATE_SUBTYPE_OUTPUT,
|
|
13
|
+
TEMPLATE_SUBTYPE_TOOLCALL,
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
# Shared attrs across template.prompt and template.output (NOT inherited by
|
|
17
|
+
# template.toolcall — see ADR-0011).
|
|
18
|
+
TEMPLATE_ATTR_PAYLOAD_REF = "payloadRef"
|
|
19
|
+
TEMPLATE_ATTR_TEXT_REF = "textRef"
|
|
20
|
+
TEMPLATE_ATTR_FORMAT = "format"
|
|
21
|
+
TEMPLATE_ATTR_MAX_CHARS = "maxChars"
|
|
22
|
+
TEMPLATE_ATTR_OWNER = "owner"
|
|
23
|
+
TEMPLATE_ATTR_SINCE = "since"
|
|
24
|
+
TEMPLATE_ATTR_REQUIRED_TAGS = "requiredTags"
|
|
25
|
+
|
|
26
|
+
# --- @kind + email part-refs (template.output only) ---
|
|
27
|
+
#
|
|
28
|
+
# A template.output is either a plain document (renders @textRef in @format ->
|
|
29
|
+
# one string) or an email (renders subject + html + optional text -> a
|
|
30
|
+
# structured EmailDocument). @kind is a closed enum; the email part-refs are
|
|
31
|
+
# 2-layer logical (group/source) textRefs resolved by a provider at render time.
|
|
32
|
+
# Cross-field rules live in validation_passes._validate_templates:
|
|
33
|
+
# - @kind="email" -> require @subjectRef AND @htmlBodyRef (textRef unused; @textBodyRef optional)
|
|
34
|
+
# - @kind="document"/absent -> require @textRef
|
|
35
|
+
# Must match TS / Java exactly (Tier-1 invariant).
|
|
36
|
+
TEMPLATE_ATTR_KIND = "kind"
|
|
37
|
+
TEMPLATE_KIND_DOCUMENT = "document"
|
|
38
|
+
TEMPLATE_KIND_EMAIL = "email"
|
|
39
|
+
TEMPLATE_KIND_DEFAULT = TEMPLATE_KIND_DOCUMENT
|
|
40
|
+
ALLOWED_KINDS = (
|
|
41
|
+
TEMPLATE_KIND_DOCUMENT,
|
|
42
|
+
TEMPLATE_KIND_EMAIL,
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
TEMPLATE_ATTR_SUBJECT_REF = "subjectRef"
|
|
46
|
+
TEMPLATE_ATTR_HTML_BODY_REF = "htmlBodyRef"
|
|
47
|
+
TEMPLATE_ATTR_TEXT_BODY_REF = "textBodyRef"
|
|
48
|
+
|
|
49
|
+
# Prompt-overlay attrs (template.prompt only).
|
|
50
|
+
TEMPLATE_ATTR_MAX_TOKENS = "maxTokens"
|
|
51
|
+
TEMPLATE_ATTR_REQUIRED_SLOTS = "requiredSlots"
|
|
52
|
+
TEMPLATE_ATTR_MODEL = "model"
|
|
53
|
+
# @responseRef — peer of @payloadRef on template.prompt ONLY (NOT shared, NOT on
|
|
54
|
+
# template.output): names the typed VO an LLM RESPONSE is extracted into, driving
|
|
55
|
+
# the derived voResponse jsonb trace column (AI LLM-call trace persistence).
|
|
56
|
+
# Cross-port vocabulary (registered in all five ports).
|
|
57
|
+
TEMPLATE_ATTR_RESPONSE_REF = "responseRef"
|
|
58
|
+
|
|
59
|
+
# Toolcall-specific attrs (template.toolcall only — see ADR-0011).
|
|
60
|
+
# Vendor-agnostic in core; vendor wire details (retry semantics, fallback
|
|
61
|
+
# shapes, parallel invocation, cache hints) added by consumer providers via
|
|
62
|
+
# registry.extend("template", "toolcall", attributes=[...]).
|
|
63
|
+
#
|
|
64
|
+
# @description is intentionally NOT declared here — it's already a documentation
|
|
65
|
+
# common attr added to every type by the doc provider. Tool descriptions
|
|
66
|
+
# surfaced to the LLM read the same @description common attr.
|
|
67
|
+
#
|
|
68
|
+
# @textRef is intentionally NOT required — a tool-call has no renderable text
|
|
69
|
+
# body. The body IS the structured output schema resolved via @payloadRef.
|
|
70
|
+
TEMPLATE_ATTR_TOOL_NAME = "toolName"
|
|
71
|
+
|
|
72
|
+
# Closed-set values for @format. Cross-port invariant.
|
|
73
|
+
TEMPLATE_FORMAT_TEXT = "text"
|
|
74
|
+
TEMPLATE_FORMAT_HTML = "html"
|
|
75
|
+
TEMPLATE_FORMAT_XML = "xml"
|
|
76
|
+
TEMPLATE_FORMAT_CSV = "csv"
|
|
77
|
+
TEMPLATE_FORMAT_JSON = "json"
|
|
78
|
+
TEMPLATE_FORMAT_MARKDOWN = "markdown"
|
|
79
|
+
TEMPLATE_FORMAT_SPREADSHEET = "spreadsheet"
|
|
80
|
+
ALLOWED_FORMATS = (
|
|
81
|
+
TEMPLATE_FORMAT_TEXT,
|
|
82
|
+
TEMPLATE_FORMAT_HTML,
|
|
83
|
+
TEMPLATE_FORMAT_XML,
|
|
84
|
+
TEMPLATE_FORMAT_CSV,
|
|
85
|
+
TEMPLATE_FORMAT_JSON,
|
|
86
|
+
TEMPLATE_FORMAT_MARKDOWN,
|
|
87
|
+
TEMPLATE_FORMAT_SPREADSHEET,
|
|
88
|
+
)
|
|
89
|
+
TEMPLATE_FORMAT_DEFAULT = TEMPLATE_FORMAT_TEXT
|
|
90
|
+
|
|
91
|
+
# FR-010 artifact-1: output-format prompt presentation style (template.output only).
|
|
92
|
+
# Closed enum, enforced via allowed_values exactly like @format. Default "guide".
|
|
93
|
+
# Guidance is NEVER carried in comments. Set project-wide via an abstract template
|
|
94
|
+
# base + extends, with a render-time PromptOverrides.style on top.
|
|
95
|
+
TEMPLATE_ATTR_PROMPT_STYLE = "promptStyle"
|
|
96
|
+
PROMPT_STYLE_GUIDE = "guide"
|
|
97
|
+
PROMPT_STYLE_INLINE = "inline"
|
|
98
|
+
PROMPT_STYLE_EXAMPLE_ONLY = "exampleOnly"
|
|
99
|
+
PROMPT_STYLE_DEFAULT = PROMPT_STYLE_GUIDE
|
|
100
|
+
PROMPT_STYLES = (
|
|
101
|
+
PROMPT_STYLE_GUIDE,
|
|
102
|
+
PROMPT_STYLE_INLINE,
|
|
103
|
+
PROMPT_STYLE_EXAMPLE_ONLY,
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
# @xmlText — a FIELD-level marker (boolean) for the tolerant extract engine: this field
|
|
107
|
+
# receives its element's TEXT CONTENT when a template.output response is parsed from XML
|
|
108
|
+
# (JAXB @XmlValue / Jackson @JacksonXmlText / .NET [XmlText]). Registered on field.* by
|
|
109
|
+
# template_provider (the prompt/output domain owns this extract concern — NOT a core field
|
|
110
|
+
# property). No effect for @format: json. Mirrors Java TemplateConstants.ATTR_XML_TEXT,
|
|
111
|
+
# TS FIELD_ATTR_XML_TEXT, and C# TemplateConstants.ATTR_XML_TEXT.
|
|
112
|
+
TEMPLATE_ATTR_XML_TEXT = "xmlText"
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"""template_provider — the template/output (serialization) MetaDataTypeProvider
|
|
2
|
+
(cross-port ``metaobjects-template``).
|
|
3
|
+
|
|
4
|
+
Registers the ``@xmlText`` field marker (XML text-content extraction) by EXTENDING the
|
|
5
|
+
core-registered field types via :meth:`TypeRegistry.extend`. ``@xmlText`` is an
|
|
6
|
+
output/extract concern, NOT a core field property, so it lives HERE in the prompt/output
|
|
7
|
+
domain — mirroring Java's ``TemplateTypesMetaDataProvider`` field extension, TS's
|
|
8
|
+
``templateProvider``, and C#'s ``TemplateTypesProvider``, and following the same pattern
|
|
9
|
+
as ``db_provider``.
|
|
10
|
+
"""
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
from ...provider import Provider
|
|
14
|
+
from ...registry import AttrSchema, TypeRegistry
|
|
15
|
+
from ...shared.base_types import TYPE_FIELD
|
|
16
|
+
from ..core.attr.attr_constants import ATTR_SUBTYPE_BOOLEAN
|
|
17
|
+
from ..core.field import field_constants as fc
|
|
18
|
+
from .template_constants import TEMPLATE_ATTR_XML_TEXT
|
|
19
|
+
|
|
20
|
+
# Every field subtype @xmlText applies to: the shared FIELD_SUBTYPES tuple (which
|
|
21
|
+
# deliberately excludes ``enum`` — registered separately in core_types) PLUS ``field.enum``.
|
|
22
|
+
# Mirrors the TS templateProvider's FIELD_SUBTYPES loop.
|
|
23
|
+
_XML_TEXT_FIELD_SUBTYPES: tuple[str, ...] = (*fc.FIELD_SUBTYPES, fc.FIELD_SUBTYPE_ENUM)
|
|
24
|
+
|
|
25
|
+
# @xmlText — when true, the field receives its element's XML text content during tolerant
|
|
26
|
+
# extract instead of a same-named child. On every field subtype. No effect for JSON.
|
|
27
|
+
_XML_TEXT_SCHEMA = AttrSchema(
|
|
28
|
+
name=TEMPLATE_ATTR_XML_TEXT, value_type=ATTR_SUBTYPE_BOOLEAN, required=False
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def _register(registry: TypeRegistry) -> None:
|
|
33
|
+
for sub_type in _XML_TEXT_FIELD_SUBTYPES:
|
|
34
|
+
registry.extend(TYPE_FIELD, sub_type, attributes=[_XML_TEXT_SCHEMA])
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def _make_template_provider() -> Provider:
|
|
38
|
+
p = Provider("metaobjects-template", dependencies=("metaobjects-core-types",))
|
|
39
|
+
p.on_register(_register)
|
|
40
|
+
return p
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
template_provider = _make_template_provider()
|