Skip to content

Commit

Permalink
feat: disable local agent in on-premise version
Browse files Browse the repository at this point in the history
  • Loading branch information
meta-d committed Jan 31, 2024
1 parent 021bae0 commit a2b55a4
Show file tree
Hide file tree
Showing 12 changed files with 100 additions and 80 deletions.
4 changes: 1 addition & 3 deletions .env.compose
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@ IS_DOCKER=true

# set true if running as a Demo
DEMO=false
ENABLE_LOCAL_AGENT=false

ALLOW_SUPER_ADMIN_ROLE=true

# set to Metad OCAP API base URL
API_BASE_URL=http://localhost:3000

# set to Metad OCAP UI base URL
CLIENT_BASE_URL=http://localhost:4200

# DB_TYPE: sqlite | postgres
DB_TYPE=postgres

Expand Down
4 changes: 1 addition & 3 deletions .env.local
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@ IS_DOCKER=false

# set true if running as a Demo
DEMO=false
ENABLE_LOCAL_AGENT=false

ALLOW_SUPER_ADMIN_ROLE=true

# set to Metad API base URL
API_BASE_URL=http://localhost:3000

# set to Metad UI base URL
CLIENT_BASE_URL=http://localhost:4200

# DB_TYPE: sqlite | postgres
DB_TYPE=postgres

Expand Down
54 changes: 30 additions & 24 deletions apps/cloud/src/app/@shared/status-bar/status-bar.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,33 +85,39 @@ <h5 class="mb-2 text-lg font-bold tracking-tight text-gray-900 dark:text-white">
<mat-menu #agentMenu="matMenu" class="ngm-menu-card">
<div class="pac-status-bar__local-agent h-60" (click)="$event.stopPropagation()">
<mat-tab-group mat-stretch-tabs class="h-full">
<mat-tab class="p-4" [label]=" 'PAC.MENU.LOCAL_AGENT' | translate: {Default: 'Local Agent'} ">
<div>
{{'PAC.KEY_WORDS.STATUS' | translate: {Default: 'Status'} }}: {{ localStatus()?.icon }} {{localStatus()?.status | translate}}
</div>

<div class="flex-1"></div>

<div class="flex justify-start">
<div ngmButtonGroup displayDensity="compact">
<button mat-stroked-button displayDensity="compact" (click)="tryConnectLocalAgent()">
{{ 'PAC.ACTIONS.Connect' | translate: {Default: 'Connect'} }}
</button>

<button mat-stroked-button displayDensity="compact" ngmAppearance="dashed">
{{'PAC.ACTIONS.DOWNLOAD_AGENT' | translate}}
</button>
@if (enableLocalAgent) {
<mat-tab class="p-4" [label]=" 'PAC.MENU.LOCAL_AGENT' | translate: {Default: 'Local Agent'} ">
<div>
{{'PAC.KEY_WORDS.STATUS' | translate: {Default: 'Status'} }}: {{ localStatus()?.icon }} {{localStatus()?.status | translate}}
</div>
</div>
</mat-tab>

<div class="flex-1"></div>

<div class="flex justify-start">
<div ngmButtonGroup displayDensity="compact">
<button mat-stroked-button displayDensity="compact" (click)="tryConnectLocalAgent()">
{{ 'PAC.ACTIONS.Connect' | translate: {Default: 'Connect'} }}
</button>

<button mat-stroked-button displayDensity="compact" ngmAppearance="dashed">
{{'PAC.ACTIONS.DOWNLOAD_AGENT' | translate}}
</button>
</div>
</div>
</mat-tab>
}
<mat-tab [label]=" 'PAC.MENU.Authentication' | translate: {Default: 'Authentication'} ">
<mat-list role="list">
<mat-list-item role="listitem" *ngFor="let item of localAgent.auth | keyvalue | filter: valueIsNotNil">
<span>{{item.value[0]}}</span>
<button mat-icon-button matListItemMeta displayDensity="compact" ngmAppearance="danger"
[matTooltip]=" 'PAC.MENU.STATUS_BAR.ClearAuthentication' | translate: {Default: 'Clear Authentication'} "
(click)="deleteAuth(localAgent, item.key)"><mat-icon>close</mat-icon></button>
</mat-list-item>
@if (enableLocalAgent && localAgent) {
@for (item of localAgent?.auth | keyvalue | filter: valueIsNotNil; track $index) {
<mat-list-item role="listitem">
<span>{{item.value[0]}}</span>
<button mat-icon-button matListItemMeta displayDensity="compact" ngmAppearance="danger"
[matTooltip]=" 'PAC.MENU.STATUS_BAR.ClearAuthentication' | translate: {Default: 'Clear Authentication'} "
(click)="deleteAuth(localAgent, item.key)"><mat-icon>close</mat-icon></button>
</mat-list-item>
}
}

