Skip to content

Commit 1e6b088

Browse files
committed
more app model refactors, more cleanups
1 parent 71ec827 commit 1e6b088

File tree

16 files changed

+77
-48
lines changed

16 files changed

+77
-48
lines changed

service/src/AppModelManager.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export class AppModelManager {
5050
)
5151
}
5252

53-
public updateAppModelState(appModelId: string, state: AppModel['state']) {
53+
private updateAppModelState(appModelId: string, state: AppModel['state']) {
5454
const appModel = this.appModels.get(appModelId)
5555
if (!appModel) {
5656
const error = new Error(`App model with id ${appModelId} is not registered`)
@@ -64,11 +64,11 @@ export class AppModelManager {
6464
})
6565
throw error
6666
}
67-
const oldStateType = appModel.state.type
67+
const oldState = appModel.state
6868
appModel.state = state
6969
void this.logger.information({
70-
message: `App model state for ${appModel.manifest.name} updated from "${oldStateType}" to "${state.type}"`,
71-
data: { appModel, state },
70+
message: `App model state for ${appModel.manifest.name} updated from "${oldState.type}" to "${state.type}"`,
71+
data: { appModel, oldState, state },
7272
})
7373
}
7474
}

service/src/ai/ai-app-model.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { Injectable, type Injector } from '@furystack/inject'
2+
import type { AppState } from 'common'
3+
import type { InternalAppModel } from '../AppModelManager.js'
4+
import { AiManifest } from './ai-manifest.js'
5+
import { setupAiRestApi } from './setup-ai-rest-api.js'
6+
import { setupAi } from './setup-ai.js'
7+
8+
@Injectable({ lifetime: 'singleton' })
9+
export class AiAppModel implements InternalAppModel {
10+
manifest = AiManifest
11+
state: AppState = {
12+
type: 'initializing',
13+
}
14+
15+
declare private injector: Injector
16+
17+
public async setup() {
18+
await Promise.all([setupAi(this.injector), setupAiRestApi(this.injector)])
19+
}
20+
}

service/src/ai/ai-manifest.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import type { AppModelManifest } from 'common'
2+
3+
export const AiManifest: AppModelManifest = {
4+
id: '@pi-rat/ai',
5+
name: 'AI',
6+
description: 'AI capabilities with Ollama',
7+
apiRedirects: {},
8+
integrations: {},
9+
requiredPermissions: {},
10+
version: '0.1.0',
11+
}

service/src/ai/ollama-client-service.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ export class OllamaClientService {
7474
}
7575

7676
public async init(injector: Injector) {
77-
await this.logger.verbose({ message: '🤖 Initializing Ollama Service' })
7877
const config = await this.getOllamaConfig(injector)
7978
if (!config) {
8079
this.config = undefined

service/src/ai/setup-ai-store.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ class AiChatMessageModel extends Model<AiChatMessage, AiChatMessage> implements
3232

3333
export const setupAiStore = async (injector: Injector) => {
3434
const logger = getLogger(injector).withScope('AI Store Setup')
35-
await logger.verbose({ message: '🤖 Initializing AI Store' })
3635

3736
const dbOptions = getDefaultDbSettings('ai.sqlite', logger)
3837

service/src/ai/setup-ai.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { setupAiStore } from './setup-ai-store.js'
1010

1111
export const setupAi = async (injector: Injector) => {
1212
const logger = getLogger(injector).withScope('AI Setup')
13-
await logger.verbose({ message: '🤖 Initializing AI Services' })
1413
const clientService = injector.getInstance(OllamaClientService)
1514

1615
const storeManager = getStoreManager(injector)

service/src/dashboards/setup-dashboards.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ export const setupDashboards = async (injector: Injector) => {
6767
)
6868
},
6969
})
70-
await logger.verbose({ message: 'Setting up repository...' })
7170
getRepository(injector).createDataSet(Dashboard, 'id', {
7271
authorizeAdd: withRole('admin'),
7372
authorizeGet: withRole('admin'),

service/src/drives/drives-manifest.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import type { AppModelManifest } from 'common'
22

33
export const DrivesManifest: AppModelManifest = {
4-
id: 'Drives',
5-
name: '@pi-rat/drives',
4+
name: 'Drives',
5+
id: '@pi-rat/drives',
66
description: 'Provides access to file system drives.',
77
version: '0.0.1',
88
apiRedirects: {},

service/src/drives/setup-drives.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ export const setupDrives = async (injector: Injector) => {
6262
},
6363
})
6464

65-
await logger.verbose({ message: 'Setting up repository...' })
6665
getRepository(injector).createDataSet(Drive, 'letter', {
6766
authorizeGet: withRole('admin'),
6867
authorizeUpdate: async (args) => {
@@ -106,6 +105,5 @@ export const setupDrives = async (injector: Injector) => {
106105
},
107106
})
108107

109-
await logger.verbose({ message: '💾 Setting up FileWatchers...' })
110108
await useFileWatchers(injector)
111109
}

service/src/identity/setup-identity-store.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ export const setupIdentity = async (injector: Injector) => {
125125
},
126126
})
127127

128-
await logger.verbose({ message: 'Setting up repository...' })
129128
getRepository(injector).createDataSet(User, 'username', {
130129
authorizeAdd: withRole('admin'),
131130
authorizeGet: withRole('admin'),

0 commit comments

Comments
 (0)