mirror of
https://github.com/rowboatlabs/rowboat.git
synced 2026-04-30 02:46:25 +02:00
add to settings
This commit is contained in:
parent
98080cc604
commit
36f700cc77
7 changed files with 148 additions and 242 deletions
|
|
@ -14,6 +14,7 @@ import { FSGranolaConfigRepo, IGranolaConfigRepo } from "../knowledge/granola/re
|
|||
import { IAbortRegistry, InMemoryAbortRegistry } from "../runs/abort-registry.js";
|
||||
import { FSAgentScheduleRepo, IAgentScheduleRepo } from "../agent-schedule/repo.js";
|
||||
import { FSAgentScheduleStateRepo, IAgentScheduleStateRepo } from "../agent-schedule/state-repo.js";
|
||||
import { FSSlackConfigRepo, ISlackConfigRepo } from "../slack/repo.js";
|
||||
|
||||
const container = createContainer({
|
||||
injectionMode: InjectionMode.PROXY,
|
||||
|
|
@ -37,6 +38,7 @@ container.register({
|
|||
granolaConfigRepo: asClass<IGranolaConfigRepo>(FSGranolaConfigRepo).singleton(),
|
||||
agentScheduleRepo: asClass<IAgentScheduleRepo>(FSAgentScheduleRepo).singleton(),
|
||||
agentScheduleStateRepo: asClass<IAgentScheduleStateRepo>(FSAgentScheduleStateRepo).singleton(),
|
||||
slackConfigRepo: asClass<ISlackConfigRepo>(FSSlackConfigRepo).singleton(),
|
||||
});
|
||||
|
||||
export default container;
|
||||
41
apps/x/packages/core/src/slack/repo.ts
Normal file
41
apps/x/packages/core/src/slack/repo.ts
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
import fs from 'fs/promises';
|
||||
import path from 'path';
|
||||
import { WorkDir } from '../config/config.js';
|
||||
import { SlackConfig } from './types.js';
|
||||
|
||||
export interface ISlackConfigRepo {
|
||||
getConfig(): Promise<SlackConfig>;
|
||||
setConfig(config: SlackConfig): Promise<void>;
|
||||
}
|
||||
|
||||
export class FSSlackConfigRepo implements ISlackConfigRepo {
|
||||
private readonly configPath = path.join(WorkDir, 'config', 'slack.json');
|
||||
private readonly defaultConfig: SlackConfig = { enabled: false };
|
||||
|
||||
constructor() {
|
||||
this.ensureConfigFile();
|
||||
}
|
||||
|
||||
private async ensureConfigFile(): Promise<void> {
|
||||
try {
|
||||
await fs.access(this.configPath);
|
||||
} catch {
|
||||
await fs.writeFile(this.configPath, JSON.stringify(this.defaultConfig, null, 2));
|
||||
}
|
||||
}
|
||||
|
||||
async getConfig(): Promise<SlackConfig> {
|
||||
try {
|
||||
const content = await fs.readFile(this.configPath, 'utf8');
|
||||
const parsed = JSON.parse(content);
|
||||
return SlackConfig.parse(parsed);
|
||||
} catch {
|
||||
return this.defaultConfig;
|
||||
}
|
||||
}
|
||||
|
||||
async setConfig(config: SlackConfig): Promise<void> {
|
||||
const validated = SlackConfig.parse(config);
|
||||
await fs.writeFile(this.configPath, JSON.stringify(validated, null, 2));
|
||||
}
|
||||
}
|
||||
6
apps/x/packages/core/src/slack/types.ts
Normal file
6
apps/x/packages/core/src/slack/types.ts
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
import z from "zod";
|
||||
|
||||
export const SlackConfig = z.object({
|
||||
enabled: z.boolean(),
|
||||
});
|
||||
export type SlackConfig = z.infer<typeof SlackConfig>;
|
||||
Loading…
Add table
Add a link
Reference in a new issue