oxap-sdk 0.1.0a34__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.
- oxap_sdk/__init__.py +195 -0
- oxap_sdk/_ids.py +62 -0
- oxap_sdk/_oap.py +703 -0
- oxap_sdk/auth.py +310 -0
- oxap_sdk/binary.py +196 -0
- oxap_sdk/client.py +219 -0
- oxap_sdk/errors.py +140 -0
- oxap_sdk/py.typed +0 -0
- oxap_sdk/sync.py +335 -0
- oxap_sdk/transport.py +656 -0
- oxap_sdk/types.py +471 -0
- oxap_sdk-0.1.0a34.dist-info/METADATA +123 -0
- oxap_sdk-0.1.0a34.dist-info/RECORD +14 -0
- oxap_sdk-0.1.0a34.dist-info/WHEEL +4 -0
oxap_sdk/__init__.py
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
"""OAP Python SDK with source-compatible Makai class names.
|
|
2
|
+
|
|
3
|
+
Starts ``oapx serve agent,provider --stdio`` by default and exposes four
|
|
4
|
+
namespaces over profiled OAP 0.1 newline-delimited JSON:
|
|
5
|
+
|
|
6
|
+
``client.auth``
|
|
7
|
+
List auth providers and run interactive logins. Token material stays in
|
|
8
|
+
the runtime and is never returned to callers.
|
|
9
|
+
``client.models``
|
|
10
|
+
Discover models. ``model_ref`` values are opaque handles -- pass them
|
|
11
|
+
through unchanged.
|
|
12
|
+
``client.provider``
|
|
13
|
+
Direct provider completions (``complete``) and streaming (``stream``).
|
|
14
|
+
``client.agent``
|
|
15
|
+
Agent sessions and runs. Client-executed tools are rejected explicitly
|
|
16
|
+
until the OAP endpoint offers ``+control-tools``.
|
|
17
|
+
|
|
18
|
+
Quick start::
|
|
19
|
+
|
|
20
|
+
import asyncio
|
|
21
|
+
import oxap_sdk
|
|
22
|
+
|
|
23
|
+
async def main() -> None:
|
|
24
|
+
async with oxap_sdk.connect() as client:
|
|
25
|
+
model = await client.models.resolve(
|
|
26
|
+
provider_id="anthropic",
|
|
27
|
+
api="anthropic-messages",
|
|
28
|
+
model_id="claude-sonnet-4-5",
|
|
29
|
+
)
|
|
30
|
+
response = await client.provider.complete(
|
|
31
|
+
model_ref=model.model_ref,
|
|
32
|
+
messages=[{"role": "user", "content": "Write a haiku about streams."}],
|
|
33
|
+
options=oxap_sdk.RunOptions(max_tokens=128),
|
|
34
|
+
)
|
|
35
|
+
print(response.text)
|
|
36
|
+
|
|
37
|
+
asyncio.run(main())
|
|
38
|
+
"""
|
|
39
|
+
|
|
40
|
+
from __future__ import annotations
|
|
41
|
+
|
|
42
|
+
from .auth import AuthApi
|
|
43
|
+
from .binary import BinaryResolverOptions, resolve_makai_binary
|
|
44
|
+
from .client import AuthOptions, MakaiClient, connect
|
|
45
|
+
from .errors import (
|
|
46
|
+
MakaiAuthError,
|
|
47
|
+
MakaiAuthErrorKind,
|
|
48
|
+
MakaiAuthRequiredError,
|
|
49
|
+
MakaiError,
|
|
50
|
+
MakaiProtocolError,
|
|
51
|
+
MakaiStreamError,
|
|
52
|
+
MakaiStreamErrorKind,
|
|
53
|
+
)
|
|
54
|
+
from ._oap import AgentApi, ModelsApi, ProviderApi
|
|
55
|
+
from .sync import SyncMakaiClient, connect_sync
|
|
56
|
+
from .transport import Frame, FrameRoute, StdioTransport
|
|
57
|
+
from .types import (
|
|
58
|
+
AgentEnd,
|
|
59
|
+
AgentStart,
|
|
60
|
+
AgentStreamEvent,
|
|
61
|
+
AssistantMessage,
|
|
62
|
+
AuthErrorEvent,
|
|
63
|
+
AuthEvent,
|
|
64
|
+
AuthKind,
|
|
65
|
+
AuthEventHandler,
|
|
66
|
+
AuthFlowHandlers,
|
|
67
|
+
AuthProgressEvent,
|
|
68
|
+
AuthPromptEvent,
|
|
69
|
+
AuthRetryPolicy,
|
|
70
|
+
AuthStatus,
|
|
71
|
+
AuthSuccessEvent,
|
|
72
|
+
AuthUrlEvent,
|
|
73
|
+
ChatMessage,
|
|
74
|
+
CompletionResponse,
|
|
75
|
+
Content,
|
|
76
|
+
ContentPart,
|
|
77
|
+
ImageContentPart,
|
|
78
|
+
UrlImageContentPart,
|
|
79
|
+
ListModelsResponse,
|
|
80
|
+
MessageEnd,
|
|
81
|
+
MessageStart,
|
|
82
|
+
ModelCapability,
|
|
83
|
+
ModelDescriptor,
|
|
84
|
+
ModelLifecycle,
|
|
85
|
+
ModelSource,
|
|
86
|
+
ProviderAuthInfo,
|
|
87
|
+
ProviderStreamEvent,
|
|
88
|
+
ReasoningEffort,
|
|
89
|
+
Role,
|
|
90
|
+
RunOptions,
|
|
91
|
+
StreamError,
|
|
92
|
+
TextContentPart,
|
|
93
|
+
TextDelta,
|
|
94
|
+
ThinkingContentPart,
|
|
95
|
+
ThinkingDelta,
|
|
96
|
+
ToolCall,
|
|
97
|
+
ToolCallContentPart,
|
|
98
|
+
ToolContext,
|
|
99
|
+
ToolDefinition,
|
|
100
|
+
ToolExecutionEnd,
|
|
101
|
+
ToolExecutionStart,
|
|
102
|
+
ToolExecutor,
|
|
103
|
+
ToolResult,
|
|
104
|
+
ToolResultContentPart,
|
|
105
|
+
TurnEnd,
|
|
106
|
+
TurnStart,
|
|
107
|
+
Usage,
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
__version__ = "0.1.0a34"
|
|
111
|
+
|
|
112
|
+
__all__ = [
|
|
113
|
+
"__version__",
|
|
114
|
+
# Entry points
|
|
115
|
+
"connect",
|
|
116
|
+
"connect_sync",
|
|
117
|
+
"MakaiClient",
|
|
118
|
+
"SyncMakaiClient",
|
|
119
|
+
"AuthOptions",
|
|
120
|
+
# Namespaces
|
|
121
|
+
"AuthApi",
|
|
122
|
+
"ModelsApi",
|
|
123
|
+
"ProviderApi",
|
|
124
|
+
"AgentApi",
|
|
125
|
+
# Transport
|
|
126
|
+
"StdioTransport",
|
|
127
|
+
"FrameRoute",
|
|
128
|
+
"Frame",
|
|
129
|
+
"BinaryResolverOptions",
|
|
130
|
+
"resolve_makai_binary",
|
|
131
|
+
# Errors
|
|
132
|
+
"MakaiError",
|
|
133
|
+
"MakaiStreamError",
|
|
134
|
+
"MakaiStreamErrorKind",
|
|
135
|
+
"MakaiAuthRequiredError",
|
|
136
|
+
"MakaiProtocolError",
|
|
137
|
+
"MakaiAuthError",
|
|
138
|
+
"MakaiAuthErrorKind",
|
|
139
|
+
# Requests
|
|
140
|
+
"ChatMessage",
|
|
141
|
+
"Role",
|
|
142
|
+
"Content",
|
|
143
|
+
"ContentPart",
|
|
144
|
+
"TextContentPart",
|
|
145
|
+
"ThinkingContentPart",
|
|
146
|
+
"ImageContentPart",
|
|
147
|
+
"UrlImageContentPart",
|
|
148
|
+
"ToolCallContentPart",
|
|
149
|
+
"ToolResultContentPart",
|
|
150
|
+
"ToolDefinition",
|
|
151
|
+
"ToolExecutor",
|
|
152
|
+
"ToolContext",
|
|
153
|
+
"ToolResult",
|
|
154
|
+
"RunOptions",
|
|
155
|
+
"AuthRetryPolicy",
|
|
156
|
+
"ReasoningEffort",
|
|
157
|
+
# Responses
|
|
158
|
+
"CompletionResponse",
|
|
159
|
+
"AssistantMessage",
|
|
160
|
+
"Usage",
|
|
161
|
+
# Provider events
|
|
162
|
+
"ProviderStreamEvent",
|
|
163
|
+
"MessageStart",
|
|
164
|
+
"TextDelta",
|
|
165
|
+
"ThinkingDelta",
|
|
166
|
+
"ToolCall",
|
|
167
|
+
"MessageEnd",
|
|
168
|
+
"StreamError",
|
|
169
|
+
# Agent events
|
|
170
|
+
"AgentStreamEvent",
|
|
171
|
+
"AgentStart",
|
|
172
|
+
"AgentEnd",
|
|
173
|
+
"TurnStart",
|
|
174
|
+
"TurnEnd",
|
|
175
|
+
"ToolExecutionStart",
|
|
176
|
+
"ToolExecutionEnd",
|
|
177
|
+
# Models
|
|
178
|
+
"ModelDescriptor",
|
|
179
|
+
"ListModelsResponse",
|
|
180
|
+
"ModelCapability",
|
|
181
|
+
"ModelLifecycle",
|
|
182
|
+
"ModelSource",
|
|
183
|
+
"AuthKind",
|
|
184
|
+
"AuthStatus",
|
|
185
|
+
# Auth
|
|
186
|
+
"ProviderAuthInfo",
|
|
187
|
+
"AuthFlowHandlers",
|
|
188
|
+
"AuthEventHandler",
|
|
189
|
+
"AuthEvent",
|
|
190
|
+
"AuthUrlEvent",
|
|
191
|
+
"AuthPromptEvent",
|
|
192
|
+
"AuthProgressEvent",
|
|
193
|
+
"AuthSuccessEvent",
|
|
194
|
+
"AuthErrorEvent",
|
|
195
|
+
]
|
oxap_sdk/_ids.py
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"""Protocol identifier generation.
|
|
2
|
+
|
|
3
|
+
The Makai protocols use two wire formats for identifiers (spec §3.1):
|
|
4
|
+
|
|
5
|
+
* ``session_id`` -- a 21-character alphanumeric NanoID.
|
|
6
|
+
* ``message_id`` / ``stream_id`` / ``flow_id`` -- a 26-character uppercase
|
|
7
|
+
Crockford Base32 ULID.
|
|
8
|
+
|
|
9
|
+
Both are generated here so the SDK has no third-party runtime dependencies.
|
|
10
|
+
Identifiers are opaque to callers; nothing outside this module parses them.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
import os
|
|
16
|
+
import secrets
|
|
17
|
+
import time
|
|
18
|
+
|
|
19
|
+
__all__ = ["new_nano_id", "new_ulid", "is_nano_id", "is_ulid"]
|
|
20
|
+
|
|
21
|
+
_NANO_ID_ALPHABET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
|
|
22
|
+
_NANO_ID_LENGTH = 21
|
|
23
|
+
|
|
24
|
+
_CROCKFORD = "0123456789ABCDEFGHJKMNPQRSTVWXYZ"
|
|
25
|
+
_ULID_LENGTH = 26
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def new_nano_id() -> str:
|
|
29
|
+
"""Return a fresh 21-character alphanumeric NanoID."""
|
|
30
|
+
return "".join(secrets.choice(_NANO_ID_ALPHABET) for _ in range(_NANO_ID_LENGTH))
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def new_ulid() -> str:
|
|
34
|
+
"""Return a fresh 26-character uppercase Crockford Base32 ULID.
|
|
35
|
+
|
|
36
|
+
The leading 48 bits encode milliseconds since the Unix epoch, so ULIDs
|
|
37
|
+
minted in the same process sort roughly by creation time. The trailing 80
|
|
38
|
+
bits come from the OS CSPRNG.
|
|
39
|
+
"""
|
|
40
|
+
timestamp_ms = int(time.time() * 1000) & ((1 << 48) - 1)
|
|
41
|
+
randomness = int.from_bytes(os.urandom(10), "big")
|
|
42
|
+
value = (timestamp_ms << 80) | randomness
|
|
43
|
+
|
|
44
|
+
out = [""] * _ULID_LENGTH
|
|
45
|
+
for index in range(_ULID_LENGTH - 1, -1, -1):
|
|
46
|
+
out[index] = _CROCKFORD[value & 0x1F]
|
|
47
|
+
value >>= 5
|
|
48
|
+
return "".join(out)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def is_nano_id(value: str) -> bool:
|
|
52
|
+
"""Return ``True`` when ``value`` has the ``session_id`` wire shape."""
|
|
53
|
+
if len(value) != _NANO_ID_LENGTH:
|
|
54
|
+
return False
|
|
55
|
+
return all(char.isascii() and char.isalnum() for char in value)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def is_ulid(value: str) -> bool:
|
|
59
|
+
"""Return ``True`` when ``value`` has the ULID wire shape."""
|
|
60
|
+
if len(value) != _ULID_LENGTH:
|
|
61
|
+
return False
|
|
62
|
+
return all(char in _CROCKFORD for char in value)
|