From 408f2c7f1770a8e76bfe27a98c78189b013b7a78 Mon Sep 17 00:00:00 2001 From: Arthur Ceccotti Date: Fri, 17 Oct 2025 15:06:52 +0100 Subject: [PATCH 1/2] Add conversation_tokens --- src/gradient_labs/_conversation_add_message.py | 6 ++++++ src/gradient_labs/_conversation_start.py | 6 ++++++ src/gradient_labs/webhook.py | 3 +++ 3 files changed, 15 insertions(+) diff --git a/src/gradient_labs/_conversation_add_message.py b/src/gradient_labs/_conversation_add_message.py index 3d5756c..15b6dbb 100644 --- a/src/gradient_labs/_conversation_add_message.py +++ b/src/gradient_labs/_conversation_add_message.py @@ -85,6 +85,10 @@ class Message: # attachments contains any files that were uploaded with this message. attachments: Optional[List[Attachment]] = None + # conversation_token is the raw sensitive token that can be optionally provided in every message. + # The latest token of the conversation will be echoed back in future Webhooks, under the header `X-GradientLabs-Token`. + conversation_token: Optional[str] = None + def add_message( *, client: HttpClient, conversation_id: str, params: AddMessageParams @@ -101,6 +105,8 @@ def add_message( body["metadata"] = params.metadata if params.attachments is not None: body["attachments"] = [a.to_dict() for a in params.attachments] + if params.conversation_token is not None: + body["conversation_token"] = params.conversation_token rsp = client.post(path=f"conversations/{conversation_id}/messages", body=body) return Message.from_dict(rsp) diff --git a/src/gradient_labs/_conversation_start.py b/src/gradient_labs/_conversation_start.py index 97d2c94..1cde523 100644 --- a/src/gradient_labs/_conversation_start.py +++ b/src/gradient_labs/_conversation_start.py @@ -47,6 +47,10 @@ class StartConversationParams: # during the conversation. You can also use resources as parameters for your tools. resources: Optional[Dict[str, Any]] = None + # conversation_token is the raw sensitive token that can be optionally provided when starting a conversation. + # The latest token of the conversation will be echoed back in future Webhooks, under the header `X-GradientLabs-Token`. + conversation_token: Optional[str] = None + def start_conversation( *, client: HttpClient, params: StartConversationParams @@ -62,6 +66,8 @@ def start_conversation( body["created"] = HttpClient.localize(params.created) if params.resources is not None: body["resources"] = params.resources + if params.conversation_token is not None: + body["conversation_token"] = params.conversation_token rsp = client.post( path="conversations", diff --git a/src/gradient_labs/webhook.py b/src/gradient_labs/webhook.py index d2d5834..707f845 100644 --- a/src/gradient_labs/webhook.py +++ b/src/gradient_labs/webhook.py @@ -28,6 +28,9 @@ class Webhook: SCHEME = "v1" LEEWAY = timedelta(minutes=5) + SIGNATURE_HEADER_NAME = "X-GradientLabs-Signature" + TOKEN_HEADER_NAME = "X-GradientLabs-Token" + @classmethod def parse_event( cls, From a8f2345ec0e6a0e0efd8bf58d43c7de0aca7bea0 Mon Sep 17 00:00:00 2001 From: Arthur Ceccotti Date: Fri, 17 Oct 2025 15:57:42 +0100 Subject: [PATCH 2/2] Comments --- src/gradient_labs/_conversation_add_message.py | 3 ++- src/gradient_labs/_conversation_start.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/gradient_labs/_conversation_add_message.py b/src/gradient_labs/_conversation_add_message.py index 15b6dbb..724657e 100644 --- a/src/gradient_labs/_conversation_add_message.py +++ b/src/gradient_labs/_conversation_add_message.py @@ -86,7 +86,8 @@ class Message: attachments: Optional[List[Attachment]] = None # conversation_token is the raw sensitive token that can be optionally provided in every message. - # The latest token of the conversation will be echoed back in future Webhooks, under the header `X-GradientLabs-Token`. + # The latest token of the conversation will be echoed back in future Webhooks, under the header `X-GradientLabs-Token`, + # as well as in HTTP Tools using templates. conversation_token: Optional[str] = None diff --git a/src/gradient_labs/_conversation_start.py b/src/gradient_labs/_conversation_start.py index 1cde523..8267baf 100644 --- a/src/gradient_labs/_conversation_start.py +++ b/src/gradient_labs/_conversation_start.py @@ -48,7 +48,8 @@ class StartConversationParams: resources: Optional[Dict[str, Any]] = None # conversation_token is the raw sensitive token that can be optionally provided when starting a conversation. - # The latest token of the conversation will be echoed back in future Webhooks, under the header `X-GradientLabs-Token`. + # The latest token of the conversation will be echoed back in future Webhooks, under the header `X-GradientLabs-Token`, + # as well as in HTTP Tools using templates. conversation_token: Optional[str] = None