MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / project

Function project

atomic-canonical/src/prov.rs:135–191  ·  view source on GitHub ↗

Project a turn's provenance into the named-subgraph JSON-LD. Builds `urn:atomic:provgraph: ` with `@graph = [prov:Activity, prov:SoftwareAgent, prov:Person]`, exactly per the doc §"A provenance graph" but with the hard-scope agent-id override (`urn:atomic:agent: `, never a DID) and `used: []` (flywheel deferred). Deterministic: fixed key insertion order + JCS canonicalizati

(input: &ProvActivityInput)

Source from the content-addressed store, hash-verified

133/// Deterministic: fixed key insertion order + JCS canonicalization at sign time
134/// make the signed bytes stable across calls.
135pub fn project(input: &ProvActivityInput) -> Value {
136 let agent_id = agent_urn(&input.agent_slug);
137
138 // --- prov:Activity ---------------------------------------------------
139 let mut activity = Map::new();
140 activity.insert("@type".into(), json!("prov:Activity"));
141 activity.insert("@id".into(), json!(activity_urn(&input.activity_id)));
142 if let Some(started) = &input.started_at {
143 activity.insert("prov:startedAtTime".into(), json!(started));
144 }
145 if let Some(ended) = &input.ended_at {
146 activity.insert("prov:endedAtTime".into(), json!(ended));
147 }
148 // wasAssociatedWith (the agent) / actedOnBehalfOf (the person).
149 activity.insert("associatedWith".into(), json!(agent_id));
150 activity.insert("actedOnBehalfOf".into(), json!(input.person_did));
151 activity.insert("generated".into(), json!(input.generated));
152 // Flywheel `used` edge — emitted only when non-empty (unknown omitted, never
153 // invented). Empty until the capture records structured inputs.
154 if !input.used.is_empty() {
155 activity.insert("used".into(), json!(input.used));
156 }
157 // turnParent — omit the key entirely when there is no parent turn.
158 if let Some(parent) = &input.turn_parent {
159 activity.insert("turnParent".into(), json!(parent));
160 }
161
162 // --- prov:SoftwareAgent (NON-VERIFIABLE descriptive label) -----------
163 let mut agent = Map::new();
164 agent.insert("@type".into(), json!("prov:SoftwareAgent"));
165 agent.insert("@id".into(), json!(agent_id));
166 agent.insert("actedOnBehalfOf".into(), json!(input.person_did));
167 // Human label as rdfs:label (there is no prov:label in PROV-O); the ctx maps
168 // the `label` term to rdfs:label.
169 agent.insert("label".into(), json!(input.agent_display_name));
170 if let Some(vendor) = &input.agent_vendor {
171 agent.insert("vendor".into(), json!(vendor));
172 }
173
174 // --- prov:Person (the real did:atomic signer) ------------------------
175 let mut person = Map::new();
176 person.insert("@type".into(), json!("prov:Person"));
177 person.insert("@id".into(), json!(input.person_did));
178
179 let mut root = Map::new();
180 root.insert("@context".into(), json!(CONTEXT_URL));
181 root.insert("@id".into(), json!(provgraph_urn(&input.change_id_base32)));
182 root.insert(
183 "@graph".into(),
184 json!([
185 Value::Object(activity),
186 Value::Object(agent),
187 Value::Object(person),
188 ]),
189 );
190 Value::Object(root)
191}
192

Calls 3

agent_urnFunction · 0.85
insertMethod · 0.45
is_emptyMethod · 0.45