mirasoth-agentspace 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.
agentspace/__init__.py ADDED
@@ -0,0 +1,118 @@
1
+ """agentspace — Python SDK and CLI for the Mirasoth AgentSpace API.
2
+
3
+ Distributed as ``mirasoth-agentspace`` on PyPI; imported as ``agentspace``.
4
+ Standalone cloud service providing isolated workspaces for agent
5
+ execution: workspace/file CRUD, streaming agent sessions (SSE), one-shot
6
+ tasks, semantic memory search — pure stdlib, zero runtime dependencies.
7
+
8
+ Quickstart::
9
+
10
+ from agentspace import AgentSpace
11
+
12
+ api = AgentSpace("http://127.0.0.1:8620", "asp_...")
13
+ ws = api.create_workspace("demo")
14
+ api.upload_file(ws.id, "docs/brief.md", b"# brief")
15
+
16
+ ses = api.create_session(ws.id, "main")
17
+ reply = api.run_turn(ws.id, ses.id, "Read docs/brief.md and summarize it.")
18
+
19
+ The package also installs an ``agentspace`` console script (see
20
+ :mod:`agentspace.cli`).
21
+ """
22
+
23
+ from .client import (
24
+ DEFAULT_TIMEOUT,
25
+ AgentSpace,
26
+ AgentSpaceClient,
27
+ HTTPResponse,
28
+ SessionHandle,
29
+ TaskHandle,
30
+ Transport,
31
+ UrllibTransport,
32
+ WorkspaceHandle,
33
+ )
34
+ from .errors import (
35
+ AgentSpaceError,
36
+ APIError,
37
+ BadRequestError,
38
+ ConflictError,
39
+ ForbiddenError,
40
+ NotFoundError,
41
+ RateLimitError,
42
+ ServerError,
43
+ TransportError,
44
+ TurnError,
45
+ UnauthorizedError,
46
+ )
47
+ from .models import (
48
+ TASK_TERMINAL_STATUSES,
49
+ ApiKey,
50
+ ApiKeyCreated,
51
+ ApiKeyList,
52
+ FileEntry,
53
+ FileEntryList,
54
+ Identity,
55
+ ImageAttachment,
56
+ Session,
57
+ SessionList,
58
+ SessionMessage,
59
+ SessionMessageList,
60
+ Task,
61
+ TaskList,
62
+ TurnAccepted,
63
+ TurnHints,
64
+ Workspace,
65
+ WorkspaceList,
66
+ )
67
+ from .sse import StreamEvent, parse_error_payload, parse_sse_stream
68
+
69
+ __version__ = "0.1.0"
70
+
71
+ __all__ = [
72
+ "__version__",
73
+ # client
74
+ "AgentSpace",
75
+ "AgentSpaceClient",
76
+ "WorkspaceHandle",
77
+ "SessionHandle",
78
+ "TaskHandle",
79
+ "Transport",
80
+ "UrllibTransport",
81
+ "HTTPResponse",
82
+ "DEFAULT_TIMEOUT",
83
+ # errors
84
+ "AgentSpaceError",
85
+ "APIError",
86
+ "BadRequestError",
87
+ "UnauthorizedError",
88
+ "ForbiddenError",
89
+ "NotFoundError",
90
+ "ConflictError",
91
+ "RateLimitError",
92
+ "ServerError",
93
+ "TransportError",
94
+ "TurnError",
95
+ # models
96
+ "Identity",
97
+ "Workspace",
98
+ "WorkspaceList",
99
+ "FileEntry",
100
+ "FileEntryList",
101
+ "Session",
102
+ "SessionList",
103
+ "SessionMessage",
104
+ "SessionMessageList",
105
+ "TurnAccepted",
106
+ "TurnHints",
107
+ "Task",
108
+ "TaskList",
109
+ "TASK_TERMINAL_STATUSES",
110
+ "ApiKey",
111
+ "ApiKeyCreated",
112
+ "ApiKeyList",
113
+ "ImageAttachment",
114
+ # sse
115
+ "StreamEvent",
116
+ "parse_sse_stream",
117
+ "parse_error_payload",
118
+ ]
agentspace/__main__.py ADDED
@@ -0,0 +1,8 @@
1
+ """``python -m agentspace`` — delegates to the ``agentspace`` CLI."""
2
+
3
+ import sys
4
+
5
+ from .cli import main
6
+
7
+ if __name__ == "__main__":
8
+ sys.exit(main())
agentspace/_config.py ADDED
@@ -0,0 +1,57 @@
1
+ """CLI credential storage, file-compatible with the Go CLI.
2
+
3
+ The Go CLI (``cmd/agentspace``) and this Python CLI share the same config
4
+ file (``~/.agentspace/config.json`` with ``{"url": ..., "apiKey": ...}``)
5
+ and the same environment variables (``AGENTSPACE_URL`` /
6
+ ``AGENTSPACE_API_KEY``), so either CLI can pick up where the other left
7
+ off. Environment variables always win over the file.
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ import json
13
+ import os
14
+ from pathlib import Path
15
+ from typing import Tuple
16
+
17
+ ENV_URL = "AGENTSPACE_URL"
18
+ ENV_API_KEY = "AGENTSPACE_API_KEY"
19
+ ENV_CONFIG = "AGENTSPACE_CONFIG"
20
+
21
+
22
+ def config_file() -> Path:
23
+ """Location of the shared CLI config file."""
24
+ override = os.environ.get(ENV_CONFIG)
25
+ if override:
26
+ return Path(override)
27
+ return Path.home() / ".agentspace" / "config.json"
28
+
29
+
30
+ def load_config() -> Tuple[str, str]:
31
+ """Resolve credentials: env vars win over the config file. May be empty."""
32
+ stored: dict = {}
33
+ path = config_file()
34
+ try:
35
+ stored = json.loads(path.read_text(encoding="utf-8"))
36
+ if not isinstance(stored, dict):
37
+ stored = {}
38
+ except (OSError, ValueError):
39
+ stored = {}
40
+ url = os.environ.get(ENV_URL, "") or str(stored.get("url") or "")
41
+ api_key = os.environ.get(ENV_API_KEY, "") or str(stored.get("apiKey") or "")
42
+ return url, api_key
43
+
44
+
45
+ def save_config(url: str, api_key: str) -> Path:
46
+ """Persist credentials to the shared config file (created 0600)."""
47
+ path = config_file()
48
+ path.parent.mkdir(parents=True, exist_ok=True)
49
+ path.write_text(
50
+ json.dumps({"url": url, "apiKey": api_key}, indent=2) + "\n",
51
+ encoding="utf-8",
52
+ )
53
+ try:
54
+ path.chmod(0o600)
55
+ except OSError:
56
+ pass # e.g. some filesystems ignore POSIX modes
57
+ return path