mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 19:24:31 +00:00
refactor(core): extract shared dedup helpers
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { parseFrontmatterBlock } from "../markdown/frontmatter.js";
|
||||
import {
|
||||
applyOpenClawManifestInstallCommonFields,
|
||||
getFrontmatterString,
|
||||
normalizeStringList,
|
||||
parseOpenClawManifestInstallBase,
|
||||
@@ -27,19 +28,12 @@ function parseInstallSpec(input: unknown): HookInstallSpec | undefined {
|
||||
return undefined;
|
||||
}
|
||||
const { raw } = parsed;
|
||||
const spec: HookInstallSpec = {
|
||||
kind: parsed.kind as HookInstallSpec["kind"],
|
||||
};
|
||||
|
||||
if (parsed.id) {
|
||||
spec.id = parsed.id;
|
||||
}
|
||||
if (parsed.label) {
|
||||
spec.label = parsed.label;
|
||||
}
|
||||
if (parsed.bins) {
|
||||
spec.bins = parsed.bins;
|
||||
}
|
||||
const spec = applyOpenClawManifestInstallCommonFields<HookInstallSpec>(
|
||||
{
|
||||
kind: parsed.kind as HookInstallSpec["kind"],
|
||||
},
|
||||
parsed,
|
||||
);
|
||||
if (typeof raw.package === "string") {
|
||||
spec.package = raw.package;
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ export type MessageSentHookEvent = InternalHookEvent & {
|
||||
context: MessageSentHookContext;
|
||||
};
|
||||
|
||||
export type MessageTranscribedHookContext = {
|
||||
type MessageEnrichedBodyHookContext = {
|
||||
/** Sender identifier (e.g., phone number, user ID) */
|
||||
from?: string;
|
||||
/** Recipient identifier */
|
||||
@@ -106,8 +106,6 @@ export type MessageTranscribedHookContext = {
|
||||
body?: string;
|
||||
/** Enriched body shown to the agent, including transcript */
|
||||
bodyForAgent?: string;
|
||||
/** The transcribed text from audio */
|
||||
transcript: string;
|
||||
/** Unix timestamp when the message was received */
|
||||
timestamp?: number;
|
||||
/** Channel identifier (e.g., "telegram", "whatsapp") */
|
||||
@@ -132,45 +130,20 @@ export type MessageTranscribedHookContext = {
|
||||
mediaType?: string;
|
||||
};
|
||||
|
||||
export type MessageTranscribedHookContext = MessageEnrichedBodyHookContext & {
|
||||
/** The transcribed text from audio */
|
||||
transcript: string;
|
||||
};
|
||||
|
||||
export type MessageTranscribedHookEvent = InternalHookEvent & {
|
||||
type: "message";
|
||||
action: "transcribed";
|
||||
context: MessageTranscribedHookContext;
|
||||
};
|
||||
|
||||
export type MessagePreprocessedHookContext = {
|
||||
/** Sender identifier (e.g., phone number, user ID) */
|
||||
from?: string;
|
||||
/** Recipient identifier */
|
||||
to?: string;
|
||||
/** Original raw message body */
|
||||
body?: string;
|
||||
/** Fully enriched body shown to the agent (transcripts, image descriptions, link summaries) */
|
||||
bodyForAgent?: string;
|
||||
export type MessagePreprocessedHookContext = MessageEnrichedBodyHookContext & {
|
||||
/** Transcribed audio text, if the message contained audio */
|
||||
transcript?: string;
|
||||
/** Unix timestamp when the message was received */
|
||||
timestamp?: number;
|
||||
/** Channel identifier (e.g., "telegram", "whatsapp") */
|
||||
channelId: string;
|
||||
/** Conversation/chat ID */
|
||||
conversationId?: string;
|
||||
/** Message ID from the provider */
|
||||
messageId?: string;
|
||||
/** Sender user ID */
|
||||
senderId?: string;
|
||||
/** Sender display name */
|
||||
senderName?: string;
|
||||
/** Sender username */
|
||||
senderUsername?: string;
|
||||
/** Provider name */
|
||||
provider?: string;
|
||||
/** Surface name */
|
||||
surface?: string;
|
||||
/** Path to the media file, if present */
|
||||
mediaPath?: string;
|
||||
/** MIME type of the media, if present */
|
||||
mediaType?: string;
|
||||
/** Whether this message was sent in a group/channel context */
|
||||
isGroup?: boolean;
|
||||
/** Group or channel identifier, if applicable */
|
||||
|
||||
@@ -213,23 +213,10 @@ export function toInternalMessageTranscribedContext(
|
||||
canonical: CanonicalInboundMessageHookContext,
|
||||
cfg: OpenClawConfig,
|
||||
): MessageTranscribedHookContext & { cfg: OpenClawConfig } {
|
||||
const shared = toInternalInboundMessageHookContextBase(canonical);
|
||||
return {
|
||||
from: canonical.from,
|
||||
to: canonical.to,
|
||||
body: canonical.body,
|
||||
bodyForAgent: canonical.bodyForAgent,
|
||||
...shared,
|
||||
transcript: canonical.transcript ?? "",
|
||||
timestamp: canonical.timestamp,
|
||||
channelId: canonical.channelId,
|
||||
conversationId: canonical.conversationId,
|
||||
messageId: canonical.messageId,
|
||||
senderId: canonical.senderId,
|
||||
senderName: canonical.senderName,
|
||||
senderUsername: canonical.senderUsername,
|
||||
provider: canonical.provider,
|
||||
surface: canonical.surface,
|
||||
mediaPath: canonical.mediaPath,
|
||||
mediaType: canonical.mediaType,
|
||||
cfg,
|
||||
};
|
||||
}
|
||||
@@ -238,12 +225,22 @@ export function toInternalMessagePreprocessedContext(
|
||||
canonical: CanonicalInboundMessageHookContext,
|
||||
cfg: OpenClawConfig,
|
||||
): MessagePreprocessedHookContext & { cfg: OpenClawConfig } {
|
||||
const shared = toInternalInboundMessageHookContextBase(canonical);
|
||||
return {
|
||||
...shared,
|
||||
transcript: canonical.transcript,
|
||||
isGroup: canonical.isGroup,
|
||||
groupId: canonical.groupId,
|
||||
cfg,
|
||||
};
|
||||
}
|
||||
|
||||
function toInternalInboundMessageHookContextBase(canonical: CanonicalInboundMessageHookContext) {
|
||||
return {
|
||||
from: canonical.from,
|
||||
to: canonical.to,
|
||||
body: canonical.body,
|
||||
bodyForAgent: canonical.bodyForAgent,
|
||||
transcript: canonical.transcript,
|
||||
timestamp: canonical.timestamp,
|
||||
channelId: canonical.channelId,
|
||||
conversationId: canonical.conversationId,
|
||||
@@ -255,9 +252,6 @@ export function toInternalMessagePreprocessedContext(
|
||||
surface: canonical.surface,
|
||||
mediaPath: canonical.mediaPath,
|
||||
mediaType: canonical.mediaType,
|
||||
isGroup: canonical.isGroup,
|
||||
groupId: canonical.groupId,
|
||||
cfg,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user