refactor: centralize task runtime contracts (#199)

This commit is contained in:
Eyejoker
2026-05-30 01:56:41 +09:00
committed by GitHub
parent 1531482363
commit 37b57b20bb
14 changed files with 152 additions and 77 deletions

View File

@@ -1,19 +1,19 @@
import type { MessageSourceKind } from './types.js';
import {
DEFAULT_MESSAGE_SOURCE_KIND,
MESSAGE_SOURCE_KINDS,
type MessageSourceKind,
} from './types.js';
const MESSAGE_SOURCE_KINDS = new Set<MessageSourceKind>([
'human',
'bot',
'trusted_external_bot',
'ipc_injected_human',
'ipc_injected_bot',
]);
const MESSAGE_SOURCE_KIND_SET = new Set<MessageSourceKind>(
MESSAGE_SOURCE_KINDS,
);
export function normalizeMessageSourceKind(
value: unknown,
fallback: MessageSourceKind = 'human',
fallback: MessageSourceKind = DEFAULT_MESSAGE_SOURCE_KIND,
): MessageSourceKind {
return typeof value === 'string' &&
MESSAGE_SOURCE_KINDS.has(value as MessageSourceKind)
MESSAGE_SOURCE_KIND_SET.has(value as MessageSourceKind)
? (value as MessageSourceKind)
: fallback;
}
@@ -25,7 +25,7 @@ export function isBotMessageSourceKind(kind: MessageSourceKind): boolean {
export function inferMessageSourceKindFromBotFlag(
isBotMessage: boolean | number | null | undefined,
): MessageSourceKind {
return isBotMessage ? 'bot' : 'human';
return isBotMessage ? 'bot' : DEFAULT_MESSAGE_SOURCE_KIND;
}
export function resolveInjectedMessageSourceKind(args: {