feat: surface system presence for the agent
This commit is contained in:
@@ -625,9 +625,10 @@ export async function runCommandReply(
|
||||
toolCallId?: string;
|
||||
tool_call_id?: string;
|
||||
};
|
||||
const role = msg.role;
|
||||
const role =
|
||||
typeof msg.role === "string" ? msg.role.toLowerCase() : "";
|
||||
const isToolResult =
|
||||
role === "toolResult" || role === "tool_result";
|
||||
role === "toolresult" || role === "tool_result";
|
||||
if (!isToolResult || !Array.isArray(msg.content)) {
|
||||
// not a tool result message we care about
|
||||
} else {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import crypto from "node:crypto";
|
||||
|
||||
import { lookupContextTokens } from "../agents/context.js";
|
||||
import { DEFAULT_CONTEXT_TOKENS, DEFAULT_MODEL } from "../agents/defaults.js";
|
||||
import { resolveBundledPiBinary } from "../agents/pi-path.js";
|
||||
@@ -13,7 +14,9 @@ import {
|
||||
saveSessionStore,
|
||||
} from "../config/sessions.js";
|
||||
import { isVerbose, logVerbose } from "../globals.js";
|
||||
import { buildProviderSummary } from "../infra/provider-summary.js";
|
||||
import { triggerWarelayRestart } from "../infra/restart.js";
|
||||
import { drainSystemEvents } from "../infra/system-events.js";
|
||||
import { runCommandWithTimeout } from "../process/exec.js";
|
||||
import { defaultRuntime } from "../runtime.js";
|
||||
import { resolveHeartbeatSeconds } from "../web/reconnect.js";
|
||||
@@ -605,6 +608,26 @@ export async function getReplyFromConfig(
|
||||
ABORT_MEMORY.set(abortKey, false);
|
||||
}
|
||||
}
|
||||
|
||||
// Prepend queued system events and (for new main sessions) a provider snapshot.
|
||||
const isGroupSession =
|
||||
typeof ctx.From === "string" &&
|
||||
(ctx.From.includes("@g.us") || ctx.From.startsWith("group:"));
|
||||
const isMainSession =
|
||||
!isGroupSession && sessionKey === (sessionCfg?.mainKey ?? "main");
|
||||
if (isMainSession) {
|
||||
const systemLines: string[] = [];
|
||||
const queued = drainSystemEvents();
|
||||
systemLines.push(...queued);
|
||||
if (isNewSession) {
|
||||
const summary = await buildProviderSummary(cfg);
|
||||
if (summary) systemLines.unshift(summary);
|
||||
}
|
||||
if (systemLines.length > 0) {
|
||||
const block = systemLines.map((l) => `System: ${l}`).join("\n");
|
||||
prefixedBodyBase = `${block}\n\n${prefixedBodyBase}`;
|
||||
}
|
||||
}
|
||||
if (
|
||||
sessionCfg &&
|
||||
sendSystemOnce &&
|
||||
|
||||
Reference in New Issue
Block a user