Skip to main content

cpex_core/cmf/
constants.rs

1// Location: ./crates/cpex-core/src/cmf/constants.rs
2// Copyright 2025
3// SPDX-License-Identifier: Apache-2.0
4// Authors: Teryl Taylor
5//
6// CMF constants — schema version, serialization field names, and defaults.
7
8/// Current CMF message schema version.
9pub const SCHEMA_VERSION: &str = "2.0";
10
11// ---------------------------------------------------------------------------
12// Serialization field names for MessageView::to_dict() / to_opa_input()
13// ---------------------------------------------------------------------------
14
15// Core view fields
16pub const FIELD_KIND: &str = "kind";
17pub const FIELD_ROLE: &str = "role";
18pub const FIELD_IS_PRE: &str = "is_pre";
19pub const FIELD_IS_POST: &str = "is_post";
20pub const FIELD_ACTION: &str = "action";
21pub const FIELD_HOOK: &str = "hook";
22pub const FIELD_URI: &str = "uri";
23pub const FIELD_NAME: &str = "name";
24pub const FIELD_CONTENT: &str = "content";
25pub const FIELD_SIZE_BYTES: &str = "size_bytes";
26pub const FIELD_MIME_TYPE: &str = "mime_type";
27pub const FIELD_ARGUMENTS: &str = "arguments";
28
29// Extensions container
30pub const FIELD_EXTENSIONS: &str = "extensions";
31
32// Subject fields
33pub const FIELD_SUBJECT: &str = "subject";
34pub const FIELD_ID: &str = "id";
35pub const FIELD_TYPE: &str = "type";
36pub const FIELD_ROLES: &str = "roles";
37pub const FIELD_PERMISSIONS: &str = "permissions";
38pub const FIELD_TEAMS: &str = "teams";
39
40// Security fields
41pub const FIELD_LABELS: &str = "labels";
42
43// Request fields
44pub const FIELD_ENVIRONMENT: &str = "environment";
45
46// HTTP fields
47pub const FIELD_HEADERS: &str = "headers";
48
49// Agent fields
50pub const FIELD_AGENT: &str = "agent";
51pub const FIELD_INPUT: &str = "input";
52pub const FIELD_SESSION_ID: &str = "session_id";
53pub const FIELD_CONVERSATION_ID: &str = "conversation_id";
54pub const FIELD_TURN: &str = "turn";
55pub const FIELD_AGENT_ID: &str = "agent_id";
56pub const FIELD_PARENT_AGENT_ID: &str = "parent_agent_id";
57
58// Meta fields
59pub const FIELD_META: &str = "meta";
60pub const FIELD_ENTITY_TYPE: &str = "entity_type";
61pub const FIELD_ENTITY_NAME: &str = "entity_name";
62pub const FIELD_TAGS: &str = "tags";
63
64// OPA envelope
65pub const FIELD_OPA_INPUT: &str = "input";
66
67// ---------------------------------------------------------------------------
68// Entity type identifiers — used in MetaExtension.entity_type and as the
69// keys for `global.defaults` per-entity-type policy groups. These are the
70// MCP entity taxonomy: tools (callable functions), LLMs (model
71// invocations), prompts (template fills), resources (URI fetches).
72// ---------------------------------------------------------------------------
73
74pub const ENTITY_TOOL: &str = "tool";
75pub const ENTITY_LLM: &str = "llm";
76pub const ENTITY_PROMPT: &str = "prompt";
77pub const ENTITY_RESOURCE: &str = "resource";
78
79/// Reserved entity type for generic (non-MCP/A2A) HTTP requests. The
80/// catch-all `global` policy is dispatched under this entity so an
81/// entity-less request can be authorized; hosts set `meta.entity_type` to
82/// this and `meta.entity_name` to [`ENTITY_NAME_GLOBAL`].
83pub const ENTITY_HTTP: &str = "http";
84
85/// Reserved entity name for the global catch-all policy annotation.
86pub const ENTITY_NAME_GLOBAL: &str = "*";
87
88// ---------------------------------------------------------------------------
89// CMF hook names — the canonical names plugins register under and hosts
90// pass to `PluginManager::invoke_named::<CmfHook>(...)`. Two per entity
91// type — pre-invocation (called from APL's policy / args phase) and
92// post-invocation (called from APL's post_policy / result phase).
93//
94// Used as keys in `hooks::metadata`'s routing table and from plugin
95// declarations.
96// ---------------------------------------------------------------------------
97
98pub const HOOK_CMF_TOOL_PRE_INVOKE: &str = "cmf.tool_pre_invoke";
99pub const HOOK_CMF_TOOL_POST_INVOKE: &str = "cmf.tool_post_invoke";
100pub const HOOK_CMF_LLM_INPUT: &str = "cmf.llm_input";
101pub const HOOK_CMF_LLM_OUTPUT: &str = "cmf.llm_output";
102pub const HOOK_CMF_PROMPT_PRE_INVOKE: &str = "cmf.prompt_pre_invoke";
103pub const HOOK_CMF_PROMPT_POST_INVOKE: &str = "cmf.prompt_post_invoke";
104pub const HOOK_CMF_RESOURCE_PRE_FETCH: &str = "cmf.resource_pre_fetch";
105pub const HOOK_CMF_RESOURCE_POST_FETCH: &str = "cmf.resource_post_fetch";
106
107/// Generic HTTP request hook. Hosts fire this for non-MCP/A2A HTTP
108/// requests; the catch-all `global` policy (if any) is annotated under
109/// it via [`ENTITY_HTTP`] / [`ENTITY_NAME_GLOBAL`]. Pre-invocation only —
110/// authorization is an admission check, so there is no post counterpart.
111pub const HOOK_CMF_HTTP_REQUEST: &str = "cmf.http_request";