Skip to content

Commit 4c0a8ce

Browse files
committed
refactor(kiloclaw): share morning briefing delivery constants
Extract delivery channel/status/reason enums into a shared module and reuse them in gateway response schemas and plugin delivery utilities to prevent drift.
1 parent fef3113 commit 4c0a8ce

3 files changed

Lines changed: 26 additions & 20 deletions

File tree

services/kiloclaw/plugins/kiloclaw-morning-briefing/src/delivery-utils.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import { formatBriefingMarkdownForMessage } from './briefing-utils';
22
import { type CommandCapableRuntime, isTimeoutExecutionError, runCommand } from './command-utils';
3+
import {
4+
MORNING_BRIEFING_DELIVERY_CHANNELS,
5+
MORNING_BRIEFING_DELIVERY_REASONS,
6+
MORNING_BRIEFING_DELIVERY_STATUSES,
7+
} from '../../../src/durable-objects/morning-briefing-delivery-constants';
38

4-
export const DELIVERY_CHANNELS = ['telegram', 'discord', 'slack'] as const;
9+
export const DELIVERY_CHANNELS = MORNING_BRIEFING_DELIVERY_CHANNELS;
510
export type DeliveryChannel = (typeof DELIVERY_CHANNELS)[number];
611

7-
export const DELIVERY_STATUSES = ['sent', 'skipped', 'failed'] as const;
12+
export const DELIVERY_STATUSES = MORNING_BRIEFING_DELIVERY_STATUSES;
813
export type DeliveryStatus = (typeof DELIVERY_STATUSES)[number];
914

10-
export const DELIVERY_REASONS = [
11-
'missing_target',
12-
'ambiguous_target',
13-
'send_failed',
14-
'config_unavailable',
15-
] as const;
15+
export const DELIVERY_REASONS = MORNING_BRIEFING_DELIVERY_REASONS;
1616
export type DeliveryReason = (typeof DELIVERY_REASONS)[number];
1717

1818
export type BriefingDeliveryResult = {

services/kiloclaw/src/durable-objects/gateway-controller-types.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
import { z, type ZodType } from 'zod';
2+
import {
3+
MORNING_BRIEFING_DELIVERY_CHANNELS,
4+
MORNING_BRIEFING_DELIVERY_REASONS,
5+
MORNING_BRIEFING_DELIVERY_STATUSES,
6+
} from './morning-briefing-delivery-constants';
27

38
export type GatewayProcessStatus = {
49
state: 'stopped' | 'starting' | 'running' | 'stopping' | 'crashed' | 'shutting_down';
@@ -104,21 +109,12 @@ const MorningBriefingSourceReadinessSchema = z.object({
104109
summary: z.string(),
105110
});
106111

107-
const DELIVERY_CHANNELS = ['telegram', 'discord', 'slack'] as const;
108-
const DELIVERY_STATUSES = ['sent', 'skipped', 'failed'] as const;
109-
const DELIVERY_REASONS = [
110-
'missing_target',
111-
'ambiguous_target',
112-
'send_failed',
113-
'config_unavailable',
114-
] as const;
115-
116112
const MorningBriefingDeliverySchema = z.object({
117-
channel: z.enum(DELIVERY_CHANNELS),
118-
status: z.enum(DELIVERY_STATUSES),
113+
channel: z.enum(MORNING_BRIEFING_DELIVERY_CHANNELS),
114+
status: z.enum(MORNING_BRIEFING_DELIVERY_STATUSES),
119115
target: z.string().optional(),
120116
accountId: z.string().optional(),
121-
reason: z.enum(DELIVERY_REASONS).optional(),
117+
reason: z.enum(MORNING_BRIEFING_DELIVERY_REASONS).optional(),
122118
error: z.string().optional(),
123119
});
124120

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export const MORNING_BRIEFING_DELIVERY_CHANNELS = ['telegram', 'discord', 'slack'] as const;
2+
3+
export const MORNING_BRIEFING_DELIVERY_STATUSES = ['sent', 'skipped', 'failed'] as const;
4+
5+
export const MORNING_BRIEFING_DELIVERY_REASONS = [
6+
'missing_target',
7+
'ambiguous_target',
8+
'send_failed',
9+
'config_unavailable',
10+
] as const;

0 commit comments

Comments
 (0)