greentic_types/
worker.rs

1//! Generic worker envelope shared across runner and messaging components.
2
3use alloc::{string::String, vec::Vec};
4
5#[cfg(feature = "schemars")]
6use schemars::JsonSchema;
7#[cfg(feature = "serde")]
8use serde::{Deserialize, Serialize};
9
10use crate::TenantCtx;
11
12/// Request payload for invoking a worker.
13#[derive(Clone, Debug, PartialEq, Eq)]
14#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
15#[cfg_attr(feature = "schemars", derive(JsonSchema))]
16pub struct WorkerRequest {
17    /// Version of the worker envelope (for example `1.0`).
18    pub version: String,
19    /// Tenant context propagated to the worker.
20    pub tenant: TenantCtx,
21    /// Identifier of the target worker (for example `greentic-repo-assistant`).
22    pub worker_id: String,
23    /// Optional correlation identifier for tracing requests across transports.
24    #[cfg_attr(
25        feature = "serde",
26        serde(default, skip_serializing_if = "Option::is_none")
27    )]
28    pub correlation_id: Option<String>,
29    /// Optional session identifier for conversational workers.
30    #[cfg_attr(
31        feature = "serde",
32        serde(default, skip_serializing_if = "Option::is_none")
33    )]
34    pub session_id: Option<String>,
35    /// Optional thread identifier when the worker groups messages into threads.
36    #[cfg_attr(
37        feature = "serde",
38        serde(default, skip_serializing_if = "Option::is_none")
39    )]
40    pub thread_id: Option<String>,
41    /// JSON-encoded payload forwarded to the worker; the ABI treats this as opaque.
42    pub payload_json: String,
43    /// UTC timestamp for when the request was created (ISO8601).
44    pub timestamp_utc: String,
45}
46
47/// Individual message emitted by a worker.
48#[derive(Clone, Debug, PartialEq, Eq)]
49#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
50#[cfg_attr(feature = "schemars", derive(JsonSchema))]
51pub struct WorkerMessage {
52    /// Message kind (for example `text`, `card`, `event`).
53    pub kind: String,
54    /// JSON-encoded message payload; workers and callers negotiate its shape.
55    pub payload_json: String,
56}
57
58/// Response envelope returned by worker executions.
59#[derive(Clone, Debug, PartialEq, Eq)]
60#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
61#[cfg_attr(feature = "schemars", derive(JsonSchema))]
62pub struct WorkerResponse {
63    /// Version of the worker envelope (mirrors the request).
64    pub version: String,
65    /// Tenant context propagated to the worker.
66    pub tenant: TenantCtx,
67    /// Identifier of the worker that handled the request.
68    pub worker_id: String,
69    /// Optional correlation identifier for tracing requests across transports.
70    #[cfg_attr(
71        feature = "serde",
72        serde(default, skip_serializing_if = "Option::is_none")
73    )]
74    pub correlation_id: Option<String>,
75    /// Optional session identifier for conversational workers.
76    #[cfg_attr(
77        feature = "serde",
78        serde(default, skip_serializing_if = "Option::is_none")
79    )]
80    pub session_id: Option<String>,
81    /// Optional thread identifier when the worker groups messages into threads.
82    #[cfg_attr(
83        feature = "serde",
84        serde(default, skip_serializing_if = "Option::is_none")
85    )]
86    pub thread_id: Option<String>,
87    /// Messages produced by the worker execution.
88    #[cfg_attr(
89        feature = "serde",
90        serde(default, skip_serializing_if = "Vec::is_empty")
91    )]
92    pub messages: Vec<WorkerMessage>,
93    /// UTC timestamp for when the response was produced (ISO8601).
94    pub timestamp_utc: String,
95}