refactor: centralize task runtime contracts (#199)
This commit is contained in:
@@ -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: {
|
||||
|
||||
Reference in New Issue
Block a user