@@ -93,15 +93,24 @@ const SYSTEM_ACTOR: DecisionMutationActor = {
9393 responsibleUserId : null ,
9494} ;
9595
96- function actorColumns ( actor : DecisionMutationActor , prefix : "added" | "set" | "created" ) {
97- const values = {
98- [ `${ prefix } ByType` ] : actor . actorType ,
99- [ `${ prefix } ByAgentId` ] : actor . agentId ,
100- [ `${ prefix } ByUserId` ] : actor . userId ,
101- [ `${ prefix } ByRunId` ] : actor . runId ,
102- [ `${ prefix } ByAgentApiKeyId` ] : actor . agentApiKeyId ,
96+ function creatorColumns ( actor : DecisionMutationActor ) {
97+ return {
98+ createdByType : actor . actorType ,
99+ createdByAgentId : actor . agentId ,
100+ createdByUserId : actor . userId ,
101+ createdByRunId : actor . runId ,
102+ createdByAgentApiKeyId : actor . agentApiKeyId ,
103+ } ;
104+ }
105+
106+ function addedByColumns ( actor : DecisionMutationActor ) {
107+ return {
108+ addedByType : actor . actorType ,
109+ addedByAgentId : actor . agentId ,
110+ addedByUserId : actor . userId ,
111+ addedByRunId : actor . runId ,
112+ addedByAgentApiKeyId : actor . agentApiKeyId ,
103113 } ;
104- return values as Record < string , string | null > ;
105114}
106115
107116function eventActorColumns ( actor : DecisionMutationActor ) {
@@ -387,7 +396,7 @@ export function decisionQueueService(db: Db) {
387396 title : input . title ,
388397 description : input . description ?? null ,
389398 retentionDays : input . retentionDays ?? null ,
390- ...( actorColumns ( input . actor , "created" ) as typeof decisionQueues . $inferInsert ) ,
399+ ...creatorColumns ( input . actor ) ,
391400 } ) . onConflictDoNothing ( { target : [ decisionQueues . companyId , decisionQueues . key ] } ) . returning ( ) ;
392401 const row = inserted [ 0 ] ?? await txDb . select ( ) . from ( decisionQueues )
393402 . where ( and ( eq ( decisionQueues . companyId , input . companyId ) , eq ( decisionQueues . key , input . key ) ) )
@@ -482,7 +491,7 @@ export function decisionQueueService(db: Db) {
482491 sourceKind : input . sourceKind ,
483492 sourceId : input . sourceId ,
484493 responsibleUserId : input . actor . responsibleUserId ,
485- ...( actorColumns ( input . actor , "added" ) as typeof decisionQueueItems . $inferInsert ) ,
494+ ...addedByColumns ( input . actor ) ,
486495 } ) . onConflictDoNothing ( {
487496 target : [ decisionQueueItems . queueId , decisionQueueItems . sourceKind , decisionQueueItems . sourceId ] ,
488497 } ) . returning ( ) ;
0 commit comments