patchr 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.
Files changed (116) hide show
  1. apps/__init__.py +2 -0
  2. apps/api/__init__.py +2 -0
  3. apps/api/main.py +652 -0
  4. apps/benchmarks/__init__.py +1 -0
  5. apps/benchmarks/main.py +20 -0
  6. apps/sandbox/__init__.py +1 -0
  7. apps/sandbox/main.py +20 -0
  8. apps/worker/__init__.py +2 -0
  9. apps/worker/main.py +15 -0
  10. apps/worker/verify.py +14 -0
  11. patchr/__init__.py +12 -0
  12. patchr/sdk/__init__.py +20 -0
  13. patchr/sdk/client.py +12 -0
  14. patchr-0.1.0.dist-info/METADATA +137 -0
  15. patchr-0.1.0.dist-info/RECORD +116 -0
  16. patchr-0.1.0.dist-info/WHEEL +5 -0
  17. patchr-0.1.0.dist-info/entry_points.txt +5 -0
  18. patchr-0.1.0.dist-info/licenses/LICENSE +17 -0
  19. patchr-0.1.0.dist-info/top_level.txt +3 -0
  20. picux/__init__.py +6 -0
  21. picux/agents/__init__.py +5 -0
  22. picux/agents/registry.py +204 -0
  23. picux/api/__init__.py +5 -0
  24. picux/api/service.py +5075 -0
  25. picux/audit/__init__.py +31 -0
  26. picux/audit/activity.py +97 -0
  27. picux/audit/observability.py +55 -0
  28. picux/audit/verification/__init__.py +21 -0
  29. picux/audit/verification/ledger.py +633 -0
  30. picux/benchmarks/__init__.py +5 -0
  31. picux/benchmarks/local.py +286 -0
  32. picux/config.py +140 -0
  33. picux/contracts/__init__.py +22 -0
  34. picux/contracts/handshake.py +122 -0
  35. picux/contracts/integration.py +385 -0
  36. picux/contracts/openapi.py +187 -0
  37. picux/contracts/protocol_map.py +152 -0
  38. picux/contracts/routes.py +980 -0
  39. picux/contracts/schema_catalog.py +125 -0
  40. picux/core/__init__.py +17 -0
  41. picux/core/models.py +148 -0
  42. picux/core/router.py +131 -0
  43. picux/core/runtime.py +42 -0
  44. picux/core/state_machine.py +38 -0
  45. picux/domains/__init__.py +2 -0
  46. picux/domains/bridge/HostRun.py +1104 -0
  47. picux/domains/bridge/__init__.py +6 -0
  48. picux/domains/bridge/engine.py +345 -0
  49. picux/domains/hunt/__init__.py +6 -0
  50. picux/domains/hunt/engine.py +307 -0
  51. picux/domains/hunt/models.py +88 -0
  52. picux/domains/pay/__init__.py +16 -0
  53. picux/domains/pay/adapters.py +607 -0
  54. picux/domains/pay/engine.py +950 -0
  55. picux/domains/pay/models.py +95 -0
  56. picux/domains/proxy/__init__.py +5 -0
  57. picux/domains/proxy/engine.py +466 -0
  58. picux/domains/resolve/__init__.py +5 -0
  59. picux/domains/resolve/engine.py +546 -0
  60. picux/orchestrator/__init__.py +3 -0
  61. picux/orchestrator/engine.py +2840 -0
  62. picux/portals/__init__.py +17 -0
  63. picux/portals/templates.py +272 -0
  64. picux/protocols/__init__.py +1 -0
  65. picux/protocols/a2a/__init__.py +6 -0
  66. picux/protocols/a2a/client.py +51 -0
  67. picux/protocols/a2a/envelope.py +132 -0
  68. picux/protocols/mcp/__init__.py +7 -0
  69. picux/protocols/mcp/client.py +69 -0
  70. picux/protocols/mcp/contract.py +67 -0
  71. picux/protocols/mcp/server.py +76 -0
  72. picux/sandbox/__init__.py +6 -0
  73. picux/sandbox/midnight_arbitrage.py +215 -0
  74. picux/sandbox/models.py +90 -0
  75. picux/sdk/__init__.py +13 -0
  76. picux/sdk/client.py +768 -0
  77. picux/sdk/external.py +245 -0
  78. picux/security/__init__.py +18 -0
  79. picux/security/auth.py +86 -0
  80. picux/security/config_validator.py +58 -0
  81. picux/security/policy.py +158 -0
  82. picux/security/secrets.py +144 -0
  83. picux/signals/__init__.py +1 -0
  84. picux/signals/community/__init__.py +24 -0
  85. picux/signals/community/adapters/__init__.py +7 -0
  86. picux/signals/community/adapters/reddit.py +37 -0
  87. picux/signals/community/adapters/shopify.py +23 -0
  88. picux/signals/community/adapters/web.py +23 -0
  89. picux/signals/community/disambiguation.py +51 -0
  90. picux/signals/community/intake.py +227 -0
  91. picux/signals/community/models.py +102 -0
  92. picux/signals/community/rules.py +91 -0
  93. picux/signals/community/scoring.py +64 -0
  94. picux/storage/__init__.py +41 -0
  95. picux/storage/agents.py +50 -0
  96. picux/storage/cases.py +440 -0
  97. picux/storage/channels.py +476 -0
  98. picux/storage/connectors.py +411 -0
  99. picux/storage/envelopes.py +137 -0
  100. picux/storage/escrows.py +168 -0
  101. picux/storage/events.py +989 -0
  102. picux/storage/keyspace.py +60 -0
  103. picux/storage/mandates.py +107 -0
  104. picux/storage/portals.py +222 -0
  105. picux/storage/postgres.py +2049 -0
  106. picux/storage/providers.py +148 -0
  107. picux/storage/proxy.py +231 -0
  108. picux/storage/receipts.py +131 -0
  109. picux/storage/signals.py +147 -0
  110. picux/storage/tasks.py +179 -0
  111. picux/tools/__init__.py +11 -0
  112. picux/tools/shared.py +2048 -0
  113. picux/verification/__init__.py +5 -0
  114. picux/verification/rollout.py +183 -0
  115. picux/workflows/__init__.py +5 -0
  116. picux/workflows/templates.py +74 -0
