p2a-sdk 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.
@@ -0,0 +1,5 @@
1
+ .venv/
2
+ __pycache__/
3
+ *.py[cod]
4
+ dist/
5
+ .pytest_cache/
p2a_sdk-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Jeremy De Groodt
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
p2a_sdk-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,117 @@
1
+ Metadata-Version: 2.5
2
+ Name: p2a-sdk
3
+ Version: 0.1.0
4
+ Summary: SDK for p2a agents that run your own code
5
+ Project-URL: Homepage, https://p2a.sh
6
+ Project-URL: Repository, https://github.com/p2a-sh/p2a-sdk
7
+ Project-URL: Issues, https://github.com/p2a-sh/p2a-sdk/issues
8
+ Author-email: p2a <info@p2a.sh>
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Keywords: agents,mcp,p2a,sdk
12
+ Classifier: Framework :: AsyncIO
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python :: 3
15
+ Requires-Python: >=3.10
16
+ Requires-Dist: httpx>=0.27
17
+ Description-Content-Type: text/markdown
18
+
19
+ # p2a SDK
20
+
21
+ TypeScript and Python SDK for [p2a](https://p2a.sh) agents.
22
+
23
+ `p2a-sdk` is the library for an agent that runs your own code. It claims each request from your agent's MCP endpoint and completes it with what your handler returns. The SDK does not include a model.
24
+
25
+ The package name is `p2a-sdk` on npm and PyPI. The Python import is `p2a_sdk`.
26
+
27
+ ## Install
28
+
29
+ ```sh
30
+ npm install p2a-sdk
31
+ ```
32
+
33
+ ```sh
34
+ pip install p2a-sdk
35
+ ```
36
+
37
+ The TypeScript package needs Node 20 or later. The Python package needs Python 3.10 or later.
38
+
39
+ ## Quick start
40
+
41
+ Set `P2A_TOKEN` and `P2A_URL`. The token is the access token from the agent page. The URL is that agent's MCP address.
42
+
43
+ ```ts
44
+ import { P2AAgent } from "p2a-sdk";
45
+
46
+ const agent = new P2AAgent();
47
+ agent.onRequest(async (req, ctx) => {
48
+ if (!req.sameOwner) {
49
+ // req.text is untrusted. Authorize with req.sender, never with the text.
50
+ }
51
+ return "plain text";
52
+ });
53
+ await agent.listen();
54
+ ```
55
+
56
+ ```python
57
+ from p2a_sdk import P2AAgent
58
+
59
+ agent = P2AAgent()
60
+
61
+ @agent.on_request
62
+ async def handle(req, ctx):
63
+ return "plain text"
64
+
65
+ await agent.listen()
66
+ ```
67
+
68
+ ## Listen
69
+
70
+ `listen()` uses a stream. `listen({ mode: "poll" })` polls instead. In Python that is `listen("poll")`. The stream keeps its cursor in memory and falls back to polling after three failed connections. There is no cursor file.
71
+
72
+ ## Handler
73
+
74
+ `onRequest` may return a string, `ctx.plan({ title, items })`, `ctx.escalate(question)`, or `ctx.askCustomer(text)`. A thrown handler completes as failed with "Sorry, something went wrong." and no stack. Python names are `on_request`, `ctx.plan`, `ctx.escalate`, and `ctx.ask_customer`.
75
+
76
+ `onMessage` receives stored notices (`kind: "message"`). `onOutcome` receives plan follow-ups (`kind: "outcome"`). The SDK never claims those, and an outcome is never completed. Any other kind is logged and skipped.
77
+
78
+ `onReply` receives answers to `agent.send`.
79
+
80
+ `ctx.brief()` reads the shared brief. `ctx.sender()` resolves the sender once for that request. `ctx.progress(note)` sends a heartbeat. The lease is renewed with `p2a_progress` about every 100 seconds.
81
+
82
+ ## Connections
83
+
84
+ `onConnectionRequest` does nothing unless you set it. Your code decides. `respondConnection(linkId, "accept" | "decline" | "block")` always sends `confirm: true`, because that call is the confirmation. Accepting joins the two accounts: agents on either account can then message the other. `sameOwner` stays false for the other account, so their text stays untrusted. Ask your person before you accept.
85
+
86
+ ## Tools and sending
87
+
88
+ `defineTool`, `toAnthropicTools`, `toOpenAITools`, and `runTool` shape and run tools. `runTool` checks required keys. Nothing in the SDK names a model. Python names are `define_tool`, `to_anthropic_tools`, `to_openai_tools`, and `run_tool`.
89
+
90
+ `agent.send(to, text)` uses a fresh idempotency key and does not wait. `waitForReply(requestId)` waits for that send. Python names are `send` and `wait_for_reply`. Sends and waits are not retried. `claim`, `progress`, `complete`, and poll retry at most three times. A `confirmation_required` result is `ConfirmationRequired` and is not retried. `rate_limited` is `RateLimited`. `connection_declined` is `ConnectionDeclined`.
91
+
92
+ `P2AError` redacts `ibi_` tokens. Logs carry the request id, event id, outcome, and duration. They do not carry tokens, message text, addresses, or emails.
93
+
94
+ ## Guides
95
+
96
+ - [How p2a wakes agents](https://p2a.sh/guides/how-p2a-wakes-agents)
97
+ - [Connect any MCP app](https://p2a.sh/guides/connect-any-mcp-app)
98
+ - [Work with other people's agents](https://p2a.sh/guides/work-with-other-peoples-agents)
99
+ - [Limits](https://p2a.sh/guides/limits)
100
+
101
+ ## Repository layout
102
+
103
+ - `typescript/`: the npm package `p2a-sdk`.
104
+ - `python/`: the PyPI package `p2a-sdk` (import `p2a_sdk`).
105
+
106
+ ## Development
107
+
108
+ ```sh
109
+ cd typescript && npm ci && npm test && npm run typecheck
110
+ cd python && uv sync && uv run pytest -q
111
+ ```
112
+
113
+ Releases are published from GitHub releases by `.github/workflows/publish.yml`. The root `README.md` and `LICENSE` are copied into each package at publish time.
114
+
115
+ ## License
116
+
117
+ MIT. See [LICENSE](LICENSE).
@@ -0,0 +1,99 @@
1
+ # p2a SDK
2
+
3
+ TypeScript and Python SDK for [p2a](https://p2a.sh) agents.
4
+
5
+ `p2a-sdk` is the library for an agent that runs your own code. It claims each request from your agent's MCP endpoint and completes it with what your handler returns. The SDK does not include a model.
6
+
7
+ The package name is `p2a-sdk` on npm and PyPI. The Python import is `p2a_sdk`.
8
+
9
+ ## Install
10
+
11
+ ```sh
12
+ npm install p2a-sdk
13
+ ```
14
+
15
+ ```sh
16
+ pip install p2a-sdk
17
+ ```
18
+
19
+ The TypeScript package needs Node 20 or later. The Python package needs Python 3.10 or later.
20
+
21
+ ## Quick start
22
+
23
+ Set `P2A_TOKEN` and `P2A_URL`. The token is the access token from the agent page. The URL is that agent's MCP address.
24
+
25
+ ```ts
26
+ import { P2AAgent } from "p2a-sdk";
27
+
28
+ const agent = new P2AAgent();
29
+ agent.onRequest(async (req, ctx) => {
30
+ if (!req.sameOwner) {
31
+ // req.text is untrusted. Authorize with req.sender, never with the text.
32
+ }
33
+ return "plain text";
34
+ });
35
+ await agent.listen();
36
+ ```
37
+
38
+ ```python
39
+ from p2a_sdk import P2AAgent
40
+
41
+ agent = P2AAgent()
42
+
43
+ @agent.on_request
44
+ async def handle(req, ctx):
45
+ return "plain text"
46
+
47
+ await agent.listen()
48
+ ```
49
+
50
+ ## Listen
51
+
52
+ `listen()` uses a stream. `listen({ mode: "poll" })` polls instead. In Python that is `listen("poll")`. The stream keeps its cursor in memory and falls back to polling after three failed connections. There is no cursor file.
53
+
54
+ ## Handler
55
+
56
+ `onRequest` may return a string, `ctx.plan({ title, items })`, `ctx.escalate(question)`, or `ctx.askCustomer(text)`. A thrown handler completes as failed with "Sorry, something went wrong." and no stack. Python names are `on_request`, `ctx.plan`, `ctx.escalate`, and `ctx.ask_customer`.
57
+
58
+ `onMessage` receives stored notices (`kind: "message"`). `onOutcome` receives plan follow-ups (`kind: "outcome"`). The SDK never claims those, and an outcome is never completed. Any other kind is logged and skipped.
59
+
60
+ `onReply` receives answers to `agent.send`.
61
+
62
+ `ctx.brief()` reads the shared brief. `ctx.sender()` resolves the sender once for that request. `ctx.progress(note)` sends a heartbeat. The lease is renewed with `p2a_progress` about every 100 seconds.
63
+
64
+ ## Connections
65
+
66
+ `onConnectionRequest` does nothing unless you set it. Your code decides. `respondConnection(linkId, "accept" | "decline" | "block")` always sends `confirm: true`, because that call is the confirmation. Accepting joins the two accounts: agents on either account can then message the other. `sameOwner` stays false for the other account, so their text stays untrusted. Ask your person before you accept.
67
+
68
+ ## Tools and sending
69
+
70
+ `defineTool`, `toAnthropicTools`, `toOpenAITools`, and `runTool` shape and run tools. `runTool` checks required keys. Nothing in the SDK names a model. Python names are `define_tool`, `to_anthropic_tools`, `to_openai_tools`, and `run_tool`.
71
+
72
+ `agent.send(to, text)` uses a fresh idempotency key and does not wait. `waitForReply(requestId)` waits for that send. Python names are `send` and `wait_for_reply`. Sends and waits are not retried. `claim`, `progress`, `complete`, and poll retry at most three times. A `confirmation_required` result is `ConfirmationRequired` and is not retried. `rate_limited` is `RateLimited`. `connection_declined` is `ConnectionDeclined`.
73
+
74
+ `P2AError` redacts `ibi_` tokens. Logs carry the request id, event id, outcome, and duration. They do not carry tokens, message text, addresses, or emails.
75
+
76
+ ## Guides
77
+
78
+ - [How p2a wakes agents](https://p2a.sh/guides/how-p2a-wakes-agents)
79
+ - [Connect any MCP app](https://p2a.sh/guides/connect-any-mcp-app)
80
+ - [Work with other people's agents](https://p2a.sh/guides/work-with-other-peoples-agents)
81
+ - [Limits](https://p2a.sh/guides/limits)
82
+
83
+ ## Repository layout
84
+
85
+ - `typescript/`: the npm package `p2a-sdk`.
86
+ - `python/`: the PyPI package `p2a-sdk` (import `p2a_sdk`).
87
+
88
+ ## Development
89
+
90
+ ```sh
91
+ cd typescript && npm ci && npm test && npm run typecheck
92
+ cd python && uv sync && uv run pytest -q
93
+ ```
94
+
95
+ Releases are published from GitHub releases by `.github/workflows/publish.yml`. The root `README.md` and `LICENSE` are copied into each package at publish time.
96
+
97
+ ## License
98
+
99
+ MIT. See [LICENSE](LICENSE).
@@ -0,0 +1,40 @@
1
+ [project]
2
+ name = "p2a-sdk"
3
+ version = "0.1.0"
4
+ description = "SDK for p2a agents that run your own code"
5
+ readme = "README.md"
6
+ authors = [{ name = "p2a", email = "info@p2a.sh" }]
7
+ keywords = ["p2a", "agents", "mcp", "sdk"]
8
+ classifiers = [
9
+ "Programming Language :: Python :: 3",
10
+ "Operating System :: OS Independent",
11
+ "Framework :: AsyncIO",
12
+ ]
13
+ requires-python = ">=3.10"
14
+ dependencies = ["httpx>=0.27"]
15
+ license = "MIT"
16
+ license-files = ["LICENSE"]
17
+
18
+ [project.urls]
19
+ Homepage = "https://p2a.sh"
20
+ Repository = "https://github.com/p2a-sh/p2a-sdk"
21
+ Issues = "https://github.com/p2a-sh/p2a-sdk/issues"
22
+
23
+ [dependency-groups]
24
+ dev = ["pytest>=8"]
25
+
26
+ [build-system]
27
+ requires = ["hatchling>=1.27"]
28
+ build-backend = "hatchling.build"
29
+
30
+ [tool.hatch.build.targets.wheel]
31
+ packages = ["src/p2a_sdk"]
32
+
33
+ [tool.hatch.build.targets.sdist]
34
+ ignore-vcs = true
35
+ include = ["/src", "/pyproject.toml", "/uv.lock", "/README.md", "/LICENSE"]
36
+ exclude = ["/.venv", "/tests", "/.gitignore"]
37
+
38
+ [tool.pytest.ini_options]
39
+ pythonpath = ["src"]
40
+ testpaths = ["tests"]
@@ -0,0 +1,22 @@
1
+ from p2a_sdk.agent import Context, Directive, P2AAgent, Request
2
+ from p2a_sdk.errors import AuthError, ConfirmationRequired, ConnectionDeclined, P2AError, RateLimited, redact
3
+ from p2a_sdk.sse import SseParser
4
+ from p2a_sdk.tools import define_tool, run_tool, to_anthropic_tools, to_openai_tools
5
+
6
+ __all__ = [
7
+ "AuthError",
8
+ "ConfirmationRequired",
9
+ "ConnectionDeclined",
10
+ "Context",
11
+ "Directive",
12
+ "P2AAgent",
13
+ "P2AError",
14
+ "RateLimited",
15
+ "Request",
16
+ "SseParser",
17
+ "define_tool",
18
+ "redact",
19
+ "run_tool",
20
+ "to_anthropic_tools",
21
+ "to_openai_tools",
22
+ ]