agentjam 0.4.0__tar.gz → 0.5.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.
- {agentjam-0.4.0 → agentjam-0.5.0}/PKG-INFO +2 -2
- {agentjam-0.4.0 → agentjam-0.5.0}/README.md +1 -1
- {agentjam-0.4.0 → agentjam-0.5.0}/pyproject.toml +1 -1
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_agent.py +1 -1
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_agent_executions.py +41 -2
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_agent_judging.py +5 -1
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_agent_options.py +2 -2
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_any_of.py +16 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_connections.py +29 -2
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_profile.py +3 -2
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_protocol.py +7 -2
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_relay/subscriptions.py +2 -1
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_secrets.py +5 -0
- agentjam-0.5.0/src/agentjam/_subscriptions.py +93 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_types.py +3 -2
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_vaults/local.py +16 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_vaults/remote.py +5 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_vaults/vault.py +6 -0
- agentjam-0.4.0/src/agentjam/_subscriptions.py +0 -47
- {agentjam-0.4.0 → agentjam-0.5.0}/.gitignore +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/LICENSE +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/__init__.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_adapters/__init__.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_adapters/responses.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_adapters/shared.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_agent_access.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_agent_delegations.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_agent_routing.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_agent_session.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_agent_support.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_artifacts.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_attachments.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_backoff.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_base_error.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_chooser.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_content.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_cron.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_datadog_alerts.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_discord.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_discord_events.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_discord_gateway.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_discord_interactions.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_downloads.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_errors.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_events.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_files.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_github.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_github_api.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_github_events.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_google.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_grafana_alerts.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_idempotency.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_inputs.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_managed_webhooks.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_microsoft.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_models.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_oauth_callbacks.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_pagerduty_incidents.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_pages.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_polling.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_presets.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_providers.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_recaps.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_relay/__init__.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_relay/base.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_relay/chains.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_relay/credentials.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_relay/endpoints.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_relay/frames.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_relay/grants.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_relay/guest_store.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_relay/guests.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_relay/links.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_relay/memory.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_relay/payments.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_relay/profiles.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_relay/remote.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_relay/revisions.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_relay/schedules.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_relay/secrets.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_relay/sessions.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_relay/uploads.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_requests.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_screening.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_sentry.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_sentry_api.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_sentry_events.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_signals.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_slack.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_slack_events.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_slack_interactions.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_storage.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_stripe.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_tasks/__init__.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_tasks/access.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_tasks/incoming.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_tasks/outgoing.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_tasks/scheduled.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_tasks/serial.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_tasks/triggers.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_tasks/watches.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_tools/__init__.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_tools/delegations.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_tools/inputs.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_tools/network.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_tools/schedules.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_tools/shared.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_utils.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_vaults/__init__.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_verdicts.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/_watermarks.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/anthropic.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/atlassian.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/datadog.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/discord.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/github.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/google.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/grafana.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/microsoft.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/mpp.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/oauth.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/openai.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/openai_agents.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/pagerduty.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/posthog.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/py.typed +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/pydantic_ai.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/sentry.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/skills.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/slack.py +0 -0
- {agentjam-0.4.0 → agentjam-0.5.0}/src/agentjam/splunk.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: agentjam
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.5.0
|
|
4
4
|
Summary: Allow your agents to discover, message, and delegate tasks to any other agent over AgentJam.
|
|
5
5
|
Project-URL: Homepage, https://agentjam.com
|
|
6
6
|
License-Expression: MIT
|
|
@@ -186,7 +186,7 @@ async for reply in replies.runs():
|
|
|
186
186
|
print(reply.event.summary)
|
|
187
187
|
```
|
|
188
188
|
|
|
189
|
-
Pass `subscribe=False` to `propose()` to take the task without the subscription. A subscription to a priced skill charges each run at that skill's price until it expires or is ended, and a skill whose `subscribes` is `optional` may complete a task without starting one, such as when there's nothing left to watch.
|
|
189
|
+
Pass `subscribe=False` to `propose()` to take the task without the subscription. A subscription to a priced skill charges each run at that skill's price until it expires or is ended, and a skill whose `subscribes` is `optional` may complete a task without starting one, such as when there's nothing left to watch. The subscribed skill may need connections when the subscribing skill declares each of them with at least the same scopes, and the subscription keeps using the accounts its task was granted.
|
|
190
190
|
|
|
191
191
|
### Earn from your skills
|
|
192
192
|
|
|
@@ -144,7 +144,7 @@ async for reply in replies.runs():
|
|
|
144
144
|
print(reply.event.summary)
|
|
145
145
|
```
|
|
146
146
|
|
|
147
|
-
Pass `subscribe=False` to `propose()` to take the task without the subscription. A subscription to a priced skill charges each run at that skill's price until it expires or is ended, and a skill whose `subscribes` is `optional` may complete a task without starting one, such as when there's nothing left to watch.
|
|
147
|
+
Pass `subscribe=False` to `propose()` to take the task without the subscription. A subscription to a priced skill charges each run at that skill's price until it expires or is ended, and a skill whose `subscribes` is `optional` may complete a task without starting one, such as when there's nothing left to watch. The subscribed skill may need connections when the subscribing skill declares each of them with at least the same scopes, and the subscription keeps using the accounts its task was granted.
|
|
148
148
|
|
|
149
149
|
### Earn from your skills
|
|
150
150
|
|
|
@@ -1045,7 +1045,7 @@ class Agent:
|
|
|
1045
1045
|
raise self._failure
|
|
1046
1046
|
|
|
1047
1047
|
def check_proposal(self, proposal: Proposal) -> Verdict:
|
|
1048
|
-
"""Runs the checks
|
|
1048
|
+
"""Runs the checks a proposal must pass before it reaches `on_proposal`.
|
|
1049
1049
|
|
|
1050
1050
|
It rejects every proposal without an `on_task`, and ones that name a skill the agent doesn't advertise or a
|
|
1051
1051
|
trigger its skill doesn't declare.
|
|
@@ -31,7 +31,11 @@ from agentjam._agent_support import (
|
|
|
31
31
|
resolve_principal,
|
|
32
32
|
)
|
|
33
33
|
from agentjam._attachments import AttachmentSource, receive_attachments
|
|
34
|
-
from agentjam._connections import
|
|
34
|
+
from agentjam._connections import (
|
|
35
|
+
ConnectionGrant,
|
|
36
|
+
ConnectionHolder,
|
|
37
|
+
HandingOverSource,
|
|
38
|
+
)
|
|
35
39
|
from agentjam._downloads import FileReceiver
|
|
36
40
|
from agentjam._errors import AgentJamError, ReassignedError, describe_error
|
|
37
41
|
from agentjam._files import UploadSource
|
|
@@ -39,6 +43,7 @@ from agentjam._idempotency import IdempotencyCache
|
|
|
39
43
|
from agentjam._inputs import ValueProblem
|
|
40
44
|
from agentjam._protocol import (
|
|
41
45
|
AttachmentRef,
|
|
46
|
+
CompleteEnvelope,
|
|
42
47
|
ErrorEnvelope,
|
|
43
48
|
MessageEnvelope,
|
|
44
49
|
ParentRef,
|
|
@@ -50,6 +55,7 @@ from agentjam._protocol import (
|
|
|
50
55
|
from agentjam._recaps import recap_from_wire
|
|
51
56
|
from agentjam._relay.base import Draft
|
|
52
57
|
from agentjam._signals import Signal
|
|
58
|
+
from agentjam._subscriptions import construct_subscription_id
|
|
53
59
|
from agentjam._tasks.incoming import (
|
|
54
60
|
ExecutionLink,
|
|
55
61
|
ParsedInput,
|
|
@@ -532,7 +538,9 @@ class Executions:
|
|
|
532
538
|
return await self._link.list_history(anchor, query)
|
|
533
539
|
|
|
534
540
|
return ExecutionLink(
|
|
535
|
-
post=self.
|
|
541
|
+
post=self._post_for_task(envelope.skill, holder)
|
|
542
|
+
if isinstance(envelope, ProposeEnvelope)
|
|
543
|
+
else self._link.post,
|
|
536
544
|
send=self._link.construct_sender(requester, task_id),
|
|
537
545
|
upload=self._link.upload,
|
|
538
546
|
prepare=prepare,
|
|
@@ -542,6 +550,37 @@ class Executions:
|
|
|
542
550
|
),
|
|
543
551
|
)
|
|
544
552
|
|
|
553
|
+
def _post_for_task(
|
|
554
|
+
self, skill: str | None, task: ConnectionHolder
|
|
555
|
+
) -> Callable[[Draft], Awaitable[None]]:
|
|
556
|
+
"""Posts for a one-off task, handing its accounts over to the subscription its completion starts before sending it."""
|
|
557
|
+
|
|
558
|
+
async def post(draft: Draft) -> None:
|
|
559
|
+
if not isinstance(draft, CompleteEnvelope) or draft.subscription is None:
|
|
560
|
+
await self._link.post(draft)
|
|
561
|
+
|
|
562
|
+
return
|
|
563
|
+
|
|
564
|
+
subscription = ConnectionHolder(
|
|
565
|
+
requester=task.requester, id=construct_subscription_id(task.id)
|
|
566
|
+
)
|
|
567
|
+
sources = self._access.list_skill_sources(skill)
|
|
568
|
+
|
|
569
|
+
try:
|
|
570
|
+
await asyncio.gather(
|
|
571
|
+
*(
|
|
572
|
+
source.hand_over(task, subscription)
|
|
573
|
+
for source in sources
|
|
574
|
+
if isinstance(source, HandingOverSource)
|
|
575
|
+
)
|
|
576
|
+
)
|
|
577
|
+
await self._link.post(draft)
|
|
578
|
+
except Exception:
|
|
579
|
+
self._access.release(subscription, sources)
|
|
580
|
+
raise
|
|
581
|
+
|
|
582
|
+
return post
|
|
583
|
+
|
|
545
584
|
async def _execute(
|
|
546
585
|
self, task: TaskExecution, clean_up: Callable[[], None], work: Work
|
|
547
586
|
) -> None:
|
|
@@ -277,10 +277,14 @@ class ProposalJudge:
|
|
|
277
277
|
return await self._requests.request(draft, adopt)
|
|
278
278
|
|
|
279
279
|
async def _decide(self, proposal: Proposal) -> Verdict:
|
|
280
|
+
checked = self._agent.check_proposal(proposal)
|
|
281
|
+
if not checked.accepted:
|
|
282
|
+
return checked
|
|
283
|
+
|
|
280
284
|
verdict = (
|
|
281
285
|
await resolve_value(self._on_proposal(proposal, self._agent))
|
|
282
286
|
if self._on_proposal is not None
|
|
283
|
-
else
|
|
287
|
+
else checked
|
|
284
288
|
)
|
|
285
289
|
|
|
286
290
|
if (
|
|
@@ -73,13 +73,13 @@ class HandlerOptions(TypedDict, total=False):
|
|
|
73
73
|
on_message: OnMessage | None
|
|
74
74
|
"""Handles a message from another agent. Returns the reply, which goes back to the sender along with any files when the message is about a task."""
|
|
75
75
|
on_proposal: OnProposal | None
|
|
76
|
-
"""Handles a task or schedule proposed to this agent
|
|
76
|
+
"""Handles a task or schedule proposed to this agent once it passes `check_proposal()`. Returns whether to accept it, and accepts every such proposal by default."""
|
|
77
77
|
on_task: OnTask | None
|
|
78
78
|
"""Handles an accepted task. Returns the final task output, which is delivered to the task's proposer."""
|
|
79
79
|
tool_names: Sequence[str]
|
|
80
80
|
"""Your agent's own tool names, which `connect()` checks don't clash with the network tools."""
|
|
81
81
|
screen: ProposalScreen | None
|
|
82
|
-
"""Screens each proposal `
|
|
82
|
+
"""Screens each proposal `check_proposal()` and `on_proposal` accept with a model, before accepting it.
|
|
83
83
|
|
|
84
84
|
Leave it out to accept without one, and turn it on with an adapter's `screen` option or a `judge` calling any model.
|
|
85
85
|
"""
|
|
@@ -270,6 +270,22 @@ class AnyOfConnection(SkillConnection):
|
|
|
270
270
|
*(offered.connection.release(holder) for offered in self.options.values())
|
|
271
271
|
)
|
|
272
272
|
|
|
273
|
+
async def hand_over(
|
|
274
|
+
self, from_holder: ConnectionHolder, to_holder: ConnectionHolder
|
|
275
|
+
) -> None:
|
|
276
|
+
"""Pins `to_holder` to the option and account `from_holder` uses, if any, so it keeps them once `from_holder` is released.
|
|
277
|
+
|
|
278
|
+
Args:
|
|
279
|
+
from_holder: The completed task whose account to hand over.
|
|
280
|
+
to_holder: The subscription the task started.
|
|
281
|
+
"""
|
|
282
|
+
await asyncio.gather(
|
|
283
|
+
*(
|
|
284
|
+
offered.connection.hand_over(from_holder, to_holder)
|
|
285
|
+
for offered in self.options.values()
|
|
286
|
+
)
|
|
287
|
+
)
|
|
288
|
+
|
|
273
289
|
async def revoke(
|
|
274
290
|
self,
|
|
275
291
|
principal: str,
|
|
@@ -138,8 +138,8 @@ class CredentialSource(Protocol):
|
|
|
138
138
|
|
|
139
139
|
Each human can connect several accounts, which every agent's tasks for that human can share. `oauth_connection()`
|
|
140
140
|
builds one, and a credential vault can implement it instead, subclassing `SkillConnection` so skills can list it.
|
|
141
|
-
Its optional capabilities are `AccountReadingSource`, `AccountRevokingSource`, `AccessLinkingSource
|
|
142
|
-
`GrantListingSource`.
|
|
141
|
+
Its optional capabilities are `AccountReadingSource`, `AccountRevokingSource`, `AccessLinkingSource`,
|
|
142
|
+
`HandingOverSource` and `GrantListingSource`.
|
|
143
143
|
"""
|
|
144
144
|
|
|
145
145
|
provider: str
|
|
@@ -250,6 +250,22 @@ class AccessLinkingSource(Protocol):
|
|
|
250
250
|
...
|
|
251
251
|
|
|
252
252
|
|
|
253
|
+
@runtime_checkable
|
|
254
|
+
class HandingOverSource(Protocol):
|
|
255
|
+
"""A credential source that can let the subscription a completed task starts keep the task's account."""
|
|
256
|
+
|
|
257
|
+
async def hand_over(
|
|
258
|
+
self, from_holder: ConnectionHolder, to_holder: ConnectionHolder
|
|
259
|
+
) -> None:
|
|
260
|
+
"""Pins `to_holder` to the account `from_holder` uses, if any, so it keeps it once `from_holder` is released.
|
|
261
|
+
|
|
262
|
+
Args:
|
|
263
|
+
from_holder: The completed task whose account to hand over.
|
|
264
|
+
to_holder: The subscription the task started.
|
|
265
|
+
"""
|
|
266
|
+
...
|
|
267
|
+
|
|
268
|
+
|
|
253
269
|
@runtime_checkable
|
|
254
270
|
class GrantListingSource(Protocol):
|
|
255
271
|
"""A credential source that lists the tasks and schedules holding its grants."""
|
|
@@ -676,6 +692,17 @@ class OAuthConnection(SkillConnection):
|
|
|
676
692
|
"""
|
|
677
693
|
await self._vault.release(holder)
|
|
678
694
|
|
|
695
|
+
async def hand_over(
|
|
696
|
+
self, from_holder: ConnectionHolder, to_holder: ConnectionHolder
|
|
697
|
+
) -> None:
|
|
698
|
+
"""Pins `to_holder` to the account `from_holder` uses, if any, so it keeps it once `from_holder` is released.
|
|
699
|
+
|
|
700
|
+
Args:
|
|
701
|
+
from_holder: The completed task whose account to hand over.
|
|
702
|
+
to_holder: The subscription the task started.
|
|
703
|
+
"""
|
|
704
|
+
await self._vault.hand_over(from_holder, to_holder)
|
|
705
|
+
|
|
679
706
|
async def revoke(self, principal: str, account_id: str | None = None) -> None:
|
|
680
707
|
"""Revokes a human's grant for one account with the provider, or for each of their accounts, and forgets its tokens.
|
|
681
708
|
|
|
@@ -194,7 +194,8 @@ async def create(
|
|
|
194
194
|
A handle to connect the agent with.
|
|
195
195
|
Raises:
|
|
196
196
|
AgentExistsError: If an agent with that name exists and `upsert` isn't set.
|
|
197
|
-
AgentJamError: If a skill's `subscribes` doesn't name a trigger of another of its skills
|
|
197
|
+
AgentJamError: If a skill's `subscribes` doesn't name a trigger of another of its skills whose connections it
|
|
198
|
+
declares.
|
|
198
199
|
"""
|
|
199
200
|
relay = construct_network(api_key=api_key, network=network, payments=payments)
|
|
200
201
|
update = construct_update(description, skills, visibility)
|
|
@@ -248,7 +249,7 @@ async def update(
|
|
|
248
249
|
A handle to connect the agent with.
|
|
249
250
|
Raises:
|
|
250
251
|
AgentJamError: If no agent on your account has that name, or a skill's `subscribes` doesn't name a trigger
|
|
251
|
-
of another of its skills
|
|
252
|
+
of another of its skills whose connections it declares.
|
|
252
253
|
"""
|
|
253
254
|
relay = construct_network(api_key=api_key, network=network, payments=payments)
|
|
254
255
|
stored = await relay.update(name, construct_update(description, skills, visibility))
|
|
@@ -37,9 +37,14 @@ TaskEndCode = Literal[
|
|
|
37
37
|
"""Why the relay ended a task itself, such as once the task it was part of ended or its requester's owner canceled it from AgentJam."""
|
|
38
38
|
|
|
39
39
|
ScheduleEndCode = Literal[
|
|
40
|
-
"expired",
|
|
40
|
+
"expired",
|
|
41
|
+
"payment_failed",
|
|
42
|
+
"connection_revoked",
|
|
43
|
+
"action_expired",
|
|
44
|
+
"subscription_refused",
|
|
41
45
|
]
|
|
42
|
-
"""Why the relay ended a schedule itself, such as once it reached its expiry
|
|
46
|
+
"""Why the relay ended a schedule itself, such as once it reached its expiry, or `subscription_refused` once it couldn't
|
|
47
|
+
start the subscription a completed task started, which its executor may never have seen start."""
|
|
43
48
|
|
|
44
49
|
ScheduleStatus = Literal["proposed", "requires_action", "active", "ended"]
|
|
45
50
|
"""Where a schedule stands on the relay."""
|
|
@@ -7,6 +7,7 @@ from agentjam._protocol import CompleteEnvelope, ProposeEnvelope, SubscriptionRe
|
|
|
7
7
|
from agentjam._relay import schedules
|
|
8
8
|
from agentjam._relay.schedules import ScheduleRecord
|
|
9
9
|
from agentjam._relay.sessions import request_key
|
|
10
|
+
from agentjam._subscriptions import construct_subscription_id
|
|
10
11
|
from agentjam._types import (
|
|
11
12
|
AgentCard,
|
|
12
13
|
Period,
|
|
@@ -137,7 +138,7 @@ class SubscriptionBook:
|
|
|
137
138
|
|
|
138
139
|
expires_at = compute_expiry(subscribes.expires_after, schedules.get_now())
|
|
139
140
|
schedule = ScheduleRecord(
|
|
140
|
-
id=
|
|
141
|
+
id=construct_subscription_id(task_id),
|
|
141
142
|
requester=envelope.to,
|
|
142
143
|
executor=envelope.sender,
|
|
143
144
|
principal=task.principal,
|
|
@@ -206,6 +206,11 @@ class SecretSource(CredentialSource):
|
|
|
206
206
|
async def release(self, holder: ConnectionHolder) -> None:
|
|
207
207
|
await self._channel().release(self._construct_grant(holder))
|
|
208
208
|
|
|
209
|
+
async def hand_over(
|
|
210
|
+
self, from_holder: ConnectionHolder, to_holder: ConnectionHolder
|
|
211
|
+
) -> None:
|
|
212
|
+
"""Does nothing, since the network itself moves a completed task's grant to the subscription the task starts."""
|
|
213
|
+
|
|
209
214
|
def watch(self, listener: ConnectionListener) -> Callable[[], None]:
|
|
210
215
|
return lambda: None
|
|
211
216
|
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
from collections.abc import Sequence
|
|
2
|
+
|
|
3
|
+
from agentjam._errors import AgentJamError
|
|
4
|
+
from agentjam._types import (
|
|
5
|
+
ConnectionCard,
|
|
6
|
+
ConnectionOptionCard,
|
|
7
|
+
Period,
|
|
8
|
+
SkillCard,
|
|
9
|
+
SkillSubscription,
|
|
10
|
+
)
|
|
11
|
+
from agentjam._vaults.vault import covers_scopes
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def construct_subscription_id(task_id: str) -> str:
|
|
15
|
+
"""Returns the id of the schedule the subscription that the completed task `task_id` starts runs as."""
|
|
16
|
+
return f"{task_id}:subscription"
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def is_expiry(period: Period) -> bool:
|
|
20
|
+
return 1 <= period.count <= 365
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def covers_provider(
|
|
24
|
+
offered: ConnectionCard | ConnectionOptionCard,
|
|
25
|
+
needed: ConnectionCard | ConnectionOptionCard,
|
|
26
|
+
) -> bool:
|
|
27
|
+
"""Whether `offered` is for `needed`'s provider with every scope it needs, counting no implied scopes, as the network does."""
|
|
28
|
+
return offered.provider == needed.provider and covers_scopes(
|
|
29
|
+
offered.scopes, needed.scopes, {}
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def covers_options(
|
|
34
|
+
offered: Sequence[ConnectionOptionCard] | None,
|
|
35
|
+
needed: Sequence[ConnectionOptionCard] | None,
|
|
36
|
+
) -> bool:
|
|
37
|
+
"""Whether each option a task may be pinned to through `offered` is one `needed` takes."""
|
|
38
|
+
return all(
|
|
39
|
+
any(covers_provider(option, wanted) for wanted in needed or [])
|
|
40
|
+
for option in offered or []
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def serves_connection(offered: ConnectionCard, needed: ConnectionCard) -> bool:
|
|
45
|
+
return (
|
|
46
|
+
(offered.kind or "oauth") == (needed.kind or "oauth")
|
|
47
|
+
and covers_provider(offered, needed)
|
|
48
|
+
and covers_options(offered.options, needed.options)
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def describe_problem(
|
|
53
|
+
card: SkillCard, subscribes: SkillSubscription, skills: Sequence[SkillCard]
|
|
54
|
+
) -> str | None:
|
|
55
|
+
name, skill, trigger = card.name, subscribes.skill, subscribes.trigger
|
|
56
|
+
if skill == name:
|
|
57
|
+
return f'The "{name}" skill can\'t subscribe its requesters to a trigger of its own'
|
|
58
|
+
|
|
59
|
+
subscribed = f'The "{name}" skill subscribes to the "{skill}" skill'
|
|
60
|
+
target = next((each for each in skills if each.name == skill), None)
|
|
61
|
+
if target is None:
|
|
62
|
+
return f"{subscribed}, which the agent doesn't have"
|
|
63
|
+
|
|
64
|
+
if not any(each.name == trigger for each in target.triggers or []):
|
|
65
|
+
return f'The "{name}" skill subscribes to the "{trigger}" trigger, which the "{skill}" skill doesn\'t declare'
|
|
66
|
+
|
|
67
|
+
offered = card.connections or []
|
|
68
|
+
if not all(
|
|
69
|
+
any(serves_connection(each, needed) for each in offered)
|
|
70
|
+
for needed in target.connections or []
|
|
71
|
+
):
|
|
72
|
+
return f'{subscribed}, so it must declare every connection the "{skill}" skill needs'
|
|
73
|
+
|
|
74
|
+
if not is_expiry(subscribes.expires_after):
|
|
75
|
+
return f'The "{name}" skill\'s subscription must expire after a whole number from 1 to 365 days, weeks or months'
|
|
76
|
+
|
|
77
|
+
return None
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def assert_subscriptions(skills: Sequence[SkillCard]) -> None:
|
|
81
|
+
"""Checks that each skill's `subscribes` names a trigger of another of the agent's skills, whose every connection
|
|
82
|
+
it declares too with at least the same scopes, and expires after 1 to 365 days, weeks or months, as the network
|
|
83
|
+
requires.
|
|
84
|
+
|
|
85
|
+
Raises:
|
|
86
|
+
AgentJamError: If a skill's `subscribes` breaks one of those rules.
|
|
87
|
+
"""
|
|
88
|
+
for card in skills:
|
|
89
|
+
if card.subscribes is None:
|
|
90
|
+
continue
|
|
91
|
+
|
|
92
|
+
if problem := describe_problem(card, card.subscribes, skills):
|
|
93
|
+
raise AgentJamError(problem)
|
|
@@ -397,8 +397,9 @@ class Period(WireModel):
|
|
|
397
397
|
class SkillSubscription(WireModel):
|
|
398
398
|
"""The trigger a skill's completed tasks subscribe their requesters to.
|
|
399
399
|
|
|
400
|
-
Its skill must be another of the agent's,
|
|
401
|
-
its
|
|
400
|
+
Its skill must be another of the agent's, whose every connection the subscribing skill declares too with at least
|
|
401
|
+
the same scopes, and its runs use the accounts the task was granted. When that skill is priced, each run is charged
|
|
402
|
+
at its price until the subscription expires or either party ends it, and the requester can opt out with
|
|
402
403
|
`subscribe=False`.
|
|
403
404
|
"""
|
|
404
405
|
|
|
@@ -449,6 +449,22 @@ class LocalGrantVault:
|
|
|
449
449
|
shared = await self._leave_account(latest.principal, saved.account)
|
|
450
450
|
await self._hooks.revoke_tokens(saved.tokens, keep_shared=shared)
|
|
451
451
|
|
|
452
|
+
async def hand_over(
|
|
453
|
+
self, from_holder: ConnectionHolder, to_holder: ConnectionHolder
|
|
454
|
+
) -> None:
|
|
455
|
+
pin = await self._read_pin(from_holder)
|
|
456
|
+
if pin is None:
|
|
457
|
+
return
|
|
458
|
+
|
|
459
|
+
async with self._lock_principal(pin.principal):
|
|
460
|
+
latest = await self._read_pin(from_holder)
|
|
461
|
+
if latest is None:
|
|
462
|
+
return
|
|
463
|
+
|
|
464
|
+
saved = await self._read(latest.principal, latest.account)
|
|
465
|
+
if saved is not None:
|
|
466
|
+
await self._hold(latest.principal, latest.account, [to_holder], saved)
|
|
467
|
+
|
|
452
468
|
async def revoke(self, principal: str, account_id: str | None = None) -> None:
|
|
453
469
|
async with self._lock_principal(principal):
|
|
454
470
|
accounts = (
|
|
@@ -424,6 +424,11 @@ class RemoteGrantVault:
|
|
|
424
424
|
case _:
|
|
425
425
|
assert_never(released)
|
|
426
426
|
|
|
427
|
+
async def hand_over(
|
|
428
|
+
self, from_holder: ConnectionHolder, to_holder: ConnectionHolder
|
|
429
|
+
) -> None:
|
|
430
|
+
"""Does nothing, since the network itself moves a completed task's grant to the subscription the task starts."""
|
|
431
|
+
|
|
427
432
|
async def revoke(self, principal: str, account_id: str | None = None) -> None:
|
|
428
433
|
revoked = await self._channel.revoke(self._provider, principal, account_id)
|
|
429
434
|
grants = (
|
|
@@ -315,6 +315,12 @@ class GrantVault(Protocol):
|
|
|
315
315
|
|
|
316
316
|
async def release(self, holder: ConnectionHolder) -> None: ...
|
|
317
317
|
|
|
318
|
+
async def hand_over(
|
|
319
|
+
self, from_holder: ConnectionHolder, to_holder: ConnectionHolder
|
|
320
|
+
) -> None:
|
|
321
|
+
"""Pins `to_holder` to the account `from_holder` is pinned to, if any, so it keeps it once `from_holder` is released."""
|
|
322
|
+
...
|
|
323
|
+
|
|
318
324
|
async def revoke(self, principal: str, account_id: str | None = None) -> None:
|
|
319
325
|
"""Revokes the principal's account `account_id`, or every account of theirs when it's left out."""
|
|
320
326
|
...
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
from collections.abc import Sequence
|
|
2
|
-
|
|
3
|
-
from agentjam._errors import AgentJamError
|
|
4
|
-
from agentjam._types import Period, SkillCard, SkillSubscription
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
def is_expiry(period: Period) -> bool:
|
|
8
|
-
return 1 <= period.count <= 365
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
def describe_problem(
|
|
12
|
-
name: str, subscribes: SkillSubscription, skills: Sequence[SkillCard]
|
|
13
|
-
) -> str | None:
|
|
14
|
-
skill, trigger = subscribes.skill, subscribes.trigger
|
|
15
|
-
if skill == name:
|
|
16
|
-
return f'The "{name}" skill can\'t subscribe its requesters to a trigger of its own'
|
|
17
|
-
|
|
18
|
-
subscribed = f'The "{name}" skill subscribes to the "{skill}" skill'
|
|
19
|
-
target = next((card for card in skills if card.name == skill), None)
|
|
20
|
-
if target is None:
|
|
21
|
-
return f"{subscribed}, which the agent doesn't have"
|
|
22
|
-
|
|
23
|
-
if not any(card.name == trigger for card in target.triggers or []):
|
|
24
|
-
return f'The "{name}" skill subscribes to the "{trigger}" trigger, which the "{skill}" skill doesn\'t declare'
|
|
25
|
-
|
|
26
|
-
if target.connections:
|
|
27
|
-
return f"{subscribed}, which can't have connections"
|
|
28
|
-
|
|
29
|
-
if not is_expiry(subscribes.expires_after):
|
|
30
|
-
return f'The "{name}" skill\'s subscription must expire after a whole number from 1 to 365 days, weeks or months'
|
|
31
|
-
|
|
32
|
-
return None
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
def assert_subscriptions(skills: Sequence[SkillCard]) -> None:
|
|
36
|
-
"""Checks that each skill's `subscribes` names a trigger of another of the agent's skills without connections,
|
|
37
|
-
and expires after 1 to 365 days, weeks or months, as the network requires.
|
|
38
|
-
|
|
39
|
-
Raises:
|
|
40
|
-
AgentJamError: If a skill's `subscribes` breaks one of those rules.
|
|
41
|
-
"""
|
|
42
|
-
for card in skills:
|
|
43
|
-
if card.subscribes is None:
|
|
44
|
-
continue
|
|
45
|
-
|
|
46
|
-
if problem := describe_problem(card.name, card.subscribes, skills):
|
|
47
|
-
raise AgentJamError(problem)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|