Allow each agent to define its own session maintenance settings (mode, pruneAfter, maxEntries, rotateBytes, maxDiskBytes, etc.) that override the global session.maintenance config. - Extract SessionMaintenanceSchema to shared zod-schema.maintenance.ts - Add maintenance field to AgentConfig and AgentEntrySchema - Merge per-agent overrides over global config in resolveMaintenanceConfig - Pass agentId through sessions-cleanup and store save paths - Add comprehensive tests for per-agent config resolution
149 lines
5.0 KiB
TypeScript
149 lines
5.0 KiB
TypeScript
import { z } from "zod";
|
|
import { ElevatedAllowFromSchema } from "./zod-schema.agent-runtime.js";
|
|
import { createAllowDenyChannelRulesSchema } from "./zod-schema.allowdeny.js";
|
|
import {
|
|
GroupChatSchema,
|
|
InboundDebounceSchema,
|
|
NativeCommandsSettingSchema,
|
|
QueueSchema,
|
|
TypingModeSchema,
|
|
TtsConfigSchema,
|
|
} from "./zod-schema.core.js";
|
|
import { SessionMaintenanceSchema } from "./zod-schema.maintenance.js";
|
|
import { sensitive } from "./zod-schema.sensitive.js";
|
|
|
|
export { SessionMaintenanceSchema };
|
|
|
|
const SessionResetConfigSchema = z
|
|
.object({
|
|
mode: z.union([z.literal("daily"), z.literal("idle")]).optional(),
|
|
atHour: z.number().int().min(0).max(23).optional(),
|
|
idleMinutes: z.number().int().positive().optional(),
|
|
})
|
|
.strict();
|
|
|
|
export const SessionSendPolicySchema = createAllowDenyChannelRulesSchema();
|
|
|
|
export const SessionSchema = z
|
|
.object({
|
|
scope: z.union([z.literal("per-sender"), z.literal("global")]).optional(),
|
|
dmScope: z
|
|
.union([
|
|
z.literal("main"),
|
|
z.literal("per-peer"),
|
|
z.literal("per-channel-peer"),
|
|
z.literal("per-account-channel-peer"),
|
|
])
|
|
.optional(),
|
|
identityLinks: z.record(z.string(), z.array(z.string())).optional(),
|
|
resetTriggers: z.array(z.string()).optional(),
|
|
idleMinutes: z.number().int().positive().optional(),
|
|
reset: SessionResetConfigSchema.optional(),
|
|
resetByType: z
|
|
.object({
|
|
direct: SessionResetConfigSchema.optional(),
|
|
/** @deprecated Use `direct` instead. Kept for backward compatibility. */
|
|
dm: SessionResetConfigSchema.optional(),
|
|
group: SessionResetConfigSchema.optional(),
|
|
thread: SessionResetConfigSchema.optional(),
|
|
})
|
|
.strict()
|
|
.optional(),
|
|
resetByChannel: z.record(z.string(), SessionResetConfigSchema).optional(),
|
|
store: z.string().optional(),
|
|
typingIntervalSeconds: z.number().int().positive().optional(),
|
|
typingMode: TypingModeSchema.optional(),
|
|
parentForkMaxTokens: z.number().int().nonnegative().optional(),
|
|
mainKey: z.string().optional(),
|
|
sendPolicy: SessionSendPolicySchema.optional(),
|
|
agentToAgent: z
|
|
.object({
|
|
maxPingPongTurns: z.number().int().min(0).max(5).optional(),
|
|
})
|
|
.strict()
|
|
.optional(),
|
|
threadBindings: z
|
|
.object({
|
|
enabled: z.boolean().optional(),
|
|
idleHours: z.number().nonnegative().optional(),
|
|
maxAgeHours: z.number().nonnegative().optional(),
|
|
})
|
|
.strict()
|
|
.optional(),
|
|
maintenance: SessionMaintenanceSchema,
|
|
})
|
|
.strict()
|
|
.optional();
|
|
|
|
export const MessagesSchema = z
|
|
.object({
|
|
messagePrefix: z.string().optional(),
|
|
responsePrefix: z.string().optional(),
|
|
groupChat: GroupChatSchema,
|
|
queue: QueueSchema,
|
|
inbound: InboundDebounceSchema,
|
|
ackReaction: z.string().optional(),
|
|
ackReactionScope: z
|
|
.enum(["group-mentions", "group-all", "direct", "all", "off", "none"])
|
|
.optional(),
|
|
removeAckAfterReply: z.boolean().optional(),
|
|
statusReactions: z
|
|
.object({
|
|
enabled: z.boolean().optional(),
|
|
emojis: z
|
|
.object({
|
|
thinking: z.string().optional(),
|
|
tool: z.string().optional(),
|
|
coding: z.string().optional(),
|
|
web: z.string().optional(),
|
|
done: z.string().optional(),
|
|
error: z.string().optional(),
|
|
stallSoft: z.string().optional(),
|
|
stallHard: z.string().optional(),
|
|
compacting: z.string().optional(),
|
|
})
|
|
.strict()
|
|
.optional(),
|
|
timing: z
|
|
.object({
|
|
debounceMs: z.number().int().min(0).optional(),
|
|
stallSoftMs: z.number().int().min(0).optional(),
|
|
stallHardMs: z.number().int().min(0).optional(),
|
|
doneHoldMs: z.number().int().min(0).optional(),
|
|
errorHoldMs: z.number().int().min(0).optional(),
|
|
})
|
|
.strict()
|
|
.optional(),
|
|
})
|
|
.strict()
|
|
.optional(),
|
|
suppressToolErrors: z.boolean().optional(),
|
|
tts: TtsConfigSchema,
|
|
})
|
|
.strict()
|
|
.optional();
|
|
|
|
export const CommandsSchema = z
|
|
.object({
|
|
native: NativeCommandsSettingSchema.optional().default("auto"),
|
|
nativeSkills: NativeCommandsSettingSchema.optional().default("auto"),
|
|
text: z.boolean().optional(),
|
|
bash: z.boolean().optional(),
|
|
bashForegroundMs: z.number().int().min(0).max(30_000).optional(),
|
|
config: z.boolean().optional(),
|
|
mcp: z.boolean().optional(),
|
|
plugins: z.boolean().optional(),
|
|
debug: z.boolean().optional(),
|
|
restart: z.boolean().optional().default(true),
|
|
useAccessGroups: z.boolean().optional(),
|
|
ownerAllowFrom: z.array(z.union([z.string(), z.number()])).optional(),
|
|
ownerDisplay: z.enum(["raw", "hash"]).optional().default("raw"),
|
|
ownerDisplaySecret: z.string().optional().register(sensitive),
|
|
allowFrom: ElevatedAllowFromSchema.optional(),
|
|
})
|
|
.strict()
|
|
.optional()
|
|
.default(
|
|
() => ({ native: "auto", nativeSkills: "auto", restart: true, ownerDisplay: "raw" }) as const,
|
|
);
|