stackshift 1.8.0__tar.gz → 1.10.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.
Files changed (82) hide show
  1. {stackshift-1.8.0 → stackshift-1.10.0}/PKG-INFO +39 -1
  2. {stackshift-1.8.0 → stackshift-1.10.0}/README.md +38 -0
  3. {stackshift-1.8.0 → stackshift-1.10.0}/pyproject.toml +1 -1
  4. {stackshift-1.8.0 → stackshift-1.10.0}/stackshift/__init__.py +6 -1
  5. {stackshift-1.8.0 → stackshift-1.10.0}/stackshift/assets.py +2 -2
  6. stackshift-1.10.0/stackshift/assets_transforms.py +56 -0
  7. {stackshift-1.8.0 → stackshift-1.10.0}/stackshift/client.py +2 -0
  8. {stackshift-1.8.0 → stackshift-1.10.0}/stackshift/computers.py +61 -4
  9. stackshift-1.10.0/stackshift/events.py +181 -0
  10. {stackshift-1.8.0 → stackshift-1.10.0}/stackshift.egg-info/PKG-INFO +39 -1
  11. {stackshift-1.8.0 → stackshift-1.10.0}/stackshift.egg-info/SOURCES.txt +5 -2
  12. stackshift-1.8.0/tests/test_assets_workflows.py → stackshift-1.10.0/tests/test_assets_transforms.py +1 -6
  13. stackshift-1.10.0/tests/test_computers_agent.py +80 -0
  14. {stackshift-1.8.0 → stackshift-1.10.0}/tests/test_computers_routes.py +9 -1
  15. stackshift-1.10.0/tests/test_events.py +52 -0
  16. stackshift-1.8.0/stackshift/assets_workflows.py +0 -184
  17. {stackshift-1.8.0 → stackshift-1.10.0}/setup.cfg +0 -0
  18. {stackshift-1.8.0 → stackshift-1.10.0}/stackshift/agents.py +0 -0
  19. {stackshift-1.8.0 → stackshift-1.10.0}/stackshift/ai_credits.py +0 -0
  20. {stackshift-1.8.0 → stackshift-1.10.0}/stackshift/assets_dam.py +0 -0
  21. {stackshift-1.8.0 → stackshift-1.10.0}/stackshift/assets_media.py +0 -0
  22. {stackshift-1.8.0 → stackshift-1.10.0}/stackshift/assets_platform.py +0 -0
  23. {stackshift-1.8.0 → stackshift-1.10.0}/stackshift/assets_video.py +0 -0
  24. {stackshift-1.8.0 → stackshift-1.10.0}/stackshift/computers_adapters.py +0 -0
  25. {stackshift-1.8.0 → stackshift-1.10.0}/stackshift/computers_transfer.py +0 -0
  26. {stackshift-1.8.0 → stackshift-1.10.0}/stackshift/databases.py +0 -0
  27. {stackshift-1.8.0 → stackshift-1.10.0}/stackshift/hosted_agents.py +0 -0
  28. {stackshift-1.8.0 → stackshift-1.10.0}/stackshift/mail.py +0 -0
  29. {stackshift-1.8.0 → stackshift-1.10.0}/stackshift/mail_advanced.py +0 -0
  30. {stackshift-1.8.0 → stackshift-1.10.0}/stackshift/mail_agent_inboxes.py +0 -0
  31. {stackshift-1.8.0 → stackshift-1.10.0}/stackshift/mail_agreements.py +0 -0
  32. {stackshift-1.8.0 → stackshift-1.10.0}/stackshift/mail_billing.py +0 -0
  33. {stackshift-1.8.0 → stackshift-1.10.0}/stackshift/mail_brands.py +0 -0
  34. {stackshift-1.8.0 → stackshift-1.10.0}/stackshift/mail_campaigns.py +0 -0
  35. {stackshift-1.8.0 → stackshift-1.10.0}/stackshift/mail_events_webhooks.py +0 -0
  36. {stackshift-1.8.0 → stackshift-1.10.0}/stackshift/mail_exports.py +0 -0
  37. {stackshift-1.8.0 → stackshift-1.10.0}/stackshift/mail_inbox_webhooks.py +0 -0
  38. {stackshift-1.8.0 → stackshift-1.10.0}/stackshift/mail_mailboxes.py +0 -0
  39. {stackshift-1.8.0 → stackshift-1.10.0}/stackshift/mail_marketing.py +0 -0
  40. {stackshift-1.8.0 → stackshift-1.10.0}/stackshift/mail_migration.py +0 -0
  41. {stackshift-1.8.0 → stackshift-1.10.0}/stackshift/mail_reputation.py +0 -0
  42. {stackshift-1.8.0 → stackshift-1.10.0}/stackshift/mail_streams.py +0 -0
  43. {stackshift-1.8.0 → stackshift-1.10.0}/stackshift/mail_team_inboxes.py +0 -0
  44. {stackshift-1.8.0 → stackshift-1.10.0}/stackshift/mail_tracking.py +0 -0
  45. {stackshift-1.8.0 → stackshift-1.10.0}/stackshift/partner.py +0 -0
  46. {stackshift-1.8.0 → stackshift-1.10.0}/stackshift/projects.py +0 -0
  47. {stackshift-1.8.0 → stackshift-1.10.0}/stackshift/support_action_manifest.py +0 -0
  48. {stackshift-1.8.0 → stackshift-1.10.0}/stackshift/support_action_receiver.py +0 -0
  49. {stackshift-1.8.0 → stackshift-1.10.0}/stackshift/support_action_sqlite.py +0 -0
  50. {stackshift-1.8.0 → stackshift-1.10.0}/stackshift/support_action_types.py +0 -0
  51. {stackshift-1.8.0 → stackshift-1.10.0}/stackshift/support_actions.py +0 -0
  52. {stackshift-1.8.0 → stackshift-1.10.0}/stackshift/teams.py +0 -0
  53. {stackshift-1.8.0 → stackshift-1.10.0}/stackshift/workload_security.py +0 -0
  54. {stackshift-1.8.0 → stackshift-1.10.0}/stackshift.egg-info/dependency_links.txt +0 -0
  55. {stackshift-1.8.0 → stackshift-1.10.0}/stackshift.egg-info/requires.txt +0 -0
  56. {stackshift-1.8.0 → stackshift-1.10.0}/stackshift.egg-info/top_level.txt +0 -0
  57. {stackshift-1.8.0 → stackshift-1.10.0}/tests/test_agents.py +0 -0
  58. {stackshift-1.8.0 → stackshift-1.10.0}/tests/test_ai_credits.py +0 -0
  59. {stackshift-1.8.0 → stackshift-1.10.0}/tests/test_assets_media.py +0 -0
  60. {stackshift-1.8.0 → stackshift-1.10.0}/tests/test_assets_platform.py +0 -0
  61. {stackshift-1.8.0 → stackshift-1.10.0}/tests/test_computers.py +0 -0
  62. {stackshift-1.8.0 → stackshift-1.10.0}/tests/test_computers_adapters.py +0 -0
  63. {stackshift-1.8.0 → stackshift-1.10.0}/tests/test_computers_controls.py +0 -0
  64. {stackshift-1.8.0 → stackshift-1.10.0}/tests/test_databases.py +0 -0
  65. {stackshift-1.8.0 → stackshift-1.10.0}/tests/test_hosted_agents.py +0 -0
  66. {stackshift-1.8.0 → stackshift-1.10.0}/tests/test_mail.py +0 -0
  67. {stackshift-1.8.0 → stackshift-1.10.0}/tests/test_mail_advanced.py +0 -0
  68. {stackshift-1.8.0 → stackshift-1.10.0}/tests/test_mail_agent_inboxes.py +0 -0
  69. {stackshift-1.8.0 → stackshift-1.10.0}/tests/test_mail_agreements.py +0 -0
  70. {stackshift-1.8.0 → stackshift-1.10.0}/tests/test_mail_diagnostics.py +0 -0
  71. {stackshift-1.8.0 → stackshift-1.10.0}/tests/test_mail_events_webhooks.py +0 -0
  72. {stackshift-1.8.0 → stackshift-1.10.0}/tests/test_mail_exports.py +0 -0
  73. {stackshift-1.8.0 → stackshift-1.10.0}/tests/test_mail_inbox_webhooks.py +0 -0
  74. {stackshift-1.8.0 → stackshift-1.10.0}/tests/test_mail_mailboxes.py +0 -0
  75. {stackshift-1.8.0 → stackshift-1.10.0}/tests/test_mail_platform.py +0 -0
  76. {stackshift-1.8.0 → stackshift-1.10.0}/tests/test_mail_simulation.py +0 -0
  77. {stackshift-1.8.0 → stackshift-1.10.0}/tests/test_mail_subscribers.py +0 -0
  78. {stackshift-1.8.0 → stackshift-1.10.0}/tests/test_mail_team_inboxes.py +0 -0
  79. {stackshift-1.8.0 → stackshift-1.10.0}/tests/test_mail_tracking.py +0 -0
  80. {stackshift-1.8.0 → stackshift-1.10.0}/tests/test_partner.py +0 -0
  81. {stackshift-1.8.0 → stackshift-1.10.0}/tests/test_support_actions.py +0 -0
  82. {stackshift-1.8.0 → stackshift-1.10.0}/tests/test_teams.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: stackshift
