kyber-runtime-sdk 1.0.1__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.
- kyber/memory/__init__.py +140 -0
- kyber/memory/client.py +583 -0
- kyber/memory/errors.py +38 -0
- kyber/memory/models.py +40 -0
- kyber/memory/proto/__init__.py +1 -0
- kyber/memory/proto/memory.proto +185 -0
- kyber/memory/proto/memory_pb2.py +80 -0
- kyber/memory/proto/memory_pb2_grpc.py +312 -0
- kyber/runtime/__init__.py +13 -0
- kyber/runtime/context.py +23 -0
- kyber/tools/__init__.py +17 -0
- kyber/tools/client.py +257 -0
- kyber/tools/errors.py +6 -0
- kyber/tools/models.py +16 -0
- kyber_runtime_sdk-1.0.1.dist-info/METADATA +26 -0
- kyber_runtime_sdk-1.0.1.dist-info/RECORD +18 -0
- kyber_runtime_sdk-1.0.1.dist-info/WHEEL +5 -0
- kyber_runtime_sdk-1.0.1.dist-info/top_level.txt +1 -0
kyber/memory/__init__.py
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"""Developer-facing access to Kyber Memory over gRPC."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from typing import Any, Mapping, Optional
|
|
8
|
+
|
|
9
|
+
from kyber.memory.client import MemoryClient, MemoryClientSettings
|
|
10
|
+
from kyber.memory.errors import (
|
|
11
|
+
MemoryConfigurationError,
|
|
12
|
+
MemoryError,
|
|
13
|
+
MemoryRpcError,
|
|
14
|
+
MemoryValidationError,
|
|
15
|
+
)
|
|
16
|
+
from kyber.memory.models import MemoryItem, MemoryScope, MemoryWriteResult
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def get_memory(
|
|
20
|
+
context: Any = None,
|
|
21
|
+
*,
|
|
22
|
+
tenant_id: Optional[str] = None,
|
|
23
|
+
read_target: Optional[str] = None,
|
|
24
|
+
write_target: Optional[str] = None,
|
|
25
|
+
platform_auth: Optional[str] = None,
|
|
26
|
+
identity_token: Optional[str] = None,
|
|
27
|
+
agent_id: Optional[str] = None,
|
|
28
|
+
circuit_id: Optional[str] = None,
|
|
29
|
+
timeout_seconds: Optional[float] = None,
|
|
30
|
+
tls: Optional[bool] = None,
|
|
31
|
+
root_certificate_path: Optional[Path] = None,
|
|
32
|
+
) -> MemoryClient:
|
|
33
|
+
"""Build a memory client from explicit, runtime-context, or environment values.
|
|
34
|
+
|
|
35
|
+
Developers supply user_id/project_id/session_id to individual operations. Tenant,
|
|
36
|
+
agent, circuit, endpoint, and credential values are runtime-owned configuration.
|
|
37
|
+
"""
|
|
38
|
+
|
|
39
|
+
tenant_id = _setting(tenant_id, context, "tenant_id", "KYBER_TENANT_ID")
|
|
40
|
+
if not tenant_id:
|
|
41
|
+
raise MemoryConfigurationError(
|
|
42
|
+
"Memory tenant identity is not configured; set KYBER_TENANT_ID"
|
|
43
|
+
)
|
|
44
|
+
if len(str(tenant_id)) > 255:
|
|
45
|
+
raise MemoryConfigurationError("tenant_id must contain at most 255 characters")
|
|
46
|
+
|
|
47
|
+
configured_timeout = _setting(
|
|
48
|
+
timeout_seconds,
|
|
49
|
+
context,
|
|
50
|
+
"memory_timeout_seconds",
|
|
51
|
+
"KYBER_MEMORY_GRPC_TIMEOUT_SECONDS",
|
|
52
|
+
)
|
|
53
|
+
try:
|
|
54
|
+
resolved_timeout = float(configured_timeout or 30.0)
|
|
55
|
+
except (TypeError, ValueError) as exc:
|
|
56
|
+
raise MemoryConfigurationError(
|
|
57
|
+
"KYBER_MEMORY_GRPC_TIMEOUT_SECONDS must be a number"
|
|
58
|
+
) from exc
|
|
59
|
+
if resolved_timeout <= 0:
|
|
60
|
+
raise MemoryConfigurationError("Memory gRPC timeout must be greater than zero")
|
|
61
|
+
|
|
62
|
+
configured_tls = _setting(tls, context, "memory_tls", "KYBER_MEMORY_GRPC_TLS")
|
|
63
|
+
resolved_tls = _boolean(configured_tls, default=True)
|
|
64
|
+
certificate = _setting(
|
|
65
|
+
root_certificate_path,
|
|
66
|
+
context,
|
|
67
|
+
"memory_root_certificate_path",
|
|
68
|
+
"KYBER_MEMORY_GRPC_ROOT_CERTIFICATE",
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
return MemoryClient(
|
|
72
|
+
MemoryClientSettings(
|
|
73
|
+
tenant_id=str(tenant_id),
|
|
74
|
+
read_target=_setting(
|
|
75
|
+
read_target,
|
|
76
|
+
context,
|
|
77
|
+
"memory_read_target",
|
|
78
|
+
"KYBER_MEMORY_GRPC_TARGET",
|
|
79
|
+
),
|
|
80
|
+
write_target=_setting(
|
|
81
|
+
write_target,
|
|
82
|
+
context,
|
|
83
|
+
"memory_write_target",
|
|
84
|
+
"KYBER_MEMORY_WRITE_GRPC_TARGET",
|
|
85
|
+
),
|
|
86
|
+
platform_auth=_setting(
|
|
87
|
+
platform_auth,
|
|
88
|
+
context,
|
|
89
|
+
"memory_platform_auth",
|
|
90
|
+
"KYBER_MEMORY_PLATFORM_AUTH",
|
|
91
|
+
),
|
|
92
|
+
identity_token=_setting(
|
|
93
|
+
identity_token,
|
|
94
|
+
context,
|
|
95
|
+
"identity_token",
|
|
96
|
+
"KYBER_MEMORY_IDENTITY_TOKEN",
|
|
97
|
+
),
|
|
98
|
+
agent_id=_setting(agent_id, context, "agent_id", "KYBER_AGENT_ID"),
|
|
99
|
+
circuit_id=_setting(circuit_id, context, "circuit_id", "KYBER_CIRCUIT_ID"),
|
|
100
|
+
timeout_seconds=resolved_timeout,
|
|
101
|
+
tls=resolved_tls,
|
|
102
|
+
root_certificate_path=Path(certificate) if certificate else None,
|
|
103
|
+
)
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def _setting(explicit, context, context_name: str, environment_name: str):
|
|
108
|
+
if explicit is not None:
|
|
109
|
+
return explicit
|
|
110
|
+
if isinstance(context, Mapping):
|
|
111
|
+
value = context.get(context_name)
|
|
112
|
+
else:
|
|
113
|
+
value = getattr(context, context_name, None) if context is not None else None
|
|
114
|
+
return value if value is not None else os.environ.get(environment_name)
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def _boolean(value, *, default: bool) -> bool:
|
|
118
|
+
if value is None:
|
|
119
|
+
return default
|
|
120
|
+
if isinstance(value, bool):
|
|
121
|
+
return value
|
|
122
|
+
normalized = str(value).strip().lower()
|
|
123
|
+
if normalized in {"1", "true", "yes", "on"}:
|
|
124
|
+
return True
|
|
125
|
+
if normalized in {"0", "false", "no", "off"}:
|
|
126
|
+
return False
|
|
127
|
+
raise MemoryConfigurationError("KYBER_MEMORY_GRPC_TLS must be true or false")
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
__all__ = [
|
|
131
|
+
"MemoryClient",
|
|
132
|
+
"MemoryConfigurationError",
|
|
133
|
+
"MemoryError",
|
|
134
|
+
"MemoryItem",
|
|
135
|
+
"MemoryRpcError",
|
|
136
|
+
"MemoryScope",
|
|
137
|
+
"MemoryValidationError",
|
|
138
|
+
"MemoryWriteResult",
|
|
139
|
+
"get_memory",
|
|
140
|
+
]
|