add to settings

This commit is contained in:
Arjun 2026-02-25 16:07:12 +05:30
parent 98080cc604
commit 36f700cc77
7 changed files with 148 additions and 242 deletions

View file

@ -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;

View 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));
}
}

View file

@ -0,0 +1,6 @@
import z from "zod";
export const SlackConfig = z.object({
enabled: z.boolean(),
});
export type SlackConfig = z.infer<typeof SlackConfig>;