MCPcopy Create free account
hub / github.com/hashintel/hash / create_ai

Method create_ai

libs/@local/graph/postgres-store/src/permissions/mod.rs:315–345  ·  view source on GitHub ↗

Creates a new AI with the given ID, or generates a new UUID if none is provided. # Errors - [`PrincipalAlreadyExists`] if an AI with the given ID already exists - [`StoreError`] if a database error occurs [`PrincipalAlreadyExists`]: PrincipalError::PrincipalAlreadyExists [`StoreError`]: PrincipalError::StoreError

(
        &mut self,
        id: Option<Uuid>,
        identifier: &str,
    )

Source from the content-addressed store, hash-verified

313 /// [`PrincipalAlreadyExists`]: PrincipalError::PrincipalAlreadyExists
314 /// [`StoreError`]: PrincipalError::StoreError
315 pub async fn create_ai(
316 &mut self,
317 id: Option<Uuid>,
318 identifier: &str,
319 ) -> Result<AiId, Report<PrincipalError>> {
320 let ai_id = AiId::new(id.unwrap_or_else(Uuid::new_v4));
321 if let Err(error) = self
322 .as_mut_client()
323 .execute(
324 "INSERT INTO ai_actor (id, identifier) VALUES ($1, $2)",
325 &[&ai_id, &identifier],
326 )
327 .instrument(tracing::info_span!(
328 "INSERT",
329 otel.kind = "client",
330 db.system = "postgresql",
331 peer.service = "Postgres",
332 ))
333 .await
334 {
335 return if error.code() == Some(&SqlState::UNIQUE_VIOLATION) {
336 Err(error).change_context(PrincipalError::PrincipalAlreadyExists {
337 id: PrincipalId::Actor(ActorId::Ai(ai_id)),
338 })
339 } else {
340 Err(error).change_context(PrincipalError::StoreError)
341 };
342 }
343
344 Ok(ai_id)
345 }
346
347 /// Checks if an AI with the given ID exists.
348 ///

Callers 8

create_ai_actorMethod · 0.45
create_aiFunction · 0.45
create_ai_with_idFunction · 0.45
delete_aiFunction · 0.45
create_web_ai_relationFunction · 0.45
ai_role_assignmentFunction · 0.45

Calls 8

ErrInterface · 0.85
ActorEnum · 0.85
OkInterface · 0.85
as_mut_clientMethod · 0.80
AiInterface · 0.50
executeMethod · 0.45
codeMethod · 0.45
change_contextMethod · 0.45

Tested by 7

create_aiFunction · 0.36
create_ai_with_idFunction · 0.36
delete_aiFunction · 0.36
create_web_ai_relationFunction · 0.36
ai_role_assignmentFunction · 0.36