mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 16:50:43 +00:00
fix(discord): return native status replies directly (#66434)
This commit is contained in:
13
src/plugin-sdk/command-status-runtime.ts
Normal file
13
src/plugin-sdk/command-status-runtime.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { createLazyRuntimeMethodBinder, createLazyRuntimeModule } from "../shared/lazy-runtime.js";
|
||||
|
||||
type CommandStatusRuntime = typeof import("./command-status.runtime.js");
|
||||
|
||||
const loadCommandStatusRuntime = createLazyRuntimeModule(
|
||||
() => import("./command-status.runtime.js"),
|
||||
);
|
||||
const bindCommandStatusRuntime = createLazyRuntimeMethodBinder(loadCommandStatusRuntime);
|
||||
|
||||
export type { ResolveDirectStatusReplyForSessionParams } from "./command-status.runtime.js";
|
||||
|
||||
export const resolveDirectStatusReplyForSession: CommandStatusRuntime["resolveDirectStatusReplyForSession"] =
|
||||
bindCommandStatusRuntime((runtime) => runtime.resolveDirectStatusReplyForSession);
|
||||
125
src/plugin-sdk/command-status.runtime.ts
Normal file
125
src/plugin-sdk/command-status.runtime.ts
Normal file
@@ -0,0 +1,125 @@
|
||||
import { listAgentEntries, resolveSessionAgentId } from "../agents/agent-scope.js";
|
||||
import { resolveDefaultModelForAgent } from "../agents/model-selection.js";
|
||||
import { buildStatusReply } from "../auto-reply/reply/commands-status.js";
|
||||
import type { CommandContext } from "../auto-reply/reply/commands-types.js";
|
||||
import { resolveDefaultModel } from "../auto-reply/reply/directive-handling.defaults.js";
|
||||
import { resolveCurrentDirectiveLevels } from "../auto-reply/reply/directive-handling.levels.js";
|
||||
import { createModelSelectionState } from "../auto-reply/reply/model-selection.js";
|
||||
import type { ReplyPayload } from "../auto-reply/types.js";
|
||||
import type { OpenClawConfig } from "../config/types.openclaw.js";
|
||||
import { loadSessionEntry } from "../gateway/session-utils.js";
|
||||
|
||||
export type ResolveDirectStatusReplyForSessionParams = {
|
||||
cfg: OpenClawConfig;
|
||||
sessionKey: string;
|
||||
channel: string;
|
||||
senderId?: string;
|
||||
senderIsOwner: boolean;
|
||||
isAuthorizedSender: boolean;
|
||||
isGroup: boolean;
|
||||
defaultGroupActivation: () => "always" | "mention";
|
||||
};
|
||||
|
||||
export async function resolveDirectStatusReplyForSession(
|
||||
params: ResolveDirectStatusReplyForSessionParams,
|
||||
): Promise<ReplyPayload | undefined> {
|
||||
const requestedSessionKey = params.sessionKey.trim();
|
||||
if (!requestedSessionKey) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const statusLoaded = loadSessionEntry(requestedSessionKey);
|
||||
const statusCfg = statusLoaded.cfg ?? params.cfg;
|
||||
const statusSessionKey = statusLoaded.canonicalKey;
|
||||
const statusEntry = statusLoaded.entry;
|
||||
const statusAgentId = resolveSessionAgentId({
|
||||
sessionKey: statusSessionKey,
|
||||
config: statusCfg,
|
||||
});
|
||||
const agentCfg = statusCfg.agents?.defaults;
|
||||
const agentEntry = listAgentEntries(statusCfg).find(
|
||||
(entry) => entry.id?.trim().toLowerCase() === statusAgentId,
|
||||
);
|
||||
const statusModel = resolveDefaultModelForAgent({
|
||||
cfg: statusCfg,
|
||||
agentId: statusAgentId,
|
||||
});
|
||||
const { defaultProvider, defaultModel } = resolveDefaultModel({
|
||||
cfg: statusCfg,
|
||||
agentId: statusAgentId,
|
||||
});
|
||||
const selectedProvider =
|
||||
statusEntry?.providerOverride?.trim() ||
|
||||
statusEntry?.modelProvider?.trim() ||
|
||||
statusModel.provider;
|
||||
const selectedModel =
|
||||
statusEntry?.modelOverride?.trim() || statusEntry?.model?.trim() || statusModel.model;
|
||||
const modelState = await createModelSelectionState({
|
||||
cfg: statusCfg,
|
||||
agentId: statusAgentId,
|
||||
agentCfg,
|
||||
sessionEntry: statusEntry,
|
||||
sessionStore: statusLoaded.store,
|
||||
sessionKey: statusSessionKey,
|
||||
parentSessionKey: statusEntry?.parentSessionKey,
|
||||
storePath: statusLoaded.storePath,
|
||||
defaultProvider,
|
||||
defaultModel,
|
||||
provider: selectedProvider,
|
||||
model: selectedModel,
|
||||
hasModelDirective: false,
|
||||
});
|
||||
const {
|
||||
currentThinkLevel,
|
||||
currentFastMode,
|
||||
currentVerboseLevel,
|
||||
currentReasoningLevel,
|
||||
currentElevatedLevel,
|
||||
} = await resolveCurrentDirectiveLevels({
|
||||
sessionEntry: statusEntry,
|
||||
agentEntry,
|
||||
agentCfg,
|
||||
resolveDefaultThinkingLevel: () => modelState.resolveDefaultThinkingLevel(),
|
||||
});
|
||||
let resolvedReasoningLevel = currentReasoningLevel;
|
||||
const hasAgentReasoningDefault =
|
||||
agentEntry?.reasoningDefault !== undefined && agentEntry.reasoningDefault !== null;
|
||||
const reasoningExplicitlySet =
|
||||
(statusEntry?.reasoningLevel !== undefined && statusEntry.reasoningLevel !== null) ||
|
||||
hasAgentReasoningDefault;
|
||||
if (!reasoningExplicitlySet && resolvedReasoningLevel === "off" && currentThinkLevel === "off") {
|
||||
resolvedReasoningLevel = await modelState.resolveDefaultReasoningLevel();
|
||||
}
|
||||
|
||||
const command: CommandContext = {
|
||||
surface: params.channel,
|
||||
channel: params.channel,
|
||||
ownerList: [],
|
||||
senderIsOwner: params.senderIsOwner,
|
||||
isAuthorizedSender: params.isAuthorizedSender,
|
||||
senderId: params.senderId,
|
||||
rawBodyNormalized: "/status",
|
||||
commandBodyNormalized: "/status",
|
||||
};
|
||||
|
||||
return await buildStatusReply({
|
||||
cfg: statusCfg,
|
||||
command,
|
||||
sessionEntry: statusEntry,
|
||||
sessionKey: statusSessionKey,
|
||||
parentSessionKey: statusEntry?.parentSessionKey,
|
||||
sessionScope: statusCfg.session?.scope,
|
||||
storePath: statusLoaded.storePath,
|
||||
provider: selectedProvider,
|
||||
model: selectedModel,
|
||||
contextTokens: statusEntry?.contextTokens ?? 0,
|
||||
resolvedThinkLevel: currentThinkLevel,
|
||||
resolvedFastMode: currentFastMode,
|
||||
resolvedVerboseLevel: currentVerboseLevel ?? "off",
|
||||
resolvedReasoningLevel,
|
||||
resolvedElevatedLevel: currentElevatedLevel,
|
||||
resolveDefaultThinkingLevel: () => modelState.resolveDefaultThinkingLevel(),
|
||||
isGroup: params.isGroup,
|
||||
defaultGroupActivation: params.defaultGroupActivation,
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user