3
- Version: 1.8.0
3
+ Version: 1.10.0
4
4
  Summary: Official Python SDK for StackShift.
5
5
  Author-email: StackShift <support@stackshift.cloud>
6
6
  Project-URL: Homepage, https://stackshift.cloud
@@ -51,6 +51,8 @@ computer.files.remove("app/tmp", recursive=True)
51
51
 
52
52
  `upload_dir` skips `.gitignore`d files in a git folder unless you pass `include_ignored=True`, and keeps modes, symlinks and modification times.
53
53
 
54
+ `computers.ensure_project()` returns the project computers go in (`id`, `name`, `created`), making one named "Computers" if the account has none; it needs a user token.
55
+
54
56
  Pick `vcpus` and `memory_gb` from the template's sizes (`templates()` lists them), for example 2 vCPU / 8 GB or 4 vCPU / 16 GB. `region` picks where it starts; `computers.regions(project_id)` lists the regions open now.
55
57
 
56
58
  Tell people what an agent is doing. The dashboard shows the task and next step beside the screen, and `ask_owner` carries the next step on its card.
@@ -181,6 +183,22 @@ computer.agent_conversations()
181
183
  computer.agent_events(conversation["id"], after_seq=10, limit=50)
182
184
  ```
183
185
 
186
+ Providers are `COMPUTER_AGENT_PROVIDERS` (`claude`, `codex`, `gemini`, `opencode`, `cursor`, `copilot`, `amp`, `qwen`). Attach files, read the result, and try one task several ways:
187
+
188
+ ```python
189
+ computer.agent_providers()
190
+ computer.agent_models(provider="claude")
191
+ spec = computer.attach_agent_file("./spec.md")
192
+ conversation = computer.prompt_agent("fix the failing tests", provider="claude", attachments=[spec])
193
+ computer.agent_result(conversation["id"], wait=True)
194
+ computer.agent_turns(limit=20)
195
+
196
+ fanout = computer.prompt_agent(prompts=["fix it with a retry", "fix it with a lock"], provider="codex")
197
+ done = computer.agent_fanout(fanout["id"])
198
+ computer.keep_agent_fork(fanout["id"], done["forks"][0]["computer_id"])
199
+ computer.agent_fanouts()
200
+ ```
201
+
184
202
  `computers.keys.create(project_id, name, scopes=["computers:read"])` limits a key to `computers:read`, `computers:write`, `computers:use` or `computers:delete`. A stuck large upload resumes with `computers.resume_upload(computer_id, transfer_id, upload_id, part_md5)`.
185
203
 
186
204
  An agent can get its own key without any existing key. The functions below send no `Authorization` header:
@@ -350,6 +368,26 @@ valid = stackshift.mail.webhooks.verify_signature(
350
368
 
351
369
  Webhook handlers should be idempotent. StackShift retries non-2xx responses. Delivery events do not include full email bodies or OTP codes by default.
352
370
 
371
+ ## Platform events
372
+
373
+ Every StackShift event reaches your endpoint signed with `StackShift-Signature`. `events.verify` checks the signature in constant time, refuses timestamps older than five minutes (`tolerance_seconds` changes that) and returns the parsed event. Failures raise `EventSignatureError` with a `code` of `missing_signature`, `invalid_signature`, `expired` or `invalid_body`:
374
+
375
+ ```python
376
+ from stackshift import EventSignatureError
377
+
378
+ try:
379
+ event = stackshift.events.verify(
380
+ raw_body=request.get_data(),
381
+ signature_header=request.headers.get("StackShift-Signature"),
382
+ secret=os.environ["STACKSHIFT_WEBHOOK_SECRET"],
383
+ )
384
+ except EventSignatureError as error:
385
+ return error.code, 400
386
+ print(event["type"], event["subject"]["id"])
387
+ ```
388
+
389
+ `events` also wraps the API: `catalog`, `list`, `get`, `create_subscription`, `list_subscriptions`, `update_subscription`, `delete_subscription`, `create_rule`, `list_rules`, `update_rule`, `delete_rule`, `preview_rule`, `test_rule`, `list_deliveries` and `replay_delivery`.
390
+
353
391
  ## Mailboxes
354
392
 
355
393
  Host real mailboxes on your own domain. The mailbox owner gets an invitation by email and sets their own password.
@@ -39,6 +39,8 @@ computer.files.remove("app/tmp", recursive=True)
39
39
 
40
40
  `upload_dir` skips `.gitignore`d files in a git folder unless you pass `include_ignored=True`, and keeps modes, symlinks and modification times.
41
41
 
42
+ `computers.ensure_project()` returns the project computers go in (`id`, `name`, `created`), making one named "Computers" if the account has none; it needs a user token.
43
+
42
44
  Pick `vcpus` and `memory_gb` from the template's sizes (`templates()` lists them), for example 2 vCPU / 8 GB or 4 vCPU / 16 GB. `region` picks where it starts; `computers.regions(project_id)` lists the regions open now.
43
45
 
44
46
  Tell people what an agent is doing. The dashboard shows the task and next step beside the screen, and `ask_owner` carries the next step on its card.
@@ -169,6 +171,22 @@ computer.agent_conversations()
169
171
  computer.agent_events(conversation["id"], after_seq=10, limit=50)
170
172
  ```
