bazaar-compute-node 0.1.3__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.
- bazaar_compute_node/__init__.py +3 -0
- bazaar_compute_node/app/__init__.py +1 -0
- bazaar_compute_node/app/application.py +398 -0
- bazaar_compute_node/app/attachments.py +154 -0
- bazaar_compute_node/app/command.py +342 -0
- bazaar_compute_node/app/config.py +121 -0
- bazaar_compute_node/app/registry.py +120 -0
- bazaar_compute_node/app/transport.py +264 -0
- bazaar_compute_node/app/windows_pipe.py +463 -0
- bazaar_compute_node/app/wrapper.py +63 -0
- bazaar_compute_node/bcc.py +524 -0
- bazaar_compute_node/cli.py +382 -0
- bazaar_compute_node/contrib/__init__.py +1 -0
- bazaar_compute_node/contrib/codex_app_server/__init__.py +63 -0
- bazaar_compute_node/contrib/codex_app_server/approval.py +168 -0
- bazaar_compute_node/contrib/codex_app_server/client.py +408 -0
- bazaar_compute_node/contrib/codex_app_server/events.py +431 -0
- bazaar_compute_node/contrib/codex_app_server/plugin.py +15 -0
- bazaar_compute_node/contrib/codex_app_server/process.py +583 -0
- bazaar_compute_node/contrib/codex_app_server/protocol.py +103 -0
- bazaar_compute_node/contrib/codex_app_server/runtime.py +513 -0
- bazaar_compute_node/contrib/logging/__init__.py +5 -0
- bazaar_compute_node/contrib/logging/audit.py +61 -0
- bazaar_compute_node/contrib/logging/plugin.py +11 -0
- bazaar_compute_node/contrib/sqlite/__init__.py +14 -0
- bazaar_compute_node/contrib/sqlite/codec.py +768 -0
- bazaar_compute_node/contrib/sqlite/database.py +282 -0
- bazaar_compute_node/contrib/sqlite/migrations.py +646 -0
- bazaar_compute_node/contrib/sqlite/plugin.py +11 -0
- bazaar_compute_node/contrib/sqlite/repository.py +1059 -0
- bazaar_compute_node/contrib/wecom/__init__.py +1 -0
- bazaar_compute_node/contrib/wecom/channel.py +960 -0
- bazaar_compute_node/contrib/wecom/markdown.py +146 -0
- bazaar_compute_node/contrib/wecom/plugin.py +29 -0
- bazaar_compute_node/core/__init__.py +5 -0
- bazaar_compute_node/core/approval.py +51 -0
- bazaar_compute_node/core/audit.py +101 -0
- bazaar_compute_node/core/channel.py +121 -0
- bazaar_compute_node/core/client.py +30 -0
- bazaar_compute_node/core/command.py +85 -0
- bazaar_compute_node/core/concurrency.py +29 -0
- bazaar_compute_node/core/correlation.py +48 -0
- bazaar_compute_node/core/instruction.py +224 -0
- bazaar_compute_node/core/lifecycle.py +48 -0
- bazaar_compute_node/core/models/__init__.py +63 -0
- bazaar_compute_node/core/models/entities.py +514 -0
- bazaar_compute_node/core/models/states.py +369 -0
- bazaar_compute_node/core/observability.py +47 -0
- bazaar_compute_node/core/orchestration/__init__.py +5 -0
- bazaar_compute_node/core/orchestration/command.py +614 -0
- bazaar_compute_node/core/orchestration/services.py +135 -0
- bazaar_compute_node/core/orchestration/session.py +891 -0
- bazaar_compute_node/core/orchestration/turn.py +451 -0
- bazaar_compute_node/core/outcomes.py +51 -0
- bazaar_compute_node/core/paths.py +19 -0
- bazaar_compute_node/core/runtime.py +118 -0
- bazaar_compute_node/core/storage.py +167 -0
- bazaar_compute_node-0.1.3.dist-info/METADATA +178 -0
- bazaar_compute_node-0.1.3.dist-info/RECORD +62 -0
- bazaar_compute_node-0.1.3.dist-info/WHEEL +4 -0
- bazaar_compute_node-0.1.3.dist-info/entry_points.txt +15 -0
- bazaar_compute_node-0.1.3.dist-info/licenses/LICENSE +613 -0
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from collections.abc import Callable, Mapping
|
|
4
|
+
|
|
5
|
+
from ..audit import AuditEvent, ErrorKind
|
|
6
|
+
from ..command import SessionNotFoundError
|
|
7
|
+
from ..concurrency import ISessionConcurrency
|
|
8
|
+
from ..correlation import CorrelationContext
|
|
9
|
+
from ..lifecycle import TimeoutBudget
|
|
10
|
+
from ..models import (
|
|
11
|
+
AgentState,
|
|
12
|
+
AgentTick,
|
|
13
|
+
RuntimeEventState,
|
|
14
|
+
reduce_agent_tick,
|
|
15
|
+
)
|
|
16
|
+
from ..observability import IAudit, LogLevel
|
|
17
|
+
from ..storage import IStorage
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class SessionAuditRecorder:
|
|
21
|
+
"""Write sanitized session audit events with one shared policy."""
|
|
22
|
+
|
|
23
|
+
_FORBIDDEN_TOOL_ARGUMENTS = frozenset(
|
|
24
|
+
{
|
|
25
|
+
"access_token",
|
|
26
|
+
"api_key",
|
|
27
|
+
"authorization",
|
|
28
|
+
"body",
|
|
29
|
+
"cookie",
|
|
30
|
+
"credential",
|
|
31
|
+
"payload",
|
|
32
|
+
"raw_payload",
|
|
33
|
+
"secret",
|
|
34
|
+
"token",
|
|
35
|
+
}
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
def __init__(
|
|
39
|
+
self,
|
|
40
|
+
*,
|
|
41
|
+
sink: IAudit,
|
|
42
|
+
timeout_budget: TimeoutBudget,
|
|
43
|
+
clock: Callable[[], int],
|
|
44
|
+
) -> None:
|
|
45
|
+
self._sink = sink
|
|
46
|
+
self._timeout_budget = timeout_budget
|
|
47
|
+
self._clock = clock
|
|
48
|
+
|
|
49
|
+
async def append(
|
|
50
|
+
self,
|
|
51
|
+
*,
|
|
52
|
+
event_name: str,
|
|
53
|
+
state: RuntimeEventState,
|
|
54
|
+
correlation: CorrelationContext,
|
|
55
|
+
error_kind: ErrorKind | None = None,
|
|
56
|
+
error_message: str | None = None,
|
|
57
|
+
metadata: Mapping[str, object] | None = None,
|
|
58
|
+
) -> None:
|
|
59
|
+
await self._sink.append(
|
|
60
|
+
AuditEvent(
|
|
61
|
+
event_name=event_name,
|
|
62
|
+
state=state,
|
|
63
|
+
created_at_ms=self._clock(),
|
|
64
|
+
correlation=correlation,
|
|
65
|
+
level=LogLevel.ERROR if error_kind else LogLevel.INFO,
|
|
66
|
+
error_kind=error_kind,
|
|
67
|
+
error_message=error_message,
|
|
68
|
+
metadata=metadata or {},
|
|
69
|
+
),
|
|
70
|
+
timeout=self._timeout_budget.command_seconds,
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
async def append_tool(
|
|
74
|
+
self,
|
|
75
|
+
*,
|
|
76
|
+
operation: str,
|
|
77
|
+
status: str,
|
|
78
|
+
state: RuntimeEventState,
|
|
79
|
+
correlation: CorrelationContext,
|
|
80
|
+
arguments: Mapping[str, object],
|
|
81
|
+
error_kind: ErrorKind | None = None,
|
|
82
|
+
error_message: str | None = None,
|
|
83
|
+
) -> None:
|
|
84
|
+
safe_arguments = {
|
|
85
|
+
key: value
|
|
86
|
+
for key, value in arguments.items()
|
|
87
|
+
if key.casefold() not in self._FORBIDDEN_TOOL_ARGUMENTS
|
|
88
|
+
}
|
|
89
|
+
await self.append(
|
|
90
|
+
event_name=f"tool.{operation}.{status}",
|
|
91
|
+
state=state,
|
|
92
|
+
correlation=correlation,
|
|
93
|
+
error_kind=error_kind,
|
|
94
|
+
error_message=error_message,
|
|
95
|
+
metadata={
|
|
96
|
+
"kind": "tool_call",
|
|
97
|
+
"operation": operation,
|
|
98
|
+
"status": status,
|
|
99
|
+
"arguments": safe_arguments,
|
|
100
|
+
},
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
class SessionStateWriter:
|
|
105
|
+
"""Serialize ticks against the process-local AgentState source of truth."""
|
|
106
|
+
|
|
107
|
+
def __init__(
|
|
108
|
+
self,
|
|
109
|
+
*,
|
|
110
|
+
storage: IStorage,
|
|
111
|
+
concurrency: ISessionConcurrency,
|
|
112
|
+
states: dict[str, AgentState],
|
|
113
|
+
) -> None:
|
|
114
|
+
self._storage = storage
|
|
115
|
+
self._concurrency = concurrency
|
|
116
|
+
self._states = states
|
|
117
|
+
|
|
118
|
+
def get(self, session_id: str) -> AgentState:
|
|
119
|
+
return self._states.get(session_id, AgentState.CREATED)
|
|
120
|
+
|
|
121
|
+
async def apply(self, session_id: str, tick: AgentTick) -> AgentState:
|
|
122
|
+
async with self._concurrency.for_session(session_id):
|
|
123
|
+
return await self.apply_locked(session_id, tick)
|
|
124
|
+
|
|
125
|
+
async def apply_locked(self, session_id: str, tick: AgentTick) -> AgentState:
|
|
126
|
+
async with self._storage.transaction() as transaction:
|
|
127
|
+
bcn_session = await transaction.get_bcn_session(session_id)
|
|
128
|
+
if bcn_session is None:
|
|
129
|
+
raise SessionNotFoundError(f"unknown bcn session: {session_id}")
|
|
130
|
+
return self.apply_observation(bcn_session.id, tick)
|
|
131
|
+
|
|
132
|
+
def apply_observation(self, session_id: str, tick: AgentTick) -> AgentState:
|
|
133
|
+
updated = reduce_agent_tick(self.get(session_id), tick)
|
|
134
|
+
self._states[session_id] = updated
|
|
135
|
+
return updated
|