Repository navigation
feat(schedule): preserve channel session identity for origin jobs #170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
d9d9bf5
chore: files changed crates/tinyflows-bus/src/schedule/mod.rs,crates/…
senamakel 8acfbf7
chore: files changed crates/tinyflows-bus/src/schedule/mod.rs,crates/…
senamakel d02a32b
chore: files changed crates/tinyflows-bus/src/schedule/mod.rs
senamakel 682cae4
chore: files changed crates/tinyflows-bus/src/schedule/wire_tests.rs,…
senamakel 78922f9
chore: files changed crates/tinyflows-bus/src/schedule/identity_tests…
senamakel aa8d258
chore: files changed crates/tinyflows-bus/src/schedule/identity_tests…
senamakel a201aeb
chore: files changed crates/tinyflows-schedule/src/validation_tests.r…
senamakel ae889c8
chore: files changed crates/tinyflows-drivers/src/schedule/test_suppo…
senamakel ca20f75
fix(schedule): re-export channel identity types
senamakel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| //! Opaque channel-session identity captured by a host from validated inbound | ||
| //! channel metadata. TinyFlows stores and forwards it with job origins; the | ||
| //! host remains responsible for validating it before use. | ||
| use serde::{Deserialize, Serialize}; | ||
|
|
||
| /// Stable identity of the channel session that created a scheduled job. | ||
| #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] | ||
| pub struct ChannelSessionIdentity { | ||
| /// Tenant or profile namespace selected by the host. | ||
| pub tenant_key: String, | ||
| /// Agent that owns the conversation. | ||
| pub agent_id: String, | ||
| /// Durable session key used to resume the transcript. | ||
| pub session_key: String, | ||
| /// Provider identifier, such as `telegram` or `slack`. | ||
| pub provider: String, | ||
| /// Account identity when the provider has multiple configured accounts. | ||
| #[serde(default, skip_serializing_if = "Option::is_none")] | ||
| pub account_id: Option<String>, | ||
| /// Provider-scoped conversation and thread identity. | ||
| pub conversation: ChannelConversationIdentity, | ||
| } | ||
|
|
||
| /// Provider-scoped identity of a channel conversation. | ||
| #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] | ||
| pub struct ChannelConversationIdentity { | ||
| /// Conversation kind, such as `direct`, `group`, or `channel`. | ||
| pub kind: String, | ||
| /// Provider-defined conversation identifier. | ||
| pub id: String, | ||
| /// Optional tenant/workspace scope for providers whose ids are local. | ||
| #[serde(default, skip_serializing_if = "Option::is_none")] | ||
| pub scope_id: Option<String>, | ||
| /// Parent conversation identifier, when the provider has nested spaces. | ||
| #[serde(default, skip_serializing_if = "Option::is_none")] | ||
| pub parent_id: Option<String>, | ||
| /// Thread identifier, when the conversation is threaded. | ||
| #[serde(default, skip_serializing_if = "Option::is_none")] | ||
| pub thread_id: Option<String>, | ||
| /// Topic identifier for providers that model topics separately. | ||
| #[serde(default, skip_serializing_if = "Option::is_none")] | ||
| pub topic_id: Option<String>, | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| use super::*; | ||
| use serde_json::json; | ||
|
|
||
| fn channel_identity() -> ChannelSessionIdentity { | ||
| ChannelSessionIdentity { | ||
| tenant_key: "tenant-1".into(), | ||
| agent_id: "agent-1".into(), | ||
| session_key: "session-1".into(), | ||
| provider: "telegram".into(), | ||
| account_id: Some("account-1".into()), | ||
| conversation: ChannelConversationIdentity { | ||
| kind: "group".into(), | ||
| id: "chat-1".into(), | ||
| scope_id: Some("tenant-1".into()), | ||
| parent_id: None, | ||
| thread_id: Some("thread-1".into()), | ||
| topic_id: Some("topic-1".into()), | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| #[test] | ||
| fn channel_session_identity_roundtrips_with_conversation_scope() { | ||
| let identity = channel_identity(); | ||
| let value = serde_json::to_value(&identity).unwrap(); | ||
|
|
||
| assert_eq!( | ||
| value, | ||
| json!({ | ||
| "tenant_key": "tenant-1", | ||
| "agent_id": "agent-1", | ||
| "session_key": "session-1", | ||
| "provider": "telegram", | ||
| "account_id": "account-1", | ||
| "conversation": { | ||
| "kind": "group", | ||
| "id": "chat-1", | ||
| "scope_id": "tenant-1", | ||
| "thread_id": "thread-1", | ||
| "topic_id": "topic-1" | ||
| } | ||
| }) | ||
| ); | ||
| assert_eq!( | ||
| serde_json::from_value::<ChannelSessionIdentity>(value).unwrap(), | ||
| identity | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn channel_job_origin_carries_optional_session_identity_without_changing_legacy_wire() { | ||
| let origin = JobOrigin::Channel { | ||
| channel: "telegram".into(), | ||
| reply_target: "chat-1".into(), | ||
| history_key: "telegram:chat-1".into(), | ||
| sender: None, | ||
| thread_id: None, | ||
| session_identity: Some(Box::new(channel_identity())), | ||
| }; | ||
| let value = serde_json::to_value(&origin).unwrap(); | ||
| assert_eq!(value["kind"], "channel"); | ||
| assert_eq!(value["session_identity"]["session_key"], "session-1"); | ||
| assert_eq!(serde_json::from_value::<JobOrigin>(value).unwrap(), origin); | ||
|
|
||
| let legacy = json!({ | ||
| "kind": "channel", | ||
| "channel": "discord", | ||
| "reply_target": "room-1", | ||
| "history_key": "discord:room-1" | ||
| }); | ||
| let parsed: JobOrigin = serde_json::from_value(legacy.clone()).unwrap(); | ||
| assert_eq!( | ||
| parsed, | ||
| JobOrigin::Channel { | ||
| channel: "discord".into(), | ||
| reply_target: "room-1".into(), | ||
| history_key: "discord:room-1".into(), | ||
| sender: None, | ||
| thread_id: None, | ||
| session_identity: None, | ||
| } | ||
| ); | ||
| assert_eq!(serde_json::to_value(parsed).unwrap(), legacy); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.