rusticai-unidb 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- rusticai_unidb-0.1.0/PKG-INFO +104 -0
- rusticai_unidb-0.1.0/README.md +83 -0
- rusticai_unidb-0.1.0/pyproject.toml +77 -0
- rusticai_unidb-0.1.0/src/rustic_ai/unidb/__init__.py +0 -0
- rusticai_unidb-0.1.0/src/rustic_ai/unidb/agent.py +104 -0
- rusticai_unidb-0.1.0/src/rustic_ai/unidb/models.py +404 -0
- rusticai_unidb-0.1.0/src/rustic_ai/unidb/resolver.py +52 -0
- rusticai_unidb-0.1.0/src/rustic_ai/unidb/runtime.py +768 -0
- rusticai_unidb-0.1.0/src/rustic_ai/unidb/serialization.py +124 -0
- rusticai_unidb-0.1.0/src/rustic_ai/unidb/tools.py +166 -0
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: rusticai-unidb
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Typed Uni-DB database capabilities for Rustic AI
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
Author: Dragonscale Industries Inc.
|
|
7
|
+
Author-email: dev@dragonscale.ai
|
|
8
|
+
Requires-Python: >=3.13,<3.14
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
11
|
+
Provides-Extra: tools
|
|
12
|
+
Requires-Dist: jsonschema (>=4.26.0,<5.0.0)
|
|
13
|
+
Requires-Dist: rusticai-core (>=1.5.0,<1.6.0)
|
|
14
|
+
Requires-Dist: rusticai-llm-agent (>=1.5.0,<1.6.0) ; extra == "tools"
|
|
15
|
+
Requires-Dist: uni-db (==6.0.0)
|
|
16
|
+
Project-URL: Homepage, https://www.rustic.ai/
|
|
17
|
+
Project-URL: Repository, https://github.com/dragonscale-ai/rustic-ai
|
|
18
|
+
Project-URL: Rustic AI Core, https://pypi.org/project/rusticai-core/
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
|
|
21
|
+
# Uni-DB agent
|
|
22
|
+
|
|
23
|
+
`rustic_ai.unidb.agent.UniDBAgent` provides typed database capabilities for Rustic guilds. It uses Uni-DB **6.0.0** and Python **3.13**. Domain schema, Locy rules, named operations, and transaction assertions are supplied by the application. Guild composition owns authentication, permissions, approvals, and result visibility.
|
|
24
|
+
|
|
25
|
+
This evolves Nihal's [PR 236](https://github.com/rustic-ai/rustic-ai/pull/236). All 15 original operation names remain, with a new v1 wire contract and no legacy adapters.
|
|
26
|
+
|
|
27
|
+
Read the [site agent guide](../docs/agents/unidb/index.md), [protocol reference](../docs/agents/unidb/protocol.md), and [resolver guide](../docs/dependencies/unidb/index.md) for the supported v1 contract.
|
|
28
|
+
|
|
29
|
+
## Initialize
|
|
30
|
+
|
|
31
|
+
Configure an agent-scoped `unidb` dependency using `rustic_ai.unidb.resolver.UniDBResolver`. Persistent locations resolve relative paths through an injected Rustic filesystem. Opening modes are explicit: `open_existing` (default), `create`, or `temporary`. No opening failure substitutes an empty database.
|
|
32
|
+
|
|
33
|
+
Agent properties contain `binding_id`, limits, `raw_operations_enabled` (default false), and a versioned operation catalog. Catalog parameters are closed JSON Schema objects. Bootstrap can apply user definitions to a new database or verify an existing database. Initialization completes before processor admission.
|
|
34
|
+
|
|
35
|
+
Complete GuildSpecs and message I/O are provided for:
|
|
36
|
+
|
|
37
|
+
- [Atomic supply graph import](../docs/design/uni-db-agent-examples/supply-network-init.json): checked batch, query, safe replay, changed-payload refusal.
|
|
38
|
+
- [Derived receivables](../docs/design/uni-db-agent-examples/receivables-init.json): exact integer cents, supplied Locy rules, native explanation, missing derivation.
|
|
39
|
+
- [Supplier scenario](../docs/design/uni-db-agent-examples/supplier-scenario-init.json): scratch before/after evaluation, discarded changes, guild-approved persistent execution.
|
|
40
|
+
|
|
41
|
+
Read the [detailed design](../docs/design/uni-db-agent-design.md) for configuration and complete exchanges. From the repository root, run the three native cases without an LLM:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
poetry install --with dev
|
|
45
|
+
PYTHONPATH=unidb/src python unidb/examples/run_examples.py
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Messages and execution
|
|
49
|
+
|
|
50
|
+
Named requests are `DBQueryRequest`, `DBQueryPlanRequest`, `DBQueryProfileRequest`, `DBEvaluateRequest`, `DBExplainRequest`, `DBMutateRequest`, and `DBScenarioRequest`. Discovery and reconciliation use `DBHealthRequest`, `DBCapabilitiesRequest`, `DBOperationStatusRequest`, and `DBBulkStatusRequest`.
|
|
51
|
+
|
|
52
|
+
Every request carries `protocol_version: 1`, `request_id`, and `correlation_id`. Named execution also carries `operation` and `params`. Persistent effects require an `operation_id`, stable across retries; caller payloads do not supply principals or credentials.
|
|
53
|
+
|
|
54
|
+
```python
|
|
55
|
+
from rustic_ai.unidb.models import DBQueryRequest
|
|
56
|
+
|
|
57
|
+
# Inside a guild caller's processor; configure an output route to the database.
|
|
58
|
+
request = DBQueryRequest(
|
|
59
|
+
request_id="query:1", correlation_id="workflow:1",
|
|
60
|
+
operation="suppliers_for_product", params={"product_id": "product:digitizer"},
|
|
61
|
+
)
|
|
62
|
+
# ctx.send(request)
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Success families contain correlated IDs, binding, a structured result, and observed metadata. Failures are typed `DBFailure` payloads emitted through `ctx.send_error`, with code, stage, and effect (`not_started`, `rolled_back`, `committed`, or `unknown`). Workflow termination belongs to the guild. A publication failure is logged; it does not produce a competing failure after delivery may have occurred.
|
|
66
|
+
|
|
67
|
+
Ordinary mutations commit their prepared receipt with the domain effect. Durable pending claims permit unknown-outcome recovery; unresolved work is never automatically reexecuted. Completed replay returns the stored result without inventing unavailable original commit metadata. Receipts are scoped by binding, runtime sender attribution, and operation ID. One authoritative write owner is supported; trusted catalogs and raw callers must preserve connector metadata.
|
|
68
|
+
|
|
69
|
+
DDL/index/flush and native bulk loads use separate bookkeeping and do not promise ordinary transaction atomicity. Bulk reconciliation preserves native load IDs and applied outcomes. Scalar/vector indexes, schema inspection, raw Cypher query/execute, and bulk vertices/edges remain available through their dedicated typed messages. Bulk edges use business external IDs; native VIDs are resolved inside the runtime.
|
|
70
|
+
|
|
71
|
+
Timeout, memory, input/output bytes, row count, and mutation statement count are bounded. Requests can only reduce configured limits. There are no automatic conflict retries. Native values use explicit serializers, including tagged identifiers and integers beyond JSON's exact number range. Explanations retain native evidence; oversized proofs fail rather than being silently trimmed.
|
|
72
|
+
|
|
73
|
+
## Query diagnostics
|
|
74
|
+
|
|
75
|
+
`DBQueryPlanRequest` and `DBQueryProfileRequest` select existing catalog operations of kind `query`. They use the same request IDs, parameters, provenance, and live-view validation as named reads. Neither requires an operation ID or creates an execution receipt.
|
|
76
|
+
|
|
77
|
+
Planning returns `executed: false` and native plan text, warnings, cost estimates, index usage, and suggestions. Uni-DB 6.0.0 plans the query template: parameter values do not specialize its estimates. The response explicitly reports `parameter_values_applied: false`, `planning_timeout_enforced: false`, and `planning_memory_enforced: false`. Only input/output byte-limit reductions are accepted for planning; other requested limits produce `unsupported_limit`.
|
|
78
|
+
|
|
79
|
+
Profiling executes the named read exactly once, enforcing native timeout and memory bounds. Its response contains `executed: true`, a bounded `query` result, and a `profile` with native operators, timing, memory, and query metrics. Empty native results can omit column names; configured catalog columns are then returned with `columns_source: catalog`. Otherwise their source is `native`. Row truncation does not erase the measurements of the complete native execution. Memory measurements are native operator figures, not process RSS.
|
|
80
|
+
|
|
81
|
+
The [query diagnostics guild](../showcase/apps/unidb_query_diagnostics.json) composes a deterministic driver with UniDB. It seeds 50 products, captures a plan/profile, adds a BTREE index, then captures both again. The lookup rows stay identical while the measured scan count changes from 50 to one. Timings are reported as observed; the example does not promise lower latency.
|
|
82
|
+
|
|
83
|
+
Run the complete guild without an LLM:
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
PYTHONPATH=unidb/src:showcase/src python unidb/examples/run_query_diagnostics.py
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
The runner owns a disposable temporary binding and explicitly closes the resolver before guild shutdown. Success and failure are typed terminal results; guild routes set completion/error status and produce the user presentation. Optional tool schemas are `DBQueryPlanArguments` and `DBQueryProfileArguments`; configure them in the embedding guild's toolset and routes. The existing assistant's 15 default tools remain unchanged.
|
|
90
|
+
|
|
91
|
+
## Optional LLM tools
|
|
92
|
+
|
|
93
|
+
Install the module's `tools` extra to use `UniDBToolsManagerPlugin` and `UniDBToolAdapter`. These are guild adapters; the database agent itself does not depend on an LLM. Argument schemas omit protocol identities, the adapter supplies them, and results retain the provider's actual tool-call ID and `ToolMessage` history. The [showcase](../showcase/apps/unidb_assistant.json) demonstrates one tool call per reasoning turn. Unknown or committed failure outcomes go to reconciliation without an automatic model retry.
|
|
94
|
+
|
|
95
|
+
## Validation and boundaries
|
|
96
|
+
|
|
97
|
+
The native suite tests all three cases, all retained operations, rollback/reopen/replay, commit and publication faults, interrupted bulk/admin outcomes, bounds, proof serialization, readiness failure, and scratch isolation. Guild tests exercise actual processor selection, routes, typed errors, and an illustrative guild-owned access boundary. The showcase tool loop uses a scripted LLM; production model quality and authorization need application validation.
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
PYTHONPATH=unidb/src:showcase/src:unidb/tests pytest unidb/tests showcase/tests/unidb
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Scenario applicability checks and a general Rustic resource shutdown hook are deliberately deferred. The embedding owner must call `UniDBResolver.close()` before guild shutdown. Native deadlines are supported; message-driven cancellation is not advertised. Remote storage certification, multiple writers, receipt retention, pinned/fork reads, and artifact transport are outside this version's supported surface. Existing-rule verification checks the connector's bootstrap digest, not out-of-band registry mutations.
|
|
104
|
+
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# Uni-DB agent
|
|
2
|
+
|
|
3
|
+
`rustic_ai.unidb.agent.UniDBAgent` provides typed database capabilities for Rustic guilds. It uses Uni-DB **6.0.0** and Python **3.13**. Domain schema, Locy rules, named operations, and transaction assertions are supplied by the application. Guild composition owns authentication, permissions, approvals, and result visibility.
|
|
4
|
+
|
|
5
|
+
This evolves Nihal's [PR 236](https://github.com/rustic-ai/rustic-ai/pull/236). All 15 original operation names remain, with a new v1 wire contract and no legacy adapters.
|
|
6
|
+
|
|
7
|
+
Read the [site agent guide](../docs/agents/unidb/index.md), [protocol reference](../docs/agents/unidb/protocol.md), and [resolver guide](../docs/dependencies/unidb/index.md) for the supported v1 contract.
|
|
8
|
+
|
|
9
|
+
## Initialize
|
|
10
|
+
|
|
11
|
+
Configure an agent-scoped `unidb` dependency using `rustic_ai.unidb.resolver.UniDBResolver`. Persistent locations resolve relative paths through an injected Rustic filesystem. Opening modes are explicit: `open_existing` (default), `create`, or `temporary`. No opening failure substitutes an empty database.
|
|
12
|
+
|
|
13
|
+
Agent properties contain `binding_id`, limits, `raw_operations_enabled` (default false), and a versioned operation catalog. Catalog parameters are closed JSON Schema objects. Bootstrap can apply user definitions to a new database or verify an existing database. Initialization completes before processor admission.
|
|
14
|
+
|
|
15
|
+
Complete GuildSpecs and message I/O are provided for:
|
|
16
|
+
|
|
17
|
+
- [Atomic supply graph import](../docs/design/uni-db-agent-examples/supply-network-init.json): checked batch, query, safe replay, changed-payload refusal.
|
|
18
|
+
- [Derived receivables](../docs/design/uni-db-agent-examples/receivables-init.json): exact integer cents, supplied Locy rules, native explanation, missing derivation.
|
|
19
|
+
- [Supplier scenario](../docs/design/uni-db-agent-examples/supplier-scenario-init.json): scratch before/after evaluation, discarded changes, guild-approved persistent execution.
|
|
20
|
+
|
|
21
|
+
Read the [detailed design](../docs/design/uni-db-agent-design.md) for configuration and complete exchanges. From the repository root, run the three native cases without an LLM:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
poetry install --with dev
|
|
25
|
+
PYTHONPATH=unidb/src python unidb/examples/run_examples.py
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Messages and execution
|
|
29
|
+
|
|
30
|
+
Named requests are `DBQueryRequest`, `DBQueryPlanRequest`, `DBQueryProfileRequest`, `DBEvaluateRequest`, `DBExplainRequest`, `DBMutateRequest`, and `DBScenarioRequest`. Discovery and reconciliation use `DBHealthRequest`, `DBCapabilitiesRequest`, `DBOperationStatusRequest`, and `DBBulkStatusRequest`.
|
|
31
|
+
|
|
32
|
+
Every request carries `protocol_version: 1`, `request_id`, and `correlation_id`. Named execution also carries `operation` and `params`. Persistent effects require an `operation_id`, stable across retries; caller payloads do not supply principals or credentials.
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
from rustic_ai.unidb.models import DBQueryRequest
|
|
36
|
+
|
|
37
|
+
# Inside a guild caller's processor; configure an output route to the database.
|
|
38
|
+
request = DBQueryRequest(
|
|
39
|
+
request_id="query:1", correlation_id="workflow:1",
|
|
40
|
+
operation="suppliers_for_product", params={"product_id": "product:digitizer"},
|
|
41
|
+
)
|
|
42
|
+
# ctx.send(request)
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Success families contain correlated IDs, binding, a structured result, and observed metadata. Failures are typed `DBFailure` payloads emitted through `ctx.send_error`, with code, stage, and effect (`not_started`, `rolled_back`, `committed`, or `unknown`). Workflow termination belongs to the guild. A publication failure is logged; it does not produce a competing failure after delivery may have occurred.
|
|
46
|
+
|
|
47
|
+
Ordinary mutations commit their prepared receipt with the domain effect. Durable pending claims permit unknown-outcome recovery; unresolved work is never automatically reexecuted. Completed replay returns the stored result without inventing unavailable original commit metadata. Receipts are scoped by binding, runtime sender attribution, and operation ID. One authoritative write owner is supported; trusted catalogs and raw callers must preserve connector metadata.
|
|
48
|
+
|
|
49
|
+
DDL/index/flush and native bulk loads use separate bookkeeping and do not promise ordinary transaction atomicity. Bulk reconciliation preserves native load IDs and applied outcomes. Scalar/vector indexes, schema inspection, raw Cypher query/execute, and bulk vertices/edges remain available through their dedicated typed messages. Bulk edges use business external IDs; native VIDs are resolved inside the runtime.
|
|
50
|
+
|
|
51
|
+
Timeout, memory, input/output bytes, row count, and mutation statement count are bounded. Requests can only reduce configured limits. There are no automatic conflict retries. Native values use explicit serializers, including tagged identifiers and integers beyond JSON's exact number range. Explanations retain native evidence; oversized proofs fail rather than being silently trimmed.
|
|
52
|
+
|
|
53
|
+
## Query diagnostics
|
|
54
|
+
|
|
55
|
+
`DBQueryPlanRequest` and `DBQueryProfileRequest` select existing catalog operations of kind `query`. They use the same request IDs, parameters, provenance, and live-view validation as named reads. Neither requires an operation ID or creates an execution receipt.
|
|
56
|
+
|
|
57
|
+
Planning returns `executed: false` and native plan text, warnings, cost estimates, index usage, and suggestions. Uni-DB 6.0.0 plans the query template: parameter values do not specialize its estimates. The response explicitly reports `parameter_values_applied: false`, `planning_timeout_enforced: false`, and `planning_memory_enforced: false`. Only input/output byte-limit reductions are accepted for planning; other requested limits produce `unsupported_limit`.
|
|
58
|
+
|
|
59
|
+
Profiling executes the named read exactly once, enforcing native timeout and memory bounds. Its response contains `executed: true`, a bounded `query` result, and a `profile` with native operators, timing, memory, and query metrics. Empty native results can omit column names; configured catalog columns are then returned with `columns_source: catalog`. Otherwise their source is `native`. Row truncation does not erase the measurements of the complete native execution. Memory measurements are native operator figures, not process RSS.
|
|
60
|
+
|
|
61
|
+
The [query diagnostics guild](../showcase/apps/unidb_query_diagnostics.json) composes a deterministic driver with UniDB. It seeds 50 products, captures a plan/profile, adds a BTREE index, then captures both again. The lookup rows stay identical while the measured scan count changes from 50 to one. Timings are reported as observed; the example does not promise lower latency.
|
|
62
|
+
|
|
63
|
+
Run the complete guild without an LLM:
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
PYTHONPATH=unidb/src:showcase/src python unidb/examples/run_query_diagnostics.py
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
The runner owns a disposable temporary binding and explicitly closes the resolver before guild shutdown. Success and failure are typed terminal results; guild routes set completion/error status and produce the user presentation. Optional tool schemas are `DBQueryPlanArguments` and `DBQueryProfileArguments`; configure them in the embedding guild's toolset and routes. The existing assistant's 15 default tools remain unchanged.
|
|
70
|
+
|
|
71
|
+
## Optional LLM tools
|
|
72
|
+
|
|
73
|
+
Install the module's `tools` extra to use `UniDBToolsManagerPlugin` and `UniDBToolAdapter`. These are guild adapters; the database agent itself does not depend on an LLM. Argument schemas omit protocol identities, the adapter supplies them, and results retain the provider's actual tool-call ID and `ToolMessage` history. The [showcase](../showcase/apps/unidb_assistant.json) demonstrates one tool call per reasoning turn. Unknown or committed failure outcomes go to reconciliation without an automatic model retry.
|
|
74
|
+
|
|
75
|
+
## Validation and boundaries
|
|
76
|
+
|
|
77
|
+
The native suite tests all three cases, all retained operations, rollback/reopen/replay, commit and publication faults, interrupted bulk/admin outcomes, bounds, proof serialization, readiness failure, and scratch isolation. Guild tests exercise actual processor selection, routes, typed errors, and an illustrative guild-owned access boundary. The showcase tool loop uses a scripted LLM; production model quality and authorization need application validation.
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
PYTHONPATH=unidb/src:showcase/src:unidb/tests pytest unidb/tests showcase/tests/unidb
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Scenario applicability checks and a general Rustic resource shutdown hook are deliberately deferred. The embedding owner must call `UniDBResolver.close()` before guild shutdown. Native deadlines are supported; message-driven cancellation is not advertised. Remote storage certification, multiple writers, receipt retention, pinned/fork reads, and artifact transport are outside this version's supported surface. Existing-rule verification checks the connector's bootstrap digest, not out-of-band registry mutations.
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["poetry-core>=2.5.0,<3.0.0"]
|
|
3
|
+
build-backend = "poetry.core.masonry.api"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "rusticai-unidb"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Typed Uni-DB database capabilities for Rustic AI"
|
|
9
|
+
dynamic = ["dependencies"]
|
|
10
|
+
authors = [{name = "Dragonscale Industries Inc.", email = "dev@dragonscale.ai"}]
|
|
11
|
+
license = "Apache-2.0"
|
|
12
|
+
readme = "README.md"
|
|
13
|
+
requires-python = ">=3.13,<3.14"
|
|
14
|
+
urls = { Homepage = "https://www.rustic.ai/", Repository = "https://github.com/dragonscale-ai/rustic-ai", "Rustic AI Core" = "https://pypi.org/project/rusticai-core/" }
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
[tool.poetry]
|
|
18
|
+
packages = [{ include = "rustic_ai", from = "src" }]
|
|
19
|
+
|
|
20
|
+
[tool.poetry.dependencies]
|
|
21
|
+
rusticai-core = { version = "1.5.0"}
|
|
22
|
+
uni-db = "==6.0.0"
|
|
23
|
+
jsonschema = ">=4.26.0,<5.0.0"
|
|
24
|
+
rusticai-llm-agent = { optional = true, version = "1.5.0"}
|
|
25
|
+
|
|
26
|
+
[tool.poetry-monorepo.deps]
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
[tool.poetry.group.dev]
|
|
30
|
+
optional = true
|
|
31
|
+
|
|
32
|
+
[tool.poetry.group.dev.dependencies]
|
|
33
|
+
pytest = "^9.2.0"
|
|
34
|
+
black = { version = "^26.10.1", extras = ["jupyter"] }
|
|
35
|
+
flake8 = "^7.5.0"
|
|
36
|
+
tox = "^4.67.16"
|
|
37
|
+
isort = "^9.0.2"
|
|
38
|
+
mypy = "^2.4.1"
|
|
39
|
+
flaky = "^3.8.1"
|
|
40
|
+
pytest-asyncio = "^1.5.0"
|
|
41
|
+
rusticai-testing = { version = "1.5.0"}
|
|
42
|
+
|
|
43
|
+
[tool.poetry.extras]
|
|
44
|
+
tools = ["rusticai-llm-agent"]
|
|
45
|
+
|
|
46
|
+
[tool.black]
|
|
47
|
+
line-length = 120
|
|
48
|
+
target-version = ['py313']
|
|
49
|
+
include = '\.pyi?$'
|
|
50
|
+
exclude = '''
|
|
51
|
+
/(
|
|
52
|
+
\.git
|
|
53
|
+
| \.mypy_cache
|
|
54
|
+
| \.tox
|
|
55
|
+
| \.venv
|
|
56
|
+
| _build
|
|
57
|
+
| buck-out
|
|
58
|
+
| build
|
|
59
|
+
| dist
|
|
60
|
+
)/
|
|
61
|
+
'''
|
|
62
|
+
|
|
63
|
+
[tool.mypy]
|
|
64
|
+
python_version = "3.13"
|
|
65
|
+
ignore_missing_imports = true
|
|
66
|
+
check_untyped_defs = true
|
|
67
|
+
plugins = ["pydantic.mypy"]
|
|
68
|
+
explicit_package_bases = true
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
[tool.isort]
|
|
72
|
+
profile = "black"
|
|
73
|
+
force_sort_within_sections = true # For the sorting order issues
|
|
74
|
+
lines_between_sections = 1 # For the newline issue
|
|
75
|
+
known_third_party = ["pydantic"]
|
|
76
|
+
known_first_party = ["rustic_ai.core"]
|
|
77
|
+
|
|
File without changes
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"""Typed Rustic database capability; guild composition owns authorization."""
|
|
2
|
+
|
|
3
|
+
from rustic_ai.core.guild.agent import Agent, ProcessContext, processor
|
|
4
|
+
|
|
5
|
+
from . import models as m
|
|
6
|
+
from .runtime import RuntimeFailure, UniDBRuntime
|
|
7
|
+
from .serialization import bounded
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def _handler(request_type, response_type):
|
|
11
|
+
def handle(self, ctx: ProcessContext, unidb: UniDBRuntime):
|
|
12
|
+
request = ctx.payload
|
|
13
|
+
result = None
|
|
14
|
+
try:
|
|
15
|
+
result = unidb.execute(request, ctx.message.sender.id or ctx.message.sender.name)
|
|
16
|
+
metadata = unidb.metadata()
|
|
17
|
+
if isinstance(request, m.DBScenarioRequest):
|
|
18
|
+
metadata["view"] = {"kind": "scratch", "base_view": {"kind": "live", "snapshot_id": None}}
|
|
19
|
+
response = response_type(
|
|
20
|
+
request_id=request.request_id,
|
|
21
|
+
correlation_id=request.correlation_id,
|
|
22
|
+
binding_id=unidb.binding_id,
|
|
23
|
+
result=result,
|
|
24
|
+
metadata=metadata,
|
|
25
|
+
)
|
|
26
|
+
try:
|
|
27
|
+
bounded(response.model_dump(), unidb.limits(request)["max_output_bytes"])
|
|
28
|
+
except (TypeError, ValueError) as exc:
|
|
29
|
+
raise RuntimeFailure(
|
|
30
|
+
"serialization_failure", "serialize", str(exc), result.get("effect", "not_started")
|
|
31
|
+
) from exc
|
|
32
|
+
except Exception as exc:
|
|
33
|
+
failure = (
|
|
34
|
+
exc
|
|
35
|
+
if isinstance(exc, RuntimeFailure)
|
|
36
|
+
else RuntimeFailure(
|
|
37
|
+
"native_error",
|
|
38
|
+
"execute",
|
|
39
|
+
str(exc),
|
|
40
|
+
result.get("effect", "not_started") if result else "not_started",
|
|
41
|
+
)
|
|
42
|
+
)
|
|
43
|
+
ctx.send_error(
|
|
44
|
+
m.DBFailure(
|
|
45
|
+
request_id=request.request_id,
|
|
46
|
+
correlation_id=request.correlation_id,
|
|
47
|
+
binding_id=unidb.binding_id,
|
|
48
|
+
outcome="unknown" if failure.effect == "unknown" else "failed",
|
|
49
|
+
error=m.ErrorDetail(
|
|
50
|
+
code=failure.code,
|
|
51
|
+
stage=failure.stage,
|
|
52
|
+
effect=failure.effect,
|
|
53
|
+
message=str(failure),
|
|
54
|
+
details=failure.details,
|
|
55
|
+
),
|
|
56
|
+
metadata=unidb.metadata(),
|
|
57
|
+
)
|
|
58
|
+
)
|
|
59
|
+
return
|
|
60
|
+
try:
|
|
61
|
+
ctx.send(response)
|
|
62
|
+
except Exception:
|
|
63
|
+
# Publication may already have delivered. Do not emit a competing outcome.
|
|
64
|
+
self.logger.exception("UniDB result publication failed; recover using operation status or replay")
|
|
65
|
+
|
|
66
|
+
handle.__name__ = request_type.__name__.removesuffix("Request").lower()
|
|
67
|
+
return processor(request_type, depends_on=["unidb"])(handle)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
class UniDBAgent(Agent[m.UniDBAgentConfig]):
|
|
71
|
+
def __init__(self):
|
|
72
|
+
runtime = self._dependency_resolvers["unidb"].get_or_resolve(self.get_organization(), self.guild_id, self.id)
|
|
73
|
+
try:
|
|
74
|
+
runtime.configure(self.config)
|
|
75
|
+
except Exception:
|
|
76
|
+
runtime.close()
|
|
77
|
+
raise
|
|
78
|
+
|
|
79
|
+
dbcapabilities = _handler(m.DBCapabilitiesRequest, m.DBCapabilitiesResponse)
|
|
80
|
+
dbhealth = _handler(m.DBHealthRequest, m.DBHealthResponse)
|
|
81
|
+
dbquery = _handler(m.DBQueryRequest, m.DBQueryResponse)
|
|
82
|
+
dbqueryplan = _handler(m.DBQueryPlanRequest, m.DBQueryPlanResponse)
|
|
83
|
+
dbqueryprofile = _handler(m.DBQueryProfileRequest, m.DBQueryProfileResponse)
|
|
84
|
+
dbevaluate = _handler(m.DBEvaluateRequest, m.DBEvaluateResponse)
|
|
85
|
+
dbexplain = _handler(m.DBExplainRequest, m.DBExplainResponse)
|
|
86
|
+
dbmutate = _handler(m.DBMutateRequest, m.DBMutateResponse)
|
|
87
|
+
dbscenario = _handler(m.DBScenarioRequest, m.DBScenarioResponse)
|
|
88
|
+
dboperationstatus = _handler(m.DBOperationStatusRequest, m.DBOperationStatusResponse)
|
|
89
|
+
dbbulkstatus = _handler(m.DBBulkStatusRequest, m.DBBulkStatusResponse)
|
|
90
|
+
createlabel = _handler(m.CreateLabelRequest, m.CreateLabelResponse)
|
|
91
|
+
createedgetype = _handler(m.CreateEdgeTypeRequest, m.CreateEdgeTypeResponse)
|
|
92
|
+
addproperty = _handler(m.AddPropertyRequest, m.AddPropertyResponse)
|
|
93
|
+
createscalarindex = _handler(m.CreateScalarIndexRequest, m.CreateScalarIndexResponse)
|
|
94
|
+
createvectorindex = _handler(m.CreateVectorIndexRequest, m.CreateVectorIndexResponse)
|
|
95
|
+
listlabels = _handler(m.ListLabelsRequest, m.ListLabelsResponse)
|
|
96
|
+
listedgetypes = _handler(m.ListEdgeTypesRequest, m.ListEdgeTypesResponse)
|
|
97
|
+
getlabelinfo = _handler(m.GetLabelInfoRequest, m.GetLabelInfoResponse)
|
|
98
|
+
getschema = _handler(m.GetSchemaRequest, m.GetSchemaResponse)
|
|
99
|
+
query = _handler(m.QueryRequest, m.QueryResponse)
|
|
100
|
+
execute = _handler(m.ExecuteRequest, m.ExecuteResponse)
|
|
101
|
+
flush = _handler(m.FlushRequest, m.FlushResponse)
|
|
102
|
+
vectorsearch = _handler(m.VectorSearchRequest, m.VectorSearchResponse)
|
|
103
|
+
insertvertices = _handler(m.InsertVerticesRequest, m.InsertVerticesResponse)
|
|
104
|
+
insertedges = _handler(m.InsertEdgesRequest, m.InsertEdgesResponse)
|