qi-runtime-postgres 2.0.2__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.
@@ -0,0 +1,73 @@
1
+ """Optional PostgreSQL Runtime Store contribution for qi-agent."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from collections.abc import Mapping
6
+ from typing import Any
7
+
8
+ from qi_runtime import PluginContext
9
+ from qi_runtime.loader import PluginContribution, PluginSpec
10
+ from qi_runtime_plane import RUNTIME_STORE, SESSION_LEASES, SUBMISSION_STORE, USER_INPUT_STORE
11
+ from qi_session import SESSION_EVENT_STORE
12
+
13
+ from .store import FencingTokenRejected, PostgresRuntimeStore, RuntimeStoreError, SequenceConflict
14
+
15
+ __version__ = "2.0.2"
16
+
17
+
18
+ class PostgresRuntimeStorePlugin:
19
+ id = "infrastructure-runtime-store-postgres"
20
+ provide = (
21
+ RUNTIME_STORE,
22
+ SUBMISSION_STORE,
23
+ SESSION_LEASES,
24
+ USER_INPUT_STORE,
25
+ SESSION_EVENT_STORE,
26
+ )
27
+ inject: tuple[()] = ()
28
+
29
+ def __init__(self, config: Mapping[str, Any]) -> None:
30
+ self.config = dict(config)
31
+
32
+ async def apply(self, ctx: PluginContext) -> None:
33
+ store = PostgresRuntimeStore(**self.config)
34
+ await ctx.effect(lambda: store.close)
35
+ await store.migrate()
36
+ for key in self.provide:
37
+ ctx.provide(key, store)
38
+
39
+
40
+ def contribution(**_options: Any) -> PluginContribution:
41
+ return PluginContribution(
42
+ "qi-runtime-postgres",
43
+ (
44
+ PluginSpec(
45
+ PostgresRuntimeStorePlugin.id,
46
+ PostgresRuntimeStorePlugin,
47
+ "PostgreSQL Runtime Store",
48
+ {
49
+ "type": "object",
50
+ "properties": {
51
+ "dsn": {"type": "string", "minLength": 1},
52
+ "min_size": {"type": "integer", "minimum": 0, "default": 1},
53
+ "max_size": {"type": "integer", "minimum": 1, "default": 10},
54
+ "timeout": {"type": "number", "exclusiveMinimum": 0, "default": 30},
55
+ },
56
+ "required": ["dsn"],
57
+ "additionalProperties": False,
58
+ },
59
+ version=__version__,
60
+ inject=PostgresRuntimeStorePlugin.inject,
61
+ ),
62
+ ),
63
+ )
64
+
65
+
66
+ __all__ = [
67
+ "FencingTokenRejected",
68
+ "PostgresRuntimeStore",
69
+ "PostgresRuntimeStorePlugin",
70
+ "RuntimeStoreError",
71
+ "SequenceConflict",
72
+ "contribution",
73
+ ]
@@ -0,0 +1,6 @@
1
+ [plugin]
2
+ manifest_version = 2
3
+ id = "qi-runtime-postgres"
4
+ version = "2.0.2"
5
+ module = "qi_runtime_postgres"
6
+ contribution = "qi_runtime_postgres:contribution"