Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
refactor(events): typed lifecycle owners and activity attribution (#6803)
Will Hutchinsonb98f171dafa0
diff --git a/Cargo.lock b/Cargo.lockindex fcc84757a3..8102eba373 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -3635,6 +3635,7 @@ dependencies = ["async-trait","attachment","axum",+ "bot_id","chrono","entity_access","entity_access_db_utils",@@ -5464,6 +5465,7 @@ dependencies = ["model-entity","model-error-response","model_notifications",+ "model_owner","models_dcs","models_opensearch","models_permissions",diff --git a/apps/web/src/lib/service-clients/service-storage/openapi.json b/apps/web/src/lib/service-clients/service-storage/openapi.jsonindex 05c0e1f925..974ec91211 100644--- a/apps/web/src/lib/service-clients/service-storage/openapi.json+++ b/apps/web/src/lib/service-clients/service-storage/openapi.json@@ -21024,7 +21024,7 @@},"owner": {"type": "string",- "description": "The owner of the new copy (the copier)."+ "description": "The principal who owns the new copy."},"project_id": {"type": ["string", "null"],@@ -21059,7 +21059,7 @@"properties": {"actor": {"type": ["string", "null"],- "description": "Who mechanically created the document. Absent on events published\nbefore attribution: ingest then treats [`Self::owner`] as the actor."+ "description": "Who mechanically created the document. Absent on events published\nbefore attribution: ingest derives a user/bot actor from [`Self::owner`].\nTeam owners fall back to [`Self::on_behalf_of`], then the system bot."},"created_at": {"type": ["string", "null"],@@ -21098,7 +21098,7 @@},"owner": {"type": "string",- "description": "The owner (creator) of the document."+ "description": "The principal who owns the document."},"project_id": {"type": ["string", "null"],diff --git a/crates/chat/Cargo.toml b/crates/chat/Cargo.tomlindex d7322ee703..89beaf0ed3 100644--- a/crates/chat/Cargo.toml+++ b/crates/chat/Cargo.toml@@ -34,6 +34,7 @@ activity = { path = "../activity", default-features = false }agent = { path = "../agent" }ai_toolset = { path = "../ai_toolset" }anyhow = { workspace = true }+bot_id = { path = "../bot_id" }attachment = { path = "../attachment" }chrono = { workspace = true }entity_access = { path = "../entity_access", default-features = false }diff --git a/crates/chat/src/domain/activity.rs b/crates/chat/src/domain/activity.rsindex e772df4e61..9414f78b26 100644--- a/crates/chat/src/domain/activity.rs+++ b/crates/chat/src/domain/activity.rs@@ -8,6 +8,7 @@ use ::activity::{event_time,};use chrono::{DateTime, Utc};+use model_owner::Owner;use uuid::Uuid;use super::events::{ChatMessageRole, ChatTopicEvent};@@ -66,7 +67,12 @@ impl ActivitySource for ChatTopicEvent {match self {ChatTopicEvent::Created(m) => common(- Actor::new_from_user(m.owner.clone()),+ match &m.owner {+ Owner::User(user) => Actor::new_from_user(user.clone()),+ Owner::Bot(bot_id) => Actor::new_from_bot(*bot_id),+ // A team is not an actor; display unattributed creation as system activity.+ Owner::Team(_) => Actor::new_from_bot(bot_id::MACRO_SYSTEM_BOT_ID),+ },CommonAction::Created,&m.chat_id,now(),diff --git a/crates/chat/src/domain/activity/test.rs b/crates/chat/src/domain/activity/test.rsindex 611b8d6767..757c4853b8 100644--- a/crates/chat/src/domain/activity/test.rs+++ b/crates/chat/src/domain/activity/test.rs@@ -33,7 +33,7 @@ fn message(role: ChatMessageRole, actor: Option<MacroUserIdStr<'static>>) -> Chafn created_and_user_message_map_to_activities() {let created = envelope(ChatTopicEvent::Created(ChatCreatedMetadata {chat_id: "chat-1".to_string(),- owner: user("macro|[email protected]"),+ owner: Owner::User(user("macro|[email protected]")),name: "planning".to_string(),project_id: None,}));@@ -53,6 +53,34 @@ fn created_and_user_message_map_to_activities() {assert_eq!(activities[0].action, Action::Messaged);}+#[test]+fn created_derives_an_actor_for_every_owner_kind() {+ let user = user("macro|[email protected]");+ let bot = bot_id::MACRO_AI_BOT_ID;+ for (owner, expected_actor) in [+ (Owner::User(user.clone()), Actor::new_from_user(user)),+ (Owner::Bot(bot), Actor::new_from_bot(bot)),+ (+ Owner::Team(Uuid::from_u128(1)),+ Actor::new_from_bot(bot_id::MACRO_SYSTEM_BOT_ID),+ ),+ ] {+ let event = envelope(ChatTopicEvent::Created(ChatCreatedMetadata {+ chat_id: "chat-1".to_string(),+ owner,+ name: "planning".to_string(),+ project_id: None,+ }));+ let Ingest::Insert(activities) = event.event.ingest(event.event_id) else {+ panic!("expected a creation activity");+ };+ assert_eq!(activities.len(), 1);+ assert_eq!(activities[0].actor, expected_actor);+ assert_eq!(activities[0].subject_id, expected_actor.as_ref());+ assert_eq!(activities[0].action, Action::Created);+ }+}+#[test]fn assistant_and_actorless_messages_are_dropped() {let assistant = envelope(message(diff --git a/crates/chat/src/domain/events.rs b/crates/chat/src/domain/events.rsindex 89d136b37a..b14c0d1ef3 100644--- a/crates/chat/src/domain/events.rs+++ b/crates/chat/src/domain/events.rs@@ -10,6 +10,7 @@ mod test;use macro_event_broker::{Event, MacroEvent, TopicEvent};use macro_event_topics::MacroChatsTopic;use macro_user_id::user_id::MacroUserIdStr;+use model_owner::Owner;use serde::{Deserialize, Serialize};/// Metadata for [`ChatTopicEvent::Created`].@@ -17,8 +18,8 @@ use serde::{Deserialize, Serialize};pub struct ChatCreatedMetadata {/// Identifier of the created chat.pub chat_id: String,- /// User who owns the chat.- pub owner: MacroUserIdStr<'static>,+ /// Principal who owns the chat.+ pub owner: Owner,/// Display name of the chat.pub name: String,/// Project the chat was created in, when any.diff --git a/crates/chat/src/domain/events/test.rs b/crates/chat/src/domain/events/test.rsindex 8efab359c0..c4b87fa0be 100644--- a/crates/chat/src/domain/events/test.rs+++ b/crates/chat/src/domain/events/test.rs@@ -16,12 +16,45 @@ fn user_id(value: &str) -> MacroUserIdStr<'static> {MacroUserIdStr::try_from(value.to_string()).expect("valid user id")}+#[test]+fn created_round_trips_all_owner_kinds_with_the_v1_string_wire_format() {+ for principal in [+ "macro|[email protected]",+ "bot|00000000-0000-0000-0000-000000000001",+ "01998a30-1a2b-7c3d-9e4f-5a6b7c8d9e0f",+ ] {+ let payload = json!({+ "event_id": EVENT_ID,+ "schema_version": 1,+ "event_type": "chat.created",+ "metadata": {+ "chat_id": CHAT_ID,+ "owner": principal,+ "name": "New Chat",+ "project_id": null,+ },+ });+ let decoded = ChatMacroEvent::decode(CHAT_ID, &serde_json::to_vec(&payload).unwrap())+ .expect("v1 owner strings decode through the broker");+ assert_eq!(decoded.event().schema_version, 1);+ assert_eq!(<ChatTopicEvent as TopicEvent>::SCHEMA_VERSION, 1);+ let ChatTopicEvent::Created(metadata) = &decoded.event().event else {+ panic!("expected a created event");+ };+ assert_eq!(+ metadata.owner,+ Owner::from_principal_str(principal).unwrap()+ );+ assert_eq!(serde_json::to_value(decoded.event()).unwrap(), payload);+ }+}+fn topic_events() -> Vec<(ChatTopicEvent, Value)> {vec![(ChatTopicEvent::Created(ChatCreatedMetadata {chat_id: CHAT_ID.to_string(),- owner: user_id("macro|[email protected]"),+ owner: Owner::User(user_id("macro|[email protected]")),name: "New Chat".to_string(),project_id: Some(PROJECT_ID.to_string()),}),diff --git a/crates/chat/src/domain/service/chat.rs b/crates/chat/src/domain/service/chat.rsindex 451513d23e..2ba08e1519 100644--- a/crates/chat/src/domain/service/chat.rs+++ b/crates/chat/src/domain/service/chat.rs@@ -24,6 +24,7 @@ use entity_access_management::domain::ports::EntityAccessManagementService;use macro_event_broker::{MacroEventBroker, NoopMacroEventBroker};use macro_user_id::user_id::MacroUserIdStr;use model_entity::EntityType;+use model_owner::Owner;use models_permissions::share_permission::SharePermissionV2;use models_permissions::share_permission::team_share::{AuthorizedTeamShareCommand, TeamShareLevel, TeamSharePolicyError, TeamShareRequest,@@ -204,7 +205,7 @@ whereself.publish_chat_event(&ChatMacroEvent::created(ChatCreatedMetadata {chat_id: chat_id.clone(),- owner: user_id,+ owner: Owner::User(user_id),name,project_id,}));diff --git a/crates/documents/src/domain/activity.rs b/crates/documents/src/domain/activity.rsindex f93a54aa36..09cea6b06e 100644--- a/crates/documents/src/domain/activity.rs+++ b/crates/documents/src/domain/activity.rs@@ -16,11 +16,19 @@ use super::events::DocumentTopicEvent;use macro_user_id::user_id::MacroUserIdStr;use model_owner::Owner;-fn actor_from_owner(owner: &Owner) -> Option<Actor<'static>> {+// Display attribution only: teams cannot act. Prefer the initiating user when+// known, otherwise represent an unattributed team creation as system activity.+fn actor_from_owner(+ owner: &Owner,+ on_behalf_of: Option<&MacroUserIdStr<'static>>,+) -> Actor<'static> {match owner {- Owner::User(user) => Some(Actor::new_from_user(user.clone())),- Owner::Bot(bot_id) => Some(Actor::new_from_bot(*bot_id)),- Owner::Team(_) => None,+ Owner::User(user) => Actor::new_from_user(user.clone()),+ Owner::Bot(bot_id) => Actor::new_from_bot(*bot_id),+ Owner::Team(_) => on_behalf_of+ .cloned()+ .map(Actor::new_from_user)+ .unwrap_or_else(|| Actor::new_from_bot(bot_id::MACRO_SYSTEM_BOT_ID)),}}@@ -61,19 +69,15 @@ impl ActivitySource for DocumentTopicEvent {match self {DocumentTopicEvent::Created(metadata) => {- match metadata- .actor- .clone()- .or_else(|| actor_from_owner(&metadata.owner))- {- Some(actor) => single(- Attribution::new(actor, metadata.on_behalf_of.clone()),- CommonAction::Created,- &metadata.document_id,- metadata.created_at.unwrap_or_else(|| event_time(event_id)),- ),- None => Ingest::Ignore,- }+ let actor = metadata.actor.clone().unwrap_or_else(|| {+ actor_from_owner(&metadata.owner, metadata.on_behalf_of.as_ref())+ });+ single(+ Attribution::new(actor, metadata.on_behalf_of.clone()),+ CommonAction::Created,+ &metadata.document_id,+ metadata.created_at.unwrap_or_else(|| event_time(event_id)),+ )}DocumentTopicEvent::Updated(metadata) => {match mutation_attribution(@@ -106,15 +110,12 @@ impl ActivitySource for DocumentTopicEvent {}}// The copy is a new document; its creation is the activity.- DocumentTopicEvent::Copied(metadata) => match actor_from_owner(&metadata.owner) {- Some(actor) => single(- Attribution::direct(actor),- CommonAction::Created,- &metadata.document_id,- event_time(event_id),- ),- None => Ingest::Ignore,- },+ DocumentTopicEvent::Copied(metadata) => single(+ Attribution::direct(actor_from_owner(&metadata.owner, None)),+ CommonAction::Created,+ &metadata.document_id,+ event_time(event_id),+ ),DocumentTopicEvent::Purged(metadata) => {Ingest::Purge(vec![(EntityType::Document, metadata.document_id.clone())])}diff --git a/crates/documents/src/domain/activity/test.rs b/crates/documents/src/domain/activity/test.rsindex 816ed9e5d6..ccb7250e46 100644--- a/crates/documents/src/domain/activity/test.rs+++ b/crates/documents/src/domain/activity/test.rs@@ -204,6 +204,107 @@ fn copied_maps_to_a_created_activity_for_the_new_document() {assert_eq!(activity.entity_id, "22222222-2222-2222-2222-222222222222");}+#[test]+fn creation_and_copy_derive_user_bot_and_team_actors() {+ let user = user("macro|[email protected]");+ let bot = bot_id::MACRO_AI_BOT_ID;+ let system = Actor::new_from_bot(bot_id::MACRO_SYSTEM_BOT_ID);+ for (owner, expected_actor) in [+ (Owner::User(user.clone()), Actor::new_from_user(user)),+ (Owner::Bot(bot), Actor::new_from_bot(bot)),+ (Owner::Team(Uuid::from_u128(1)), system),+ ] {+ let events = [+ DocumentTopicEvent::Created(DocumentCreatedMetadata {+ document_id: DOCUMENT_ID.to_string(),+ owner: owner.clone(),+ actor: None,+ on_behalf_of: None,+ document_name: "notes".to_string(),+ file_type: None,+ project_id: None,+ sub_type: None,+ created_at: None,+ }),+ DocumentTopicEvent::Copied(DocumentCopiedMetadata {+ document_id: DOCUMENT_ID.to_string(),+ source_document_id: "source-document".to_string(),+ source_version_id: None,+ owner,+ document_name: "copy".to_string(),+ file_type: None,+ project_id: None,+ sub_type: None,+ }),+ ];+ for event in events {+ let event = envelope(event);+ let activity = single_activity(event.event.ingest(event.event_id));+ assert_eq!(activity.action, Action::Created);+ assert_eq!(activity.actor, expected_actor);+ assert_eq!(activity.subject_id, expected_actor.as_ref());+ assert_eq!(activity.entity_id, DOCUMENT_ID);+ assert_eq!(activity.occurred_at, event_time(event.event_id));+ }+ }+}++#[test]+fn team_creation_prefers_explicit_actor_then_on_behalf_of_then_system() {+ let initiating_user = user("macro|[email protected]");+ let user_actor = Actor::new_from_user(initiating_user.clone());+ let bot_actor = Actor::new_from_bot(bot_id::MACRO_AI_BOT_ID);+ let system_actor = Actor::new_from_bot(bot_id::MACRO_SYSTEM_BOT_ID);+ for (actor, on_behalf_of, expected_actor, expected_subject) in [+ (+ Some(bot_actor.clone()),+ Some(initiating_user.clone()),+ bot_actor.clone(),+ initiating_user.to_string(),+ ),+ (+ Some(bot_actor.clone()),+ None,+ bot_actor.clone(),+ bot_actor.as_ref().to_string(),+ ),+ (+ Some(user_actor.clone()),+ None,+ user_actor.clone(),+ initiating_user.to_string(),+ ),+ (+ None,+ Some(initiating_user.clone()),+ user_actor,+ initiating_user.to_string(),+ ),+ (+ None,+ None,+ system_actor.clone(),+ system_actor.as_ref().to_string(),+ ),+ ] {+ let event = envelope(DocumentTopicEvent::Created(DocumentCreatedMetadata {+ document_id: DOCUMENT_ID.to_string(),+ owner: Owner::Team(Uuid::from_u128(1)),+ actor,+ on_behalf_of,+ document_name: "team notes".to_string(),+ file_type: None,+ project_id: None,+ sub_type: None,+ created_at: None,+ }));+ let activity = single_activity(event.event.ingest(event.event_id));+ assert_eq!(activity.action, Action::Created);+ assert_eq!(activity.actor, expected_actor);+ assert_eq!(activity.subject_id, expected_subject);+ }+}+#[test]fn purge_requests_entity_deletion() {let event = envelope(DocumentTopicEvent::Purged(DocumentPurgedMetadata {diff --git a/crates/documents/src/domain/events.rs b/crates/documents/src/domain/events.rsindex ae37a24446..1dbd17475c 100644--- a/crates/documents/src/domain/events.rs+++ b/crates/documents/src/domain/events.rs@@ -25,11 +25,12 @@ use super::models::FileTypeUpdate;pub struct DocumentCreatedMetadata {/// The id of the created document.pub document_id: String,- /// The owner (creator) of the document.+ /// The principal who owns the document.#[cfg_attr(feature = "schema", schema(value_type = String))]pub owner: Owner,/// Who mechanically created the document. Absent on events published- /// before attribution: ingest then treats [`Self::owner`] as the actor.+ /// before attribution: ingest derives a user/bot actor from [`Self::owner`].+ /// Team owners fall back to [`Self::on_behalf_of`], then the system bot.#[serde(default, skip_serializing_if = "Option::is_none")]#[cfg_attr(feature = "schema", schema(value_type = Option<String>))]pub actor: Option<Actor<'static>>,@@ -206,7 +207,7 @@ pub struct DocumentCopiedMetadata {pub source_document_id: String,/// The specific source version copied, when requested.pub source_version_id: Option<i64>,- /// The owner of the new copy (the copier).+ /// The principal who owns the new copy.#[cfg_attr(feature = "schema", schema(value_type = String))]pub owner: Owner,/// The name of the new document.diff --git a/crates/documents/src/domain/events/fixtures/document_created_v1.json b/crates/documents/src/domain/events/fixtures/document_created_v1.jsonnew file mode 100644index 0000000000..1d2db3ce27--- /dev/null+++ b/crates/documents/src/domain/events/fixtures/document_created_v1.json@@ -0,0 +1,14 @@+{+ "event_id": "00000000-0000-0000-0000-000000000005",+ "schema_version": 1,+ "event_type": "document.created",+ "metadata": {+ "document_id": "11111111-1111-1111-1111-111111111111",+ "owner": "macro|[email protected]",+ "document_name": "notes",+ "file_type": null,+ "project_id": null,+ "sub_type": null,+ "created_at": null+ }+}diff --git a/crates/documents/src/domain/events/test.rs b/crates/documents/src/domain/events/test.rsindex 47620724aa..c5db749a78 100644--- a/crates/documents/src/domain/events/test.rs+++ b/crates/documents/src/domain/events/test.rs@@ -5,8 +5,9 @@ use serde_json::{Value, json};use uuid::Uuid;use super::{- DocumentContentUploadedMetadata, DocumentInteractionMetadata, DocumentMacroEvent,- DocumentPurgedMetadata, DocumentSyncContentUpdatedMetadata, DocumentTopicEvent,+ DocumentContentUploadedMetadata, DocumentCopiedMetadata, DocumentCreatedMetadata,+ DocumentInteractionMetadata, DocumentMacroEvent, DocumentPurgedMetadata,+ DocumentSyncContentUpdatedMetadata, DocumentTopicEvent, DocumentUpdatedMetadata,InteractionReason,};@@ -27,6 +28,68 @@ fn assert_wire_round_trip(event: Event<DocumentTopicEvent>, expected: Value) {assert_eq!(decoded, event);}+#[test]+fn owner_bearing_events_round_trip_all_owner_kinds_as_strings() {+ for principal in [+ "macro|[email protected]",+ "bot|00000000-0000-0000-0000-000000000001",+ "01998a30-1a2b-7c3d-9e4f-5a6b7c8d9e0f",+ ] {+ let owner = Owner::from_principal_str(principal).unwrap();+ let events = [+ DocumentTopicEvent::Created(DocumentCreatedMetadata {+ document_id: DOCUMENT_ID.to_string(),+ owner: owner.clone(),+ actor: None,+ on_behalf_of: None,+ document_name: "notes".to_string(),+ file_type: None,+ project_id: None,+ sub_type: None,+ created_at: None,+ }),+ DocumentTopicEvent::Updated(DocumentUpdatedMetadata {+ document_id: DOCUMENT_ID.to_string(),+ owner: owner.clone(),+ actor_user_id: None,+ actor: None,+ on_behalf_of: None,+ document_name: None,+ previous_project_id: None,+ project_id: None,+ file_type: None,+ share_permission_updated: false,+ }),+ DocumentTopicEvent::ContentUploaded(DocumentContentUploadedMetadata {+ document_id: DOCUMENT_ID.to_string(),+ owner: owner.clone(),+ file_type: FileType::Pdf,+ document_version_id: None,+ }),+ DocumentTopicEvent::Copied(DocumentCopiedMetadata {+ document_id: DOCUMENT_ID.to_string(),+ source_document_id: "source-document".to_string(),+ source_version_id: None,+ owner,+ document_name: "copy".to_string(),+ file_type: None,+ project_id: None,+ sub_type: None,+ }),+ ];+ for event in events {+ let envelope = Event::with_event_id(Uuid::from_u128(1), event);+ let payload = serde_json::to_value(&envelope).unwrap();+ assert_eq!(payload["schema_version"], 1);+ assert_eq!(payload["metadata"]["owner"], principal);+ let decoded =+ DocumentMacroEvent::decode(DOCUMENT_ID, &serde_json::to_vec(&payload).unwrap())+ .expect("all owner kinds decode through the broker");+ assert_eq!(decoded.event(), &envelope);+ }+ }+}+#[test]fn content_uploaded_serializes_to_the_exact_envelope() {let event = Event::with_event_id(@@ -192,25 +255,15 @@ fn search_event_constructors_use_the_document_key_and_schema_v1() {#[test]fn created_events_without_attribution_still_decode() {- let payload = json!({- "event_id": "00000000-0000-0000-0000-000000000005",- "schema_version": 1,- "event_type": "document.created",- "metadata": {- "document_id": DOCUMENT_ID,- "owner": "macro|[email protected]",- "document_name": "notes",- "file_type": null,- "project_id": null,- "sub_type": null,- "created_at": null,- },- });-- let decoded: Event<DocumentTopicEvent> =- serde_json::from_value(payload).expect("pre-attribution created event decodes");+ // Frozen pre-attribution v1 payload, not generated by the current serializer.+ let payload = include_bytes!("fixtures/document_created_v1.json");+ let decoded = DocumentMacroEvent::decode(DOCUMENT_ID, payload)+ .expect("pre-attribution created event decodes through the broker");+ assert_eq!(decoded.event().schema_version, 1);+ let expected: Value = serde_json::from_slice(payload).unwrap();+ assert_eq!(serde_json::to_value(decoded.event()).unwrap(), expected);- match decoded.event {+ match &decoded.event().event {DocumentTopicEvent::Created(metadata) => {assert_eq!(metadata.owner,diff --git a/crates/projects/src/domain/events.rs b/crates/projects/src/domain/events.rsindex c288c60935..60f1f7776b 100644--- a/crates/projects/src/domain/events.rs+++ b/crates/projects/src/domain/events.rs@@ -1,5 +1,8 @@//! Kafka event models for the `macro.projects` topic.+#[cfg(test)]+mod test;+use chrono::{DateTime, Utc};use macro_event_broker::{Event, MacroEvent, TopicEvent};use macro_event_topics::MacroProjectsTopic;diff --git a/crates/projects/src/domain/events/test.rs b/crates/projects/src/domain/events/test.rsnew file mode 100644index 0000000000..ccd50c157b--- /dev/null+++ b/crates/projects/src/domain/events/test.rs@@ -0,0 +1,69 @@+use super::*;+use serde_json::json;++const PROJECT_ID: &str = "11111111-1111-1111-1111-111111111111";++#[test]+fn lifecycle_events_round_trip_all_owner_kinds_with_v1_strings() {+ assert_eq!(<ProjectTopicEvent as TopicEvent>::SCHEMA_VERSION, 1);+ for principal in [+ "macro|[email protected]",+ "bot|00000000-0000-0000-0000-000000000001",+ "01998a30-1a2b-7c3d-9e4f-5a6b7c8d9e0f",+ ] {+ for (event_type, metadata) in [+ (+ "project.created",+ json!({+ "project_id": PROJECT_ID,+ "owner": principal,+ "name": "project",+ "parent_project_id": null,+ "created_at": null,+ }),+ ),+ (+ "project.updated",+ json!({+ "project_id": PROJECT_ID,+ "owner": principal,+ "actor_user_id": null,+ "name": null,+ "previous_parent_id": null,+ "parent_id": null,+ "share_permission_updated": false,+ }),+ ),+ (+ "project.deleted",+ json!({+ "project_id": PROJECT_ID,+ "owner": principal,+ "actor_user_id": null,+ "parent_project_id": null,+ "deleted_project_ids": [PROJECT_ID],+ "deleted_document_ids": [],+ "deleted_chat_ids": [],+ }),+ ),+ ] {+ let payload = json!({+ "event_id": "00000000-0000-0000-0000-000000000001",+ "schema_version": 1,+ "event_type": event_type,+ "metadata": metadata,+ });+ let decoded =+ ProjectMacroEvent::decode(PROJECT_ID, &serde_json::to_vec(&payload).unwrap())+ .expect("v1 owner strings decode through the broker");+ let owner = match &decoded.event().event {+ ProjectTopicEvent::Created(metadata) => &metadata.owner,+ ProjectTopicEvent::Updated(metadata) => &metadata.owner,+ ProjectTopicEvent::Deleted(metadata) => &metadata.owner,+ other => panic!("unexpected event {other:?}"),+ };+ assert_eq!(owner, &Owner::from_principal_str(principal).unwrap());+ assert_eq!(serde_json::to_value(decoded.event()).unwrap(), payload);+ }+ }+}diff --git a/packages/sdk/generated/storage/types.gen.ts b/packages/sdk/generated/storage/types.gen.tsindex 2ec12196db..fb549e4745 100644--- a/packages/sdk/generated/storage/types.gen.ts+++ b/packages/sdk/generated/storage/types.gen.ts@@ -4522,7 +4522,7 @@ export type DocumentCopiedMetadata = {document_name: string;file_type?: null | FileType;/**- * The owner of the new copy (the copier).+ * The principal who owns the new copy.*/owner: string;/**@@ -4546,7 +4546,8 @@ export type DocumentCopiedMetadata = {export type DocumentCreatedMetadata = {/*** Who mechanically created the document. Absent on events published- * before attribution: ingest then treats [`Self::owner`] as the actor.+ * before attribution: ingest derives a user/bot actor from [`Self::owner`].+ * Team owners fall back to [`Self::on_behalf_of`], then the system bot.*/actor?: string | null;/**@@ -4564,7 +4565,7 @@ export type DocumentCreatedMetadata = {file_type?: null | FileType;on_behalf_of?: null | MacroUserIdStr;/**- * The owner (creator) of the document.+ * The principal who owns the document.*/owner: string;/**diff --git a/packages/sdk/specs/storage.json b/packages/sdk/specs/storage.jsonindex 05c0e1f925..974ec91211 100644--- a/packages/sdk/specs/storage.json+++ b/packages/sdk/specs/storage.json@@ -21024,7 +21024,7 @@},"owner": {"type": "string",- "description": "The owner of the new copy (the copier)."+ "description": "The principal who owns the new copy."},"project_id": {"type": ["string", "null"],@@ -21059,7 +21059,7 @@"properties": {"actor": {"type": ["string", "null"],- "description": "Who mechanically created the document. Absent on events published\nbefore attribution: ingest then treats [`Self::owner`] as the actor."+ "description": "Who mechanically created the document. Absent on events published\nbefore attribution: ingest derives a user/bot actor from [`Self::owner`].\nTeam owners fall back to [`Self::on_behalf_of`], then the system bot."},"created_at": {"type": ["string", "null"],@@ -21098,7 +21098,7 @@},"owner": {"type": "string",- "description": "The owner (creator) of the document."+ "description": "The principal who owns the document."},"project_id": {"type": ["string", "null"],diff --git a/services/document_cognition_service/Cargo.toml b/services/document_cognition_service/Cargo.tomlindex 76166595ac..8508baa8dd 100644--- a/services/document_cognition_service/Cargo.toml+++ b/services/document_cognition_service/Cargo.toml@@ -95,6 +95,7 @@ onboarding = { path = "../../crates/onboarding" }model = { path = "../../crates/model" }model-entity = { path = "../../crates/model-entity" }model_notifications = { path = "../../crates/model_notifications" }+model_owner = { path = "../../crates/model_owner" }models_dcs = { path = "../../crates/models_dcs" }models_opensearch = { path = "../../crates/models_opensearch" }models_permissions = { path = "../../crates/models_permissions" }diff --git a/services/document_cognition_service/src/api/stream/chat_message.rs b/services/document_cognition_service/src/api/stream/chat_message.rsindex 83753c2ad7..0e08f51218 100644--- a/services/document_cognition_service/src/api/stream/chat_message.rs+++ b/services/document_cognition_service/src/api/stream/chat_message.rs@@ -404,7 +404,7 @@ async fn create_new_chat(// the stream on publish errors.let event = ChatMacroEvent::created(ChatCreatedMetadata {chat_id: new_chat_id.clone(),- owner: (**user_id).clone(),+ owner: model_owner::Owner::User((**user_id).clone()),name: DEFAULT_CHAT_NAME.to_string(),project_id: None,});diff --git a/services/search_processing_service/src/inbound/kafka_consumer/test.rs b/services/search_processing_service/src/inbound/kafka_consumer/test.rsindex 52962298f6..3cf15ebc61 100644--- a/services/search_processing_service/src/inbound/kafka_consumer/test.rs+++ b/services/search_processing_service/src/inbound/kafka_consumer/test.rs@@ -552,7 +552,7 @@ fn chat_event_cases() -> Vec<(ChatTopicEvent, ChatEventDescription<'static>)> {(ChatTopicEvent::Created(ChatCreatedMetadata {chat_id: CHAT_ID.to_string(),- owner: owner.clone(),+ owner: Owner::User(owner.clone()),name: "Chat".to_string(),project_id: Some(PROJECT_ID.to_string()),}),