171
173
 
174
+ Providers are `COMPUTER_AGENT_PROVIDERS` (`claude`, `codex`, `gemini`, `opencode`, `cursor`, `copilot`, `amp`, `qwen`). Attach files, read the result, and try one task several ways:
175
+
176
+ ```python
177
+ computer.agent_providers()
178
+ computer.agent_models(provider="claude")
179
+ spec = computer.attach_agent_file("./spec.md")
180
+ conversation = computer.prompt_agent("fix the failing tests", provider="claude", attachments=[spec])
181
+ computer.agent_result(conversation["id"], wait=True)
182
+ computer.agent_turns(limit=20)
183
+
184
+ fanout = computer.prompt_agent(prompts=["fix it with a retry", "fix it with a lock"], provider="codex")
185
+ done = computer.agent_fanout(fanout["id"])
186
+ computer.keep_agent_fork(fanout["id"], done["forks"][0]["computer_id"])
187
+ computer.agent_fanouts()
188
+ ```
189
+
172
190
  `computers.keys.create(project_id, name, scopes=["computers:read"])` limits a key to `computers:read`, `computers:write`, `computers:use` or `computers:delete`. A stuck large upload resumes with `computers.resume_upload(computer_id, transfer_id, upload_id, part_md5)`.
173
191
 
174
192
  An agent can get its own key without any existing key. The functions below send no `Authorization` header:
