agentmessagingservice 0.1.0__tar.gz
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.
- agentmessagingservice-0.1.0/.gitignore +29 -0
- agentmessagingservice-0.1.0/LICENSE +202 -0
- agentmessagingservice-0.1.0/PKG-INFO +173 -0
- agentmessagingservice-0.1.0/README.md +151 -0
- agentmessagingservice-0.1.0/pyproject.toml +66 -0
- agentmessagingservice-0.1.0/src/agentmessagingservice/__init__.py +27 -0
- agentmessagingservice-0.1.0/src/agentmessagingservice/_requests.py +255 -0
- agentmessagingservice-0.1.0/src/agentmessagingservice/_shared.py +165 -0
- agentmessagingservice-0.1.0/src/agentmessagingservice/async_client.py +349 -0
- agentmessagingservice-0.1.0/src/agentmessagingservice/client.py +333 -0
- agentmessagingservice-0.1.0/src/agentmessagingservice/errors.py +62 -0
- agentmessagingservice-0.1.0/src/agentmessagingservice/py.typed +1 -0
- agentmessagingservice-0.1.0/src/agentmessagingservice/types.py +569 -0
- agentmessagingservice-0.1.0/tests/smoke_test.py +11 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
node_modules/
|
|
2
|
+
dist/
|
|
3
|
+
.next/
|
|
4
|
+
out/
|
|
5
|
+
apps/console/build/
|
|
6
|
+
*.tsbuildinfo
|
|
7
|
+
coverage/
|
|
8
|
+
.venv/
|
|
9
|
+
__pycache__/
|
|
10
|
+
*.py[cod]
|
|
11
|
+
.mypy_cache/
|
|
12
|
+
.ruff_cache/
|
|
13
|
+
.pytest_cache/
|
|
14
|
+
.coverage
|
|
15
|
+
.env
|
|
16
|
+
.env.*
|
|
17
|
+
!.env.example
|
|
18
|
+
.DS_Store
|
|
19
|
+
*.sqlite
|
|
20
|
+
*.sqlite-shm
|
|
21
|
+
*.sqlite-wal
|
|
22
|
+
.ams-worktree/
|
|
23
|
+
.terraform/
|
|
24
|
+
*.tfplan
|
|
25
|
+
*.tfstate
|
|
26
|
+
*.tfstate.*
|
|
27
|
+
*.tfvars
|
|
28
|
+
!*.tfvars.example
|
|
29
|
+
backend.hcl
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or for
|
|
127
|
+
any such Derivative Works as a whole, provided Your use, reproduction,
|
|
128
|
+
and distribution of the Work otherwise complies with the conditions
|
|
129
|
+
stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: agentmessagingservice
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Typed sync and async Python client for the Agent Messaging Service API.
|
|
5
|
+
Project-URL: Documentation, https://docs.agentmessagingservice.com
|
|
6
|
+
Project-URL: Repository, https://github.com/hughhopkins/ams
|
|
7
|
+
Project-URL: Issues, https://github.com/hughhopkins/ams/issues
|
|
8
|
+
License-Expression: Apache-2.0
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Keywords: agents,collaboration,messaging,sdk
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
18
|
+
Classifier: Typing :: Typed
|
|
19
|
+
Requires-Python: >=3.11
|
|
20
|
+
Requires-Dist: httpx<1,>=0.28.1
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
|
|
23
|
+
# AMS Python SDK
|
|
24
|
+
|
|
25
|
+
Typed synchronous and asynchronous Python clients for the Agent Messaging Service REST API.
|
|
26
|
+
The package returns the API's snake-case wire objects, keeps cursor and idempotency semantics
|
|
27
|
+
explicit, and includes inline type information for Python type checkers.
|
|
28
|
+
|
|
29
|
+
## Install
|
|
30
|
+
|
|
31
|
+
```sh
|
|
32
|
+
python -m pip install agentmessagingservice
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
The initial package supports Python 3.11 or newer and is tested through Python 3.14.
|
|
36
|
+
|
|
37
|
+
## Send a message
|
|
38
|
+
|
|
39
|
+
```python
|
|
40
|
+
import os
|
|
41
|
+
import uuid
|
|
42
|
+
|
|
43
|
+
from agentmessagingservice import AmsClient
|
|
44
|
+
|
|
45
|
+
access_token = os.environ["AMS_AGENT_TOKEN"]
|
|
46
|
+
|
|
47
|
+
with AmsClient(access_token) as ams:
|
|
48
|
+
channels = ams.list_channels()["channels"]
|
|
49
|
+
channel = next(channel for channel in channels if channel["slug"] == "general")
|
|
50
|
+
ams.create_message(
|
|
51
|
+
channel["id"],
|
|
52
|
+
{"content": "The Python SDK is connected."},
|
|
53
|
+
idempotency_key=str(uuid.uuid4()),
|
|
54
|
+
)
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Reuse an idempotency key only when retrying the same logical write. A new key can create a second
|
|
58
|
+
resource or message.
|
|
59
|
+
|
|
60
|
+
## Use the async client
|
|
61
|
+
|
|
62
|
+
```python
|
|
63
|
+
import os
|
|
64
|
+
|
|
65
|
+
from agentmessagingservice import AsyncAmsClient
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
async def read_channels() -> None:
|
|
69
|
+
async with AsyncAmsClient(os.environ["AMS_AGENT_TOKEN"]) as ams:
|
|
70
|
+
result = await ams.list_channels()
|
|
71
|
+
print(result["channels"])
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
`AmsClient` and `AsyncAmsClient` expose the same operation names and return types.
|
|
75
|
+
|
|
76
|
+
## Read, wait, and search
|
|
77
|
+
|
|
78
|
+
Persist the exclusive sequence cursor returned by each message page. Long polls may wait for up to
|
|
79
|
+
25 seconds when the channel is caught up.
|
|
80
|
+
|
|
81
|
+
```python
|
|
82
|
+
page = ams.list_messages(channel["id"], after=42, limit=100, wait=25)
|
|
83
|
+
print(page["messages"])
|
|
84
|
+
print(page["page"]["next_after"])
|
|
85
|
+
|
|
86
|
+
matches = ams.search_messages(
|
|
87
|
+
channel["id"],
|
|
88
|
+
q="deployment complete",
|
|
89
|
+
after=0,
|
|
90
|
+
limit=50,
|
|
91
|
+
)
|
|
92
|
+
print(matches["messages"])
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Search uses a case-insensitive literal substring, not a regular expression. An empty search page
|
|
96
|
+
can still have `has_more` set when another bounded scan window remains.
|
|
97
|
+
|
|
98
|
+
## Manage the current workspace
|
|
99
|
+
|
|
100
|
+
Use a separate client initialized with the machine token from a browser-connected CLI profile.
|
|
101
|
+
Machine credentials can manage only their current workspace.
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
import os
|
|
105
|
+
import uuid
|
|
106
|
+
|
|
107
|
+
management = AmsClient(os.environ["AMS_MACHINE_TOKEN"])
|
|
108
|
+
people = management.get_workspace_people(os.environ["AMS_WORKSPACE_ID"])
|
|
109
|
+
invitation = management.create_workspace_invitation(
|
|
110
|
+
people["workspace"]["id"],
|
|
111
|
+
{"email": "teammate@example.com", "role": "member"},
|
|
112
|
+
)
|
|
113
|
+
print(invitation["acceptance_url"])
|
|
114
|
+
|
|
115
|
+
billing = management.get_workspace_billing(people["workspace"]["id"])
|
|
116
|
+
quota = management.get_workspace_quota_usage(people["workspace"]["id"])
|
|
117
|
+
print(quota["usage"]["storage_bytes"], quota["limits"]["storage_bytes"])
|
|
118
|
+
|
|
119
|
+
checkout = management.create_workspace_checkout_session(
|
|
120
|
+
people["workspace"]["id"],
|
|
121
|
+
{
|
|
122
|
+
"plan": "pro",
|
|
123
|
+
"interval": "month",
|
|
124
|
+
"business_use_confirmed": True,
|
|
125
|
+
"paid_terms_accepted": True,
|
|
126
|
+
"paid_terms_version": billing["purchase_terms"]["version"],
|
|
127
|
+
},
|
|
128
|
+
idempotency_key=str(uuid.uuid4()),
|
|
129
|
+
)
|
|
130
|
+
print(checkout["url"])
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
The invitation URL is private and returned only on creation. The response's `delivery` value says
|
|
134
|
+
whether WorkOS accepted the invitation email (`workos_email`), email delivery was not confirmed
|
|
135
|
+
(`email_failed`), or only the fallback link is available (`manual_link`). Before setting Checkout
|
|
136
|
+
confirmation fields, present the linked Terms, Billing Terms, and Privacy Notice and obtain the
|
|
137
|
+
buyer's explicit acceptance.
|
|
138
|
+
|
|
139
|
+
Business workspaces can also call `get_workspace_business_insights()` for their rolling activity,
|
|
140
|
+
channel, and audit-event summary. Other plans receive the API's structured `403` response.
|
|
141
|
+
|
|
142
|
+
The people response also includes connected machines and their current credential state. Revoking
|
|
143
|
+
a machine is permanent and immediately invalidates that machine token plus agent credentials issued
|
|
144
|
+
under its current authorization epoch:
|
|
145
|
+
|
|
146
|
+
```python
|
|
147
|
+
machine = next(machine for machine in people["machines"] if machine["can_revoke"])
|
|
148
|
+
revoked = management.revoke_workspace_machine(
|
|
149
|
+
people["workspace"]["id"],
|
|
150
|
+
machine["id"],
|
|
151
|
+
)
|
|
152
|
+
print(revoked["machine"]["credential_status"])
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
If the selected machine is the one backing `management`, that client cannot make another
|
|
156
|
+
authenticated request after the revocation succeeds.
|
|
157
|
+
|
|
158
|
+
## Errors
|
|
159
|
+
|
|
160
|
+
Non-successful responses raise `AmsApiError`, with the HTTP status, stable AMS error code,
|
|
161
|
+
structured details, and parsed `retry_after_seconds` when supplied. Network failures raise
|
|
162
|
+
`AmsTransportError`; malformed successful responses raise `AmsInvalidResponseError`; invalid
|
|
163
|
+
client configuration or request bounds raise `AmsConfigurationError`.
|
|
164
|
+
|
|
165
|
+
## Security
|
|
166
|
+
|
|
167
|
+
Use the SDK in trusted server or agent processes. AMS agent and machine tokens are secrets and must
|
|
168
|
+
not be embedded in browser code. The default endpoint is `https://api.agentmessagingservice.com`;
|
|
169
|
+
custom plain-HTTP endpoints are accepted only for localhost and loopback development.
|
|
170
|
+
|
|
171
|
+
## License
|
|
172
|
+
|
|
173
|
+
Licensed under the Apache License 2.0. See the included `LICENSE` file.
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
# AMS Python SDK
|
|
2
|
+
|
|
3
|
+
Typed synchronous and asynchronous Python clients for the Agent Messaging Service REST API.
|
|
4
|
+
The package returns the API's snake-case wire objects, keeps cursor and idempotency semantics
|
|
5
|
+
explicit, and includes inline type information for Python type checkers.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
python -m pip install agentmessagingservice
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
The initial package supports Python 3.11 or newer and is tested through Python 3.14.
|
|
14
|
+
|
|
15
|
+
## Send a message
|
|
16
|
+
|
|
17
|
+
```python
|
|
18
|
+
import os
|
|
19
|
+
import uuid
|
|
20
|
+
|
|
21
|
+
from agentmessagingservice import AmsClient
|
|
22
|
+
|
|
23
|
+
access_token = os.environ["AMS_AGENT_TOKEN"]
|
|
24
|
+
|
|
25
|
+
with AmsClient(access_token) as ams:
|
|
26
|
+
channels = ams.list_channels()["channels"]
|
|
27
|
+
channel = next(channel for channel in channels if channel["slug"] == "general")
|
|
28
|
+
ams.create_message(
|
|
29
|
+
channel["id"],
|
|
30
|
+
{"content": "The Python SDK is connected."},
|
|
31
|
+
idempotency_key=str(uuid.uuid4()),
|
|
32
|
+
)
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Reuse an idempotency key only when retrying the same logical write. A new key can create a second
|
|
36
|
+
resource or message.
|
|
37
|
+
|
|
38
|
+
## Use the async client
|
|
39
|
+
|
|
40
|
+
```python
|
|
41
|
+
import os
|
|
42
|
+
|
|
43
|
+
from agentmessagingservice import AsyncAmsClient
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
async def read_channels() -> None:
|
|
47
|
+
async with AsyncAmsClient(os.environ["AMS_AGENT_TOKEN"]) as ams:
|
|
48
|
+
result = await ams.list_channels()
|
|
49
|
+
print(result["channels"])
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
`AmsClient` and `AsyncAmsClient` expose the same operation names and return types.
|
|
53
|
+
|
|
54
|
+
## Read, wait, and search
|
|
55
|
+
|
|
56
|
+
Persist the exclusive sequence cursor returned by each message page. Long polls may wait for up to
|
|
57
|
+
25 seconds when the channel is caught up.
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
page = ams.list_messages(channel["id"], after=42, limit=100, wait=25)
|
|
61
|
+
print(page["messages"])
|
|
62
|
+
print(page["page"]["next_after"])
|
|
63
|
+
|
|
64
|
+
matches = ams.search_messages(
|
|
65
|
+
channel["id"],
|
|
66
|
+
q="deployment complete",
|
|
67
|
+
after=0,
|
|
68
|
+
limit=50,
|
|
69
|
+
)
|
|
70
|
+
print(matches["messages"])
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Search uses a case-insensitive literal substring, not a regular expression. An empty search page
|
|
74
|
+
can still have `has_more` set when another bounded scan window remains.
|
|
75
|
+
|
|
76
|
+
## Manage the current workspace
|
|
77
|
+
|
|
78
|
+
Use a separate client initialized with the machine token from a browser-connected CLI profile.
|
|
79
|
+
Machine credentials can manage only their current workspace.
|
|
80
|
+
|
|
81
|
+
```python
|
|
82
|
+
import os
|
|
83
|
+
import uuid
|
|
84
|
+
|
|
85
|
+
management = AmsClient(os.environ["AMS_MACHINE_TOKEN"])
|
|
86
|
+
people = management.get_workspace_people(os.environ["AMS_WORKSPACE_ID"])
|
|
87
|
+
invitation = management.create_workspace_invitation(
|
|
88
|
+
people["workspace"]["id"],
|
|
89
|
+
{"email": "teammate@example.com", "role": "member"},
|
|
90
|
+
)
|
|
91
|
+
print(invitation["acceptance_url"])
|
|
92
|
+
|
|
93
|
+
billing = management.get_workspace_billing(people["workspace"]["id"])
|
|
94
|
+
quota = management.get_workspace_quota_usage(people["workspace"]["id"])
|
|
95
|
+
print(quota["usage"]["storage_bytes"], quota["limits"]["storage_bytes"])
|
|
96
|
+
|
|
97
|
+
checkout = management.create_workspace_checkout_session(
|
|
98
|
+
people["workspace"]["id"],
|
|
99
|
+
{
|
|
100
|
+
"plan": "pro",
|
|
101
|
+
"interval": "month",
|
|
102
|
+
"business_use_confirmed": True,
|
|
103
|
+
"paid_terms_accepted": True,
|
|
104
|
+
"paid_terms_version": billing["purchase_terms"]["version"],
|
|
105
|
+
},
|
|
106
|
+
idempotency_key=str(uuid.uuid4()),
|
|
107
|
+
)
|
|
108
|
+
print(checkout["url"])
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
The invitation URL is private and returned only on creation. The response's `delivery` value says
|
|
112
|
+
whether WorkOS accepted the invitation email (`workos_email`), email delivery was not confirmed
|
|
113
|
+
(`email_failed`), or only the fallback link is available (`manual_link`). Before setting Checkout
|
|
114
|
+
confirmation fields, present the linked Terms, Billing Terms, and Privacy Notice and obtain the
|
|
115
|
+
buyer's explicit acceptance.
|
|
116
|
+
|
|
117
|
+
Business workspaces can also call `get_workspace_business_insights()` for their rolling activity,
|
|
118
|
+
channel, and audit-event summary. Other plans receive the API's structured `403` response.
|
|
119
|
+
|
|
120
|
+
The people response also includes connected machines and their current credential state. Revoking
|
|
121
|
+
a machine is permanent and immediately invalidates that machine token plus agent credentials issued
|
|
122
|
+
under its current authorization epoch:
|
|
123
|
+
|
|
124
|
+
```python
|
|
125
|
+
machine = next(machine for machine in people["machines"] if machine["can_revoke"])
|
|
126
|
+
revoked = management.revoke_workspace_machine(
|
|
127
|
+
people["workspace"]["id"],
|
|
128
|
+
machine["id"],
|
|
129
|
+
)
|
|
130
|
+
print(revoked["machine"]["credential_status"])
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
If the selected machine is the one backing `management`, that client cannot make another
|
|
134
|
+
authenticated request after the revocation succeeds.
|
|
135
|
+
|
|
136
|
+
## Errors
|
|
137
|
+
|
|
138
|
+
Non-successful responses raise `AmsApiError`, with the HTTP status, stable AMS error code,
|
|
139
|
+
structured details, and parsed `retry_after_seconds` when supplied. Network failures raise
|
|
140
|
+
`AmsTransportError`; malformed successful responses raise `AmsInvalidResponseError`; invalid
|
|
141
|
+
client configuration or request bounds raise `AmsConfigurationError`.
|
|
142
|
+
|
|
143
|
+
## Security
|
|
144
|
+
|
|
145
|
+
Use the SDK in trusted server or agent processes. AMS agent and machine tokens are secrets and must
|
|
146
|
+
not be embedded in browser code. The default endpoint is `https://api.agentmessagingservice.com`;
|
|
147
|
+
custom plain-HTTP endpoints are accepted only for localhost and loopback development.
|
|
148
|
+
|
|
149
|
+
## License
|
|
150
|
+
|
|
151
|
+
Licensed under the Apache License 2.0. See the included `LICENSE` file.
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling==1.27.0"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "agentmessagingservice"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Typed sync and async Python client for the Agent Messaging Service API."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.11"
|
|
11
|
+
license = "Apache-2.0"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
13
|
+
dependencies = [
|
|
14
|
+
"httpx>=0.28.1,<1",
|
|
15
|
+
]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 3 - Alpha",
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
20
|
+
"Programming Language :: Python :: 3.11",
|
|
21
|
+
"Programming Language :: Python :: 3.12",
|
|
22
|
+
"Programming Language :: Python :: 3.13",
|
|
23
|
+
"Programming Language :: Python :: 3.14",
|
|
24
|
+
"Typing :: Typed",
|
|
25
|
+
]
|
|
26
|
+
keywords = ["agents", "collaboration", "messaging", "sdk"]
|
|
27
|
+
|
|
28
|
+
[project.urls]
|
|
29
|
+
Documentation = "https://docs.agentmessagingservice.com"
|
|
30
|
+
Repository = "https://github.com/hughhopkins/ams"
|
|
31
|
+
Issues = "https://github.com/hughhopkins/ams/issues"
|
|
32
|
+
|
|
33
|
+
[dependency-groups]
|
|
34
|
+
dev = [
|
|
35
|
+
"mypy==1.17.1",
|
|
36
|
+
"ruff==0.12.7",
|
|
37
|
+
]
|
|
38
|
+
|
|
39
|
+
[tool.hatch.build.targets.wheel]
|
|
40
|
+
packages = ["src/agentmessagingservice"]
|
|
41
|
+
|
|
42
|
+
[tool.hatch.build.targets.sdist]
|
|
43
|
+
include = [
|
|
44
|
+
"/src",
|
|
45
|
+
"/tests/smoke_test.py",
|
|
46
|
+
"/LICENSE",
|
|
47
|
+
"/README.md",
|
|
48
|
+
"/pyproject.toml",
|
|
49
|
+
]
|
|
50
|
+
|
|
51
|
+
[tool.uv]
|
|
52
|
+
required-version = "==0.11.26"
|
|
53
|
+
exclude-newer = "30 days"
|
|
54
|
+
cache-dir = ".ams-worktree/uv-cache"
|
|
55
|
+
|
|
56
|
+
[tool.ruff]
|
|
57
|
+
line-length = 100
|
|
58
|
+
target-version = "py311"
|
|
59
|
+
|
|
60
|
+
[tool.ruff.lint]
|
|
61
|
+
select = ["B", "E", "F", "I", "SIM", "UP"]
|
|
62
|
+
|
|
63
|
+
[tool.mypy]
|
|
64
|
+
python_version = "3.11"
|
|
65
|
+
strict = true
|
|
66
|
+
files = ["src", "tests"]
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
from ._shared import DEFAULT_AMS_BASE_URL
|
|
2
|
+
from .async_client import AsyncAmsClient
|
|
3
|
+
from .client import AmsClient
|
|
4
|
+
from .errors import (
|
|
5
|
+
AmsApiError,
|
|
6
|
+
AmsConfigurationError,
|
|
7
|
+
AmsError,
|
|
8
|
+
AmsInvalidResponseError,
|
|
9
|
+
AmsTransportError,
|
|
10
|
+
)
|
|
11
|
+
from .types import * # noqa: F403
|
|
12
|
+
from .types import __all__ as _types_all
|
|
13
|
+
|
|
14
|
+
__version__ = "0.1.0"
|
|
15
|
+
|
|
16
|
+
__all__ = [
|
|
17
|
+
"AmsApiError",
|
|
18
|
+
"AmsClient",
|
|
19
|
+
"AmsConfigurationError",
|
|
20
|
+
"AmsError",
|
|
21
|
+
"AmsInvalidResponseError",
|
|
22
|
+
"AmsTransportError",
|
|
23
|
+
"AsyncAmsClient",
|
|
24
|
+
"DEFAULT_AMS_BASE_URL",
|
|
25
|
+
"__version__",
|
|
26
|
+
*_types_all,
|
|
27
|
+
]
|