harness-sdk-python 0.40.4__py3-none-any.whl → 0.40.11__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.
- harness_sdk/deepagents.py +124 -20
- harness_sdk/deepagents_host.py +11 -1
- harness_sdk/run_manager.py +49 -43
- harness_sdk/threads.py +26 -3
- harness_sdk/wire.py +20 -7
- {harness_sdk_python-0.40.4.dist-info → harness_sdk_python-0.40.11.dist-info}/METADATA +2 -2
- {harness_sdk_python-0.40.4.dist-info → harness_sdk_python-0.40.11.dist-info}/RECORD +8 -8
- {harness_sdk_python-0.40.4.dist-info → harness_sdk_python-0.40.11.dist-info}/WHEEL +0 -0
harness_sdk/deepagents.py
CHANGED
|
@@ -7,6 +7,7 @@ namespace on the langgraph thread ``<thread_id>/<ns>``, concurrent with the
|
|
|
7
7
|
main run; its rows persist under ``checkpoint_ns == ns``.
|
|
8
8
|
"""
|
|
9
9
|
|
|
10
|
+
import logging
|
|
10
11
|
from typing import Any, Callable
|
|
11
12
|
|
|
12
13
|
from statepatch import plain
|
|
@@ -22,6 +23,8 @@ from .messages import MAIN_NS, MessageTree
|
|
|
22
23
|
from .parts import PartsAssembler, text_of
|
|
23
24
|
from .voice_thread import upsert_voice_turn
|
|
24
25
|
|
|
26
|
+
logger = logging.getLogger(__name__)
|
|
27
|
+
|
|
25
28
|
_TYPE_TO_ROLE = {"human": "user", "ai": "assistant", "tool": "assistant", "system": "assistant"}
|
|
26
29
|
|
|
27
30
|
|
|
@@ -114,6 +117,7 @@ class DeepagentsThread:
|
|
|
114
117
|
self._touched: set[tuple[str, str]] = set()
|
|
115
118
|
self._subagents: set[str] = set()
|
|
116
119
|
self.interrupt: dict[str, Any] | None = None
|
|
120
|
+
self._raised: dict[Any, str] = {}
|
|
117
121
|
|
|
118
122
|
async def boot(self) -> None:
|
|
119
123
|
"""Hydrate the tree from the index rows and the main branch window from the checkpointer."""
|
|
@@ -165,16 +169,21 @@ class DeepagentsThread:
|
|
|
165
169
|
if ctx.trigger == "input-resume":
|
|
166
170
|
from langgraph.types import Command
|
|
167
171
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
if
|
|
171
|
-
raise KeyError(f"head {thread.head!r} holds no tool part for {
|
|
172
|
-
|
|
172
|
+
requested = [r["toolCallId"] for r, _response, _meta in ctx.input_outcomes]
|
|
173
|
+
path = self._parked_path(MAIN_NS, set(requested))
|
|
174
|
+
if path is None:
|
|
175
|
+
raise KeyError(f"head {thread.head!r} holds no tool part for {requested!r}")
|
|
176
|
+
for ns in path:
|
|
177
|
+
self._mount(ns, self.tree.thread(ns).head)
|
|
173
178
|
if ctx.resume:
|
|
174
179
|
return None, config
|
|
180
|
+
# The middleware reads decisions positionally, in tool_calls order:
|
|
181
|
+
# the parked reply's tool parts carry that order, the outcomes may not.
|
|
182
|
+
order = [p.get("toolInvocationId") for p in plain(self._assemblers[path[-1]].parts)]
|
|
183
|
+
outcomes = sorted(ctx.input_outcomes, key=lambda o: order.index(o[0]["toolCallId"]))
|
|
175
184
|
decisions = [
|
|
176
185
|
{"type": "approve"} if response and response.get("decision") == "approve" else {"type": "reject"}
|
|
177
|
-
for _request, response, _meta in
|
|
186
|
+
for _request, response, _meta in outcomes
|
|
178
187
|
]
|
|
179
188
|
self._admission = ctx.applied()
|
|
180
189
|
return Command(resume={"decisions": decisions}), config
|
|
@@ -199,7 +208,7 @@ class DeepagentsThread:
|
|
|
199
208
|
from langchain_core.messages import HumanMessage
|
|
200
209
|
|
|
201
210
|
turn: list[Any] = [*plan.replay]
|
|
202
|
-
for message in ctx.messages:
|
|
211
|
+
for message in self._without_agent_ids(ctx.messages):
|
|
203
212
|
turn.append(HumanMessage(id=message["id"], content=_user_content(message)))
|
|
204
213
|
self._append_user(message, parent)
|
|
205
214
|
parent = message["id"]
|
|
@@ -218,6 +227,47 @@ class DeepagentsThread:
|
|
|
218
227
|
self._changed()
|
|
219
228
|
return ({"messages": turn} if turn else None), config
|
|
220
229
|
|
|
230
|
+
def _parked_path(self, ns: str, tool_ids: set[str]) -> list[str] | None:
|
|
231
|
+
"""The namespaces from ``ns``'s head down to the reply whose parts pending
|
|
232
|
+
approval hold ``tool_ids``, through the ``task`` parts that link a subagent's thread."""
|
|
233
|
+
parts = plain(self.tree.get(ns, self.tree.thread(ns).head)["parts"])
|
|
234
|
+
if tool_ids <= {p.get("toolInvocationId") for p in parts if p.get("state") == "pendingApproval"}:
|
|
235
|
+
return [ns]
|
|
236
|
+
for part in parts:
|
|
237
|
+
sub = (part.get("metadata") or {}).get("ns") if part["type"] == "tool" else None
|
|
238
|
+
if sub in self.tree.threads:
|
|
239
|
+
path = self._parked_path(sub, tool_ids)
|
|
240
|
+
if path is not None:
|
|
241
|
+
return [ns, *path]
|
|
242
|
+
return None
|
|
243
|
+
|
|
244
|
+
def _agent_ids(self) -> set[str]:
|
|
245
|
+
# user messages mount on the main graph; a subagent runs on its own
|
|
246
|
+
# LangGraph thread, so only main-namespace ids can collide
|
|
247
|
+
main = self.tree.threads.get(MAIN_NS)
|
|
248
|
+
messages = main.messages.values() if main is not None else ()
|
|
249
|
+
return {id for m in messages for id in _provider_ids(m)}
|
|
250
|
+
|
|
251
|
+
def check_user_id(self, message_id: Any) -> None:
|
|
252
|
+
"""Reject a user message id that names a message the agent wrote: the
|
|
253
|
+
harness id becomes the LangChain id, and ``add_messages`` replaces a
|
|
254
|
+
message with the same id. Called per command at intake, so only the
|
|
255
|
+
offending send fails."""
|
|
256
|
+
if isinstance(message_id, str) and message_id in self._agent_ids():
|
|
257
|
+
raise StatewireReject(f"message id {message_id} is already used", payload={"reason": "duplicate-id"})
|
|
258
|
+
|
|
259
|
+
def _without_agent_ids(self, messages: Any) -> list[Any]:
|
|
260
|
+
"""Dispatch-time guard for an id the agent wrote after the send's
|
|
261
|
+
intake check: drop only that message, keep the run and the rest."""
|
|
262
|
+
taken = self._agent_ids()
|
|
263
|
+
kept = []
|
|
264
|
+
for message in messages:
|
|
265
|
+
if message["id"] in taken:
|
|
266
|
+
logger.warning("dropping user message %r: the agent wrote a message with that id", message["id"])
|
|
267
|
+
else:
|
|
268
|
+
kept.append(message)
|
|
269
|
+
return kept
|
|
270
|
+
|
|
221
271
|
def _append_user(self, message: dict[str, Any], parent: str | None) -> None:
|
|
222
272
|
if self.tree.get(MAIN_NS, message["id"]) is not None:
|
|
223
273
|
return
|
|
@@ -236,6 +286,7 @@ class DeepagentsThread:
|
|
|
236
286
|
"""Append steered user messages after the head; returns the langgraph turn entries."""
|
|
237
287
|
from langchain_core.messages import HumanMessage
|
|
238
288
|
|
|
289
|
+
messages = self._without_agent_ids(messages)
|
|
239
290
|
thread = self.tree.thread(MAIN_NS)
|
|
240
291
|
turn = []
|
|
241
292
|
for message in messages:
|
|
@@ -356,14 +407,31 @@ class DeepagentsThread:
|
|
|
356
407
|
assembler.tool_result(message)
|
|
357
408
|
self._changed()
|
|
358
409
|
return
|
|
359
|
-
if mode == "updates" and isinstance(event, dict) and "__interrupt__" in event
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
410
|
+
if mode == "updates" and isinstance(event, dict) and "__interrupt__" in event:
|
|
411
|
+
if ns == MAIN_NS:
|
|
412
|
+
self._park(event["__interrupt__"])
|
|
413
|
+
elif _root_of(ns) not in self._subagents:
|
|
414
|
+
# a subagent's interrupt reaches the main namespace after its own, with the same id
|
|
415
|
+
for interrupt in event["__interrupt__"]:
|
|
416
|
+
self._raised.setdefault(getattr(interrupt, "id", None), ns)
|
|
417
|
+
|
|
418
|
+
def _park(self, interrupts: Any) -> None:
|
|
419
|
+
"""Park the calls ``interrupts`` name, in the namespace that raised them."""
|
|
420
|
+
if self.interrupt is not None:
|
|
421
|
+
raise ValueError("unsupported interrupt: approvals from more than one agent at once")
|
|
422
|
+
namespaces = {self._raised.get(getattr(i, "id", None), MAIN_NS) for i in interrupts} or {MAIN_NS}
|
|
423
|
+
if len(namespaces) > 1:
|
|
424
|
+
raise ValueError(f"unsupported interrupt: approvals from more than one agent at once ({sorted(namespaces)})")
|
|
425
|
+
(ns,) = namespaces
|
|
426
|
+
assembler = self._assemblers.get(ns)
|
|
427
|
+
# no streamed message: still validate, so an unmatched interrupt fails the run
|
|
428
|
+
parts = plain(assembler.parts) if assembler is not None else []
|
|
429
|
+
tool_ids = _pending_tool_ids(parts, interrupts)
|
|
430
|
+
for tool_id in tool_ids:
|
|
431
|
+
assert assembler is not None
|
|
432
|
+
assembler.amend(tool_id, state="pendingApproval")
|
|
433
|
+
self.interrupt = {"toolCallIds": tool_ids}
|
|
434
|
+
self._changed()
|
|
367
435
|
|
|
368
436
|
def _finish(self, ns: str, outcome: dict[str, Any] | None = None) -> None:
|
|
369
437
|
assembler = self._assemblers.pop(ns, None)
|
|
@@ -384,11 +452,12 @@ class DeepagentsThread:
|
|
|
384
452
|
await self._thread.ingest(langgraph_snapshot(captured))
|
|
385
453
|
if self._input_checkpoint_seen:
|
|
386
454
|
self._confirm_admission()
|
|
387
|
-
|
|
388
|
-
|
|
455
|
+
# parked: every open namespace is on the path to the parked call
|
|
456
|
+
if self.interrupt is None:
|
|
457
|
+
for ns in self._turn_namespaces():
|
|
389
458
|
self._finish(ns, outcome)
|
|
390
459
|
for ns in self.tree.threads:
|
|
391
|
-
if ns != MAIN_NS and _root_of(ns) not in self._subagents:
|
|
460
|
+
if ns != MAIN_NS and _root_of(ns) not in self._subagents and ns not in self._assemblers:
|
|
392
461
|
self._thread_state(ns, status="idle")
|
|
393
462
|
await self._persist()
|
|
394
463
|
self._changed()
|
|
@@ -477,11 +546,46 @@ class DeepagentsThread:
|
|
|
477
546
|
self._admission = None
|
|
478
547
|
self._input_checkpoint_seen = False
|
|
479
548
|
self.interrupt = None
|
|
549
|
+
self._raised = {}
|
|
480
550
|
for ns in self._turn_namespaces():
|
|
481
551
|
self._finish(ns, outcome)
|
|
482
552
|
self._thread.abandon_plan()
|
|
483
553
|
|
|
484
554
|
|
|
555
|
+
def _pending_tool_ids(parts: list[dict[str, Any]], interrupts: Any) -> list[str]:
|
|
556
|
+
"""The tool call ids a HumanInTheLoopMiddleware interrupt asks about, in
|
|
557
|
+
``action_requests`` order. The middleware lists the reviewed calls of the
|
|
558
|
+
last AI message in ``tool_calls`` order and carries no ids, so each request
|
|
559
|
+
matches the next streaming tool part with the same name and args. An
|
|
560
|
+
interrupt that does not match raises: approving a guessed call is unsafe."""
|
|
561
|
+
requests: list[Any] = []
|
|
562
|
+
for interrupt in interrupts:
|
|
563
|
+
value = getattr(interrupt, "value", None)
|
|
564
|
+
action_requests = value.get("action_requests") if isinstance(value, dict) else None
|
|
565
|
+
if not isinstance(action_requests, list) or not action_requests:
|
|
566
|
+
raise ValueError("unsupported interrupt: expected HumanInTheLoopMiddleware action_requests")
|
|
567
|
+
requests.extend(action_requests)
|
|
568
|
+
waiting = [p for p in parts if p["type"] == "tool" and p["state"] == "streaming"]
|
|
569
|
+
tool_ids: list[str] = []
|
|
570
|
+
for request in requests:
|
|
571
|
+
if not isinstance(request, dict):
|
|
572
|
+
raise ValueError("unsupported interrupt: action request is not an object")
|
|
573
|
+
while waiting:
|
|
574
|
+
part = waiting.pop(0)
|
|
575
|
+
if part["toolName"] == request.get("name") and part.get("input") == request.get("args"):
|
|
576
|
+
tool_ids.append(part["toolInvocationId"])
|
|
577
|
+
break
|
|
578
|
+
else:
|
|
579
|
+
raise ValueError(f"interrupt asks about a {request.get('name')!r} call this turn did not stream")
|
|
580
|
+
return tool_ids
|
|
581
|
+
|
|
582
|
+
|
|
485
583
|
def _provider_ids(message: Any) -> list[str]:
|
|
486
|
-
|
|
487
|
-
|
|
584
|
+
"""The LangChain ids an agent message folds. A user message's metadata is
|
|
585
|
+
the client's, so it names none."""
|
|
586
|
+
if message is None or message.get("role") == "user":
|
|
587
|
+
return []
|
|
588
|
+
metadata = plain(message.get("metadata"))
|
|
589
|
+
provider = metadata.get("provider") if isinstance(metadata, dict) else None
|
|
590
|
+
ids = provider.get("ids") if isinstance(provider, dict) else None
|
|
591
|
+
return [i for i in ids if isinstance(i, str)] if isinstance(ids, list) else []
|
harness_sdk/deepagents_host.py
CHANGED
|
@@ -153,7 +153,10 @@ class DeepagentsHost(VoiceThread, HarnessMessages, Statewire):
|
|
|
153
153
|
interrupt = self.messages.interrupt
|
|
154
154
|
if interrupt is not None:
|
|
155
155
|
return RunManager.InputRequired(
|
|
156
|
-
(
|
|
156
|
+
tuple(
|
|
157
|
+
{"id": tool_id, "type": "tool-approval", "toolCallId": tool_id}
|
|
158
|
+
for tool_id in interrupt["toolCallIds"]
|
|
159
|
+
)
|
|
157
160
|
)
|
|
158
161
|
steered = self.messages.append_users(ctx.steering.take())
|
|
159
162
|
if not steered:
|
|
@@ -187,8 +190,14 @@ class DeepagentsHost(VoiceThread, HarnessMessages, Statewire):
|
|
|
187
190
|
with contextlib.suppress(Exception):
|
|
188
191
|
await stream.aclose()
|
|
189
192
|
|
|
193
|
+
def _check_user_message(self, params: Any) -> None:
|
|
194
|
+
message = params.get("message") if isinstance(params, dict) else None
|
|
195
|
+
if isinstance(message, dict):
|
|
196
|
+
self.messages.check_user_id(message.get("id"))
|
|
197
|
+
|
|
190
198
|
@command("run/send")
|
|
191
199
|
async def run_send(self, params, *, ctx, auth_result):
|
|
200
|
+
self._check_user_message(params)
|
|
192
201
|
return await self.run.send(params, applied=ctx.applied, auth_result=auth_result, version=ctx.version)
|
|
193
202
|
|
|
194
203
|
@command("run/dequeue")
|
|
@@ -197,6 +206,7 @@ class DeepagentsHost(VoiceThread, HarnessMessages, Statewire):
|
|
|
197
206
|
|
|
198
207
|
@command("run/edit")
|
|
199
208
|
async def run_edit(self, params, *, ctx, auth_result):
|
|
209
|
+
self._check_user_message(params)
|
|
200
210
|
return await self.run.edit(params, applied=ctx.applied, auth_result=auth_result)
|
|
201
211
|
|
|
202
212
|
@command("run/reload")
|
harness_sdk/run_manager.py
CHANGED
|
@@ -52,20 +52,14 @@ so a settled stop covers every durable effect the runner enlisted. On run end
|
|
|
52
52
|
one envelope promotes ``nextDispatch`` into ``dispatching`` and clears the
|
|
53
53
|
window.
|
|
54
54
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
whose ``authorize`` returns ``None`` keeps client-trusting behavior, and a
|
|
64
|
-
machine whose first admission is a pooled command replayed cold after a
|
|
65
|
-
restart records no principal (such replays run with ``auth_result`` ``None``
|
|
66
|
-
per the statewire replay contract). Principals stay off the wire
|
|
67
|
-
projections; ``authorize`` must return a JSON-serializable value with stable
|
|
68
|
-
equality per principal.
|
|
55
|
+
Run control: every attached caller may stop, continue, edit, reload, answer
|
|
56
|
+
input on, and preempt or steer the run, and dequeue, rewrite, or move any
|
|
57
|
+
queued message. Attach authorization is the gate; a finer security-gate
|
|
58
|
+
system is planned. The machine still records the minting caller's
|
|
59
|
+
``auth_result`` as ``principal`` and each queued message's as ``authors``
|
|
60
|
+
(persisted state kept for compatibility; ``authors`` also counts toward the
|
|
61
|
+
tracked-id capacity), but neither is enforced. Principals stay off the wire
|
|
62
|
+
projections.
|
|
69
63
|
"""
|
|
70
64
|
|
|
71
65
|
import asyncio
|
|
@@ -100,6 +94,7 @@ from statewire.ops import encode_envelope
|
|
|
100
94
|
logger = logging.getLogger(__name__)
|
|
101
95
|
|
|
102
96
|
MAX_MESSAGE_ID_LENGTH = 256
|
|
97
|
+
MAX_RUN_ID_LENGTH = 256
|
|
103
98
|
MAX_MESSAGE_BYTES = 1 << 20
|
|
104
99
|
MAX_RUN_IDS = 4096
|
|
105
100
|
|
|
@@ -172,9 +167,22 @@ def _run_id_of(params: Any) -> str:
|
|
|
172
167
|
run_id = params.get("runId") if isinstance(params, dict) else None
|
|
173
168
|
if not isinstance(run_id, str) or run_id == "":
|
|
174
169
|
raise _reject("invalid-message", "runId must be a non-empty string")
|
|
170
|
+
# the run id becomes the machine's tray id, a primary-key column in the store
|
|
171
|
+
if len(run_id) > MAX_RUN_ID_LENGTH:
|
|
172
|
+
raise _reject(
|
|
173
|
+
"invalid-message", f"runId exceeds {MAX_RUN_ID_LENGTH} characters"
|
|
174
|
+
)
|
|
175
175
|
return run_id
|
|
176
176
|
|
|
177
177
|
|
|
178
|
+
def _refuse_request_options(params: Any) -> None:
|
|
179
|
+
if isinstance(params, dict) and "requestOptions" in params:
|
|
180
|
+
raise _reject(
|
|
181
|
+
"capability-missing",
|
|
182
|
+
"requestOptions is accepted only by the AI SDK transport",
|
|
183
|
+
)
|
|
184
|
+
|
|
185
|
+
|
|
178
186
|
def _prepared(
|
|
179
187
|
hook: Callable[[dict[str, Any]], dict[str, Any]] | None,
|
|
180
188
|
name: str,
|
|
@@ -430,6 +438,7 @@ class RunManager(Tray):
|
|
|
430
438
|
|
|
431
439
|
queue = persistent_queue()
|
|
432
440
|
steerQueue = persistent_queue()
|
|
441
|
+
# Recorded but not enforced; kept so persisted state keeps its shape.
|
|
433
442
|
principal = persistent(None) # the minting caller's auth_result; never on the wire
|
|
434
443
|
authors = persistent({}) # message id -> the enqueueing caller's auth_result
|
|
435
444
|
outbox = persistent_outbox() # {"record": ..., "lanes": [...]}: the in-flight dispatch
|
|
@@ -610,19 +619,6 @@ class RunManager(Tray):
|
|
|
610
619
|
|
|
611
620
|
# ─── State access ───────────────────────────────────────
|
|
612
621
|
|
|
613
|
-
def _check_owner(self, recorded: Any, principal: Any, what: str) -> None:
|
|
614
|
-
# a None record is unbound: a host without authorize keeps legacy behavior
|
|
615
|
-
if recorded is not None and recorded != principal:
|
|
616
|
-
raise _reject("not-owner", f"{what} belongs to another caller")
|
|
617
|
-
|
|
618
|
-
def _check_run_owner(self, principal: Any) -> None:
|
|
619
|
-
self._check_owner(self.principal.value, principal, f"run {self.id}")
|
|
620
|
-
|
|
621
|
-
def _check_author(self, message_id: str, principal: Any) -> None:
|
|
622
|
-
self._check_owner(
|
|
623
|
-
self.authors.value.get(message_id), principal, f"message {message_id}"
|
|
624
|
-
)
|
|
625
|
-
|
|
626
622
|
def _in_flight(self) -> bool:
|
|
627
623
|
return self.outbox.value is not None
|
|
628
624
|
|
|
@@ -1656,7 +1652,8 @@ class RunManager(Tray):
|
|
|
1656
1652
|
return self._apply_move(e, fx)
|
|
1657
1653
|
current = self._lane_of(e.message_id)
|
|
1658
1654
|
if current is not None:
|
|
1659
|
-
|
|
1655
|
+
# Run control is open to every attached caller; attach authorization is the
|
|
1656
|
+
# gate. A finer security-gate system is planned.
|
|
1660
1657
|
self._check_anchor(e)
|
|
1661
1658
|
self._place(e.lane, current, e.message, e.params, e.meta)
|
|
1662
1659
|
if e.lane == "steerQueue":
|
|
@@ -1674,8 +1671,8 @@ class RunManager(Tray):
|
|
|
1674
1671
|
raise _reject("invalid-message", "runAnchorMessageId is required")
|
|
1675
1672
|
else:
|
|
1676
1673
|
self._check_anchor(e)
|
|
1677
|
-
#
|
|
1678
|
-
|
|
1674
|
+
# Run control is open to every attached caller; attach authorization is the
|
|
1675
|
+
# gate. A finer security-gate system is planned.
|
|
1679
1676
|
self._check_id_capacity((e.message_id,))
|
|
1680
1677
|
if self._dispatchable(e.lane):
|
|
1681
1678
|
self._stage_batch(e)
|
|
@@ -1704,7 +1701,8 @@ class RunManager(Tray):
|
|
|
1704
1701
|
f"message {e.message_id} already dispatched",
|
|
1705
1702
|
)
|
|
1706
1703
|
raise _reject("unknown-id", f"message {e.message_id} is not queued")
|
|
1707
|
-
|
|
1704
|
+
# Run control is open to every attached caller; attach authorization is the
|
|
1705
|
+
# gate. A finer security-gate system is planned.
|
|
1708
1706
|
item = next(i for i in self._lane_items(current) if i["id"] == e.message_id)
|
|
1709
1707
|
self._place(e.lane, current, item, e.params, item.get("meta"))
|
|
1710
1708
|
if e.lane == "steerQueue":
|
|
@@ -1749,7 +1747,8 @@ class RunManager(Tray):
|
|
|
1749
1747
|
|
|
1750
1748
|
def _park_dispatched_edit(self, e: _Send) -> Any:
|
|
1751
1749
|
assert e.message is not None
|
|
1752
|
-
|
|
1750
|
+
# Run control is open to every attached caller; attach authorization is the
|
|
1751
|
+
# gate. A finer security-gate system is planned.
|
|
1753
1752
|
_check_rewind_gate(self.capabilities, self._in_flight(), "editing")
|
|
1754
1753
|
if e.source_meta is None:
|
|
1755
1754
|
raise _reject("unknown-id", f"message {e.message_id} is unknown")
|
|
@@ -1769,8 +1768,8 @@ class RunManager(Tray):
|
|
|
1769
1768
|
lane = self._lane_of(e.message_id)
|
|
1770
1769
|
if lane is None:
|
|
1771
1770
|
raise _reject("unknown-id", f"message {e.message_id} is not queued")
|
|
1772
|
-
|
|
1773
|
-
|
|
1771
|
+
# Run control is open to every attached caller; attach authorization is the
|
|
1772
|
+
# gate. A finer security-gate system is planned.
|
|
1774
1773
|
self._lane(lane).value = [
|
|
1775
1774
|
item for item in self._lane_items(lane) if item["id"] != e.message_id
|
|
1776
1775
|
]
|
|
@@ -1780,7 +1779,8 @@ class RunManager(Tray):
|
|
|
1780
1779
|
def _apply_input(self, e: _Input) -> Any:
|
|
1781
1780
|
if self._status() != "input-required":
|
|
1782
1781
|
raise _reject("wrong-state", f"run/input is rejected in {self._status()}")
|
|
1783
|
-
|
|
1782
|
+
# Run control is open to every attached caller; attach authorization is the
|
|
1783
|
+
# gate. A finer security-gate system is planned.
|
|
1784
1784
|
index = next(
|
|
1785
1785
|
(
|
|
1786
1786
|
i
|
|
@@ -1808,7 +1808,8 @@ class RunManager(Tray):
|
|
|
1808
1808
|
return None
|
|
1809
1809
|
|
|
1810
1810
|
def _apply_edit(self, e: _Edit) -> Any:
|
|
1811
|
-
|
|
1811
|
+
# Run control is open to every attached caller; attach authorization is the
|
|
1812
|
+
# gate. A finer security-gate system is planned.
|
|
1812
1813
|
self._check_id_capacity((e.message["id"],))
|
|
1813
1814
|
staged = self._staged_rewind
|
|
1814
1815
|
if (
|
|
@@ -1830,7 +1831,8 @@ class RunManager(Tray):
|
|
|
1830
1831
|
return _PARKED
|
|
1831
1832
|
|
|
1832
1833
|
def _apply_reload(self, e: _Reload) -> Any:
|
|
1833
|
-
|
|
1834
|
+
# Run control is open to every attached caller; attach authorization is the
|
|
1835
|
+
# gate. A finer security-gate system is planned.
|
|
1834
1836
|
if self._staged_rewind is not None:
|
|
1835
1837
|
raise _reject("wrong-state", "a rewind is already staged")
|
|
1836
1838
|
self._stage_rewind(
|
|
@@ -1876,7 +1878,8 @@ class RunManager(Tray):
|
|
|
1876
1878
|
status == "stopping" and stop_held
|
|
1877
1879
|
):
|
|
1878
1880
|
raise _reject("wrong-state", f"run/stop is rejected in {status}")
|
|
1879
|
-
|
|
1881
|
+
# Run control is open to every attached caller; attach authorization is the
|
|
1882
|
+
# gate. A finer security-gate system is planned.
|
|
1880
1883
|
run_id = _run_id_of(params)
|
|
1881
1884
|
if run_id != self.id:
|
|
1882
1885
|
raise _reject(
|
|
@@ -1905,7 +1908,8 @@ class RunManager(Tray):
|
|
|
1905
1908
|
status = self._status()
|
|
1906
1909
|
if status not in ("error", "stopped"):
|
|
1907
1910
|
raise _reject("wrong-state", f"run/continue is rejected in {status}")
|
|
1908
|
-
|
|
1911
|
+
# Run control is open to every attached caller; attach authorization is the
|
|
1912
|
+
# gate. A finer security-gate system is planned.
|
|
1909
1913
|
if not self._lane_items("steerQueue") and (
|
|
1910
1914
|
"incomplete-continuation" not in self.capabilities
|
|
1911
1915
|
):
|
|
@@ -2254,7 +2258,8 @@ class RunManagerNamespace(TrayMapNamespace):
|
|
|
2254
2258
|
if not requests and not has_pending_tasks:
|
|
2255
2259
|
return False
|
|
2256
2260
|
tray, _ = await self._machine(self._api.domain.token_hex(16), principal)
|
|
2257
|
-
|
|
2261
|
+
# Run control is open to every attached caller; attach authorization is the
|
|
2262
|
+
# gate. A finer security-gate system is planned.
|
|
2258
2263
|
if (
|
|
2259
2264
|
tray._in_flight()
|
|
2260
2265
|
or tray._intake
|
|
@@ -2390,6 +2395,7 @@ class RunManagerNamespace(TrayMapNamespace):
|
|
|
2390
2395
|
cls: type[RunManager] = self._spec.tray_cls # type: ignore[assignment]
|
|
2391
2396
|
if not isinstance(params, dict):
|
|
2392
2397
|
raise _reject("invalid-message", "params must be an object")
|
|
2398
|
+
_refuse_request_options(params)
|
|
2393
2399
|
run_id = _run_id_of(params)
|
|
2394
2400
|
behavior = params.get("behavior", "auto")
|
|
2395
2401
|
if behavior not in _BEHAVIORS:
|
|
@@ -2527,15 +2533,13 @@ class RunManagerNamespace(TrayMapNamespace):
|
|
|
2527
2533
|
behavior: str,
|
|
2528
2534
|
message: dict[str, Any] | None,
|
|
2529
2535
|
message_id: str,
|
|
2530
|
-
principal: Any,
|
|
2536
|
+
principal: Any, # unused: run control is open to every attached caller
|
|
2531
2537
|
) -> dict[str, Any] | None:
|
|
2532
2538
|
"""The message an auto send consults the prioritizer on; None stages without one."""
|
|
2533
2539
|
cls: type[RunManager] = self._spec.tray_cls # type: ignore[assignment]
|
|
2534
2540
|
if behavior != "auto" or cls.prioritize is None or tray._status() not in _LIVE:
|
|
2535
2541
|
return None
|
|
2536
2542
|
lane = tray._lane_of(message_id)
|
|
2537
|
-
if lane is not None:
|
|
2538
|
-
tray._check_author(message_id, principal) # before the prioritizer sees it
|
|
2539
2543
|
if message is not None:
|
|
2540
2544
|
return message
|
|
2541
2545
|
if lane is None:
|
|
@@ -2606,6 +2610,7 @@ class RunManagerNamespace(TrayMapNamespace):
|
|
|
2606
2610
|
) -> Any:
|
|
2607
2611
|
cls: type[RunManager] = self._spec.tray_cls # type: ignore[assignment]
|
|
2608
2612
|
self._check_rewind_gate("run/edit")
|
|
2613
|
+
_refuse_request_options(params)
|
|
2609
2614
|
run_id = _run_id_of(params)
|
|
2610
2615
|
source_id = params.get("sourceId") if isinstance(params, dict) else None
|
|
2611
2616
|
if not isinstance(source_id, str):
|
|
@@ -2645,6 +2650,7 @@ class RunManagerNamespace(TrayMapNamespace):
|
|
|
2645
2650
|
) -> Any:
|
|
2646
2651
|
cls: type[RunManager] = self._spec.tray_cls # type: ignore[assignment]
|
|
2647
2652
|
self._check_rewind_gate("run/reload")
|
|
2653
|
+
_refuse_request_options(params)
|
|
2648
2654
|
run_id = _run_id_of(params)
|
|
2649
2655
|
source_id = params.get("sourceId") if isinstance(params, dict) else None
|
|
2650
2656
|
if not isinstance(source_id, str):
|
harness_sdk/threads.py
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
"""HarnessThreads: a Statewire host serving one thread list over the
|
|
2
|
-
``harness-sdk-threads`` protocol
|
|
1
|
+
"""HarnessThreads: a Statewire host serving one workspace's thread list over the
|
|
2
|
+
``harness-sdk-threads`` protocol. The instance id is the workspace id; threads
|
|
3
|
+
list themselves on their own workspace's instance (``HarnessMessages.workspace_id``),
|
|
4
|
+
and ``authorize`` admits callers with access to that workspace. The list
|
|
5
|
+
instance is the store's only writer.
|
|
3
6
|
|
|
4
7
|
.. versionadded:: alpha
|
|
5
8
|
"""
|
|
@@ -115,13 +118,33 @@ def _thread_id(params: Any) -> str:
|
|
|
115
118
|
|
|
116
119
|
|
|
117
120
|
class HarnessThreads(Statewire):
|
|
118
|
-
"""One thread list
|
|
121
|
+
"""One workspace's thread list: the instance id is the workspace id. ``thread_store()`` names its store
|
|
122
|
+
(in-memory per instance by default).
|
|
119
123
|
|
|
120
124
|
.. versionadded:: alpha
|
|
121
125
|
"""
|
|
122
126
|
|
|
123
127
|
protocols = (HARNESS_THREADS_PROTOCOL,)
|
|
124
128
|
|
|
129
|
+
@property
|
|
130
|
+
def workspace_id(self) -> str:
|
|
131
|
+
"""The workspace this list serves: its instance id."""
|
|
132
|
+
return self.id
|
|
133
|
+
|
|
134
|
+
async def authorize(self, conn: HTTPConnection) -> Any:
|
|
135
|
+
"""The list's only gate: every attacher reads and edits every thread of the workspace. Override to admit
|
|
136
|
+
callers with access to ``self.workspace_id`` and return the caller's identity.
|
|
137
|
+
|
|
138
|
+
``POST /touch`` keeps its own instance-only check.
|
|
139
|
+
|
|
140
|
+
.. versionchanged:: alpha
|
|
141
|
+
Refuses every attach (403) until overridden.
|
|
142
|
+
"""
|
|
143
|
+
raise AuthRejected(
|
|
144
|
+
"HarnessThreads is closed until a subclass overrides authorize to admit the workspace's members",
|
|
145
|
+
status_code=403,
|
|
146
|
+
)
|
|
147
|
+
|
|
125
148
|
def thread_store(self) -> ThreadStore:
|
|
126
149
|
return MemoryThreadStore()
|
|
127
150
|
|
harness_sdk/wire.py
CHANGED
|
@@ -63,11 +63,23 @@ class _Interests:
|
|
|
63
63
|
class HarnessMessages:
|
|
64
64
|
"""Statewire mixin: ``tree`` holds the messages; call ``refresh_messages()`` after the tree changes."""
|
|
65
65
|
|
|
66
|
-
#:
|
|
67
|
-
|
|
66
|
+
#: The workspace this thread belongs to; it lists itself only on that workspace's ``HarnessThreads`` instance,
|
|
67
|
+
#: ``{thread_lists}/{workspace_id}``. ``None`` keeps the thread off every list. Fix it per thread (a class
|
|
68
|
+
#: attribute, or a property over the thread's own record); never take it from an attacher. Alpha.
|
|
69
|
+
workspace_id: str | None = None
|
|
70
|
+
#: Namespace of the ``HarnessThreads`` host. Alpha.
|
|
71
|
+
thread_lists: str = "/thread-lists"
|
|
68
72
|
_touching: "asyncio.Task[None] | None" = None
|
|
69
73
|
_titled = False
|
|
70
74
|
|
|
75
|
+
def __init_subclass__(cls, **kwargs: Any) -> None:
|
|
76
|
+
super().__init_subclass__(**kwargs)
|
|
77
|
+
if "thread_list" in cls.__dict__:
|
|
78
|
+
raise TypeError(
|
|
79
|
+
f"{cls.__name__}.thread_list was removed: set workspace_id; the thread lists itself on "
|
|
80
|
+
f"{{thread_lists}}/{{workspace_id}}"
|
|
81
|
+
)
|
|
82
|
+
|
|
71
83
|
@property
|
|
72
84
|
def state_key(self) -> tuple[str, ...]:
|
|
73
85
|
return (self.id,)
|
|
@@ -80,7 +92,7 @@ class HarnessMessages:
|
|
|
80
92
|
self._touch(activity=_ACTIVITY[status])
|
|
81
93
|
|
|
82
94
|
def _touch(self, **fields: str) -> None:
|
|
83
|
-
if self.
|
|
95
|
+
if self.workspace_id is None:
|
|
84
96
|
return
|
|
85
97
|
if not self._titled and (title := self.thread_list_title()) is not None:
|
|
86
98
|
self._titled = True
|
|
@@ -95,12 +107,13 @@ class HarnessMessages:
|
|
|
95
107
|
) -> None:
|
|
96
108
|
if after is not None:
|
|
97
109
|
await asyncio.wait({after})
|
|
98
|
-
|
|
99
|
-
f"
|
|
100
|
-
|
|
110
|
+
if not self.workspace_id or "/" in self.workspace_id:
|
|
111
|
+
raise ValueError(f"workspace_id must be one path segment: {self.workspace_id!r}")
|
|
112
|
+
path = f"{self.thread_lists}/{self.workspace_id}/touch"
|
|
113
|
+
response = await self.cluster.post(path, json={"threadId": self.id, **fields})
|
|
101
114
|
if response.status_code != 200:
|
|
102
115
|
raise RuntimeError(
|
|
103
|
-
f"{
|
|
116
|
+
f"{path} answered {response.status_code}: {response.text}"
|
|
104
117
|
)
|
|
105
118
|
|
|
106
119
|
@cached_property
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: harness-sdk-python
|
|
3
|
-
Version: 0.40.
|
|
3
|
+
Version: 0.40.11
|
|
4
4
|
Summary: RunManager: the harness-sdk runs subsystem for Python Statewire hosts
|
|
5
5
|
Project-URL: Repository, https://github.com/assistant-ui/harness-sdk
|
|
6
6
|
License-Expression: MIT
|
|
7
7
|
Requires-Python: <4.0,>=3.12
|
|
8
8
|
Requires-Dist: pinboard-sdk>=0.18.0
|
|
9
|
-
Requires-Dist: statewire<0.
|
|
9
|
+
Requires-Dist: statewire<0.25,>=0.24.0
|
|
10
10
|
Provides-Extra: deepagents
|
|
11
11
|
Requires-Dist: deepagents>=0.6.12; extra == 'deepagents'
|
|
12
12
|
Requires-Dist: langchain-core>=0.3; extra == 'deepagents'
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
harness_sdk/__init__.py,sha256=x-vDKSqkPGcjLZ3N2nWtM37RyS-KifXtfKBPy4IOnjE,2285
|
|
2
2
|
harness_sdk/checkpoints.py,sha256=Iuum5x4KjsvJajDPP9TLFKcKQouOo-05jnCP3SJCD2s,30726
|
|
3
|
-
harness_sdk/deepagents.py,sha256=
|
|
4
|
-
harness_sdk/deepagents_host.py,sha256=
|
|
3
|
+
harness_sdk/deepagents.py,sha256=eKkNGgEXEFMUY9FDT-REKGHmkfbOofiw5oH3k7jt9lg,27346
|
|
4
|
+
harness_sdk/deepagents_host.py,sha256=Psv66_Y0eJQu4sjBdGiwqrEdusY6kHXOotb1v35NNT8,9668
|
|
5
5
|
harness_sdk/fenced_postgres.py,sha256=hbbrMR1WaqrHTNgd4wFrXfRrzQFGnyim-c8nZXgwWp4,13235
|
|
6
6
|
harness_sdk/interest.py,sha256=KnmbTcF7fQha69Zuvu0_solI44Olp-eSv-qkltZ-hAU,5141
|
|
7
7
|
harness_sdk/langgraph.py,sha256=35r1KSgrqK8KUPe6ELAGq3q5TuyeTeXwmkOnlbC5F9c,2682
|
|
@@ -10,13 +10,13 @@ harness_sdk/messages.py,sha256=amx-vPWlZh-W2fKrPgmaspSvc90rqcIqXgkr9aj_k5w,6148
|
|
|
10
10
|
harness_sdk/parts.py,sha256=mHhYvmQx6J56Ah5K7dUZ4qUOlKk-L02AR64asSqOT5I,6400
|
|
11
11
|
harness_sdk/prioritize.py,sha256=Li8IoI_ACiwbWDNa2DSDpNhoXY0utPhGevBQqQonsQc,4203
|
|
12
12
|
harness_sdk/protocol.py,sha256=VxWOIg_2vitFGTJmpiD2wNNAJnwSgQFy69Hds-frfvs,1207
|
|
13
|
-
harness_sdk/run_manager.py,sha256=
|
|
14
|
-
harness_sdk/threads.py,sha256=
|
|
13
|
+
harness_sdk/run_manager.py,sha256=nXxXJAGaTVKh_yv6_sF7DQ-V_wY0sIFV2AQBJOwOFNY,111859
|
|
14
|
+
harness_sdk/threads.py,sha256=eSe1c_xR7bobIKKFbuvNUSHFexTkzkd6FEpcmKyGVG0,8148
|
|
15
15
|
harness_sdk/voice.py,sha256=XJakSJrjS-RVT1PIaDDxm1RZDp9QpLWCdX36k-UvGHA,25852
|
|
16
16
|
harness_sdk/voice_thread.py,sha256=B616W1efohEd9RwWssrOkTne7Lu8s0kn07kMof1v_nI,6910
|
|
17
|
-
harness_sdk/wire.py,sha256=
|
|
17
|
+
harness_sdk/wire.py,sha256=Ln7uBcH2SS08U61ueLYX1M8il_4HMX27GmfRe7ZsnhI,8787
|
|
18
18
|
harness_sdk/providers/__init__.py,sha256=PjVKflqdtYSipq0ISTNuIYKeCOm3KX8ov9XuNtBhFrs,75
|
|
19
19
|
harness_sdk/providers/gpt_live.py,sha256=cuODSm3Kztemf51BIOuPwy1Wf-0pOhf1LPYzmSdCvl8,8453
|
|
20
|
-
harness_sdk_python-0.40.
|
|
21
|
-
harness_sdk_python-0.40.
|
|
22
|
-
harness_sdk_python-0.40.
|
|
20
|
+
harness_sdk_python-0.40.11.dist-info/METADATA,sha256=UoQQ4speHkz6mqGpuGFvYWgiz6uAO8ezu1oQ_u8P9-E,4023
|
|
21
|
+
harness_sdk_python-0.40.11.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
22
|
+
harness_sdk_python-0.40.11.dist-info/RECORD,,
|
|
File without changes
|