Skip to content

Commit 4721f0d

Browse files
committed
fix(line): pace block replies with the agent's humanDelay
1 parent 32edafc commit 4721f0d

2 files changed

Lines changed: 68 additions & 2 deletions

File tree

‎extensions/line/src/monitor.lifecycle.test.ts‎

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,8 @@ describe("monitorLineProvider lifecycle", () => {
410410
accountId: "default",
411411
turn: { record: {} },
412412
} as unknown as Parameters<typeof onMessage>[0],
413-
{} as Parameters<typeof onMessage>[1],
413+
// Admission always hands the turn its live config; an empty one is unreachable.
414+
{ cfg: {} } as Parameters<typeof onMessage>[1],
414415
);
415416

416417
const prepared = resolvedTurn?.delivery.preparePayload?.({
@@ -434,6 +435,64 @@ describe("monitorLineProvider lifecycle", () => {
434435
}
435436
});
436437

438+
it("paces block replies with the humanDelay the turn's own config carries", async () => {
439+
// humanDelay lives on the agent, but only the dispatcher can act on it, so a
440+
// turn that never forwards it paces every block reply at zero.
441+
const { setLineRuntime } = await import("./runtime.js");
442+
type ResolvedTurn = { dispatcherOptions?: { humanDelay?: unknown } };
443+
let resolvedTurn: ResolvedTurn | undefined;
444+
const runTurn = async (params: {
445+
adapter: { resolveTurn: () => ResolvedTurn };
446+
}): Promise<{ dispatched: false }> => {
447+
resolvedTurn = params.adapter.resolveTurn();
448+
return { dispatched: false };
449+
};
450+
setLineRuntime({
451+
channel: { inbound: { run: runTurn } },
452+
} as unknown as Parameters<typeof setLineRuntime>[0]);
453+
const monitor = await monitorLineProvider({
454+
channelAccessToken: "token",
455+
channelSecret: "secret", // pragma: allowlist secret
456+
config: {} as OpenClawConfig,
457+
runtime: {} as RuntimeEnv,
458+
});
459+
const onMessage = createLineBotMock.mock.calls[0]?.[0]?.onMessage;
460+
if (!onMessage) {
461+
throw new Error("expected the LINE bot to receive an inbound message handler");
462+
}
463+
464+
try {
465+
await onMessage(
466+
{
467+
ctxPayload: { From: "line:U1", MessageSid: "m1", RawBody: "hi" },
468+
replyToken: "reply-token",
469+
route: { accountId: "default", agentId: "ops", sessionKey: "line:U1" },
470+
isGroup: false,
471+
accountId: "default",
472+
turn: { record: {} },
473+
} as unknown as Parameters<typeof onMessage>[0],
474+
{
475+
// The per-agent entry wins, so a turn reading only the defaults would
476+
// pace at the wrong interval rather than not at all.
477+
cfg: {
478+
agents: {
479+
defaults: { humanDelay: { mode: "natural" } },
480+
entries: { ops: { humanDelay: { mode: "custom", minMs: 3_000, maxMs: 4_000 } } },
481+
},
482+
},
483+
} as Parameters<typeof onMessage>[1],
484+
);
485+
486+
expect(resolvedTurn?.dispatcherOptions?.humanDelay).toEqual({
487+
mode: "custom",
488+
minMs: 3_000,
489+
maxMs: 4_000,
490+
});
491+
} finally {
492+
await monitor.stop();
493+
}
494+
});
495+
437496
it("carries a group's skill scope into the turn that answers it", async () => {
438497
// The scope is configured per group but enforced per turn: it only applies
439498
// if the reply options reaching the agent carry it.
@@ -470,7 +529,8 @@ describe("monitorLineProvider lifecycle", () => {
470529
skillFilter: ["triage"],
471530
turn: { record: {} },
472531
} as unknown as Parameters<typeof onMessage>[0],
473-
{} as Parameters<typeof onMessage>[1],
532+
// Admission always hands the turn its live config; an empty one is unreachable.
533+
{ cfg: {} } as Parameters<typeof onMessage>[1],
474534
);
475535

476536
expect(resolvedTurn?.replyOptions?.skillFilter).toEqual(["triage"]);

‎extensions/line/src/monitor.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Line plugin module implements monitor behavior.
22
import type { webhook } from "@line/bot-sdk";
3+
import { resolveHumanDelayConfig } from "openclaw/plugin-sdk/agent-runtime";
34
import type { ChannelAccountSnapshot } from "openclaw/plugin-sdk/channel-contract";
45
import { hasFinalInboundReplyDispatch } from "openclaw/plugin-sdk/channel-inbound";
56
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-contracts";
@@ -225,6 +226,11 @@ export async function monitorLineProvider(
225226
ctxPayload,
226227
record: ctx.turn.record,
227228
replyPipeline: {},
229+
// Block replies are paced by the agent's own humanDelay; nothing else
230+
// reads it, so a turn that never forwards it silently paces at zero.
231+
dispatcherOptions: {
232+
humanDelay: resolveHumanDelayConfig(turnConfig, route.agentId),
233+
},
228234
...(replyOptions ? { replyOptions } : {}),
229235
delivery: {
230236
// Core renders presentations inside the outbound send pipeline only,

0 commit comments

Comments
 (0)