38 lines
1.2 KiB
TypeScript
38 lines
1.2 KiB
TypeScript
import {
|
|
extractDiscordChannelId,
|
|
extractDiscordChannelIdFromConversationMetadata,
|
|
extractDiscordChannelIdFromSessionKey,
|
|
extractUntrustedConversationInfo,
|
|
} from "./channel-resolver.js";
|
|
|
|
export type DerivedDecisionInput = {
|
|
channel: string;
|
|
channelId?: string;
|
|
senderId?: string;
|
|
content: string;
|
|
conv: Record<string, unknown>;
|
|
};
|
|
|
|
export function deriveDecisionInputFromPrompt(params: {
|
|
prompt: string;
|
|
messageProvider?: string;
|
|
sessionKey?: string;
|
|
ctx?: Record<string, unknown>;
|
|
event?: Record<string, unknown>;
|
|
}): DerivedDecisionInput {
|
|
const { prompt, messageProvider, sessionKey, ctx, event } = params;
|
|
const conv = extractUntrustedConversationInfo(prompt) || {};
|
|
const channel = (messageProvider || "").toLowerCase();
|
|
|
|
let channelId = extractDiscordChannelId(ctx || {}, event);
|
|
if (!channelId) channelId = extractDiscordChannelIdFromSessionKey(sessionKey);
|
|
if (!channelId) channelId = extractDiscordChannelIdFromConversationMetadata(conv);
|
|
|
|
const senderId =
|
|
(typeof conv.sender_id === "string" && conv.sender_id) ||
|
|
(typeof conv.sender === "string" && conv.sender) ||
|
|
undefined;
|
|
|
|
return { channel, channelId, senderId, content: prompt, conv };
|
|
}
|