@@ -338,6 +356,26 @@ valid = stackshift.mail.webhooks.verify_signature(
338
356
 
339
357
  Webhook handlers should be idempotent. StackShift retries non-2xx responses. Delivery events do not include full email bodies or OTP codes by default.
340
358
 
359
+ ## Platform events
360
+
361
+ Every StackShift event reaches your endpoint signed with `StackShift-Signature`. `events.verify` checks the signature in constant time, refuses timestamps older than five minutes (`tolerance_seconds` changes that) and returns the parsed event. Failures raise `EventSignatureError` with a `code` of `missing_signature`, `invalid_signature`, `expired` or `invalid_body`:
362
+
363
+ ```python
364
+ from stackshift import EventSignatureError
365
+
366
+ try:
367
+ event = stackshift.events.verify(
368
+ raw_body=request.get_data(),
369
+ signature_header=request.headers.get("StackShift-Signature"),
370
+ secret=os.environ["STACKSHIFT_WEBHOOK_SECRET"],
371
+ )
372
+ except EventSignatureError as error:
373
+ return error.code, 400
374
+ print(event["type"], event["subject"]["id"])
375
+ ```
376
+
377
+ `events` also wraps the API: `catalog`, `list`, `get`, `create_subscription`, `list_subscriptions`, `update_subscription`, `delete_subscription`, `create_rule`, `list_rules`, `update_rule`, `delete_rule`, `preview_rule`, `test_rule`, `list_deliveries` and `replay_delivery`.
378
+
341
379
  ## Mailboxes
342
380
 
343
381
  Host real mailboxes on your own domain. The mailbox owner gets an invitation by email and sets their own password.
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "stackshift"
7
- version = "1.8.0"
7
+ version = "1.10.0"
8
8
  description = "Official Python SDK for StackShift."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.9"
@@ -2,7 +2,7 @@ from .client import StackShift
2
2
  from .agents import AgentConnectionOperationsClient, AgentConnectionsClient, AgentsClient
3
3
  from .ai_credits import AICreditsClient
4
4
  from .assets import ASSET_TRANSFORM_PRESETS, AssetsClient, asset_transform_options, asset_transform_spec, get_asset_transform_preset
5
- from .computers import COMPUTER_CAPACITY_BUSY, COMPUTER_LIMIT_EXCEEDED, COMPUTER_SPEND_CAP_REACHED, Computer, ComputerActionError, ComputerCIClient, ComputerKeysClient, ComputersClient, ComputerSnapshotsClient, ComputerTransferError, ComputerWaitError, computer_public_pricing, exchange_computer_agent_claim, register_computer_agent, wait_for_computer_agent_key
5
+ from .computers import COMPUTER_AGENT_PROVIDERS, COMPUTER_CAPACITY_BUSY, COMPUTER_LIMIT_EXCEEDED, COMPUTER_SPEND_CAP_REACHED, Computer, ComputerActionError, ComputerCIClient, ComputerKeysClient, ComputersClient, ComputerSnapshotsClient, ComputerTransferError, ComputerWaitError, computer_public_pricing, exchange_computer_agent_claim, register_computer_agent, wait_for_computer_agent_key
6
6
  from .computers_adapters import (
7
7
  AnthropicComputerAdapter,
8
8
  FunctionComputerAdapter,
@@ -12,6 +12,7 @@ from .computers_adapters import (
12
12
  COMPUTER_FUNCTION_TOOLS,
13
13
  )
14
14
  from .databases import DatabaseBranchesClient, DatabaseOperationFailed, DatabasesClient
15
+ from .events import EventSignatureError, EventsClient, verify_event
15
16
  from .hosted_agents import HostedAgentBudgetClient, HostedAgentSecretsClient, HostedAgentsClient
16
17
  from .mail import (
17
18
  MailClient,
@@ -59,6 +60,7 @@ from .workload_security import WorkloadSecurityClient
59
60
 
60
61
  __all__ = [
61
62
  "StackShift",
63
+ "COMPUTER_AGENT_PROVIDERS",
62
64
  "COMPUTER_CAPACITY_BUSY",
63
65
  "COMPUTER_LIMIT_EXCEEDED",
64
66
  "COMPUTER_SPEND_CAP_REACHED",
@@ -137,6 +139,9 @@ __all__ = [
137
139
  "asset_transform_spec",
138
140
  "get_asset_transform_preset",
139
141
  "verify_webhook_signature",
142
+ "EventSignatureError",
143
+ "EventsClient",
144
+ "verify_event",
140
145
  ]
141
146
 
142
147
  from .support_actions import (ActionProtocolError, sign_action, verify_action, verify_receipt, encode_receipt)
@@ -6,7 +6,7 @@ from pathlib import Path
6
6
  from typing import Any, BinaryIO
7
7
  from urllib.parse import quote
8
8
 
9
- from .assets_workflows import AssetWorkflowsMixin
9
+ from .assets_transforms import AssetTransformsMixin
10
10
  from .assets_dam import AssetDAMClient
11
11
  from .assets_video import AssetVideoClient
12
12
  from .assets_platform import AssetPlatformClient
@@ -52,7 +52,7 @@ def asset_transform_spec(**options: Any) -> str:
52
52
  return _transform_spec(options)
53
53
 
54
54
 
55
- class AssetsClient(AssetWorkflowsMixin):
55
+ class AssetsClient(AssetTransformsMixin):
56
56
  def __init__(self, client: Any) -> None:
57
57
  self._client = client
58
58
  self.dam = AssetDAMClient(client)
@@ -0,0 +1,56 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import Any
4
+ from urllib.parse import quote
5
+
6
+
7
+ class AssetTransformsMixin:
8
+ """Typed route helpers for deterministic media transforms and generation."""
9
+
10
+ _client: Any
11
+
12
+ def create_transformation_v2(
13
+ self, name: str, definition: dict[str, Any], *, eager: bool = False
14
+ ) -> dict[str, Any]:
15
+ return self._client.request(
16
+ "POST", "/assets/transformations",
17
+ json={"name": name, "definition": definition, "eager": eager},
18
+ )
19
+
20
+ def estimate_transform(
21
+ self, asset_id: str, version_id: str, definition: dict[str, Any]
22
+ ) -> dict[str, Any]:
23
+ return self._client.request(
24
+ "POST", f"/assets/{quote(asset_id, safe='')}/transforms/estimate",
25
+ json={"version_id": version_id, "definition": definition},
26
+ )
27
+
28
+ def materialize_transform(
29
+ self,
30
+ asset_id: str,
31
+ *,
32
+ definition: dict[str, Any] | None = None,
33
+ preset: str | None = None,
34
+ idempotency_key: str | None = None,
35
+ ) -> dict[str, Any]:
36
+ payload = {key: value for key, value in {
37
+ "definition": definition, "preset": preset,
38
+ }.items() if value not in (None, "")}
39
+ headers = {"Idempotency-Key": idempotency_key} if idempotency_key else None
40
+ return self._client.request(
41
+ "POST", f"/assets/{quote(asset_id, safe='')}/transforms", json=payload, headers=headers
42
+ )
43
+
44
+ def derivatives(self, asset_id: str) -> dict[str, Any]:
45
+ return self._client.request("GET", f"/assets/{quote(asset_id, safe='')}/derivatives")
46
+
47
+ def generate(
48
+ self, payload: dict[str, Any], *, idempotency_key: str
49
+ ) -> dict[str, Any]:
50
+ return self._client.request(
51
+ "POST", "/assets/generations", json=payload,
52
+ headers={"Idempotency-Key": idempotency_key},
53
+ )
54
+
55
+ def automation(self) -> dict[str, Any]:
56
+ return self._client.request("GET", "/assets/automation")
@@ -32,6 +32,7 @@ class StackShift:
32
32
  from .assets import AssetsClient
33
33
  from .computers import ComputersClient
34
34
  from .databases import DatabasesClient
35
+ from .events import EventsClient
35
36
  from .hosted_agents import HostedAgentsClient
36
37
  from .mail import MailClient
37
38
  from .partner import PartnerClient
@@ -47,6 +48,7 @@ class StackShift:
47
48
  self.computers.teams = ComputerTeamsClient(self)
48
49
  self.teams = self.computers.teams
49
50
  self.databases = DatabasesClient(self)
51
+ self.events = EventsClient(self)
50
52
  self.hosted_agents = HostedAgentsClient(self)
51
53
  self.mail = MailClient(self)
52
54
  self.partner = PartnerClient(self)
@@ -1,6 +1,7 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  import json
4
+ import os
4
5
  import time
5
6
  import uuid
6
7
  from typing import Any, Iterator
@@ -16,6 +17,8 @@ COMPUTER_LIMIT_EXCEEDED = "limit_exceeded"
16
17
  COMPUTER_CAPACITY_BUSY = "capacity_busy"
17
18
  COMPUTER_SPEND_CAP_REACHED = "spend_cap_reached"
18
19
 
20
+ COMPUTER_AGENT_PROVIDERS = ("claude", "codex", "gemini", "opencode", "cursor", "copilot", "amp", "qwen")
21
+
19
22
 
20
23
  class ComputerWaitError(RuntimeError):
21
24
  def __init__(self, message: str, computer: dict[str, Any] | None = None) -> None:
@@ -193,6 +196,9 @@ class ComputersClient:
193
196
  self.snapshots = ComputerSnapshotsClient(client)
194
197
  self.ci = ComputerCIClient(client)
195
198
 
199
+ def ensure_project(self) -> dict[str, Any]:
200
+ return self._client.request("POST", "/computers/project")
201
+
196
202
  def templates(self, project_id: str) -> list[dict[str, Any]]:
197
203
  return self._client.request("GET", "/computers/templates", params={"project_id": project_id})
198
204
 
@@ -367,9 +373,36 @@ class ComputersClient:
367
373
  def ssh_certificate(self, computer_id: str, public_key: str) -> dict[str, Any]:
368
374
  return self._client.request("POST", "/computers/ssh/certificates", json={"computer_id": computer_id, "public_key": public_key})
369
375
 
370
- def prompt_agent(self, computer_id: str, prompt: str, *, conversation_id: str | None = None, provider: str | None = None, model: str | None = None, cwd: str | None = None, env: dict[str, str] | None = None, secret_binding_ids: list[str] | None = None) -> dict[str, Any]:
371
- optional = {"conversation_id": conversation_id, "provider": provider, "model": model, "cwd": cwd, "env": env, "secret_binding_ids": secret_binding_ids}
372
- return self._client.request("POST", f"/computers/{_seg(computer_id)}/agent/prompt", json={"prompt": prompt, **{key: value for key, value in optional.items() if value is not None}})
376
+ def prompt_agent(self, computer_id: str, prompt: str | None = None, *, conversation_id: str | None = None, provider: str | None = None, model: str | None = None, cwd: str | None = None, env: dict[str, str] | None = None, secret_binding_ids: list[str] | None = None, attachments: list[str] | None = None, forks: int | None = None, prompts: list[str] | None = None) -> dict[str, Any]:
377
+ """Send a prompt. Returns a conversation, or a fan-out when `forks` or `prompts` is set."""
378
+ optional = {"prompt": prompt, "conversation_id": conversation_id, "provider": provider, "model": model, "cwd": cwd, "env": env, "secret_binding_ids": secret_binding_ids, "attachments": attachments, "forks": forks, "prompts": prompts}
379
+ return self._client.request("POST", f"/computers/{_seg(computer_id)}/agent/prompt", json={key: value for key, value in optional.items() if value is not None})
380
+
381
+ def attach_agent_file(self, computer_id: str, local_path: str) -> str:
382
+ remote = f"/workspace/.stackshift/attachments/{uuid.uuid4().hex}/{os.path.basename(local_path)}"
383
+ self.upload(computer_id, local_path, remote)
384
+ return remote
385
+
386
+ def agent_providers(self, computer_id: str, *, refresh: bool = False) -> list[dict[str, Any]]:
387
+ return self._client.request("GET", f"/computers/{_seg(computer_id)}/agent/providers", params=_params(refresh="1" if refresh else None))["providers"]
388
+
389
+ def agent_models(self, computer_id: str, *, provider: str | None = None, secret_binding_id: str | None = None) -> dict[str, Any]:
390
+ return self._client.request("GET", f"/computers/{_seg(computer_id)}/agent/models", params=_params(provider=provider, secret_binding_id=secret_binding_id))
391
+
392
+ def agent_result(self, computer_id: str, conversation_id: str, *, wait: bool = False) -> dict[str, Any]:
393
+ return self._client.request("GET", f"/computers/{_seg(computer_id)}/agent/conversations/{_seg(conversation_id)}/result", params=_params(wait="1" if wait else None))
394
+
395
+ def agent_turns(self, computer_id: str, *, limit: int | None = None) -> list[dict[str, Any]]:
396
+ return self._client.request("GET", f"/computers/{_seg(computer_id)}/agent/turns", params=_params(limit=limit))["turns"]
397
+
398
+ def agent_fanouts(self, computer_id: str) -> list[dict[str, Any]]:
399
+ return self._client.request("GET", f"/computers/{_seg(computer_id)}/agent/fanouts")["fanouts"]
400
+
401
+ def agent_fanout(self, computer_id: str, fanout_id: str) -> dict[str, Any]:
402
+ return self._client.request("GET", f"/computers/{_seg(computer_id)}/agent/fanouts/{_seg(fanout_id)}")
403
+
404
+ def keep_agent_fork(self, computer_id: str, fanout_id: str, fork_computer_id: str) -> dict[str, Any]:
405
+ return self._client.request("POST", f"/computers/{_seg(computer_id)}/agent/fanouts/{_seg(fanout_id)}/keep", json={"computer_id": fork_computer_id})
373
406
 
374
407
  def agent_conversations(self, computer_id: str) -> list[dict[str, Any]]:
375
408
  return self._client.request("GET", f"/computers/{_seg(computer_id)}/agent/conversations")["conversations"]
@@ -835,9 +868,33 @@ class Computer:
835
868
  def revoke_ssh_tokens(self) -> None:
836
869
  self._client.revoke_ssh_tokens(self.id)
837
870
 
838
- def prompt_agent(self, prompt: str, **options: Any) -> dict[str, Any]:
871
+ def prompt_agent(self, prompt: str | None = None, **options: Any) -> dict[str, Any]:
839
872
  return self._client.prompt_agent(self.id, prompt, **options)
840
873
 
874
+ def attach_agent_file(self, local_path: str) -> str:
875
+ return self._client.attach_agent_file(self.id, local_path)
876
+
877
+ def agent_providers(self, *, refresh: bool = False) -> list[dict[str, Any]]:
878
+ return self._client.agent_providers(self.id, refresh=refresh)
879
+
880
+ def agent_models(self, *, provider: str | None = None, secret_binding_id: str | None = None) -> dict[str, Any]:
881
+ return self._client.agent_models(self.id, provider=provider, secret_binding_id=secret_binding_id)
882
+
883
+ def agent_result(self, conversation_id: str, *, wait: bool = False) -> dict[str, Any]:
884
+ return self._client.agent_result(self.id, conversation_id, wait=wait)
885
+
886
+ def agent_turns(self, *, limit: int | None = None) -> list[dict[str, Any]]:
887
+ return self._client.agent_turns(self.id, limit=limit)
888
+
889
+ def agent_fanouts(self) -> list[dict[str, Any]]:
890
+ return self._client.agent_fanouts(self.id)
891
+
892
+ def agent_fanout(self, fanout_id: str) -> dict[str, Any]:
893
+ return self._client.agent_fanout(self.id, fanout_id)
894
+
895
+ def keep_agent_fork(self, fanout_id: str, fork_computer_id: str) -> dict[str, Any]:
896
+ return self._client.keep_agent_fork(self.id, fanout_id, fork_computer_id)
897
+
841
898
  def agent_conversations(self) -> list[dict[str, Any]]:
842
899
  return self._client.agent_conversations(self.id)
843
900
 
@@ -0,0 +1,181 @@
1
+ from __future__ import annotations
2
+
3
+ import json
4
+ import time
5
+ from typing import Any
6
+ from urllib.parse import quote
7
+
8
+ from .mail_events_webhooks import verify_webhook_signature
9
+
10
+
11
+ class EventSignatureError(ValueError):
12
+ def __init__(self, code: str, message: str) -> None:
13
+ super().__init__(message)
14
+ self.code = code
15
+
16
+
17
+ def verify_event(
18
+ *,
19
+ raw_body: bytes | str,
20
+ signature_header: str | None,
21
+ secret: str,
22
+ tolerance_seconds: int = 300,
23
+ timestamp: int | None = None,
24
+ now: int | None = None,
25
+ ) -> dict[str, Any]:
26
+ if not signature_header:
27
+ raise EventSignatureError("missing_signature", "The StackShift-Signature header is missing.")
28
+ signed_at = timestamp if timestamp is not None else _signed_timestamp(signature_header)
29
+ if signed_at is None:
30
+ raise EventSignatureError("invalid_signature", "The StackShift-Signature header has no timestamp.")
31
+ matches = verify_webhook_signature(
32
+ raw_body=raw_body,
33
+ signature_header=signature_header,
34
+ timestamp_header=str(signed_at),
35
+ secret=secret,
36
+ tolerance_seconds=2**62,
37
+ )
38
+ if not matches:
39
+ raise EventSignatureError("invalid_signature", "The StackShift-Signature header does not match the body.")
40
+ current = int(time.time()) if now is None else int(now)
41
+ if tolerance_seconds > 0 and abs(current - signed_at) > tolerance_seconds:
42
+ raise EventSignatureError("expired", "The StackShift-Signature timestamp is outside the allowed tolerance.")
43
+ try:
44
+ return json.loads(raw_body)
45
+ except ValueError as error:
46
+ raise EventSignatureError("invalid_body", "The event body is not valid JSON.") from error
47
+
48
+
49
+ def _signed_timestamp(header: str) -> int | None:
50
+ for part in header.split(","):
51
+ key, _, value = part.strip().partition("=")
52
+ if key == "t":
53
+ try:
54
+ return int(value)
55
+ except ValueError:
56
+ return None
57
+ return None
58
+
59
+
60
+ def _clean(params: dict[str, Any]) -> dict[str, Any]:
61
+ return {key: value for key, value in params.items() if value not in (None, "")}
62
+
63
+
64
+ def _id(value: str) -> str:
65
+ return quote(value, safe="")
66
+
67
+
68
+ class EventsClient:
69
+ def __init__(self, client: Any) -> None:
70
+ self._client = client
71
+
72
+ def verify(
73
+ self,
74
+ *,
75
+ raw_body: bytes | str,
76
+ signature_header: str | None,
77
+ secret: str,
78
+ tolerance_seconds: int = 300,
79
+ timestamp: int | None = None,
80
+ now: int | None = None,
81
+ ) -> dict[str, Any]:
82
+ return verify_event(
83
+ raw_body=raw_body,
84
+ signature_header=signature_header,
85
+ secret=secret,
86
+ tolerance_seconds=tolerance_seconds,
87
+ timestamp=timestamp,
88
+ now=now,
89
+ )
90
+
91
+ def catalog(self) -> dict[str, Any]:
92
+ return self._client.request("GET", "/events/catalog")
93
+
94
+ def list(
95
+ self,
96
+ *,
97
+ type: str | None = None,
98
+ product: str | None = None,
99
+ project_id: str | None = None,
100
+ since: str | None = None,
101
+ cursor: str | None = None,
102
+ limit: int | None = None,
103
+ team_id: str | None = None,
104
+ ) -> dict[str, Any]:
105
+ params = _clean({"type": type, "product": product, "project_id": project_id, "since": since, "cursor": cursor, "limit": limit, "team_id": team_id})
106
+ return self._client.request("GET", "/events", params=params)
107
+
108
+ def get(self, event_id: str) -> dict[str, Any]:
109
+ return self._client.request("GET", f"/events/{_id(event_id)}")
110
+
111
+ def create_subscription(self, **body: Any) -> dict[str, Any]:
112
+ return self._client.request("POST", "/events/subscriptions", json=_clean(body))
113
+
114
+ def list_subscriptions(self, *, team_id: str | None = None, project_id: str | None = None) -> dict[str, Any]:
115
+ return self._client.request("GET", "/events/subscriptions", params=_clean({"team_id": team_id, "project_id": project_id}))
116
+
117
+ def get_subscription(self, subscription_id: str) -> dict[str, Any]:
118
+ return self._client.request("GET", f"/events/subscriptions/{_id(subscription_id)}")
119
+
120
+ def update_subscription(self, subscription_id: str, **body: Any) -> dict[str, Any]:
121
+ return self._client.request("PATCH", f"/events/subscriptions/{_id(subscription_id)}", json=_clean(body))
122
+
123
+ def delete_subscription(self, subscription_id: str) -> None:
124
+ return self._client.request("DELETE", f"/events/subscriptions/{_id(subscription_id)}")
125
+
126
+ def rotate_subscription_secret(self, subscription_id: str) -> dict[str, Any]:
127
+ return self._client.request("POST", f"/events/subscriptions/{_id(subscription_id)}/rotate-secret")
128
+
129
+ def test_subscription(self, subscription_id: str) -> dict[str, Any]:
130
+ return self._client.request("POST", f"/events/subscriptions/{_id(subscription_id)}/test")
131
+
132
+ def create_rule(self, **body: Any) -> dict[str, Any]:
133
+ return self._client.request("POST", "/events/rules", json=_clean(body))
134
+
135
+ def list_rules(self, *, team_id: str | None = None, project_id: str | None = None) -> dict[str, Any]:
136
+ return self._client.request("GET", "/events/rules", params=_clean({"team_id": team_id, "project_id": project_id}))
137
+
138
+ def get_rule(self, rule_id: str) -> dict[str, Any]:
139
+ return self._client.request("GET", f"/events/rules/{_id(rule_id)}")
140
+
141
+ def update_rule(self, rule_id: str, **body: Any) -> dict[str, Any]:
142
+ return self._client.request("PATCH", f"/events/rules/{_id(rule_id)}", json=_clean(body))
143
+
144
+ def delete_rule(self, rule_id: str) -> None:
145
+ return self._client.request("DELETE", f"/events/rules/{_id(rule_id)}")
146
+
147
+ def preview_rule(self, **body: Any) -> dict[str, Any]:
148
+ return self._client.request("POST", "/events/rules/preview", json=_clean(body))
149
+
150
+ def test_rule(self, rule_id: str) -> dict[str, Any]:
151
+ return self._client.request("POST", f"/events/rules/{_id(rule_id)}/test")
152
+
153
+ def list_deliveries(
154
+ self,
155
+ *,
156
+ status: str | None = None,
157
+ dead_letter: bool | None = None,
158
+ subscription_id: str | None = None,
159
+ rule_id: str | None = None,
160
+ event_id: str | None = None,
161
+ team_id: str | None = None,
162
+ cursor: str | None = None,
163
+ limit: int | None = None,
164
+ ) -> dict[str, Any]:
165
+ params = _clean({
166
+ "status": status,
167
+ "dead_letter": None if dead_letter is None else str(dead_letter).lower(),
168
+ "subscription_id": subscription_id,
169
+ "rule_id": rule_id,
170
+ "event_id": event_id,
171
+ "team_id": team_id,
172
+ "cursor": cursor,
173
+ "limit": limit,
174
+ })
175
+ return self._client.request("GET", "/events/deliveries", params=params)
176
+
177
+ def get_delivery(self, delivery_id: str) -> dict[str, Any]:
178
+ return self._client.request("GET", f"/events/deliveries/{_id(delivery_id)}")
179
+
180
+ def replay_delivery(self, delivery_id: str) -> dict[str, Any]:
181
+ return self._client.request("POST", f"/events/deliveries/{_id(delivery_id)}/replay")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: stackshift
3
- Version: 1.8.0
3
+ Version: 1.10.0
4
4
  Summary: Official Python SDK for StackShift.
5
5
  Author-email: StackShift <support@stackshift.cloud>
6
6
  Project-URL: Homepage, https://stackshift.cloud
@@ -51,6 +51,8 @@ computer.files.remove("app/tmp", recursive=True)
51
51
 
52
52
  `upload_dir` skips `.gitignore`d files in a git folder unless you pass `include_ignored=True`, and keeps modes, symlinks and modification times.
53
53
 
54
+ `computers.ensure_project()` returns the project computers go in (`id`, `name`, `created`), making one named "Computers" if the account has none; it needs a user token.
55
+
54
56
  Pick `vcpus` and `memory_gb` from the template's sizes (`templates()` lists them), for example 2 vCPU / 8 GB or 4 vCPU / 16 GB. `region` picks where it starts; `computers.regions(project_id)` lists the regions open now.
55
57
 
56
58
  Tell people what an agent is doing. The dashboard shows the task and next step beside the screen, and `ask_owner` carries the next step on its card.
@@ -181,6 +183,22 @@ computer.agent_conversations()
181
183
  computer.agent_events(conversation["id"], after_seq=10, limit=50)
182
184
  ```
183
185
 
186
+ Providers are `COMPUTER_AGENT_PROVIDERS` (`claude`, `codex`, `gemini`, `opencode`, `cursor`, `copilot`, `amp`, `qwen`). Attach files, read the result, and try one task several ways:
187
+
188
+ ```python
189
+ computer.agent_providers()
190
+ computer.agent_models(provider="claude")
191
+ spec = computer.attach_agent_file("./spec.md")
192
+ conversation = computer.prompt_agent("fix the failing tests", provider="claude", attachments=[spec])
193
+ computer.agent_result(conversation["id"], wait=True)
194
+ computer.agent_turns(limit=20)
195
+
196
+ fanout = computer.prompt_agent(prompts=["fix it with a retry", "fix it with a lock"], provider="codex")
197
+ done = computer.agent_fanout(fanout["id"])
198
+ computer.keep_agent_fork(fanout["id"], done["forks"][0]["computer_id"])
199
+ computer.agent_fanouts()
200
+ ```
201
+
184
202
  `computers.keys.create(project_id, name, scopes=["computers:read"])` limits a key to `computers:read`, `computers:write`, `computers:use` or `computers:delete`. A stuck large upload resumes with `computers.resume_upload(computer_id, transfer_id, upload_id, part_md5)`.
185
203
 
186
204
  An agent can get its own key without any existing key. The functions below send no `Authorization` header:
@@ -350,6 +368,26 @@ valid = stackshift.mail.webhooks.verify_signature(
350
368
 
351
369
  Webhook handlers should be idempotent. StackShift retries non-2xx responses. Delivery events do not include full email bodies or OTP codes by default.
352
370
 
371
+ ## Platform events
372
+
373
+ Every StackShift event reaches your endpoint signed with `StackShift-Signature`. `events.verify` checks the signature in constant time, refuses timestamps older than five minutes (`tolerance_seconds` changes that) and returns the parsed event. Failures raise `EventSignatureError` with a `code` of `missing_signature`, `invalid_signature`, `expired` or `invalid_body`:
374
+
375
+ ```python
376
+ from stackshift import EventSignatureError
377
+
378
+ try:
379
+ event = stackshift.events.verify(
380
+ raw_body=request.get_data(),
381
+ signature_header=request.headers.get("StackShift-Signature"),
382
+ secret=os.environ["STACKSHIFT_WEBHOOK_SECRET"],
383
+ )
384
+ except EventSignatureError as error:
385
+ return error.code, 400
386
+ print(event["type"], event["subject"]["id"])
387
+ ```
388
+
389
+ `events` also wraps the API: `catalog`, `list`, `get`, `create_subscription`, `list_subscriptions`, `update_subscription`, `delete_subscription`, `create_rule`, `list_rules`, `update_rule`, `delete_rule`, `preview_rule`, `test_rule`, `list_deliveries` and `replay_delivery`.
390
+
353
391
  ## Mailboxes
354
392
 
355
393
  Host real mailboxes on your own domain. The mailbox owner gets an invitation by email and sets their own password.
@@ -7,13 +7,14 @@ stackshift/assets.py
7
7
  stackshift/assets_dam.py
8
8
  stackshift/assets_media.py
9
9
  stackshift/assets_platform.py
10
+ stackshift/assets_transforms.py
10
11
  stackshift/assets_video.py
11
- stackshift/assets_workflows.py
12
12
  stackshift/client.py
13
13
  stackshift/computers.py
14
14
  stackshift/computers_adapters.py
15
15
  stackshift/computers_transfer.py
16
16
  stackshift/databases.py
17
+ stackshift/events.py
17
18
  stackshift/hosted_agents.py
18
19
  stackshift/mail.py
19
20
  stackshift/mail_advanced.py
@@ -50,12 +51,14 @@ tests/test_agents.py
50
51
  tests/test_ai_credits.py
51
52
  tests/test_assets_media.py
52
53
  tests/test_assets_platform.py
53
- tests/test_assets_workflows.py
54
+ tests/test_assets_transforms.py
54
55
  tests/test_computers.py
55
56
  tests/test_computers_adapters.py
57
+ tests/test_computers_agent.py
56
58
  tests/test_computers_controls.py
57
59
  tests/test_computers_routes.py
58
60
  tests/test_databases.py
61
+ tests/test_events.py
59
62
  tests/test_hosted_agents.py
60
63
  tests/test_mail.py
61
64
  tests/test_mail_advanced.py
@@ -10,7 +10,7 @@ class FakeClient:
10
10
  return {"method": method, "path": path}
11
11
 
12
12
 
13
- def test_transform_generation_and_workflow_routes():
13
+ def test_transform_and_generation_routes():
14
14
  transport = FakeClient()
15
15
  assets = AssetsClient(transport)
16
16
 
@@ -44,8 +44,3 @@ def test_transform_generation_and_workflow_routes():
44
44
  idempotency_key="generation-1",
45
45
  )
46
46
  assert transport.calls[-1][2]["headers"]["Idempotency-Key"] == "generation-1"
47
-
48
- assets.publish_workflow("workflow/1", 4)
49
- method, path, options = transport.calls[-1]
50
- assert (method, path) == ("POST", "/assets/workflows/workflow%2F1/publish")
51
- assert options["json"] == {"expected_revision": 4}