bitfab-py 0.78.3__tar.gz → 0.78.4__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 (75) hide show
  1. {bitfab_py-0.78.3 → bitfab_py-0.78.4}/PKG-INFO +1 -1
  2. {bitfab_py-0.78.3 → bitfab_py-0.78.4}/bitfab/__init__.py +2 -0
  3. {bitfab_py-0.78.3 → bitfab_py-0.78.4}/bitfab/gmail_sandbox.py +22 -6
  4. {bitfab_py-0.78.3 → bitfab_py-0.78.4}/bitfab/replay.py +1 -0
  5. {bitfab_py-0.78.3 → bitfab_py-0.78.4}/bitfab/sandbox.py +40 -0
  6. {bitfab_py-0.78.3 → bitfab_py-0.78.4}/pyproject.toml +1 -1
  7. {bitfab_py-0.78.3 → bitfab_py-0.78.4}/README.md +0 -0
  8. {bitfab_py-0.78.3 → bitfab_py-0.78.4}/bitfab/agent_middleware.py +0 -0
  9. {bitfab_py-0.78.3 → bitfab_py-0.78.4}/bitfab/approval.py +0 -0
  10. {bitfab_py-0.78.3 → bitfab_py-0.78.4}/bitfab/assertion_categories.py +0 -0
  11. {bitfab_py-0.78.3 → bitfab_py-0.78.4}/bitfab/baml.py +0 -0
  12. {bitfab_py-0.78.3 → bitfab_py-0.78.4}/bitfab/baml_auto_trace.py +0 -0
  13. {bitfab_py-0.78.3 → bitfab_py-0.78.4}/bitfab/categories.py +0 -0
  14. {bitfab_py-0.78.3 → bitfab_py-0.78.4}/bitfab/claude_agent_sdk.py +0 -0
  15. {bitfab_py-0.78.3 → bitfab_py-0.78.4}/bitfab/client.py +0 -0
  16. {bitfab_py-0.78.3 → bitfab_py-0.78.4}/bitfab/client_patching.py +0 -0
  17. {bitfab_py-0.78.3 → bitfab_py-0.78.4}/bitfab/cloudReplay.py +0 -0
  18. {bitfab_py-0.78.3 → bitfab_py-0.78.4}/bitfab/cloud_replay_cli.py +0 -0
  19. {bitfab_py-0.78.3 → bitfab_py-0.78.4}/bitfab/commit_ref.py +0 -0
  20. {bitfab_py-0.78.3 → bitfab_py-0.78.4}/bitfab/compress.py +0 -0
  21. {bitfab_py-0.78.3 → bitfab_py-0.78.4}/bitfab/constants.py +0 -0
  22. {bitfab_py-0.78.3 → bitfab_py-0.78.4}/bitfab/datasets.py +0 -0
  23. {bitfab_py-0.78.3 → bitfab_py-0.78.4}/bitfab/db_snapshot.py +0 -0
  24. {bitfab_py-0.78.3 → bitfab_py-0.78.4}/bitfab/error_chain.py +0 -0
  25. {bitfab_py-0.78.3 → bitfab_py-0.78.4}/bitfab/experiment_id.py +0 -0
  26. {bitfab_py-0.78.3 → bitfab_py-0.78.4}/bitfab/experiments.py +0 -0
  27. {bitfab_py-0.78.3 → bitfab_py-0.78.4}/bitfab/finalizers.py +0 -0
  28. {bitfab_py-0.78.3 → bitfab_py-0.78.4}/bitfab/git_command.py +0 -0
  29. {bitfab_py-0.78.3 → bitfab_py-0.78.4}/bitfab/git_state.py +0 -0
  30. {bitfab_py-0.78.3 → bitfab_py-0.78.4}/bitfab/google_calls.py +0 -0
  31. {bitfab_py-0.78.3 → bitfab_py-0.78.4}/bitfab/graders.py +0 -0
  32. {bitfab_py-0.78.3 → bitfab_py-0.78.4}/bitfab/http.py +0 -0
  33. {bitfab_py-0.78.3 → bitfab_py-0.78.4}/bitfab/integration_fixture.py +0 -0
  34. {bitfab_py-0.78.3 → bitfab_py-0.78.4}/bitfab/jev.py +0 -0
  35. {bitfab_py-0.78.3 → bitfab_py-0.78.4}/bitfab/labels.py +0 -0
  36. {bitfab_py-0.78.3 → bitfab_py-0.78.4}/bitfab/langgraph.py +0 -0
  37. {bitfab_py-0.78.3 → bitfab_py-0.78.4}/bitfab/langgraph_integration.py +0 -0
  38. {bitfab_py-0.78.3 → bitfab_py-0.78.4}/bitfab/langgraph_runs.py +0 -0
  39. {bitfab_py-0.78.3 → bitfab_py-0.78.4}/bitfab/mock_matching.py +0 -0
  40. {bitfab_py-0.78.3 → bitfab_py-0.78.4}/bitfab/mock_override.py +0 -0
  41. {bitfab_py-0.78.3 → bitfab_py-0.78.4}/bitfab/openai_agent_sdk.py +0 -0
  42. {bitfab_py-0.78.3 → bitfab_py-0.78.4}/bitfab/openai_agents_usage.py +0 -0
  43. {bitfab_py-0.78.3 → bitfab_py-0.78.4}/bitfab/organization_members.py +0 -0
  44. {bitfab_py-0.78.3 → bitfab_py-0.78.4}/bitfab/otel.py +0 -0
  45. {bitfab_py-0.78.3 → bitfab_py-0.78.4}/bitfab/payload_budget.py +0 -0
  46. {bitfab_py-0.78.3 → bitfab_py-0.78.4}/bitfab/processor_payload.py +0 -0
  47. {bitfab_py-0.78.3 → bitfab_py-0.78.4}/bitfab/provider_calls.py +0 -0
  48. {bitfab_py-0.78.3 → bitfab_py-0.78.4}/bitfab/replay_branch.py +0 -0
  49. {bitfab_py-0.78.3 → bitfab_py-0.78.4}/bitfab/replay_cli.py +0 -0
  50. {bitfab_py-0.78.3 → bitfab_py-0.78.4}/bitfab/replay_heartbeat.py +0 -0
  51. {bitfab_py-0.78.3 → bitfab_py-0.78.4}/bitfab/replay_interrupt.py +0 -0
  52. {bitfab_py-0.78.3 → bitfab_py-0.78.4}/bitfab/replay_invocation.py +0 -0
  53. {bitfab_py-0.78.3 → bitfab_py-0.78.4}/bitfab/replay_memory.py +0 -0
  54. {bitfab_py-0.78.3 → bitfab_py-0.78.4}/bitfab/replay_processes.py +0 -0
  55. {bitfab_py-0.78.3 → bitfab_py-0.78.4}/bitfab/replay_registry.py +0 -0
  56. {bitfab_py-0.78.3 → bitfab_py-0.78.4}/bitfab/seed_cli.py +0 -0
  57. {bitfab_py-0.78.3 → bitfab_py-0.78.4}/bitfab/selective_replay.py +0 -0
  58. {bitfab_py-0.78.3 → bitfab_py-0.78.4}/bitfab/serialize.py +0 -0
  59. {bitfab_py-0.78.3 → bitfab_py-0.78.4}/bitfab/service_calls.py +0 -0
  60. {bitfab_py-0.78.3 → bitfab_py-0.78.4}/bitfab/simulation_plan.py +0 -0
  61. {bitfab_py-0.78.3 → bitfab_py-0.78.4}/bitfab/span_meta.py +0 -0
  62. {bitfab_py-0.78.3 → bitfab_py-0.78.4}/bitfab/span_origin.py +0 -0
  63. {bitfab_py-0.78.3 → bitfab_py-0.78.4}/bitfab/spans.py +0 -0
  64. {bitfab_py-0.78.3 → bitfab_py-0.78.4}/bitfab/subtree.py +0 -0
  65. {bitfab_py-0.78.3 → bitfab_py-0.78.4}/bitfab/thread_propagation.py +0 -0
  66. {bitfab_py-0.78.3 → bitfab_py-0.78.4}/bitfab/timestamp.py +0 -0
  67. {bitfab_py-0.78.3 → bitfab_py-0.78.4}/bitfab/trace_completion.py +0 -0
  68. {bitfab_py-0.78.3 → bitfab_py-0.78.4}/bitfab/trace_metadata.py +0 -0
  69. {bitfab_py-0.78.3 → bitfab_py-0.78.4}/bitfab/trace_payload.py +0 -0
  70. {bitfab_py-0.78.3 → bitfab_py-0.78.4}/bitfab/traces.py +0 -0
  71. {bitfab_py-0.78.3 → bitfab_py-0.78.4}/bitfab/tracing.py +0 -0
  72. {bitfab_py-0.78.3 → bitfab_py-0.78.4}/bitfab/transport.py +0 -0
  73. {bitfab_py-0.78.3 → bitfab_py-0.78.4}/bitfab/transport_types.py +0 -0
  74. {bitfab_py-0.78.3 → bitfab_py-0.78.4}/bitfab/verdicts.py +0 -0
  75. {bitfab_py-0.78.3 → bitfab_py-0.78.4}/bitfab/warn_once.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: bitfab-py
