mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-04 18:00:22 +00:00
feat(plugins): expose llm input/output hook payloads (openclaw#16724) thanks @SecondThread
Verified: - pnpm build - pnpm check - pnpm test:macmini Co-authored-by: SecondThread <18317476+SecondThread@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
This commit is contained in:
@@ -954,6 +954,32 @@ export async function runEmbeddedAttempt(
|
||||
);
|
||||
}
|
||||
|
||||
if (hookRunner?.hasHooks("llm_input")) {
|
||||
hookRunner
|
||||
.runLlmInput(
|
||||
{
|
||||
runId: params.runId,
|
||||
sessionId: params.sessionId,
|
||||
provider: params.provider,
|
||||
model: params.modelId,
|
||||
systemPrompt: systemPromptText,
|
||||
prompt: effectivePrompt,
|
||||
historyMessages: activeSession.messages,
|
||||
imagesCount: imageResult.images.length,
|
||||
},
|
||||
{
|
||||
agentId: hookAgentId,
|
||||
sessionKey: params.sessionKey,
|
||||
sessionId: params.sessionId,
|
||||
workspaceDir: params.workspaceDir,
|
||||
messageProvider: params.messageProvider ?? undefined,
|
||||
},
|
||||
)
|
||||
.catch((err) => {
|
||||
log.warn(`llm_input hook failed: ${String(err)}`);
|
||||
});
|
||||
}
|
||||
|
||||
// Only pass images option if there are actually images to pass
|
||||
// This avoids potential issues with models that don't expect the images parameter
|
||||
if (imageResult.images.length > 0) {
|
||||
@@ -1103,6 +1129,31 @@ export async function runEmbeddedAttempt(
|
||||
)
|
||||
.map((entry) => ({ toolName: entry.toolName, meta: entry.meta }));
|
||||
|
||||
if (hookRunner?.hasHooks("llm_output")) {
|
||||
hookRunner
|
||||
.runLlmOutput(
|
||||
{
|
||||
runId: params.runId,
|
||||
sessionId: params.sessionId,
|
||||
provider: params.provider,
|
||||
model: params.modelId,
|
||||
assistantTexts,
|
||||
lastAssistant,
|
||||
usage: getUsageTotals(),
|
||||
},
|
||||
{
|
||||
agentId: hookAgentId,
|
||||
sessionKey: params.sessionKey,
|
||||
sessionId: params.sessionId,
|
||||
workspaceDir: params.workspaceDir,
|
||||
messageProvider: params.messageProvider ?? undefined,
|
||||
},
|
||||
)
|
||||
.catch((err) => {
|
||||
log.warn(`llm_output hook failed: ${String(err)}`);
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
aborted,
|
||||
timedOut,
|
||||
|
||||
Reference in New Issue
Block a user