agent-ecosystem/agent-teams-controller/src/internal/crossTeamProtocol.js
iliya 71143db3ac feat: update cross-team messaging protocol and enhance team provisioning
- Refactored cross-team message formatting to use a canonical XML-like tag structure for improved clarity and consistency.
- Introduced new attributes for cross-team messages, including 'from', 'depth', 'conversationId', and 'replyToConversationId'.
- Enhanced TeamProvisioningService to manage pending cross-team reply expectations, ensuring proper message handling and relay.
- Updated UI components to reflect changes in cross-team messaging, including stripping metadata from displayed messages.
- Added tests to validate new cross-team message handling and ensure proper functionality across services.
2026-03-10 14:48:55 +02:00

48 lines
1.5 KiB
JavaScript

// Cross-team message protocol constants.
// Mirror of src/shared/constants/crossTeam.ts — keep in sync.
const CROSS_TEAM_TAG_NAME = 'cross-team';
const CROSS_TEAM_ATTR_FROM = 'from';
const CROSS_TEAM_ATTR_DEPTH = 'depth';
const CROSS_TEAM_ATTR_CONVERSATION_ID = 'conversationId';
const CROSS_TEAM_ATTR_REPLY_TO_CONVERSATION_ID = 'replyToConversationId';
const CROSS_TEAM_SOURCE = 'cross_team';
const CROSS_TEAM_SENT_SOURCE = 'cross_team_sent';
function escapeCrossTeamAttribute(value) {
return String(value)
.replace(/&/g, '&')
.replace(/"/g, '"')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;');
}
function formatCrossTeamPrefix(from, chainDepth, meta) {
const attrs = [
`${CROSS_TEAM_ATTR_FROM}="${escapeCrossTeamAttribute(from)}"`,
`${CROSS_TEAM_ATTR_DEPTH}="${String(chainDepth)}"`,
];
if (meta && meta.conversationId) {
attrs.push(
`${CROSS_TEAM_ATTR_CONVERSATION_ID}="${escapeCrossTeamAttribute(meta.conversationId)}"`
);
}
if (meta && meta.replyToConversationId) {
attrs.push(
`${CROSS_TEAM_ATTR_REPLY_TO_CONVERSATION_ID}="${escapeCrossTeamAttribute(meta.replyToConversationId)}"`
);
}
return `<${CROSS_TEAM_TAG_NAME} ${attrs.join(' ')} />`;
}
function formatCrossTeamText(from, chainDepth, text, meta) {
return `${formatCrossTeamPrefix(from, chainDepth, meta)}\n${text}`;
}
module.exports = {
CROSS_TEAM_TAG_NAME,
CROSS_TEAM_SOURCE,
CROSS_TEAM_SENT_SOURCE,
formatCrossTeamPrefix,
formatCrossTeamText,
};