picux/storage/tasks.py ADDED
@@ -0,0 +1,179 @@
1
+ from __future__ import annotations
2
+
3
+ import copy
4
+ import time
5
+ from dataclasses import replace
6
+ from typing import Any
7
+
8
+ from picux.core import Domain, ProtocolTask, ProtocolTaskStatus
9
+
10
+
11
+ class TaskBook:
12
+ """Protocol task storage with optional durable backing."""
13
+
14
+ def __init__(self, *, backing: Any | None = None) -> None:
15
+ self.backing = backing
16
+ self._tasks: dict[str, ProtocolTask] = {}
17
+
18
+ def saveTask(self, task: ProtocolTask | dict[str, Any]) -> dict[str, Any]:
19
+ item = task if isinstance(task, ProtocolTask) else taskFromObj(task)
20
+ if not item.taskId:
21
+ return {"ok": False, "error": "missing:taskId"}
22
+ self._tasks[item.taskId] = copy.deepcopy(item)
23
+ if self._backingEnabled() and hasattr(self.backing, "upsertTask"):
24
+ self.backing.upsertTask(item)
25
+ return {"ok": True, "taskId": item.taskId}
26
+
27
+ def getTask(self, taskId: str) -> dict[str, Any]:
28
+ taskId = str(taskId or "")
29
+ task = self._tasks.get(taskId)
30
+ if task is None and self._backingEnabled() and hasattr(self.backing, "fetchTask"):
31
+ task = self.backing.fetchTask(taskId)
32
+ if task:
33
+ self._tasks[taskId] = copy.deepcopy(task)
34
+ if task is None:
35
+ return {"ok": False, "error": "taskNotFound", "taskId": taskId}
36
+ return {"ok": True, "task": taskView(task)}
37
+
38
+ def getTaskByConversationId(self, conversationId: str) -> dict[str, Any]:
39
+ conversationId = str(conversationId or "")
40
+ if not conversationId:
41
+ return {"ok": False, "error": "missing:conversationId", "conversationId": ""}
42
+ direct = self.getTask(conversationId)
43
+ if direct.get("ok"):
44
+ return direct
45
+ self._loadBacking()
46
+ matches: list[ProtocolTask] = []
47
+ for task in self._tasks.values():
48
+ meta = task.meta if isinstance(task.meta, dict) else {}
49
+ outData = task.outData if isinstance(task.outData, dict) else {}
50
+ candidates = {
51
+ str(task.taskId or ""),
52
+ str(task.extRef or ""),
53
+ str(meta.get("conversationId", "") or ""),
54
+ str(outData.get("conversationId", "") or ""),
55
+ }
56
+ if conversationId in candidates:
57
+ matches.append(task)
58
+ if not matches:
59
+ return {"ok": False, "error": "conversationNotFound", "conversationId": conversationId}
60
+ matches.sort(key=lambda item: (item.updatedAt, item.createdAt, item.taskId), reverse=True)
61
+ return {"ok": True, "task": taskView(matches[0])}
62
+
63
+ def listTasks(self, filters: dict[str, Any] | None = None) -> dict[str, Any]:
64
+ self._loadBacking()
65
+ filters = filters or {}
66
+ tasks = list(self._tasks.values())
67
+ userId = str(filters.get("userId", "") or "")
68
+ domain = str(filters.get("domain", "") or "").lower()
69
+ status = str(filters.get("status", "") or "").lower()
70
+ channel = str(filters.get("channel", "") or "")
71
+ if userId:
72
+ tasks = [task for task in tasks if task.userId == userId]
73
+ if domain:
74
+ tasks = [task for task in tasks if task.domain.value == domain]
75
+ if status:
76
+ tasks = [task for task in tasks if task.status.value == status]
77
+ if channel:
78
+ tasks = [task for task in tasks if task.channel == channel]
79
+ tasks.sort(key=lambda item: (item.createdAt, item.taskId), reverse=True)
80
+ limit = _limit(filters.get("limit", 100))
81
+ return {"ok": True, "tasks": [taskView(task) for task in tasks[:limit]], "count": min(len(tasks), limit)}
82
+
83
+ def updateTask(self, taskId: str, updates: dict[str, Any]) -> dict[str, Any]:
84
+ current = self.getTask(taskId)
85
+ if not current.get("ok"):
86
+ return current
87
+ task = taskFromObj(current["task"])
88
+ status = str(updates.get("status", task.status.value) or task.status.value)
89
+ domain = str(updates.get("domain", task.domain.value) or task.domain.value)
90
+ nextTask = replace(
91
+ task,
92
+ domain=Domain(domain) if domain in Domain._value2member_map_ else task.domain,
93
+ status=ProtocolTaskStatus(status)
94
+ if status in ProtocolTaskStatus._value2member_map_
95
+ else task.status,
96
+ outData=updates.get("outData", task.outData) if isinstance(updates.get("outData", task.outData), dict) else task.outData,
97
+ meta=updates.get("meta", task.meta) if isinstance(updates.get("meta", task.meta), dict) else task.meta,
98
+ errorMsg=str(updates.get("errorMsg", task.errorMsg) or ""),
99
+ needsApproval=bool(updates.get("needsApproval", task.needsApproval)),
100
+ updatedAt=int(updates.get("updatedAt", int(time.time())) or int(time.time())),
101
+ )
102
+ self.saveTask(nextTask)
103
+ return {"ok": True, "task": taskView(nextTask)}
104
+
105
+ def _loadBacking(self) -> None:
106
+ if self.backing is None or not self._backingEnabled() or not hasattr(self.backing, "listTasks"):
107
+ return
108
+ for item in self.backing.listTasks():
109
+ task = item if isinstance(item, ProtocolTask) else taskFromObj(item)
110
+ if task.taskId:
111
+ self._tasks[task.taskId] = copy.deepcopy(task)
112
+
113
+ def _backingEnabled(self) -> bool:
114
+ if self.backing is None:
115
+ return False
116
+ return bool(getattr(self.backing, "enabled", True))
117
+
118
+
119
+ def taskView(task: ProtocolTask) -> dict[str, Any]:
120
+ return {
121
+ "taskId": task.taskId,
122
+ "userId": task.userId,
123
+ "domain": task.domain.value,
124
+ "status": task.status.value,
125
+ "channel": task.channel,
126
+ "inData": task.inData,
127
+ "outData": task.outData,
128
+ "needsApproval": task.needsApproval,
129
+ "mandateId": task.mandateId,
130
+ "extRef": task.extRef,
131
+ "errorMsg": task.errorMsg,
132
+ "meta": task.meta,
133
+ "createdAt": task.createdAt,
134
+ "updatedAt": task.updatedAt,
135
+ "approvalBy": task.approvalBy,
136
+ }
137
+
138
+
139
+ def taskFromObj(value: dict[str, Any]) -> ProtocolTask:
140
+ domain = str(value.get("domain", Domain.UNKNOWN.value) or Domain.UNKNOWN.value)
141
+ status = str(value.get("status", ProtocolTaskStatus.PENDING.value) or ProtocolTaskStatus.PENDING.value)
142
+ now = int(time.time())
143
+ return ProtocolTask(
144
+ taskId=str(value.get("taskId", "") or ""),
145
+ userId=str(value.get("userId", "api") or "api"),
146
+ domain=Domain(domain) if domain in Domain._value2member_map_ else Domain.UNKNOWN,
147
+ status=ProtocolTaskStatus(status)
148
+ if status in ProtocolTaskStatus._value2member_map_
149
+ else ProtocolTaskStatus.PENDING,
150
+ channel=str(value.get("channel", "api") or "api"),
151
+ inData=value.get("inData", {}) if isinstance(value.get("inData", {}), dict) else {},
152
+ outData=value.get("outData", {}) if isinstance(value.get("outData", {}), dict) else {},
153
+ needsApproval=bool(value.get("needsApproval", False)),
154
+ mandateId=str(value.get("mandateId", "") or ""),
155
+ extRef=str(value.get("extRef", "") or ""),
156
+ errorMsg=str(value.get("errorMsg", "") or ""),
157
+ meta=value.get("meta", {}) if isinstance(value.get("meta", {}), dict) else {},
158
+ createdAt=int(value.get("createdAt", now) or now),
159
+ updatedAt=int(value.get("updatedAt", now) or now),
160
+ approvalBy=_approvalBy(value.get("approvalBy")),
161
+ )
162
+
163
+
164
+ def _approvalBy(value: Any) -> int | None:
165
+ if value in ("", None):
166
+ return None
167
+ try:
168
+ parsed = int(value)
169
+ except (TypeError, ValueError):
170
+ return None
171
+ return parsed or None
172
+
173
+
174
+ def _limit(value: Any) -> int:
175
+ try:
176
+ parsed = int(value)
177
+ except (TypeError, ValueError):
178
+ return 100
179
+ return max(1, min(parsed, 500))
@@ -0,0 +1,11 @@
1
+ from .shared import BrowserCheckout, BrowserReader, ImageReader, MapTool, NLPTool, PortalBrowser, SharedToolbox
2
+
3
+ __all__ = [
4
+ "BrowserCheckout",
5
+ "BrowserReader",
6
+ "ImageReader",
7
+ "MapTool",
8
+ "NLPTool",
9
+ "PortalBrowser",
10
+ "SharedToolbox",
11
+ ]