3
- Version: 0.78.3
3
+ Version: 0.78.4
4
4
  Summary: Bitfab client for provider-based API calls with local BAML execution
5
5
  Author: Harvest Team
6
6
  Requires-Python: >=3.10
@@ -155,6 +155,7 @@ from bitfab.sandbox import (
155
155
  Sandbox,
156
156
  SandboxStartCtx,
157
157
  sandbox_active,
158
+ sandbox_now,
158
159
  sandbox_state,
159
160
  without_sandbox,
160
161
  )
@@ -432,6 +433,7 @@ __all__ = [
432
433
  "report_replay_progress",
433
434
  "reseed_from_registry",
434
435
  "sandbox_active",
436
+ "sandbox_now",
435
437
  "sandbox_state",
436
438
  "seed_from_registry",
437
439
  "serialize_replay_result",
@@ -12,7 +12,12 @@ from typing import Any
12
12
 
13
13
  from bitfab.google_calls import CREDENTIAL_PARAM, HTTP_ERROR_KEY, request_credentials
14
14
  from bitfab.mock_override import MockOverrideCtx, SpanNodeMeta
15
- from bitfab.sandbox import Sandbox, SandboxStartCtx, sandbox_state
15
+ from bitfab.sandbox import (
16
+ Sandbox,
17
+ SandboxStartCtx,
18
+ sandbox_elapsed_ms,
19
+ sandbox_state,
20
+ )
16
21
  from bitfab.service_calls import ServiceCallHeldBackError
17
22
 
18
23
  GMAIL_SANDBOX_NAME = "Gmail"
@@ -334,6 +339,7 @@ def as_mailboxes(ctx: SandboxStartCtx, started: Any) -> dict[str, Any]:
334
339
  searches=box.get("searches"),
335
340
  labels=box.get("labels"),
336
341
  send_as=box.get("sendAs"),
342
+ clock=box.get("clock"),
337
343
  )
