@@ -80,9 +80,10 @@ export class MetadataProjector {
8080 }
8181
8282 try {
83- // Check if projection already exists
83+ // Check if projection already exists (scoped by env_id for isolation)
84+ const envId = this . scope . environmentId ?? null ;
8485 const existing = await this . _findOne ( targetTable , {
85- where : { name } ,
86+ where : { name, env_id : envId } ,
8687 } ) ;
8788
8889 if ( existing ) {
@@ -112,9 +113,10 @@ export class MetadataProjector {
112113 }
113114
114115 try {
115- // Find the projection
116+ // Find the projection (scoped by env_id for isolation)
117+ const envId = this . scope . environmentId ?? null ;
116118 const existing = await this . _findOne ( targetTable , {
117- where : { name } ,
119+ where : { name, env_id : envId } ,
118120 } ) ;
119121
120122 if ( existing ) {
@@ -153,6 +155,7 @@ export class MetadataProjector {
153155 private projectObject ( name : string , data : any , now : string ) : Record < string , any > {
154156 return {
155157 name,
158+ env_id : this . scope . environmentId ?? null ,
156159 label : data . label || name ,
157160 plural_label : data . pluralLabel || data . label || name ,
158161 description : data . description || '' ,
@@ -202,6 +205,7 @@ export class MetadataProjector {
202205 private projectView ( name : string , data : any , now : string ) : Record < string , any > {
203206 return {
204207 name,
208+ env_id : this . scope . environmentId ?? null ,
205209 label : data . label || name ,
206210 description : data . description || '' ,
207211 object_name : data . object || '' ,
@@ -234,6 +238,7 @@ export class MetadataProjector {
234238 private projectAgent ( name : string , data : any , now : string ) : Record < string , any > {
235239 return {
236240 name,
241+ env_id : this . scope . environmentId ?? null ,
237242 label : data . label || name ,
238243 description : data . description || '' ,
239244 agent_type : data . type || 'conversational' ,
@@ -269,6 +274,7 @@ export class MetadataProjector {
269274 private projectTool ( name : string , data : any , now : string ) : Record < string , any > {
270275 return {
271276 name,
277+ env_id : this . scope . environmentId ?? null ,
272278 label : data . label || name ,
273279 description : data . description || '' ,
274280 // Parameters and implementation
@@ -293,6 +299,7 @@ export class MetadataProjector {
293299 private projectFlow ( name : string , data : any , now : string ) : Record < string , any > {
294300 return {
295301 name,
302+ env_id : this . scope . environmentId ?? null ,
296303 label : data . label || name ,
297304 description : data . description || '' ,
298305 flow_type : data . type || 'autolaunched' ,
0 commit comments