Skip to content

Commit 8f5a4d4

Browse files
authored
feat(subscriptions): add inline_body kwarg (cueapi #791 / Item 1 parity) (#42)
Server-side Item 1 (hosted PR #791) added `subscriptions.inline_body` opt-in body embedding for pull subscriptions — when True, the source message body is embedded in the event payload as `payload.body`, eliminating the extra GET /v1/messages/{id} round-trip on the consumer side. This SDK port wires the kwarg through `AgentsResource.subscriptions_create()`: optional `inline_body: Optional[bool] = None`. When None (default), the field is OMITTED from the wire body — server default of False applies. When True or False, the value is passed through verbatim. Docstring updates: - Document the 32KB cap (bodies > 32KB → `payload.body_omitted = "size_too_large"` + `payload.body_size_bytes = N`, consumer falls back to fetch). - Note that both pull and webhook subscription responses surface `inline_body` so list-callers can observe own state. Tests (3 new): - test_inline_body_omitted_when_none — default case, no payload noise - test_inline_body_true_passes_through — opt-in path - test_inline_body_false_explicit_passes_through — explicit-False path (distinct from None for callers who want to force the no-embed contract). Out of scope: - Parity-manifest refresh: manifest is dated 2026-05-07 and missing the entire PR-1b event-emit coverage (subscriptions_create/list/ delete + events_pull). Filing a separate Backlog row for the manifest refresh + audit-date bump. Backlog row: cmp1v3ck3.
1 parent ba1c45f commit 8f5a4d4

2 files changed

Lines changed: 76 additions & 1 deletion

File tree

cueapi/resources/agents.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ def subscriptions_create(
252252
event_type: str,
253253
delivery_target: str,
254254
webhook_url: Optional[str] = None,
255+
inline_body: Optional[bool] = None,
255256
) -> Dict[str, Any]:
256257
"""Create a subscription for an agent (PR-1b event-emit primitive).
257258
@@ -266,11 +267,22 @@ def subscriptions_create(
266267
``"webhook"`` (server POSTs to ``webhook_url`` with HMAC).
267268
webhook_url: Required when ``delivery_target="webhook"``;
268269
HTTPS only. Ignored for pull subscriptions.
270+
inline_body: Opt into body embedding on emitted events
271+
(server Item 1, hosted PR #791). When ``True``, the source
272+
message body is embedded in the event payload as
273+
``payload.body`` — eliminates the extra
274+
``GET /v1/messages/{id}`` round-trip on the consumer side.
275+
Bodies > 32KB are NOT embedded; instead the payload carries
276+
``payload.body_omitted = "size_too_large"`` and
277+
``payload.body_size_bytes = N`` so consumers can fall back
278+
to the fetch. Default ``None`` means "don't send the field"
279+
— server default is ``False``.
269280
270281
Returns:
271282
Subscription dict. For webhook subscriptions, the response
272283
includes ``webhook_secret`` ONE-TIME — save it now; the
273-
server never re-exposes it.
284+
server never re-exposes it. Both pull and webhook responses
285+
surface ``inline_body`` so list-callers can observe own state.
274286
275287
Errors:
276288
400 ``unknown_event_type`` / ``invalid_delivery_target`` /
@@ -282,6 +294,8 @@ def subscriptions_create(
282294
}
283295
if webhook_url is not None:
284296
body["webhook_url"] = webhook_url
297+
if inline_body is not None:
298+
body["inline_body"] = inline_body
285299
return self._client._post(f"/v1/agents/{ref}/subscriptions", json=body)
286300

287301
def subscriptions_list(self, ref: str) -> Dict[str, Any]:

tests/test_agents_resource.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,67 @@ def test_webhook_url_omitted_when_none(self):
346346
body = mock_client._post.call_args.kwargs["json"]
347347
assert "webhook_url" not in body
348348

349+
def test_inline_body_omitted_when_none(self):
350+
# Server-side default is False; sending an unset kwarg should
351+
# NOT put the field on the wire (avoid payload noise for
352+
# callers who don't care about body embedding).
353+
mock_client = MagicMock()
354+
mock_client._post.return_value = {"id": "sub_uuid"}
355+
r = AgentsResource(mock_client)
356+
357+
r.subscriptions_create(
358+
"agt_x",
359+
event_type="message.received",
360+
delivery_target="pull",
361+
)
362+
363+
body = mock_client._post.call_args.kwargs["json"]
364+
assert "inline_body" not in body
365+
366+
def test_inline_body_true_passes_through(self):
367+
# Opt-in: inline_body=True embeds message.body on emitted events
368+
# (server Item 1, hosted PR #791).
369+
mock_client = MagicMock()
370+
mock_client._post.return_value = {
371+
"id": "sub_uuid",
372+
"delivery_target": "pull",
373+
"inline_body": True,
374+
}
375+
r = AgentsResource(mock_client)
376+
377+
r.subscriptions_create(
378+
"agt_x",
379+
event_type="message.received",
380+
delivery_target="pull",
381+
inline_body=True,
382+
)
383+
384+
body = mock_client._post.call_args.kwargs["json"]
385+
assert body["inline_body"] is True
386+
387+
def test_inline_body_false_explicit_passes_through(self):
388+
# Explicit False (distinct from None / unset) — caller may want
389+
# to force the no-embed contract on a per-subscription basis.
390+
# We pass it through verbatim; server treats False the same as
391+
# the schema default but explicit is non-noisy.
392+
mock_client = MagicMock()
393+
mock_client._post.return_value = {
394+
"id": "sub_uuid",
395+
"delivery_target": "pull",
396+
"inline_body": False,
397+
}
398+
r = AgentsResource(mock_client)
399+
400+
r.subscriptions_create(
401+
"agt_x",
402+
event_type="message.received",
403+
delivery_target="pull",
404+
inline_body=False,
405+
)
406+
407+
body = mock_client._post.call_args.kwargs["json"]
408+
assert body["inline_body"] is False
409+
349410

350411
class TestSubscriptionsList:
351412
def test_get_path(self):

0 commit comments

Comments
 (0)