qoni 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.
qoni/__init__.py ADDED
@@ -0,0 +1,101 @@
1
+ """Qoni — unified Python SDK for Qoni Agent delegation, GenAuth user
2
+ management, GUMem memory, and WebAgent automation.
3
+
4
+ Quick start::
5
+
6
+ from qoni import Qoni
7
+
8
+ qoni = Qoni(access_key=..., secret_key=...)
9
+
10
+ delegation = qoni.delegate_token(user_id=..., products=["do_anything"])
11
+ run = qoni.do_anything.run(
12
+ token=delegation.data["token"],
13
+ prompt="Open example.com and summarize it.",
14
+ )
15
+ result = run.wait(timeout=600)
16
+ print(result.status, result.output)
17
+ """
18
+
19
+ from .client import Qoni
20
+ from .errors import (
21
+ QoniAuthError,
22
+ QoniDelegationRequiredError,
23
+ QoniError,
24
+ QoniPermissionDeniedError,
25
+ QoniRateLimitError,
26
+ QoniTimeoutError,
27
+ QoniTokenExpiredError,
28
+ QoniUpstreamError,
29
+ QoniValidationError,
30
+ )
31
+ from .interactions import (
32
+ Action,
33
+ ActionKinds,
34
+ Interaction,
35
+ InteractionHandle,
36
+ InteractionStatuses,
37
+ InteractionTypes,
38
+ )
39
+ from .run_events import QoniEventTypes, RunEvent, RunImage
40
+ from .run_handle import (
41
+ Artifact,
42
+ CaptureOptions,
43
+ RunHandle,
44
+ RunLimits,
45
+ RunResult,
46
+ RunStatus,
47
+ SessionRef,
48
+ )
49
+ from .scopes import KNOWN_SCOPES, QONI_PRODUCT_SCOPES, QONI_SCOPE_BUNDLES, QoniScopes
50
+ from .signature import build_authorization, build_signature, build_string_to_sign
51
+ from .track import MonitorHandle
52
+ from .types import QoniResponse, SSEEvent
53
+
54
+ __version__ = "0.1.0"
55
+
56
+ __all__ = [
57
+ # client
58
+ "Qoni",
59
+ "QoniResponse",
60
+ "SSEEvent",
61
+ # errors
62
+ "QoniError",
63
+ "QoniAuthError",
64
+ "QoniDelegationRequiredError",
65
+ "QoniPermissionDeniedError",
66
+ "QoniRateLimitError",
67
+ "QoniTimeoutError",
68
+ "QoniTokenExpiredError",
69
+ "QoniUpstreamError",
70
+ "QoniValidationError",
71
+ # scopes
72
+ "QoniScopes",
73
+ "QONI_PRODUCT_SCOPES",
74
+ "QONI_SCOPE_BUNDLES",
75
+ "KNOWN_SCOPES",
76
+ # runs
77
+ "RunHandle",
78
+ "RunStatus",
79
+ "RunResult",
80
+ "Artifact",
81
+ "SessionRef",
82
+ "CaptureOptions",
83
+ "RunLimits",
84
+ # events
85
+ "QoniEventTypes",
86
+ "RunEvent",
87
+ "RunImage",
88
+ # interactions
89
+ "Interaction",
90
+ "InteractionHandle",
91
+ "InteractionTypes",
92
+ "InteractionStatuses",
93
+ "ActionKinds",
94
+ "Action",
95
+ # track
96
+ "MonitorHandle",
97
+ # signature helpers
98
+ "build_authorization",
99
+ "build_signature",
100
+ "build_string_to_sign",
101
+ ]
qoni/auth.py ADDED
@@ -0,0 +1,45 @@
1
+ """Signed request headers for AK/SK control-plane calls."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import threading
6
+ import time
7
+ from typing import Any, Dict, Mapping
8
+
9
+ from .signature import build_authorization, build_string_to_sign
10
+
11
+ _lock = threading.Lock()
12
+ _last_signing_timestamp = 0
13
+
14
+
15
+ def _next_signing_timestamp() -> int:
16
+ """Strictly monotonic millisecond timestamp.
17
+
18
+ GenAuth rejects an already-consumed signature, so otherwise identical
19
+ requests (retries, concurrent calls in the same millisecond) must stay
20
+ unique within a process.
21
+ """
22
+
23
+ global _last_signing_timestamp
24
+ with _lock:
25
+ now = int(time.time() * 1000)
26
+ _last_signing_timestamp = max(now, _last_signing_timestamp + 1)
27
+ return _last_signing_timestamp
28
+
29
+
30
+ def build_signed_headers(
31
+ access_key: str,
32
+ secret_key: str,
33
+ method: str,
34
+ pathname: str,
35
+ payload: Mapping[str, Any],
36
+ ) -> Dict[str, str]:
37
+ headers: Dict[str, str] = {
38
+ "content-type": "application/json",
39
+ "x-authing-date": str(_next_signing_timestamp()),
40
+ "x-authing-signature-method": "HMAC-SHA1",
41
+ "x-authing-signature-version": "1.0",
42
+ }
43
+ string_to_sign = build_string_to_sign(method, pathname, headers, payload)
44
+ headers["authorization"] = build_authorization(access_key, secret_key, string_to_sign)
45
+ return headers