<mat-list-item role="listitem" *ngFor="let item of serverAgent.auth | keyvalue | filter: valueIsNotNil">
<span>{{item.value[0]}}</span>
Expand Down
12 changes: 7 additions & 5 deletions apps/cloud/src/app/@shared/status-bar/status-bar.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import { CommonModule } from '@angular/common'
import { ChangeDetectorRef, Component, OnInit, computed, inject } from '@angular/core'
import { takeUntilDestroyed, toSignal } from '@angular/core/rxjs-interop'
import { FormsModule } from '@angular/forms'
import { NgFilterPipeModule } from '@metad/core'
import { ButtonGroupDirective, NgmAgentService, NgmDSCacheService, OcapCoreModule } from '@metad/ocap-angular/core'
import { WasmAgentService } from '@metad/ocap-angular/wasm-agent'
import { AgentStatus, AgentStatusEnum } from '@metad/ocap-core'
import { TranslateModule } from '@ngx-translate/core'
import { NgFilterPipeModule } from '@metad/core'
import { Observable, merge } from 'rxjs'
import { environment } from 'apps/cloud/src/environments/environment'
import { Observable, merge, of } from 'rxjs'
import { AbstractAgent, LocalAgent, ServerAgent, Store, ToastrService } from '../../@core'
import { TranslationBaseComponent } from '../language/translation-base.component'
import { MaterialModule } from '../material.module'
Expand All @@ -33,18 +34,19 @@ import { MaterialModule } from '../material.module'
})
export class PACStatusBarComponent extends TranslationBaseComponent implements OnInit {
AgentStatusEnum = AgentStatusEnum
enableLocalAgent = environment.enableLocalAgent

private store = inject(Store)
private cacheService = inject(NgmDSCacheService)
private agentService = inject(NgmAgentService)
public localAgent = inject(LocalAgent)
public localAgent? = inject(LocalAgent, { optional: true })
public serverAgent = inject(ServerAgent)
private wasmAgentService = inject(WasmAgentService)
private toastrService = inject(ToastrService)
private _cdr = inject(ChangeDetectorRef)

public readonly localAgentStatus = toSignal<AgentStatus>(
this.agentService.selectLocalAgentStatus() as Observable<AgentStatus>
(this.localAgent?.selectStatus() as Observable<AgentStatus>) ?? of({ status: AgentStatusEnum.OFFLINE })
)
public readonly localStatus = computed(() => {
if (this.localAgentStatus() && typeof this.localAgentStatus() !== 'string') {
Expand Down Expand Up @@ -103,7 +105,7 @@ export class PACStatusBarComponent extends TranslationBaseComponent implements O
}

tryConnectLocalAgent() {
this.localAgent.connect()
this.localAgent?.connect()
}

cacheLevelFormatter(value: number): string {
Expand Down
39 changes: 14 additions & 25 deletions apps/cloud/src/app/features/features.module.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CommonModule } from '@angular/common'
import { NgModule } from '@angular/core'
import { PacAuthModule } from '@metad/cloud/auth'
import { CopilotService, ICopilot } from '@metad/copilot'
import { CopilotService } from '@metad/copilot'
import { NgmFormlyModule, provideFormly } from '@metad/formly'
import { PACMaterialThemeModule } from '@metad/material-theme'
import { NgmDrawerTriggerComponent, NgmTableComponent, ResizerModule } from '@metad/ocap-angular/common'
Expand All @@ -18,13 +18,10 @@ import { DataSource, Type } from '@metad/ocap-core'
import { NX_STORY_FEED, NX_STORY_MODEL, NX_STORY_STORE } from '@metad/story/core'
import { LetDirective } from '@ngrx/component'
import { NgxPopperjsModule } from 'ngx-popperjs'
import { DirtyCheckGuard, LocalAgent, ServerAgent, PACCopilotService } from '../@core/index'
import { environment } from '../../environments/environment'
import { DirtyCheckGuard, LocalAgent, PACCopilotService, ServerAgent } from '../@core/index'
import { AssetsComponent } from '../@shared/assets/assets.component'
import {
MaterialModule,
PACStatusBarComponent,
SharedModule
} from '../@shared/index'
import { MaterialModule, PACStatusBarComponent, SharedModule } from '../@shared/index'
import { HeaderSettingsComponent, ProjectSelectorComponent } from '../@theme/header'
import { PACThemeModule } from '../@theme/theme.module'
import { StoryFeedService, StoryModelService, StoryStoreService } from '../services/index'
Expand Down Expand Up @@ -72,13 +69,17 @@ import { FeaturesComponent } from './features.component'
useExisting: WasmAgentService,
multi: true
},
LocalAgent,
...(environment.enableLocalAgent
? [
LocalAgent,
{
provide: OCAP_AGENT_TOKEN,
useExisting: LocalAgent,
multi: true
}
]
: []),
ServerAgent,
{
provide: OCAP_AGENT_TOKEN,
useExisting: LocalAgent,
multi: true
},
{
provide: OCAP_AGENT_TOKEN,
useExisting: ServerAgent,
Expand Down Expand Up @@ -118,18 +119,6 @@ import { FeaturesComponent } from './features.component'
provide: NX_STORY_FEED,
useClass: StoryFeedService
},
// {
// // Provide CopilotConfig factory to PACCopilotService
// provide: PACCopilotService.CopilotConfigFactoryToken,
// useFactory: (copilotService: CopilotAPIService) => async (): Promise<ICopilot> => {
// const copilot = await copilotService.getOne()
// return {
// ...copilot,
// chatUrl: '/api/ai/chat'
// }
// },
// deps: [CopilotAPIService]
// },
{
provide: CopilotService,
useExisting: PACCopilotService
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,11 @@
</mat-form-field>

<div class="flex justify-between items-center mx-2 mb-6">
<mat-slide-toggle formControlName="useLocalAgent" disableRipple labelPosition="before">
{{ 'PAC.MENU.DATA_SOURCES.USE_LOCAL_AGENT' | translate: {Default: 'Use Local Agent'} }}
</mat-slide-toggle>
@if (enableLocalAgent) {
<mat-slide-toggle formControlName="useLocalAgent" disableRipple labelPosition="before">
{{ 'PAC.MENU.DATA_SOURCES.USE_LOCAL_AGENT' | translate: {Default: 'Use Local Agent'} }}
</mat-slide-toggle>
}

<div class="flex justify-end items-center gap-2">
<mat-label>{{ 'PAC.MENU.DATA_SOURCES.AuthType' | translate: {Default: 'Auth Type'} }}</mat-label>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
convertConfigurationSchema,
getErrorMessage
} from '../../../../@core/index'
import { environment } from 'apps/cloud/src/environments/environment'

@Component({
selector: 'pac-data-source-creation',
Expand All @@ -22,6 +23,7 @@ import {
})
export class PACDataSourceCreationComponent implements OnInit {
AuthenticationEnum = AuthenticationEnum
enableLocalAgent = environment.enableLocalAgent

private typesService = inject(DataSourceTypesService)
private dataSourceService = inject(DataSourceService)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ <h4 style="pointer-events: none;">
</mat-form-field>

<div class="flex justify-between items-center mx-2 mb-6">
@if (enableLocalAgent) {
<mat-slide-toggle formControlName="useLocalAgent" disableRipple labelPosition="before">
{{ 'PAC.MENU.DATA_SOURCES.USE_LOCAL_AGENT' | translate: {Default: 'Use Local Agent'} }}
</mat-slide-toggle>
}

<div class="flex justify-end items-center gap-2">
<mat-label>{{ 'PAC.MENU.DATA_SOURCES.AuthType' | translate: {Default: 'Auth Type'} }}</mat-label>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
ToastrService
} from '../../../../@core'
import { takeUntilDestroyed, toSignal } from '@angular/core/rxjs-interop'
import { environment } from 'apps/cloud/src/environments/environment'

@Component({
standalone: true,
Expand All @@ -35,6 +36,7 @@ import { takeUntilDestroyed, toSignal } from '@angular/core/rxjs-interop'
})
export class PACDataSourceEditComponent implements OnInit {
AuthenticationEnum = AuthenticationEnum
enableLocalAgent = environment.enableLocalAgent
@HostBinding('class.ngm-dialog-container') isDialogContainer = true

loading = false
Expand Down
9 changes: 6 additions & 3 deletions apps/cloud/src/environments/environment.prod.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
export const environment = {
import { IEnvironment } from './types'

export const environment: IEnvironment = {
production: true,
DEMO: false,
API_BASE_URL: 'DOCKER_API_BASE_URL',
IS_ELECTRON: false
};
IS_ELECTRON: false,
enableLocalAgent: 'DOCKER_ENABLE_LOCAL_AGENT'
}
18 changes: 4 additions & 14 deletions apps/cloud/src/environments/environment.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
// This file can be replaced during build by using the `fileReplacements` array.
// `ng build` replaces `environment.ts` with `environment.prod.ts`.
// The list of file replacements can be found in `angular.json`.
import { IEnvironment } from "./types"

let API_BASE_URL = 'http://localhost:3000'

export const environment = {
export const environment: IEnvironment = {
production: false,
DEMO: false,
API_BASE_URL: '',
IS_ELECTRON: false,
enableLocalAgent: false,

GOOGLE_AUTH_LINK: API_BASE_URL + '/api/auth/google',
FACEBOOK_AUTH_LINK: API_BASE_URL + '/api/auth/facebook',
Expand All @@ -17,13 +16,4 @@ export const environment = {
TWITTER_AUTH_LINK: API_BASE_URL + '/api/auth/twitter',
MICROSOFT_AUTH_LINK: API_BASE_URL + '/api/auth/microsoft',
AUTH0_AUTH_LINK: API_BASE_URL + '/api/auth/auth0'
}

/*
* For easier debugging in development mode, you can import the following file
* to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`.
*
* This import should be commented out in production mode because it will have a negative impact
* on performance if an error is thrown.
*/
// import 'zone.js/plugins/zone-error'; // Included with Angular CLI.
}
26 changes: 26 additions & 0 deletions apps/cloud/src/environments/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
export type IEnvironment = {
/**
* Is `production` or `development` evnironment
*/
production: boolean
/**
* Enable local agent
*/
enableLocalAgent: boolean | string
/**
* Is Demo system
*/
DEMO: boolean

API_BASE_URL: string

IS_ELECTRON: boolean

GOOGLE_AUTH_LINK?: string
FACEBOOK_AUTH_LINK?: string
LINKEDIN_AUTH_LINK?: string
GITHUB_AUTH_LINK?: string
TWITTER_AUTH_LINK?: string
MICROSOFT_AUTH_LINK?: string
AUTH0_AUTH_LINK?: string
}

0 comments on commit a2b55a4

Please sign in to comment.