memoryking 0.1.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.
- memoryking/__init__.py +3 -0
- memoryking/__main__.py +1328 -0
- memoryking/adapters/__init__.py +1 -0
- memoryking/adapters/adapter_state.py +242 -0
- memoryking/adapters/anchor_schema.sql +7 -0
- memoryking/adapters/atlas.py +441 -0
- memoryking/adapters/browser_commands.py +125 -0
- memoryking/adapters/dashboard.py +510 -0
- memoryking/adapters/dense_search.py +86 -0
- memoryking/adapters/egress_policy.py +244 -0
- memoryking/adapters/egress_schema.sql +13 -0
- memoryking/adapters/embedding.schema.json +302 -0
- memoryking/adapters/embedding_store.py +469 -0
- memoryking/adapters/execution.py +369 -0
- memoryking/adapters/experience.py +423 -0
- memoryking/adapters/experience.schema.json +1508 -0
- memoryking/adapters/experience_records.py +239 -0
- memoryking/adapters/experience_schema.sql +23 -0
- memoryking/adapters/handoff.py +494 -0
- memoryking/adapters/handoff.schema.json +299 -0
- memoryking/adapters/handoff_schema.sql +17 -0
- memoryking/adapters/index_schema.sql +11 -0
- memoryking/adapters/inference.py +454 -0
- memoryking/adapters/inference.schema.json +541 -0
- memoryking/adapters/inspection.py +1128 -0
- memoryking/adapters/inspection.schema.json +568 -0
- memoryking/adapters/knowledge.schema.json +633 -0
- memoryking/adapters/knowledge_schema.sql +37 -0
- memoryking/adapters/knowledge_store.py +800 -0
- memoryking/adapters/legacy_snapshot.py +358 -0
- memoryking/adapters/legacy_tables.py +49 -0
- memoryking/adapters/local_contract.py +45 -0
- memoryking/adapters/local_embeddings.py +189 -0
- memoryking/adapters/local_files.py +242 -0
- memoryking/adapters/local_ipc.py +258 -0
- memoryking/adapters/local_schema.sql +44 -0
- memoryking/adapters/local_store.py +632 -0
- memoryking/adapters/local_wire.schema.json +7672 -0
- memoryking/adapters/models/minilm-l6-v2-onnx.json +57 -0
- memoryking/adapters/models/ms-marco-minilm-l6-v2-onnx.json +57 -0
- memoryking/adapters/optional_schema.sql +43 -0
- memoryking/adapters/plan_dashboard.py +51 -0
- memoryking/adapters/plans.py +253 -0
- memoryking/adapters/postgres_admin.py +300 -0
- memoryking/adapters/postgres_anchor_schema.sql +9 -0
- memoryking/adapters/postgres_counter.sql +14 -0
- memoryking/adapters/postgres_egress_schema.sql +15 -0
- memoryking/adapters/postgres_experience_schema.sql +39 -0
- memoryking/adapters/postgres_index_schema.sql +7 -0
- memoryking/adapters/postgres_optional_schema.sql +71 -0
- memoryking/adapters/postgres_pool.py +77 -0
- memoryking/adapters/postgres_recovery.py +525 -0
- memoryking/adapters/postgres_schema.sql +365 -0
- memoryking/adapters/postgres_sql.py +102 -0
- memoryking/adapters/postgres_store.py +428 -0
- memoryking/adapters/postgres_summary_schema.sql +12 -0
- memoryking/adapters/postgres_trust_schema.sql +20 -0
- memoryking/adapters/processing.schema.json +471 -0
- memoryking/adapters/processing_store.py +346 -0
- memoryking/adapters/projects.py +83 -0
- memoryking/adapters/proposals.py +238 -0
- memoryking/adapters/ranking.py +315 -0
- memoryking/adapters/repository.schema.json +664 -0
- memoryking/adapters/repository_git.py +264 -0
- memoryking/adapters/repository_schema.sql +25 -0
- memoryking/adapters/repository_store.py +960 -0
- memoryking/adapters/retrieval.py +1285 -0
- memoryking/adapters/retrieval.schema.json +553 -0
- memoryking/adapters/retrieval_schema.sql +10 -0
- memoryking/adapters/shared_control.py +40 -0
- memoryking/adapters/shared_dashboard.py +636 -0
- memoryking/adapters/shared_gateway.py +63 -0
- memoryking/adapters/shared_http.py +216 -0
- memoryking/adapters/shared_mcp.py +159 -0
- memoryking/adapters/shared_service.py +124 -0
- memoryking/adapters/stdio.py +193 -0
- memoryking/adapters/stdio.tools.json +6776 -0
- memoryking/adapters/summary_schema.sql +10 -0
- memoryking/adapters/team.py +253 -0
- memoryking/adapters/timeline.py +80 -0
- memoryking/adapters/token_count.py +55 -0
- memoryking/adapters/tokenizers/LICENSE +21 -0
- memoryking/adapters/tokenizers/cl100k_base.tiktoken +100256 -0
- memoryking/adapters/trust.py +123 -0
- memoryking/adapters/trust_schema.sql +13 -0
- memoryking/adapters/web/app.css +1251 -0
- memoryking/adapters/web/app.js +907 -0
- memoryking/adapters/web/brand.js +44 -0
- memoryking/adapters/web/crown-mono.svg +1 -0
- memoryking/adapters/web/crown.svg +8 -0
- memoryking/adapters/web/elephant.png +0 -0
- memoryking/adapters/web/favicon.svg +8 -0
- memoryking/adapters/web/graph-layout.js +52 -0
- memoryking/adapters/web/graph-worker.js +10 -0
- memoryking/adapters/web/graph.js +570 -0
- memoryking/adapters/web/index.html +208 -0
- memoryking/adapters/web/observatory.js +1208 -0
- memoryking/adapters/web/team.js +151 -0
- memoryking/adapters/web/wordmark.svg +1 -0
- memoryking/adapters/working.py +971 -0
- memoryking/adapters/working.schema.json +1717 -0
- memoryking/adapters/working_schema.sql +24 -0
- memoryking/application/__init__.py +1 -0
- memoryking/application/conformance.py +50 -0
- memoryking/application/legacy_import.py +337 -0
- memoryking/application/local_port.py +9 -0
- memoryking/application/storage.py +117 -0
- memoryking/application/store_core.py +1292 -0
- memoryking/backups.py +131 -0
- memoryking/contracts/__init__.py +6 -0
- memoryking/contracts/__main__.py +20 -0
- memoryking/contracts/canonical.py +88 -0
- memoryking/contracts/embedding.schema.json +302 -0
- memoryking/contracts/embedding_generated.py +65 -0
- memoryking/contracts/experience.schema.json +1508 -0
- memoryking/contracts/experience_generated.py +239 -0
- memoryking/contracts/generated.py +122 -0
- memoryking/contracts/handoff.schema.json +299 -0
- memoryking/contracts/handoff_generated.py +69 -0
- memoryking/contracts/inference.schema.json +541 -0
- memoryking/contracts/inference_generated.py +106 -0
- memoryking/contracts/processing.schema.json +471 -0
- memoryking/contracts/processing_generated.py +82 -0
- memoryking/contracts/py.typed +0 -0
- memoryking/contracts/repository.schema.json +664 -0
- memoryking/contracts/repository_generated.py +144 -0
- memoryking/contracts/retrieval.schema.json +553 -0
- memoryking/contracts/retrieval_generated.py +110 -0
- memoryking/contracts/schema.json +696 -0
- memoryking/contracts/validation.py +92 -0
- memoryking/contracts/working.schema.json +1717 -0
- memoryking/contracts/working_generated.py +291 -0
- memoryking/domain/__init__.py +1 -0
- memoryking/domain/anchors.py +97 -0
- memoryking/domain/briefing.py +108 -0
- memoryking/domain/briefing_text.py +222 -0
- memoryking/domain/checkpoint.py +118 -0
- memoryking/domain/compression.py +64 -0
- memoryking/domain/delta.py +129 -0
- memoryking/domain/embeddings.py +90 -0
- memoryking/domain/hints.py +465 -0
- memoryking/domain/http_status.py +45 -0
- memoryking/domain/learning.py +62 -0
- memoryking/domain/local.py +65 -0
- memoryking/domain/plans.py +140 -0
- memoryking/domain/repository.py +118 -0
- memoryking/domain/selectors.py +356 -0
- memoryking/domain/summary.py +88 -0
- memoryking/domain/usage.py +163 -0
- memoryking/embedding_loop.py +98 -0
- memoryking/embedding_worker.py +131 -0
- memoryking/harness.py +882 -0
- memoryking/harness_context.py +376 -0
- memoryking/hooks.py +171 -0
- memoryking/host_hooks.py +454 -0
- memoryking/lean.py +352 -0
- memoryking/memory_tool.py +776 -0
- memoryking/migration.py +194 -0
- memoryking/model_install.py +78 -0
- memoryking/observability.py +101 -0
- memoryking/observability_metrics.py +100 -0
- memoryking/profiles.py +150 -0
- memoryking/providers.py +330 -0
- memoryking/py.typed +0 -0
- memoryking/pytest_plugin.py +69 -0
- memoryking/reference_agent.py +152 -0
- memoryking/repository_worker.py +57 -0
- memoryking/resume_adapter.py +154 -0
- memoryking/sdk.py +302 -0
- memoryking/shared.py +301 -0
- memoryking/shared_sdk.py +101 -0
- memoryking/vault.py +176 -0
- memoryking-0.1.0.dist-info/METADATA +157 -0
- memoryking-0.1.0.dist-info/RECORD +179 -0
- memoryking-0.1.0.dist-info/WHEEL +5 -0
- memoryking-0.1.0.dist-info/entry_points.txt +7 -0
- memoryking-0.1.0.dist-info/licenses/LICENSE +202 -0
- memoryking-0.1.0.dist-info/licenses/NOTICE +12 -0
- memoryking-0.1.0.dist-info/top_level.txt +1 -0
memoryking/backups.py
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"""Scheduled backups with retention, run by the daemon that owns the store.
|
|
2
|
+
|
|
3
|
+
Backups land in `DIR/backup-<UTC timestamp>` next to each other; retention keeps the
|
|
4
|
+
newest N directories that carry a signed manifest and never touches anything else in
|
|
5
|
+
the directory. The daemon checks the policy between requests, so a backup happens while
|
|
6
|
+
the store is quiet and the exclusive owner is the daemon itself.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import re
|
|
12
|
+
import shutil
|
|
13
|
+
from datetime import datetime, timezone
|
|
14
|
+
from pathlib import Path
|
|
15
|
+
from typing import Any
|
|
16
|
+
|
|
17
|
+
from memoryking.adapters.local_files import private_dir
|
|
18
|
+
from memoryking.domain.local import LocalError
|
|
19
|
+
from memoryking.observability import event, failure
|
|
20
|
+
|
|
21
|
+
PATTERN = re.compile(r"^backup-(\d{8}T\d{6}Z)$")
|
|
22
|
+
DURATIONS = {"m": 60_000, "h": 3_600_000, "d": 86_400_000}
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def interval_ms(text: str) -> int:
|
|
26
|
+
if len(text) < 2 or text[-1] not in DURATIONS or not text[:-1].isdigit() or int(text[:-1]) < 1:
|
|
27
|
+
raise LocalError("invalid_duration")
|
|
28
|
+
return int(text[:-1]) * DURATIONS[text[-1]]
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def stamp(at_ms: int) -> str:
|
|
32
|
+
return datetime.fromtimestamp(at_ms / 1000, timezone.utc).strftime("%Y%m%dT%H%M%SZ")
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def parse_stamp(name: str) -> int:
|
|
36
|
+
match = PATTERN.match(name)
|
|
37
|
+
if match is None:
|
|
38
|
+
raise ValueError(name)
|
|
39
|
+
moment = datetime.strptime(match.group(1), "%Y%m%dT%H%M%SZ").replace(tzinfo=timezone.utc)
|
|
40
|
+
return int(moment.timestamp() * 1000)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def existing(directory: Path) -> list[tuple[int, Path]]:
|
|
44
|
+
"""(timestamp ms, path) for every complete backup, oldest first."""
|
|
45
|
+
if not directory.exists():
|
|
46
|
+
return []
|
|
47
|
+
found = []
|
|
48
|
+
for path in directory.iterdir():
|
|
49
|
+
if path.is_dir() and PATTERN.match(path.name) and (path / "manifest").is_file():
|
|
50
|
+
found.append((parse_stamp(path.name), path))
|
|
51
|
+
return sorted(found)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def due(directory: Path, every_ms: int, now_ms: int) -> bool:
|
|
55
|
+
backups = existing(directory)
|
|
56
|
+
return not backups or now_ms - backups[-1][0] >= every_ms
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def prune(directory: Path, keep: int) -> list[Path]:
|
|
60
|
+
"""Remove the oldest complete backups beyond `keep`; returns what was removed."""
|
|
61
|
+
removed = []
|
|
62
|
+
for _, path in existing(directory)[:-keep] if keep > 0 else []:
|
|
63
|
+
shutil.rmtree(path)
|
|
64
|
+
removed.append(path)
|
|
65
|
+
return removed
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
class Policy:
|
|
69
|
+
def __init__(self, directory: Path, every: str, keep: int):
|
|
70
|
+
if keep < 1:
|
|
71
|
+
raise LocalError("invalid_request")
|
|
72
|
+
self.directory, self.every_ms, self.keep = directory, interval_ms(every), keep
|
|
73
|
+
self.checked_ms = 0
|
|
74
|
+
self.failed_ms: int | None = None
|
|
75
|
+
|
|
76
|
+
def maybe_run(self, store: Any, now_ms: int, check_every_ms: int = 60_000) -> Path | None:
|
|
77
|
+
"""Back up when due; at most one check per minute, errors logged and swallowed."""
|
|
78
|
+
if now_ms - self.checked_ms < check_every_ms:
|
|
79
|
+
return None
|
|
80
|
+
self.checked_ms = now_ms
|
|
81
|
+
if not due(self.directory, self.every_ms, now_ms):
|
|
82
|
+
return None
|
|
83
|
+
# After a failure, wait the interval (at most an hour) instead of retrying
|
|
84
|
+
# every minute: a persistent cause would otherwise fill the disk.
|
|
85
|
+
if self.failed_ms is not None and now_ms - self.failed_ms < min(self.every_ms, 3_600_000):
|
|
86
|
+
return None
|
|
87
|
+
return self.run(store, now_ms)
|
|
88
|
+
|
|
89
|
+
def run(self, store: Any, now_ms: int) -> Path | None:
|
|
90
|
+
private_dir(self.directory, create=True)
|
|
91
|
+
target = self.directory / ("backup-" + stamp(now_ms))
|
|
92
|
+
created = not target.exists()
|
|
93
|
+
try:
|
|
94
|
+
manifest = store.backup(target)
|
|
95
|
+
removed = prune(self.directory, self.keep)
|
|
96
|
+
event(
|
|
97
|
+
"backup",
|
|
98
|
+
"complete",
|
|
99
|
+
archive_bytes=manifest.get("archive_bytes", 0),
|
|
100
|
+
blobs=len(manifest.get("blobs", [])),
|
|
101
|
+
pruned=len(removed),
|
|
102
|
+
)
|
|
103
|
+
self.failed_ms = None
|
|
104
|
+
return target
|
|
105
|
+
except (LocalError, OSError) as exc:
|
|
106
|
+
failure("backup", exc)
|
|
107
|
+
self.failed_ms = now_ms
|
|
108
|
+
# A partial copy has no manifest, so retention would never remove it.
|
|
109
|
+
if created and target.is_dir() and not (target / "manifest").exists():
|
|
110
|
+
shutil.rmtree(target, ignore_errors=True)
|
|
111
|
+
return None
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def check(directory: Path | None, every: str | None, now_ms: int) -> tuple[str, str]:
|
|
115
|
+
"""A doctor finding: (level, detail) about the newest backup against the policy."""
|
|
116
|
+
if directory is None:
|
|
117
|
+
return (
|
|
118
|
+
"warn",
|
|
119
|
+
"no backup directory configured; `serve --backup-dir DIR --backup-every 1d` schedules them",
|
|
120
|
+
)
|
|
121
|
+
backups = existing(directory)
|
|
122
|
+
if not backups:
|
|
123
|
+
return "warn", f"no complete backup in {directory} yet"
|
|
124
|
+
age_ms = now_ms - backups[-1][0]
|
|
125
|
+
age = f"{age_ms / 3_600_000:.1f} h"
|
|
126
|
+
if every is not None and age_ms > 2 * interval_ms(every):
|
|
127
|
+
return (
|
|
128
|
+
"fail",
|
|
129
|
+
f"newest backup {backups[-1][1].name} is {age} old, past twice the {every} policy",
|
|
130
|
+
)
|
|
131
|
+
return "ok", f"{len(backups)} backups, newest {backups[-1][1].name} ({age} old)"
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"""Versioned wire contracts with strict validation and canonical serialization."""
|
|
2
|
+
|
|
3
|
+
from .canonical import ContractError, canonical_bytes, canonical_hash, load_strict
|
|
4
|
+
from .validation import validate_contract
|
|
5
|
+
|
|
6
|
+
__all__ = ["ContractError", "canonical_bytes", "canonical_hash", "load_strict", "validate_contract"]
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"""Developer contract inspector, not the future memory service CLI."""
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
from . import canonical_hash, load_strict, validate_contract
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def main() -> None:
|
|
10
|
+
parser = argparse.ArgumentParser(description=__doc__)
|
|
11
|
+
parser.add_argument("contract")
|
|
12
|
+
parser.add_argument("file", type=Path)
|
|
13
|
+
args = parser.parse_args()
|
|
14
|
+
value = load_strict(args.file.read_bytes())
|
|
15
|
+
validate_contract(args.contract, value)
|
|
16
|
+
print(canonical_hash(value))
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
if __name__ == "__main__":
|
|
20
|
+
main()
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"""MK-C14N-1: a bounded, integer-only canonical JSON profile, not RFC 8785."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import hashlib
|
|
6
|
+
import json
|
|
7
|
+
import re
|
|
8
|
+
from typing import Any
|
|
9
|
+
|
|
10
|
+
MAX_BYTES = 1_048_576
|
|
11
|
+
MAX_DEPTH = 64
|
|
12
|
+
MAX_INTEGER = 9_007_199_254_740_991
|
|
13
|
+
# A C-level search keeps the MK-C14N-1 rejection without a Python call per character.
|
|
14
|
+
_SURROGATE = re.compile(r"[\ud800-\udfff]")
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class ContractError(ValueError):
|
|
18
|
+
"""Invalid input; messages contain no caller-supplied content."""
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def _pairs(items: list[tuple[str, Any]]) -> dict[str, Any]:
|
|
22
|
+
result: dict[str, Any] = {}
|
|
23
|
+
for key, value in items:
|
|
24
|
+
if key in result:
|
|
25
|
+
raise ContractError("duplicate_key")
|
|
26
|
+
result[key] = value
|
|
27
|
+
return result
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _not_integer(value: str) -> None:
|
|
31
|
+
raise ContractError("integer_profile_required")
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def _check(value: Any, depth: int = 0) -> None:
|
|
35
|
+
if depth > MAX_DEPTH:
|
|
36
|
+
raise ContractError("document_too_deep")
|
|
37
|
+
if value is None or isinstance(value, bool):
|
|
38
|
+
return
|
|
39
|
+
if isinstance(value, int):
|
|
40
|
+
if abs(value) > MAX_INTEGER:
|
|
41
|
+
raise ContractError("unsafe_integer")
|
|
42
|
+
elif isinstance(value, str):
|
|
43
|
+
if _SURROGATE.search(value) is not None:
|
|
44
|
+
raise ContractError("invalid_unicode")
|
|
45
|
+
elif isinstance(value, list):
|
|
46
|
+
for item in value:
|
|
47
|
+
_check(item, depth + 1)
|
|
48
|
+
elif isinstance(value, dict):
|
|
49
|
+
for key, item in value.items():
|
|
50
|
+
if not isinstance(key, str):
|
|
51
|
+
raise ContractError("non_string_key")
|
|
52
|
+
_check(key, depth)
|
|
53
|
+
_check(item, depth + 1)
|
|
54
|
+
else:
|
|
55
|
+
raise ContractError("unsupported_value")
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def load_strict(raw: str | bytes) -> Any:
|
|
59
|
+
"""Reject duplicates, decimals, nonfinite values, unsafe integers and bad Unicode."""
|
|
60
|
+
try:
|
|
61
|
+
data = raw.encode("utf-8") if isinstance(raw, str) else raw
|
|
62
|
+
if len(data) > MAX_BYTES:
|
|
63
|
+
raise ContractError("document_too_large")
|
|
64
|
+
value = json.loads(
|
|
65
|
+
data.decode("utf-8"),
|
|
66
|
+
object_pairs_hook=_pairs,
|
|
67
|
+
parse_float=_not_integer,
|
|
68
|
+
parse_constant=_not_integer,
|
|
69
|
+
)
|
|
70
|
+
_check(value)
|
|
71
|
+
return value
|
|
72
|
+
except ContractError:
|
|
73
|
+
raise
|
|
74
|
+
except (UnicodeError, RecursionError, ValueError) as exc:
|
|
75
|
+
raise ContractError("invalid_json") from exc
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def canonical_bytes(value: Any) -> bytes:
|
|
79
|
+
"""Preserve string content/array order; sort keys by Unicode scalar value."""
|
|
80
|
+
_check(value)
|
|
81
|
+
result = json.dumps(value, ensure_ascii=False, sort_keys=True, separators=(",", ":")).encode()
|
|
82
|
+
if len(result) > MAX_BYTES:
|
|
83
|
+
raise ContractError("document_too_large")
|
|
84
|
+
return result
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def canonical_hash(value: Any) -> str:
|
|
88
|
+
return hashlib.sha256(canonical_bytes(value)).hexdigest()
|
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://memoryking.invalid/embedding-v1",
|
|
4
|
+
"title": "MemoryKing optional embedding administration and workers v1",
|
|
5
|
+
"oneOf": [
|
|
6
|
+
{
|
|
7
|
+
"type": "object",
|
|
8
|
+
"additionalProperties": false,
|
|
9
|
+
"properties": {
|
|
10
|
+
"version": {
|
|
11
|
+
"const": 1
|
|
12
|
+
},
|
|
13
|
+
"incarnation": {
|
|
14
|
+
"type": "string",
|
|
15
|
+
"pattern": "^[A-Za-z0-9_-]{1,96}(?![\\s\\S])"
|
|
16
|
+
},
|
|
17
|
+
"action": {
|
|
18
|
+
"const": "configure"
|
|
19
|
+
},
|
|
20
|
+
"args": {
|
|
21
|
+
"$ref": "#/$defs/Configure"
|
|
22
|
+
},
|
|
23
|
+
"key": {
|
|
24
|
+
"type": "string",
|
|
25
|
+
"pattern": "^[A-Za-z0-9_-]{1,96}(?![\\s\\S])"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"required": [
|
|
29
|
+
"version",
|
|
30
|
+
"incarnation",
|
|
31
|
+
"action",
|
|
32
|
+
"args",
|
|
33
|
+
"key"
|
|
34
|
+
]
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
"type": "object",
|
|
38
|
+
"additionalProperties": false,
|
|
39
|
+
"properties": {
|
|
40
|
+
"version": {
|
|
41
|
+
"const": 1
|
|
42
|
+
},
|
|
43
|
+
"incarnation": {
|
|
44
|
+
"type": "string",
|
|
45
|
+
"pattern": "^[A-Za-z0-9_-]{1,96}(?![\\s\\S])"
|
|
46
|
+
},
|
|
47
|
+
"action": {
|
|
48
|
+
"const": "claim"
|
|
49
|
+
},
|
|
50
|
+
"args": {
|
|
51
|
+
"$ref": "#/$defs/Partition"
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
"required": [
|
|
55
|
+
"version",
|
|
56
|
+
"incarnation",
|
|
57
|
+
"action",
|
|
58
|
+
"args"
|
|
59
|
+
]
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
"type": "object",
|
|
63
|
+
"additionalProperties": false,
|
|
64
|
+
"properties": {
|
|
65
|
+
"version": {
|
|
66
|
+
"const": 1
|
|
67
|
+
},
|
|
68
|
+
"incarnation": {
|
|
69
|
+
"type": "string",
|
|
70
|
+
"pattern": "^[A-Za-z0-9_-]{1,96}(?![\\s\\S])"
|
|
71
|
+
},
|
|
72
|
+
"action": {
|
|
73
|
+
"const": "complete"
|
|
74
|
+
},
|
|
75
|
+
"args": {
|
|
76
|
+
"$ref": "#/$defs/Complete"
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
"required": [
|
|
80
|
+
"version",
|
|
81
|
+
"incarnation",
|
|
82
|
+
"action",
|
|
83
|
+
"args"
|
|
84
|
+
]
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
"type": "object",
|
|
88
|
+
"additionalProperties": false,
|
|
89
|
+
"properties": {
|
|
90
|
+
"version": {
|
|
91
|
+
"const": 1
|
|
92
|
+
},
|
|
93
|
+
"incarnation": {
|
|
94
|
+
"type": "string",
|
|
95
|
+
"pattern": "^[A-Za-z0-9_-]{1,96}(?![\\s\\S])"
|
|
96
|
+
},
|
|
97
|
+
"action": {
|
|
98
|
+
"const": "fail"
|
|
99
|
+
},
|
|
100
|
+
"args": {
|
|
101
|
+
"$ref": "#/$defs/Fail"
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
"required": [
|
|
105
|
+
"version",
|
|
106
|
+
"incarnation",
|
|
107
|
+
"action",
|
|
108
|
+
"args"
|
|
109
|
+
]
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
"type": "object",
|
|
113
|
+
"additionalProperties": false,
|
|
114
|
+
"properties": {
|
|
115
|
+
"version": {
|
|
116
|
+
"const": 1
|
|
117
|
+
},
|
|
118
|
+
"incarnation": {
|
|
119
|
+
"type": "string",
|
|
120
|
+
"pattern": "^[A-Za-z0-9_-]{1,96}(?![\\s\\S])"
|
|
121
|
+
},
|
|
122
|
+
"action": {
|
|
123
|
+
"const": "status"
|
|
124
|
+
},
|
|
125
|
+
"args": {
|
|
126
|
+
"$ref": "#/$defs/Partition"
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
"required": [
|
|
130
|
+
"version",
|
|
131
|
+
"incarnation",
|
|
132
|
+
"action",
|
|
133
|
+
"args"
|
|
134
|
+
]
|
|
135
|
+
}
|
|
136
|
+
],
|
|
137
|
+
"$defs": {
|
|
138
|
+
"Configure": {
|
|
139
|
+
"type": "object",
|
|
140
|
+
"additionalProperties": false,
|
|
141
|
+
"properties": {
|
|
142
|
+
"project": {
|
|
143
|
+
"type": "string",
|
|
144
|
+
"pattern": "^[A-Za-z0-9_-]{1,96}(?![\\s\\S])"
|
|
145
|
+
},
|
|
146
|
+
"model": {
|
|
147
|
+
"type": "string",
|
|
148
|
+
"enum": [
|
|
149
|
+
"minilm-l6-v2-onnx"
|
|
150
|
+
]
|
|
151
|
+
},
|
|
152
|
+
"state": {
|
|
153
|
+
"type": "string",
|
|
154
|
+
"enum": [
|
|
155
|
+
"experimental",
|
|
156
|
+
"disabled"
|
|
157
|
+
]
|
|
158
|
+
},
|
|
159
|
+
"expected_generation": {
|
|
160
|
+
"type": "integer",
|
|
161
|
+
"minimum": 0,
|
|
162
|
+
"maximum": 9007199254740991
|
|
163
|
+
}
|
|
164
|
+
},
|
|
165
|
+
"required": [
|
|
166
|
+
"project",
|
|
167
|
+
"model",
|
|
168
|
+
"state",
|
|
169
|
+
"expected_generation"
|
|
170
|
+
]
|
|
171
|
+
},
|
|
172
|
+
"Partition": {
|
|
173
|
+
"type": "object",
|
|
174
|
+
"additionalProperties": false,
|
|
175
|
+
"properties": {
|
|
176
|
+
"project": {
|
|
177
|
+
"type": "string",
|
|
178
|
+
"pattern": "^[A-Za-z0-9_-]{1,96}(?![\\s\\S])"
|
|
179
|
+
},
|
|
180
|
+
"fingerprint": {
|
|
181
|
+
"type": "string",
|
|
182
|
+
"pattern": "^[a-f0-9]{64}(?![\\s\\S])"
|
|
183
|
+
}
|
|
184
|
+
},
|
|
185
|
+
"required": [
|
|
186
|
+
"project",
|
|
187
|
+
"fingerprint"
|
|
188
|
+
]
|
|
189
|
+
},
|
|
190
|
+
"Complete": {
|
|
191
|
+
"type": "object",
|
|
192
|
+
"additionalProperties": false,
|
|
193
|
+
"properties": {
|
|
194
|
+
"project": {
|
|
195
|
+
"type": "string",
|
|
196
|
+
"pattern": "^[A-Za-z0-9_-]{1,96}(?![\\s\\S])"
|
|
197
|
+
},
|
|
198
|
+
"lease": {
|
|
199
|
+
"type": "string",
|
|
200
|
+
"minLength": 1,
|
|
201
|
+
"maxLength": 8192
|
|
202
|
+
},
|
|
203
|
+
"fingerprint": {
|
|
204
|
+
"type": "string",
|
|
205
|
+
"pattern": "^[a-f0-9]{64}(?![\\s\\S])"
|
|
206
|
+
},
|
|
207
|
+
"input_hash": {
|
|
208
|
+
"type": "string",
|
|
209
|
+
"pattern": "^[a-f0-9]{64}(?![\\s\\S])"
|
|
210
|
+
},
|
|
211
|
+
"vector": {
|
|
212
|
+
"type": "array",
|
|
213
|
+
"minItems": 1,
|
|
214
|
+
"maxItems": 4096,
|
|
215
|
+
"items": {
|
|
216
|
+
"type": "integer",
|
|
217
|
+
"minimum": -1000000,
|
|
218
|
+
"maximum": 1000000
|
|
219
|
+
}
|
|
220
|
+
},
|
|
221
|
+
"input_tokens": {
|
|
222
|
+
"anyOf": [
|
|
223
|
+
{
|
|
224
|
+
"type": "integer",
|
|
225
|
+
"minimum": 0,
|
|
226
|
+
"maximum": 1000000
|
|
227
|
+
},
|
|
228
|
+
{
|
|
229
|
+
"type": "null"
|
|
230
|
+
}
|
|
231
|
+
]
|
|
232
|
+
},
|
|
233
|
+
"truncated": {
|
|
234
|
+
"type": "boolean"
|
|
235
|
+
},
|
|
236
|
+
"duration_ms": {
|
|
237
|
+
"type": "integer",
|
|
238
|
+
"minimum": 0,
|
|
239
|
+
"maximum": 600000
|
|
240
|
+
}
|
|
241
|
+
},
|
|
242
|
+
"required": [
|
|
243
|
+
"project",
|
|
244
|
+
"lease",
|
|
245
|
+
"fingerprint",
|
|
246
|
+
"input_hash",
|
|
247
|
+
"vector",
|
|
248
|
+
"input_tokens",
|
|
249
|
+
"truncated",
|
|
250
|
+
"duration_ms"
|
|
251
|
+
]
|
|
252
|
+
},
|
|
253
|
+
"Fail": {
|
|
254
|
+
"type": "object",
|
|
255
|
+
"additionalProperties": false,
|
|
256
|
+
"properties": {
|
|
257
|
+
"project": {
|
|
258
|
+
"type": "string",
|
|
259
|
+
"pattern": "^[A-Za-z0-9_-]{1,96}(?![\\s\\S])"
|
|
260
|
+
},
|
|
261
|
+
"lease": {
|
|
262
|
+
"type": "string",
|
|
263
|
+
"minLength": 1,
|
|
264
|
+
"maxLength": 8192
|
|
265
|
+
},
|
|
266
|
+
"reason": {
|
|
267
|
+
"type": "string",
|
|
268
|
+
"enum": [
|
|
269
|
+
"provider_unavailable",
|
|
270
|
+
"model_invalid",
|
|
271
|
+
"interrupted",
|
|
272
|
+
"provider_failure"
|
|
273
|
+
]
|
|
274
|
+
},
|
|
275
|
+
"input_tokens": {
|
|
276
|
+
"anyOf": [
|
|
277
|
+
{
|
|
278
|
+
"type": "integer",
|
|
279
|
+
"minimum": 0,
|
|
280
|
+
"maximum": 1000000
|
|
281
|
+
},
|
|
282
|
+
{
|
|
283
|
+
"type": "null"
|
|
284
|
+
}
|
|
285
|
+
]
|
|
286
|
+
},
|
|
287
|
+
"duration_ms": {
|
|
288
|
+
"type": "integer",
|
|
289
|
+
"minimum": 0,
|
|
290
|
+
"maximum": 600000
|
|
291
|
+
}
|
|
292
|
+
},
|
|
293
|
+
"required": [
|
|
294
|
+
"project",
|
|
295
|
+
"lease",
|
|
296
|
+
"reason",
|
|
297
|
+
"input_tokens",
|
|
298
|
+
"duration_ms"
|
|
299
|
+
]
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"""Generated embedding requests; runtime schema is authoritative."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
from typing import Literal, TypedDict
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class Configure(TypedDict):
|
|
8
|
+
project: str
|
|
9
|
+
model: Literal["minilm-l6-v2-onnx"]
|
|
10
|
+
state: Literal["experimental", "disabled"]
|
|
11
|
+
expected_generation: int
|
|
12
|
+
|
|
13
|
+
class Partition(TypedDict):
|
|
14
|
+
project: str
|
|
15
|
+
fingerprint: str
|
|
16
|
+
|
|
17
|
+
class Complete(TypedDict):
|
|
18
|
+
project: str
|
|
19
|
+
lease: str
|
|
20
|
+
fingerprint: str
|
|
21
|
+
input_hash: str
|
|
22
|
+
vector: list[int]
|
|
23
|
+
input_tokens: int | None
|
|
24
|
+
truncated: bool
|
|
25
|
+
duration_ms: int
|
|
26
|
+
|
|
27
|
+
class Fail(TypedDict):
|
|
28
|
+
project: str
|
|
29
|
+
lease: str
|
|
30
|
+
reason: Literal["provider_unavailable", "model_invalid", "interrupted", "provider_failure"]
|
|
31
|
+
input_tokens: int | None
|
|
32
|
+
duration_ms: int
|
|
33
|
+
|
|
34
|
+
class Command0(TypedDict):
|
|
35
|
+
version: Literal[1]
|
|
36
|
+
incarnation: str
|
|
37
|
+
action: Literal["configure"]
|
|
38
|
+
args: Configure
|
|
39
|
+
key: str
|
|
40
|
+
|
|
41
|
+
class Command1(TypedDict):
|
|
42
|
+
version: Literal[1]
|
|
43
|
+
incarnation: str
|
|
44
|
+
action: Literal["claim"]
|
|
45
|
+
args: Partition
|
|
46
|
+
|
|
47
|
+
class Command2(TypedDict):
|
|
48
|
+
version: Literal[1]
|
|
49
|
+
incarnation: str
|
|
50
|
+
action: Literal["complete"]
|
|
51
|
+
args: Complete
|
|
52
|
+
|
|
53
|
+
class Command3(TypedDict):
|
|
54
|
+
version: Literal[1]
|
|
55
|
+
incarnation: str
|
|
56
|
+
action: Literal["fail"]
|
|
57
|
+
args: Fail
|
|
58
|
+
|
|
59
|
+
class Command4(TypedDict):
|
|
60
|
+
version: Literal[1]
|
|
61
|
+
incarnation: str
|
|
62
|
+
action: Literal["status"]
|
|
63
|
+
args: Partition
|
|
64
|
+
|
|
65
|
+
EmbeddingCommand = Command0 | Command1 | Command2 | Command3 | Command4
|