agentjam 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.
- agentjam/__init__.py +435 -0
- agentjam/_adapters/__init__.py +0 -0
- agentjam/_adapters/responses.py +73 -0
- agentjam/_adapters/shared.py +435 -0
- agentjam/_agent.py +1032 -0
- agentjam/_agent_access.py +360 -0
- agentjam/_agent_delegations.py +376 -0
- agentjam/_agent_executions.py +566 -0
- agentjam/_agent_judging.py +288 -0
- agentjam/_agent_options.py +122 -0
- agentjam/_agent_routing.py +214 -0
- agentjam/_agent_session.py +195 -0
- agentjam/_agent_support.py +415 -0
- agentjam/_artifacts.py +565 -0
- agentjam/_attachments.py +112 -0
- agentjam/_connections.py +1282 -0
- agentjam/_content.py +29 -0
- agentjam/_cron.py +302 -0
- agentjam/_errors.py +238 -0
- agentjam/_events.py +113 -0
- agentjam/_files.py +55 -0
- agentjam/_github.py +742 -0
- agentjam/_idempotency.py +68 -0
- agentjam/_inputs.py +79 -0
- agentjam/_models.py +21 -0
- agentjam/_polling.py +139 -0
- agentjam/_profile.py +244 -0
- agentjam/_protocol.py +480 -0
- agentjam/_providers.py +365 -0
- agentjam/_recaps.py +67 -0
- agentjam/_relay/__init__.py +0 -0
- agentjam/_relay/actions.py +234 -0
- agentjam/_relay/artifacts.py +96 -0
- agentjam/_relay/base.py +387 -0
- agentjam/_relay/commits.py +77 -0
- agentjam/_relay/copies.py +66 -0
- agentjam/_relay/credentials.py +127 -0
- agentjam/_relay/endpoints.py +39 -0
- agentjam/_relay/follow_ups.py +548 -0
- agentjam/_relay/frames.py +443 -0
- agentjam/_relay/guest_store.py +114 -0
- agentjam/_relay/guests.py +55 -0
- agentjam/_relay/inputs.py +119 -0
- agentjam/_relay/lineage.py +294 -0
- agentjam/_relay/memory.py +1045 -0
- agentjam/_relay/payments.py +204 -0
- agentjam/_relay/profiles.py +95 -0
- agentjam/_relay/remote.py +826 -0
- agentjam/_relay/resumptions.py +65 -0
- agentjam/_relay/revisions.py +43 -0
- agentjam/_relay/schedule_follow_ups.py +274 -0
- agentjam/_relay/schedules.py +547 -0
- agentjam/_relay/secrets.py +275 -0
- agentjam/_relay/sessions.py +640 -0
- agentjam/_relay/uploads.py +71 -0
- agentjam/_requests.py +178 -0
- agentjam/_screening.py +368 -0
- agentjam/_secrets.py +153 -0
- agentjam/_sentry.py +233 -0
- agentjam/_signals.py +98 -0
- agentjam/_slack.py +468 -0
- agentjam/_stripe.py +93 -0
- agentjam/_tasks/__init__.py +0 -0
- agentjam/_tasks/access.py +142 -0
- agentjam/_tasks/incoming.py +952 -0
- agentjam/_tasks/outgoing.py +472 -0
- agentjam/_tasks/scheduled.py +206 -0
- agentjam/_tasks/serial.py +40 -0
- agentjam/_tasks/triggers.py +258 -0
- agentjam/_tasks/watches.py +77 -0
- agentjam/_tools.py +1035 -0
- agentjam/_types.py +965 -0
- agentjam/_utils.py +75 -0
- agentjam/_verdicts.py +21 -0
- agentjam/_watermarks.py +59 -0
- agentjam/anthropic.py +442 -0
- agentjam/mpp.py +233 -0
- agentjam/openai.py +141 -0
- agentjam/openai_agents.py +253 -0
- agentjam/py.typed +0 -0
- agentjam/pydantic_ai.py +301 -0
- agentjam/skills.py +69 -0
- agentjam-0.1.0.dist-info/METADATA +210 -0
- agentjam-0.1.0.dist-info/RECORD +86 -0
- agentjam-0.1.0.dist-info/WHEEL +4 -0
- agentjam-0.1.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
from typing import Any, Literal
|
|
3
|
+
|
|
4
|
+
import httpx
|
|
5
|
+
|
|
6
|
+
from agentjam._errors import AgentJamError, ConnectionRevokedError, RequestRefusedError
|
|
7
|
+
from agentjam._models import WireModel
|
|
8
|
+
from agentjam._relay.base import SecretGrant
|
|
9
|
+
from agentjam._relay.endpoints import AGENT_NAME_HEADER, encode_component
|
|
10
|
+
from agentjam._relay.profiles import get_message, parse_body
|
|
11
|
+
from agentjam._utils import encode_json
|
|
12
|
+
|
|
13
|
+
REFUSAL_HEADER = "x-agentjam-refusal"
|
|
14
|
+
"""The header the proxy names its reason in when it refuses to send a request."""
|
|
15
|
+
|
|
16
|
+
LOST_REASONS = frozenset({"missing_credential", "grant_closed"})
|
|
17
|
+
|
|
18
|
+
LOST_CREDENTIAL = "The human's credential was deleted or expired"
|
|
19
|
+
|
|
20
|
+
PROXY_PATH = "/fetch"
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class GrantOutcome(WireModel):
|
|
24
|
+
status: Literal["ready", "required"]
|
|
25
|
+
url: str | None = None
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def construct_refusal_error(
|
|
29
|
+
provider: str, reason: str, response: httpx.Response
|
|
30
|
+
) -> AgentJamError:
|
|
31
|
+
error = parse_body(response).get("error")
|
|
32
|
+
message = error.get("message") if isinstance(error, dict) else None
|
|
33
|
+
if not isinstance(message, str):
|
|
34
|
+
message = f"The credential proxy refused the request ({reason})"
|
|
35
|
+
|
|
36
|
+
if reason in LOST_REASONS:
|
|
37
|
+
return ConnectionRevokedError(provider, message)
|
|
38
|
+
|
|
39
|
+
return RequestRefusedError(provider, reason, message)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
@dataclass(frozen=True, kw_only=True)
|
|
43
|
+
class RemoteCredentials:
|
|
44
|
+
"""Reaches the credentials the AgentJam platform holds for secret connections, through its API and credential proxy."""
|
|
45
|
+
|
|
46
|
+
api_url: str
|
|
47
|
+
proxy_url: str
|
|
48
|
+
api_key: str
|
|
49
|
+
name: str
|
|
50
|
+
|
|
51
|
+
async def authorize(self, grant: SecretGrant) -> str | None:
|
|
52
|
+
outcome = GrantOutcome.model_validate(
|
|
53
|
+
await self._post("credentials/grants", grant)
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
return outcome.url if outcome.status == "required" else None
|
|
57
|
+
|
|
58
|
+
async def release(self, grant: SecretGrant) -> None:
|
|
59
|
+
await self._post("credentials/grants/release", grant)
|
|
60
|
+
|
|
61
|
+
async def config(self, grant: SecretGrant) -> dict[str, str]:
|
|
62
|
+
config: dict[str, str] | None = await self._post(
|
|
63
|
+
"credentials/grants/config", grant
|
|
64
|
+
)
|
|
65
|
+
if config is None:
|
|
66
|
+
raise ConnectionRevokedError(grant.provider, LOST_CREDENTIAL)
|
|
67
|
+
|
|
68
|
+
return config
|
|
69
|
+
|
|
70
|
+
async def fetch(self, grant: SecretGrant, request: httpx.Request) -> httpx.Response:
|
|
71
|
+
headers = httpx.Headers(request.headers)
|
|
72
|
+
headers.pop("host", None)
|
|
73
|
+
headers.update(self._compute_proxy_headers(grant, str(request.url)))
|
|
74
|
+
proxied = httpx.Request(
|
|
75
|
+
request.method,
|
|
76
|
+
f"{self.proxy_url}{PROXY_PATH}",
|
|
77
|
+
headers=headers,
|
|
78
|
+
stream=request.stream,
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
async with httpx.AsyncClient() as client:
|
|
82
|
+
response = await client.send(proxied, follow_redirects=False)
|
|
83
|
+
|
|
84
|
+
reason = response.headers.get(REFUSAL_HEADER)
|
|
85
|
+
if reason is None:
|
|
86
|
+
return response
|
|
87
|
+
|
|
88
|
+
raise construct_refusal_error(grant.provider, reason, response)
|
|
89
|
+
|
|
90
|
+
def _compute_authentication_headers(self) -> dict[str, str]:
|
|
91
|
+
return {
|
|
92
|
+
"authorization": f"Bearer {self.api_key}",
|
|
93
|
+
AGENT_NAME_HEADER: encode_component(self.name),
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
def _compute_proxy_headers(self, grant: SecretGrant, target: str) -> dict[str, str]:
|
|
97
|
+
return {
|
|
98
|
+
**self._compute_authentication_headers(),
|
|
99
|
+
"x-agentjam-requester": grant.requester,
|
|
100
|
+
"x-agentjam-holder": grant.id,
|
|
101
|
+
"x-agentjam-provider": grant.provider,
|
|
102
|
+
"x-agentjam-target": target,
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
async def _post(self, path: str, grant: SecretGrant) -> Any:
|
|
106
|
+
body = {
|
|
107
|
+
"requester": grant.requester,
|
|
108
|
+
"id": grant.id,
|
|
109
|
+
"provider": grant.provider,
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
async with httpx.AsyncClient() as client:
|
|
113
|
+
response = await client.post(
|
|
114
|
+
f"{self.api_url}/{path}",
|
|
115
|
+
headers={
|
|
116
|
+
**self._compute_authentication_headers(),
|
|
117
|
+
"content-type": "application/json",
|
|
118
|
+
},
|
|
119
|
+
content=encode_json(body),
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
if not response.is_success:
|
|
123
|
+
raise AgentJamError(
|
|
124
|
+
f"Couldn't reach the {grant.provider} credential: {get_message(response)}"
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
return response.json()["data"]
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import os
|
|
2
|
+
from collections.abc import Mapping
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
from urllib.parse import quote
|
|
5
|
+
|
|
6
|
+
AGENT_NAME_HEADER = "x-agentjam-agent"
|
|
7
|
+
"""The header naming the agent a request acts as, which an account's API key needs to pick one of its agents."""
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@dataclass(frozen=True, kw_only=True)
|
|
11
|
+
class Endpoints:
|
|
12
|
+
"""Where an `AgentJamRelay` reaches the network."""
|
|
13
|
+
|
|
14
|
+
relay_url: str
|
|
15
|
+
"""The transport's WebSocket URL, which agents connect to."""
|
|
16
|
+
api_url: str
|
|
17
|
+
"""The API gateway's HTTP URL."""
|
|
18
|
+
proxy_url: str
|
|
19
|
+
"""The credential proxy's HTTP URL, which sends the requests of secret connections with their credentials."""
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
HOSTED_ENDPOINTS = Endpoints(
|
|
23
|
+
relay_url="wss://relay.agentjam.com",
|
|
24
|
+
api_url="https://api.agentjam.com",
|
|
25
|
+
proxy_url="https://proxy.agentjam.com",
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def resolve_endpoints(environment: Mapping[str, str] = os.environ) -> Endpoints:
|
|
30
|
+
return Endpoints(
|
|
31
|
+
relay_url=environment.get("AGENTJAM_RELAY_URL") or HOSTED_ENDPOINTS.relay_url,
|
|
32
|
+
api_url=environment.get("AGENTJAM_API_URL") or HOSTED_ENDPOINTS.api_url,
|
|
33
|
+
proxy_url=environment.get("AGENTJAM_PROXY_URL") or HOSTED_ENDPOINTS.proxy_url,
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def encode_component(value: str) -> str:
|
|
38
|
+
"""Percent-encodes `value` the way JS `encodeURIComponent` does."""
|
|
39
|
+
return quote(value, safe="!*'()")
|