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.
- apps/__init__.py +2 -0
- apps/api/__init__.py +2 -0
- apps/api/main.py +652 -0
- apps/benchmarks/__init__.py +1 -0
- apps/benchmarks/main.py +20 -0
- apps/sandbox/__init__.py +1 -0
- apps/sandbox/main.py +20 -0
- apps/worker/__init__.py +2 -0
- apps/worker/main.py +15 -0
- apps/worker/verify.py +14 -0
- patchr/__init__.py +12 -0
- patchr/sdk/__init__.py +20 -0
- patchr/sdk/client.py +12 -0
- patchr-0.1.0.dist-info/METADATA +137 -0
- patchr-0.1.0.dist-info/RECORD +116 -0
- patchr-0.1.0.dist-info/WHEEL +5 -0
- patchr-0.1.0.dist-info/entry_points.txt +5 -0
- patchr-0.1.0.dist-info/licenses/LICENSE +17 -0
- patchr-0.1.0.dist-info/top_level.txt +3 -0
- picux/__init__.py +6 -0
- picux/agents/__init__.py +5 -0
- picux/agents/registry.py +204 -0
- picux/api/__init__.py +5 -0
- picux/api/service.py +5075 -0
- picux/audit/__init__.py +31 -0
- picux/audit/activity.py +97 -0
- picux/audit/observability.py +55 -0
- picux/audit/verification/__init__.py +21 -0
- picux/audit/verification/ledger.py +633 -0
- picux/benchmarks/__init__.py +5 -0
- picux/benchmarks/local.py +286 -0
- picux/config.py +140 -0
- picux/contracts/__init__.py +22 -0
- picux/contracts/handshake.py +122 -0
- picux/contracts/integration.py +385 -0
- picux/contracts/openapi.py +187 -0
- picux/contracts/protocol_map.py +152 -0
- picux/contracts/routes.py +980 -0
- picux/contracts/schema_catalog.py +125 -0
- picux/core/__init__.py +17 -0
- picux/core/models.py +148 -0
- picux/core/router.py +131 -0
- picux/core/runtime.py +42 -0
- picux/core/state_machine.py +38 -0
- picux/domains/__init__.py +2 -0
- picux/domains/bridge/HostRun.py +1104 -0
- picux/domains/bridge/__init__.py +6 -0
- picux/domains/bridge/engine.py +345 -0
- picux/domains/hunt/__init__.py +6 -0
- picux/domains/hunt/engine.py +307 -0
- picux/domains/hunt/models.py +88 -0
- picux/domains/pay/__init__.py +16 -0
- picux/domains/pay/adapters.py +607 -0
- picux/domains/pay/engine.py +950 -0
- picux/domains/pay/models.py +95 -0
- picux/domains/proxy/__init__.py +5 -0
- picux/domains/proxy/engine.py +466 -0
- picux/domains/resolve/__init__.py +5 -0
- picux/domains/resolve/engine.py +546 -0
- picux/orchestrator/__init__.py +3 -0
- picux/orchestrator/engine.py +2840 -0
- picux/portals/__init__.py +17 -0
- picux/portals/templates.py +272 -0
- picux/protocols/__init__.py +1 -0
- picux/protocols/a2a/__init__.py +6 -0
- picux/protocols/a2a/client.py +51 -0
- picux/protocols/a2a/envelope.py +132 -0
- picux/protocols/mcp/__init__.py +7 -0
- picux/protocols/mcp/client.py +69 -0
- picux/protocols/mcp/contract.py +67 -0
- picux/protocols/mcp/server.py +76 -0
- picux/sandbox/__init__.py +6 -0
- picux/sandbox/midnight_arbitrage.py +215 -0
- picux/sandbox/models.py +90 -0
- picux/sdk/__init__.py +13 -0
- picux/sdk/client.py +768 -0
- picux/sdk/external.py +245 -0
- picux/security/__init__.py +18 -0
- picux/security/auth.py +86 -0
- picux/security/config_validator.py +58 -0
- picux/security/policy.py +158 -0
- picux/security/secrets.py +144 -0
- picux/signals/__init__.py +1 -0
- picux/signals/community/__init__.py +24 -0
- picux/signals/community/adapters/__init__.py +7 -0
- picux/signals/community/adapters/reddit.py +37 -0
- picux/signals/community/adapters/shopify.py +23 -0
- picux/signals/community/adapters/web.py +23 -0
- picux/signals/community/disambiguation.py +51 -0
- picux/signals/community/intake.py +227 -0
- picux/signals/community/models.py +102 -0
- picux/signals/community/rules.py +91 -0
- picux/signals/community/scoring.py +64 -0
- picux/storage/__init__.py +41 -0
- picux/storage/agents.py +50 -0
- picux/storage/cases.py +440 -0
- picux/storage/channels.py +476 -0
- picux/storage/connectors.py +411 -0
- picux/storage/envelopes.py +137 -0
- picux/storage/escrows.py +168 -0
- picux/storage/events.py +989 -0
- picux/storage/keyspace.py +60 -0
- picux/storage/mandates.py +107 -0
- picux/storage/portals.py +222 -0
- picux/storage/postgres.py +2049 -0
- picux/storage/providers.py +148 -0
- picux/storage/proxy.py +231 -0
- picux/storage/receipts.py +131 -0
- picux/storage/signals.py +147 -0
- picux/storage/tasks.py +179 -0
- picux/tools/__init__.py +11 -0
- picux/tools/shared.py +2048 -0
- picux/verification/__init__.py +5 -0
- picux/verification/rollout.py +183 -0
- picux/workflows/__init__.py +5 -0
- 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))
|
picux/tools/__init__.py
ADDED