Files
Genarrative/src/services/creation-agent/creationAgentChat.ts

64 lines
1.7 KiB
TypeScript

export const CREATION_AGENT_SUMMARY_ACTION_KEY = 'summarize';
export const CREATION_AGENT_QUICK_FILL_ACTION_KEY = 'quickFill';
export const CREATION_AGENT_SUMMARY_ACTION_LABEL = '总结当前设定';
export const CREATION_AGENT_QUICK_FILL_ACTION_LABEL = '补充剩余设定';
export const CREATION_AGENT_QUICK_FILL_MESSAGE = '请补充剩余设定。';
type CreationAgentChatQuickAction = {
key: string;
label: string;
minTurn?: number;
};
type CreationAgentChatMessageBase = {
clientMessageId: string;
text: string;
quickFillRequested?: boolean;
};
export function createCreationAgentChatQuickActions(): CreationAgentChatQuickAction[] {
return [
{
key: CREATION_AGENT_SUMMARY_ACTION_KEY,
label: CREATION_AGENT_SUMMARY_ACTION_LABEL,
},
{
key: CREATION_AGENT_QUICK_FILL_ACTION_KEY,
label: CREATION_AGENT_QUICK_FILL_ACTION_LABEL,
minTurn: 2,
},
];
}
export function resolveCreationAgentQuickActionMessage(
actionKey: string,
summaryMessage: string,
) {
const quickFillRequested = actionKey === CREATION_AGENT_QUICK_FILL_ACTION_KEY;
return {
text: quickFillRequested ? CREATION_AGENT_QUICK_FILL_MESSAGE : summaryMessage,
quickFillRequested,
};
}
export function buildCreationAgentChatMessage<TExtraPayload extends object = Record<string, never>>({
clientMessageId,
text,
quickFillRequested = false,
extraPayload,
}: {
clientMessageId: string;
text: string;
quickFillRequested?: boolean;
extraPayload?: TExtraPayload;
}): CreationAgentChatMessageBase & TExtraPayload {
return {
...(extraPayload ?? ({} as TExtraPayload)),
clientMessageId,
text,
quickFillRequested,
};
}