338
344
  for index, box in enumerate(boxes or [{}])
339
345
  ]
@@ -351,6 +357,7 @@ def new_mailbox(
351
357
  searches: list[dict[str, Any]] | None = None,
352
358
  labels: list[dict[str, Any] | str] | None = None,
353
359
  send_as: list[dict[str, Any]] | None = None,
360
+ clock: str | None = None,
354
361
  ) -> dict[str, Any]:
355
362
  normalized = [gmail_message(message) for message in messages or []]
356
363
  notes: list[str] = []
@@ -377,7 +384,7 @@ def new_mailbox(
377
384
  "emailAddress": email_address,
378
385
  "credential": credential,
379
386
  "details": dict(details or {}),
380
- "clock": ctx.trace_started_at,
387
+ "clock": clock or ctx.trace_started_at,
381
388
  "historyId": 1000,
382
389
  "nextId": index * 1_000_000 + 1,
383
390
  "messages": normalized,
@@ -515,9 +522,16 @@ def _shaped(
515
522
 
516
523
 
517
524
  def _clock_millis(state: dict[str, Any]) -> int:
518
- return _millis(state.get("clock")) or int(
519
- datetime.datetime.now(datetime.timezone.utc).timestamp() * 1000
520
- )
525
+ started = _millis(state.get("clock"))
526
+ if started is None:
527
+ return int(datetime.datetime.now(datetime.timezone.utc).timestamp() * 1000)
528
+ return started + sandbox_elapsed_ms()
529
+
530
+
531
+ def _created_millis(state: dict[str, Any]) -> int:
532
+ created = max(_clock_millis(state), int(state.get("lastCreatedAt") or 0) + 1)
533
+ state["lastCreatedAt"] = created
534
+ return created
521
535
 
522
536
 
523
537
  def _date_bound(value: str) -> int | None:
@@ -798,7 +812,7 @@ def _from_raw(
798
812
  "id": message_id,
799
813
  "threadId": thread_id or message_id,
800
814
  "labelIds": labels,
801
- "internalDate": _clock_millis(state),
815
+ "internalDate": _created_millis(state),
802
816
  }
803
817
  )
804
818
  message["historyId"] = _bump_history(state)
@@ -1263,6 +1277,8 @@ def gmail_sandbox(
1263
1277
  send-as entries (``sendAsEmail``, ``displayName``, ``signature``,
1264
1278
  ...). Without ``sendAs``, the account's address is listed with no
1265
1279
  signature.
1280
+ ``clock`` (ISO 8601) is where the mailbox's time starts, in place
1281
+ of the original trace's start time.
1266
1282
  Each message is a Gmail API message or plain fields as
1267
1283
  ``gmail_message`` takes them; a plain ``account`` field puts the
1268
1284
  message in that account's mailbox. Each draft is
@@ -2962,6 +2962,7 @@ def _sandbox_session(
2962
2962
  sandboxes=sandboxes,
2963
2963
  client=client,
2964
2964
  make_start_ctx=make_start_ctx,
2965
+ trace_started_at=trace_started_at,
2965
2966
  )
2966
2967
 
2967
2968
 
@@ -1,9 +1,11 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  import copy
4
+ import datetime
4
5
  import json
5
6
  import sys
6
7
  import threading
8
+ import time
7
9
  from collections.abc import Callable, Sequence
8
10
  from dataclasses import dataclass, field
9
11
  from typing import Any
@@ -122,10 +124,15 @@ class SandboxSession:
122
124
  sandboxes: Sequence[Sandbox]
123
125
  client: Any
124
126
  make_start_ctx: Callable[[Sandbox], SandboxStartCtx]
127
+ trace_started_at: str | None = None
128
+ started: float = field(default_factory=time.monotonic)
125
129
  _states: dict[str, Any] = field(default_factory=dict)
126
130
  _reports: dict[str, dict[str, Any]] = field(default_factory=dict)
127
131
  _lock: threading.RLock = field(default_factory=threading.RLock)
128
132
 
133
+ def elapsed_ms(self) -> int:
134
+ return int((time.monotonic() - self.started) * 1000)
135
+
129
136
  def find(self, node: SpanNodeMeta) -> Sandbox | None:
130
137
  return next(
131
138
  (sandbox for sandbox in self.sandboxes if sandbox.match(node)), None
@@ -256,3 +263,36 @@ def sandbox_state(name: str) -> Any:
256
263
  if session is None or sandbox is None:
257
264
  return None
258
265
  return session.state_of(sandbox, _attach_to_replay_root)
266
+
267
+
268
+ def sandbox_elapsed_ms() -> int:
269
+ session = current_session()
270
+ return session.elapsed_ms() if session is not None else 0
271
+
272
+
273
+ def parse_timestamp(value: str | None) -> datetime.datetime | None:
274
+ if not value:
275
+ return None
276
+ try:
277
+ parsed = datetime.datetime.fromisoformat(value.strip().replace("Z", "+00:00"))
278
+ except ValueError:
279
+ return None
280
+ if parsed.tzinfo is None:
281
+ return parsed.replace(tzinfo=datetime.timezone.utc)
282
+ return parsed
283
+
284
+
285
+ def sandbox_now() -> datetime.datetime | None:
286
+ """The time sandboxes use in the current replay item.
287
+
288
+ It starts at the moment the original trace started and moves forward as
289
+ the replay item runs, so a sandbox answers as if the run were happening
290
+ again at its original time. Use it in a sandbox's ``handle`` to date what
291
+ the call writes. Returns ``None`` outside a replay item, or when the
292
+ original start time is not known. ``datetime.now()`` is not changed.
293
+ """
294
+ session = current_session()
295
+ started_at = parse_timestamp(session.trace_started_at) if session else None
296
+ if session is None or started_at is None:
297
+ return None
298
+ return started_at + datetime.timedelta(milliseconds=session.elapsed_ms())
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "bitfab-py"
3
- version = "0.78.3"
3
+ version = "0.78.4"
4
4
  description = "Bitfab client for provider-based API calls with local BAML execution"
5
5
  authors = ["Harvest Team"]
6
6
  readme = "README.md"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes