bitfab-py 0.78.0__tar.gz → 0.78.1__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.0 → bitfab_py-0.78.1}/PKG-INFO +1 -1
  2. {bitfab_py-0.78.0 → bitfab_py-0.78.1}/bitfab/gmail_sandbox.py +182 -8
  3. {bitfab_py-0.78.0 → bitfab_py-0.78.1}/pyproject.toml +1 -1
  4. {bitfab_py-0.78.0 → bitfab_py-0.78.1}/README.md +0 -0
  5. {bitfab_py-0.78.0 → bitfab_py-0.78.1}/bitfab/__init__.py +0 -0
  6. {bitfab_py-0.78.0 → bitfab_py-0.78.1}/bitfab/agent_middleware.py +0 -0
  7. {bitfab_py-0.78.0 → bitfab_py-0.78.1}/bitfab/approval.py +0 -0
  8. {bitfab_py-0.78.0 → bitfab_py-0.78.1}/bitfab/assertion_categories.py +0 -0
  9. {bitfab_py-0.78.0 → bitfab_py-0.78.1}/bitfab/baml.py +0 -0
  10. {bitfab_py-0.78.0 → bitfab_py-0.78.1}/bitfab/baml_auto_trace.py +0 -0
  11. {bitfab_py-0.78.0 → bitfab_py-0.78.1}/bitfab/categories.py +0 -0
  12. {bitfab_py-0.78.0 → bitfab_py-0.78.1}/bitfab/claude_agent_sdk.py +0 -0
  13. {bitfab_py-0.78.0 → bitfab_py-0.78.1}/bitfab/client.py +0 -0
  14. {bitfab_py-0.78.0 → bitfab_py-0.78.1}/bitfab/client_patching.py +0 -0
  15. {bitfab_py-0.78.0 → bitfab_py-0.78.1}/bitfab/cloudReplay.py +0 -0
  16. {bitfab_py-0.78.0 → bitfab_py-0.78.1}/bitfab/cloud_replay_cli.py +0 -0
  17. {bitfab_py-0.78.0 → bitfab_py-0.78.1}/bitfab/commit_ref.py +0 -0
  18. {bitfab_py-0.78.0 → bitfab_py-0.78.1}/bitfab/compress.py +0 -0
  19. {bitfab_py-0.78.0 → bitfab_py-0.78.1}/bitfab/constants.py +0 -0
  20. {bitfab_py-0.78.0 → bitfab_py-0.78.1}/bitfab/datasets.py +0 -0
  21. {bitfab_py-0.78.0 → bitfab_py-0.78.1}/bitfab/db_snapshot.py +0 -0
  22. {bitfab_py-0.78.0 → bitfab_py-0.78.1}/bitfab/error_chain.py +0 -0
  23. {bitfab_py-0.78.0 → bitfab_py-0.78.1}/bitfab/experiment_id.py +0 -0
  24. {bitfab_py-0.78.0 → bitfab_py-0.78.1}/bitfab/experiments.py +0 -0
  25. {bitfab_py-0.78.0 → bitfab_py-0.78.1}/bitfab/finalizers.py +0 -0
  26. {bitfab_py-0.78.0 → bitfab_py-0.78.1}/bitfab/git_command.py +0 -0
  27. {bitfab_py-0.78.0 → bitfab_py-0.78.1}/bitfab/git_state.py +0 -0
  28. {bitfab_py-0.78.0 → bitfab_py-0.78.1}/bitfab/google_calls.py +0 -0
  29. {bitfab_py-0.78.0 → bitfab_py-0.78.1}/bitfab/graders.py +0 -0
  30. {bitfab_py-0.78.0 → bitfab_py-0.78.1}/bitfab/http.py +0 -0
  31. {bitfab_py-0.78.0 → bitfab_py-0.78.1}/bitfab/integration_fixture.py +0 -0
  32. {bitfab_py-0.78.0 → bitfab_py-0.78.1}/bitfab/jev.py +0 -0
  33. {bitfab_py-0.78.0 → bitfab_py-0.78.1}/bitfab/labels.py +0 -0
  34. {bitfab_py-0.78.0 → bitfab_py-0.78.1}/bitfab/langgraph.py +0 -0
  35. {bitfab_py-0.78.0 → bitfab_py-0.78.1}/bitfab/langgraph_integration.py +0 -0
  36. {bitfab_py-0.78.0 → bitfab_py-0.78.1}/bitfab/langgraph_runs.py +0 -0
  37. {bitfab_py-0.78.0 → bitfab_py-0.78.1}/bitfab/mock_matching.py +0 -0
  38. {bitfab_py-0.78.0 → bitfab_py-0.78.1}/bitfab/mock_override.py +0 -0
  39. {bitfab_py-0.78.0 → bitfab_py-0.78.1}/bitfab/openai_agent_sdk.py +0 -0
  40. {bitfab_py-0.78.0 → bitfab_py-0.78.1}/bitfab/openai_agents_usage.py +0 -0
  41. {bitfab_py-0.78.0 → bitfab_py-0.78.1}/bitfab/organization_members.py +0 -0
  42. {bitfab_py-0.78.0 → bitfab_py-0.78.1}/bitfab/otel.py +0 -0
  43. {bitfab_py-0.78.0 → bitfab_py-0.78.1}/bitfab/payload_budget.py +0 -0
  44. {bitfab_py-0.78.0 → bitfab_py-0.78.1}/bitfab/processor_payload.py +0 -0
  45. {bitfab_py-0.78.0 → bitfab_py-0.78.1}/bitfab/provider_calls.py +0 -0
  46. {bitfab_py-0.78.0 → bitfab_py-0.78.1}/bitfab/replay.py +0 -0
  47. {bitfab_py-0.78.0 → bitfab_py-0.78.1}/bitfab/replay_branch.py +0 -0
  48. {bitfab_py-0.78.0 → bitfab_py-0.78.1}/bitfab/replay_cli.py +0 -0
  49. {bitfab_py-0.78.0 → bitfab_py-0.78.1}/bitfab/replay_heartbeat.py +0 -0
  50. {bitfab_py-0.78.0 → bitfab_py-0.78.1}/bitfab/replay_interrupt.py +0 -0
  51. {bitfab_py-0.78.0 → bitfab_py-0.78.1}/bitfab/replay_invocation.py +0 -0
  52. {bitfab_py-0.78.0 → bitfab_py-0.78.1}/bitfab/replay_memory.py +0 -0
  53. {bitfab_py-0.78.0 → bitfab_py-0.78.1}/bitfab/replay_processes.py +0 -0
  54. {bitfab_py-0.78.0 → bitfab_py-0.78.1}/bitfab/replay_registry.py +0 -0
  55. {bitfab_py-0.78.0 → bitfab_py-0.78.1}/bitfab/sandbox.py +0 -0
  56. {bitfab_py-0.78.0 → bitfab_py-0.78.1}/bitfab/seed_cli.py +0 -0
  57. {bitfab_py-0.78.0 → bitfab_py-0.78.1}/bitfab/selective_replay.py +0 -0
  58. {bitfab_py-0.78.0 → bitfab_py-0.78.1}/bitfab/serialize.py +0 -0
  59. {bitfab_py-0.78.0 → bitfab_py-0.78.1}/bitfab/service_calls.py +0 -0
  60. {bitfab_py-0.78.0 → bitfab_py-0.78.1}/bitfab/simulation_plan.py +0 -0
  61. {bitfab_py-0.78.0 → bitfab_py-0.78.1}/bitfab/span_meta.py +0 -0
  62. {bitfab_py-0.78.0 → bitfab_py-0.78.1}/bitfab/span_origin.py +0 -0
  63. {bitfab_py-0.78.0 → bitfab_py-0.78.1}/bitfab/spans.py +0 -0
  64. {bitfab_py-0.78.0 → bitfab_py-0.78.1}/bitfab/subtree.py +0 -0
  65. {bitfab_py-0.78.0 → bitfab_py-0.78.1}/bitfab/thread_propagation.py +0 -0
  66. {bitfab_py-0.78.0 → bitfab_py-0.78.1}/bitfab/timestamp.py +0 -0
  67. {bitfab_py-0.78.0 → bitfab_py-0.78.1}/bitfab/trace_completion.py +0 -0
  68. {bitfab_py-0.78.0 → bitfab_py-0.78.1}/bitfab/trace_metadata.py +0 -0
  69. {bitfab_py-0.78.0 → bitfab_py-0.78.1}/bitfab/trace_payload.py +0 -0
  70. {bitfab_py-0.78.0 → bitfab_py-0.78.1}/bitfab/traces.py +0 -0
  71. {bitfab_py-0.78.0 → bitfab_py-0.78.1}/bitfab/tracing.py +0 -0
  72. {bitfab_py-0.78.0 → bitfab_py-0.78.1}/bitfab/transport.py +0 -0
  73. {bitfab_py-0.78.0 → bitfab_py-0.78.1}/bitfab/transport_types.py +0 -0
  74. {bitfab_py-0.78.0 → bitfab_py-0.78.1}/bitfab/verdicts.py +0 -0
  75. {bitfab_py-0.78.0 → bitfab_py-0.78.1}/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.0
3
+ Version: 0.78.1
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
@@ -19,6 +19,9 @@ GMAIL_SANDBOX_NAME = "Gmail"
19
19
  GET_METHOD = "gmail.users.messages.get"
20
20
  LIST_METHOD = "gmail.users.messages.list"
21
21
  PROFILE_METHOD = "gmail.users.getProfile"
22
+ LABELS_LIST_METHOD = "gmail.users.labels.list"
23
+ LABEL_GET_METHOD = "gmail.users.labels.get"
24
+ SEND_AS_LIST_METHOD = "gmail.users.settings.sendAs.list"
22
25
  SYSTEM_LABELS = (
23
26
  "INBOX",
24
27
  "SENT",
@@ -185,7 +188,14 @@ def mailbox_from_recorded_calls(ctx: SandboxStartCtx) -> dict[str, Any]:
185
188
  if ctx.recorded_state is not None:
186
189
  return as_mailboxes(ctx, ctx.recorded_state)
187
190
  by_credential: dict[str | None, dict[str, Any]] = {}
188
- for name in (GET_METHOD, PROFILE_METHOD, LIST_METHOD):
191
+ for name in (
192
+ GET_METHOD,
193
+ PROFILE_METHOD,
194
+ LIST_METHOD,
195
+ LABELS_LIST_METHOD,
196
+ LABEL_GET_METHOD,
197
+ SEND_AS_LIST_METHOD,
198
+ ):
189
199
  for span in ctx.recorded_spans(name):
190
200
  output = span.output
191
201
  if not isinstance(output, dict) or HTTP_ERROR_KEY in output:
@@ -199,6 +209,8 @@ def mailbox_from_recorded_calls(ctx: SandboxStartCtx) -> dict[str, Any]:
199
209
  "emailAddress": None,
200
210
  "messages": {},
201
211
  "searches": [],
212
+ "labels": {},
213
+ "sendAs": None,
202
214
  },
203
215
  )
204
216
  if name == LIST_METHOD and not given.get("pageToken"):
@@ -214,13 +226,32 @@ def mailbox_from_recorded_calls(ctx: SandboxStartCtx) -> dict[str, Any]:
214
226
  )
215
227
  if name == PROFILE_METHOD:
216
228
  box["emailAddress"] = output.get("emailAddress") or box["emailAddress"]
229
+ if name == LABELS_LIST_METHOD:
230
+ for label in output.get("labels") or []:
231
+ _keep_user_label(box["labels"], label)
232
+ if name == LABEL_GET_METHOD:
233
+ _keep_user_label(box["labels"], output)
234
+ if name == SEND_AS_LIST_METHOD and isinstance(output.get("sendAs"), list):
235
+ box["sendAs"] = output["sendAs"]
217
236
  boxes = [
218
- {**box, "messages": list(box["messages"].values())}
237
+ {
238
+ **box,
239
+ "messages": list(box["messages"].values()),
240
+ "labels": list(box["labels"].values()),
241
+ }
219
242
  for box in by_credential.values()
220
243
  ]
221
244
  return as_mailboxes(ctx, {"mailboxes": boxes or [{}]})
222
245
 
223
246
 
247
+ def _keep_user_label(into: dict[str, dict[str, Any]], label: Any) -> None:
248
+ if not isinstance(label, dict) or not label.get("id"):
249
+ return
250
+ if label.get("type") == "system" or label["id"] in SYSTEM_LABELS:
251
+ return
252
+ into[str(label["id"])] = label
253
+
254
+
224
255
  def as_mailboxes(ctx: SandboxStartCtx, started: Any) -> dict[str, Any]:
225
256
  if isinstance(started, dict) and isinstance(started.get("mailboxes"), list):
226
257
  boxes = started["mailboxes"]
@@ -255,6 +286,8 @@ def as_mailboxes(ctx: SandboxStartCtx, started: Any) -> dict[str, Any]:
255
286
  drafts=box.get("drafts"),
256
287
  details=box.get("details"),
257
288
  searches=box.get("searches"),
289
+ labels=box.get("labels"),
290
+ send_as=box.get("sendAs"),
258
291
  )
259
292
  for index, box in enumerate(boxes or [{}])
260
293
  ]
@@ -270,6 +303,8 @@ def new_mailbox(
270
303
  drafts: list[dict[str, Any]] | None = None,
271
304
  details: dict[str, Any] | None = None,
272
305
  searches: list[dict[str, Any]] | None = None,
306
+ labels: list[dict[str, Any] | str] | None = None,
307
+ send_as: list[dict[str, Any]] | None = None,
273
308
  ) -> dict[str, Any]:
274
309
  normalized = [gmail_message(message) for message in messages or []]
275
310
  for message in normalized:
@@ -296,10 +331,25 @@ def new_mailbox(
296
331
  "messages": normalized,
297
332
  "drafts": list(drafts or []),
298
333
  "searches": list(searches or []),
334
+ "labels": [_user_label(label) for label in labels or []],
335
+ "sendAs": None if send_as is None else [dict(entry) for entry in send_as],
299
336
  "notes": [],
300
337
  }
301
338
 
302
339
 
340
+ def _user_label(label: dict[str, Any] | str) -> dict[str, Any]:
341
+ given = {"name": label} if isinstance(label, str) else dict(label)
342
+ name = str(given.get("name") or given.get("id") or "")
343
+ return {
344
+ "id": str(given.get("id") or name),
345
+ "name": name,
346
+ "type": "user",
347
+ "messageListVisibility": "show",
348
+ "labelListVisibility": "labelShow",
349
+ **given,
350
+ }
351
+
352
+
303
353
  def _note(state: dict[str, Any], text: str) -> None:
304
354
  notes = state.setdefault("notes", [])
305
355
  if text not in notes:
@@ -387,6 +437,19 @@ def _relative_millis(value: str) -> int | None:
387
437
  return days * 86_400_000
388
438
 
389
439
 
440
+ def _search_name(name: str) -> str:
441
+ return re.sub(r"[\s/&]+", "-", name.strip().lower())
442
+
443
+
444
+ def _label_ids_named(state: dict[str, Any], value: str) -> set[str]:
445
+ wanted = _search_name(value)
446
+ return {
447
+ str(label.get("id"))
448
+ for label in state.get("labels") or []
449
+ if _search_name(str(label.get("name") or "")) == wanted
450
+ }
451
+
452
+
390
453
  def _contains(haystack: str, needle: str) -> bool:
391
454
  return needle.lower() in haystack.lower()
392
455
 
@@ -422,7 +485,12 @@ def _term_matches(state: dict[str, Any], message: dict[str, Any], term: str) ->
422
485
  return wanted.upper() in labels
423
486
  if operator in {"in", "label"}:
424
487
  wanted = value.upper().replace("-", "_")
425
- return wanted == "ANYWHERE" or wanted in labels or value in labels
488
+ return (
489
+ wanted == "ANYWHERE"
490
+ or wanted in labels
491
+ or value in labels
492
+ or bool(_label_ids_named(state, value) & labels)
493
+ )
426
494
  if operator == "has":
427
495
  return value.lower() != "attachment" or bool(
428
496
  _attachments(message.get("payload") or {})
@@ -782,10 +850,106 @@ def _profile(state: dict[str, Any], _params: dict[str, Any]) -> dict[str, Any]:
782
850
  }
783
851
 
784
852
 
785
- def _labels(_state: dict[str, Any], _params: dict[str, Any]) -> dict[str, Any]:
853
+ def _all_labels(state: dict[str, Any]) -> list[dict[str, Any]]:
854
+ found = [{"id": label, "name": label, "type": "system"} for label in SYSTEM_LABELS]
855
+ known = set(SYSTEM_LABELS)
856
+ for label in state.setdefault("labels", []):
857
+ if label["id"] not in known:
858
+ known.add(label["id"])
859
+ found.append(label)
860
+ for message in state["messages"]:
861
+ for label_id in message.get("labelIds") or []:
862
+ if label_id in known:
863
+ continue
864
+ known.add(label_id)
865
+ _note(
866
+ state,
867
+ f"label {label_id} was only seen on messages, so its name is its id",
868
+ )
869
+ found.append(_user_label({"id": label_id, "name": label_id}))
870
+ return found
871
+
872
+
873
+ def _labels(state: dict[str, Any], _params: dict[str, Any]) -> dict[str, Any]:
874
+ return {"labels": _all_labels(state)}
875
+
876
+
877
+ def _label_get(state: dict[str, Any], params: dict[str, Any]) -> dict[str, Any]:
878
+ wanted = str(params.get("id"))
879
+ label = next((lb for lb in _all_labels(state) if lb["id"] == wanted), None)
880
+ if label is None:
881
+ return _not_found(f"label {wanted}")
882
+ return copy.deepcopy(label)
883
+
884
+
885
+ def _conflict(message: str) -> dict[str, Any]:
786
886
  return {
787
- "labels": [
788
- {"id": label, "name": label, "type": "system"} for label in SYSTEM_LABELS
887
+ HTTP_ERROR_KEY: {
888
+ "code": 409,
889
+ "message": message,
890
+ "status": "ABORTED",
891
+ "errors": [{"message": message, "domain": "global", "reason": "aborted"}],
892
+ }
893
+ }
894
+
895
+
896
+ def _invalid(message: str) -> dict[str, Any]:
897
+ return {
898
+ HTTP_ERROR_KEY: {
899
+ "code": 400,
900
+ "message": message,
901
+ "status": "INVALID_ARGUMENT",
902
+ "errors": [{"message": message, "domain": "global", "reason": "invalid"}],
903
+ }
904
+ }
905
+
906
+
907
+ def _label_create(state: dict[str, Any], params: dict[str, Any]) -> dict[str, Any]:
908
+ body = params.get("body") or {}
909
+ name = str(body.get("name") or "").strip()
910
+ if not name:
911
+ return _invalid("Invalid label name")
912
+ if any(lb["name"].lower() == name.lower() for lb in _all_labels(state)):
913
+ return _conflict("Label name exists or conflicts")
914
+ label = _user_label(
915
+ {
916
+ **{k: v for k, v in body.items() if k not in {"id", "type"}},
917
+ "id": _next_id(state, "Label_sandbox"),
918
+ "name": name,
919
+ }
920
+ )
921
+ state["labels"].append(label)
922
+ return copy.deepcopy(label)
923
+
924
+
925
+ def _send_as(state: dict[str, Any], _params: dict[str, Any]) -> dict[str, Any]:
926
+ recorded = state.get("sendAs")
927
+ if recorded is not None:
928
+ return {"sendAs": copy.deepcopy(recorded)}
929
+ address = state.get("emailAddress")
930
+ if not address:
931
+ _note(
932
+ state,
933
+ "the account's address was never recorded, so it has no send-as addresses",
934
+ )
935
+ return {"sendAs": []}
936
+ _note(
937
+ state,
938
+ "send-as settings were never recorded, so the account's own address is "
939
+ "listed with no display name or signature",
940
+ )
941
+ return {
942
+ "sendAs": [
943
+ {
944
+ "sendAsEmail": address,
945
+ "displayName": "",
946
+ "replyToAddress": "",
947
+ "signature": "",
948
+ "isPrimary": True,
949
+ "isDefault": True,
950
+ "treatAsAlias": False,
951
+ "verificationStatus": "accepted",
952
+ }
789
953
  ]
790
954
  }
791
955
 
@@ -808,7 +972,10 @@ HANDLERS: dict[str, Callable[[dict[str, Any], dict[str, Any]], dict[str, Any]]]
808
972
  "gmail.users.drafts.list": _drafts_list,
809
973
  "gmail.users.threads.get": _thread,
810
974
  "gmail.users.history.list": _history,
811
- "gmail.users.labels.list": _labels,
975
+ LABELS_LIST_METHOD: _labels,
976
+ LABEL_GET_METHOD: _label_get,
977
+ "gmail.users.labels.create": _label_create,
978
+ SEND_AS_LIST_METHOD: _send_as,
812
979
  PROFILE_METHOD: _profile,
813
980
  }
814
981
 
@@ -880,6 +1047,8 @@ def _empty_mailbox_for(boxes: list[dict[str, Any]], address: str) -> dict[str, A
880
1047
  "messages": [],
881
1048
  "drafts": [],
882
1049
  "searches": [],
1050
+ "labels": [],
1051
+ "sendAs": None,
883
1052
  "notes": [f"{address} had no mailbox in the original run, so it starts empty"],
884
1053
  }
885
1054
 
@@ -918,7 +1087,12 @@ def gmail_sandbox(
918
1087
  Args:
919
1088
  start: Builds the mailbox for one replay item from a
920
1089
  ``SandboxStartCtx``. Return a list of messages, or
921
- ``{"messages": [...], "emailAddress": ..., "drafts": [...]}``.
1090
+ ``{"messages": [...], "emailAddress": ..., "drafts": [...],
1091
+ "labels": [...], "sendAs": [...]}``. ``labels`` are the account's
1092
+ own labels, each a Gmail label or a name; ``sendAs`` are Gmail
1093
+ send-as entries (``sendAsEmail``, ``displayName``, ``signature``,
1094
+ ...). Without ``sendAs``, the account's address is listed with no
1095
+ signature.
922
1096
  Each message is a Gmail API message or plain fields as
923
1097
  ``gmail_message`` takes them; a plain ``account`` field puts the
924
1098
  message in that account's mailbox. For several accounts, return
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "bitfab-py"
3
- version = "0.78.0"
3
+ version = "0.78.1"
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
File without changes
File without changes